thanatosxia / yii2-wechat
基于 overtrue/easywechat 的 yii2 微信 SDK
1.1.2
2018-09-18 08:17 UTC
Requires
- overtrue/wechat: ~4.0
- yiisoft/yii2: *
This package is auto-updated.
Last update: 2024-09-18 22:10:56 UTC
README
为 Yii 2 定制的 Wechat Sdk 扩展
安装
composer require thanatosxia/yii2-wechat
使用
将配置添加到 main.php/config.php
'wechat' => [ 'class' => 'thanatos\wechat\Wechat', 'log' => [ 'level' => 'debug', 'permission' => '0777', 'file' => '@runtime/logs/wechat.log' ], 'app_id' => '', 'secret' => '', 'token' => '', /** * official 公众号 * miniProgram 小程序 * open 开放平台 * weWork 企业微信 * payment 微信支付 */ 'app_type' => '', ],
对接微信
$app = Yii::$app->wechat->app; $app->server->push(EventMessageHandle::class); $response = $app->server->serve(); $response->send();
新建 EventMessageHandle 类, extends thanatos\wechat\MessageHandler
class EventMessageHandle extends MessageHandler { // 在执行处理之前会被执行,如果返回false则不继续执行 public function beforeHandle() { return parent::beforeHandle(); } // 默认的消息处理方法 public function handleDefault() { $string = 123 . Yii::$app->user->id; return $string; } public function getUnionid() { return $this->wechatInfo->unionid; } // 处理用户关注事件 public function eventSubscribe() { } }
对于微信的时间推荐,可以在自定义的消息处理类中添加方法,来处理 如
subscribe对应的处理方法是eventSubscribescan对应的处理方法是eventScan