From c5f290bd5a993554118c921287a27c11aeca6991 Mon Sep 17 00:00:00 2001 From: Jason Date: Fri, 9 Sep 2022 11:27:40 +0800 Subject: [PATCH] wechat --- app/controller/Wechat.php | 11 ++----- config/wechat.php | 68 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+), 9 deletions(-) create mode 100644 config/wechat.php diff --git a/app/controller/Wechat.php b/app/controller/Wechat.php index be967eb..7f32f9e 100644 --- a/app/controller/Wechat.php +++ b/app/controller/Wechat.php @@ -11,20 +11,13 @@ class Wechat private function initWechat() { - $config = [ - 'app_id' => 'wx3793a03c18984e4f', - 'secret' => 'f1c242f4f28f735d4687abb469072xxx', - 'token' => 'TestToken', - 'response_type' => 'array', - ]; - $this->app = Factory::officialAccount($config); + $this->app = Factory::officialAccount(config('wechat')); } public function config() { $this->initWechat(); - $response = $this->app->oauth->scopes(['snsapi_userinfo'])->redirect(); - return $response->send(); + redirect($this->app->oauth->scopes(['snsapi_userinfo'])->redirect()); } } \ No newline at end of file diff --git a/config/wechat.php b/config/wechat.php new file mode 100644 index 0000000..02c6644 --- /dev/null +++ b/config/wechat.php @@ -0,0 +1,68 @@ + 'wx3793a03c18984e4f', // AppID + 'secret' => 'f1c242f4f28f735d4687abb469072xxx', // AppSecret + 'token' => 'iQoSaqys8cQawIusDZn6H5LPYTMIOWVg', // Token + 'aes_key' => 'fmkgnwli1JaabwxlcZdkI6bZ2lwxiVGnxg5o0mSHsuB', // EncodingAESKey,兼容与安全模式下请一定要填写!!! + + /** + * 指定 API 调用返回结果的类型:array(default)/collection/object/raw/自定义类名 + * 使用自定义类名时,构造函数将会接收一个 `EasyWeChat\Kernel\Http\Response` 实例 + */ + 'response_type' => 'array', + + /** + * 日志配置 + * + * level: 日志级别, 可选为: + * debug/info/notice/warning/error/critical/alert/emergency + * path:日志文件位置(绝对路径!!!),要求可写权限 + */ + 'log' => [ + 'default' => 'dev', // 默认使用的 channel,生产环境可以改为下面的 prod + 'channels' => [ + // 测试环境 + 'dev' => [ + 'driver' => 'single', + 'path' => '/tmp/easywechat.log', + 'level' => 'debug', + ], + // 生产环境 + 'prod' => [ + 'driver' => 'daily', + 'path' => '/tmp/easywechat.log', + 'level' => 'info', + ], + ], + ], + + /** + * 接口请求相关配置,超时时间等,具体可用参数请参考: + * http://docs.guzzlephp.org/en/stable/request-config.html + * + * - retries: 重试次数,默认 1,指定当 http 请求失败时重试的次数。 + * - retry_delay: 重试延迟间隔(单位:ms),默认 500 + * - log_template: 指定 HTTP 日志模板,请参考:https://github.com/guzzle/guzzle/blob/master/src/MessageFormatter.php + */ + 'http' => [ + 'max_retries' => 1, + 'retry_delay' => 500, + 'timeout' => 5.0, + // 'base_uri' => 'https://api.weixin.qq.com/', // 如果你在国外想要覆盖默认的 url 的时候才使用,根据不同的模块配置不同的 uri + ], + + /** + * OAuth 配置 + * + * scopes:公众平台(snsapi_userinfo / snsapi_base),开放平台:snsapi_login + * callback:OAuth授权完成后的回调页地址 + */ + 'oauth' => [ + 'scopes' => ['snsapi_userinfo'], + 'callback' => '/wechat/callback', + ], +];