|
|
<?php
|
|
|
|
|
|
namespace app\server;
|
|
|
use EasyWeChat\Factory;
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 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::$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;
|
|
|
}
|
|
|
|
|
|
static public function initWechat(){
|
|
|
|
|
|
self::$app = Factory::officialAccount(self::$config);
|
|
|
return self::$app;
|
|
|
}
|
|
|
} |
...
|
...
|
|