Wechat.php
1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<?php
namespace app\server;
use EasyWeChat\Factory;
/**
* easyWechat 插件
使用
$app = app\server\Wechat::getInstance()->initWechat();
$app 为 easyWechat的对象 根据官网接口调用或二开
*/
class Wechat {
static public $app = null;
static private $appid= '';
static private $appsecret= '';
static private $config= [];
static private $inc = null;
function __construct(){
//self::$appid= config("site.appid");
//self::$appsecret= config("site.appsecret");
//测试公众号
self::$appid= 'wxb9b259e7a17bda27';
self::$appsecret= '2af20d18bf969d8a26691dfd54cc6380';
//easyWechat配置
self::$config = [
'app_id' => self::$appid,
'secret' => self::$appsecret,
// 指定 API 调用返回结果的类型:array(default)/collection/object/raw/自定义类名
'response_type' => 'array',
'log' => [
'default' => 'dev', // 默认使用的 channel,生产环境可以改为下面的 prod
'channels' => [
// 测试环境
'dev' => [
'driver' => 'single',
'path' => '/tmp/easywechat.log',
'level' => 'debug',
],
// 生产环境
'prod' => [
'driver' => 'daily',
'path' => '/tmp/easywechat.log',
'level' => 'info',
],
],
],
/**
* OAuth 配置
*
* scopes:公众平台(snsapi_userinfo / snsapi_base),开放平台:snsapi_login
* callback:OAuth授权完成后的回调页地址:需要前端提供完整的url
*/
'oauth' => [
'scopes' => ['snsapi_base'],
'callback' => '/api/oauth_callback.php',
],
];
}
//静态函数
static public function getInstance(){
if(self::$inc == null){
self::$inc = new self();
}
return self::$inc;
}
//初始化 easywechat app
static public function initWechat(){
self::$app = Factory::officialAccount(self::$config);
return self::$app;
}
}