thanatosxia / yii2-wechat
WeChat SDK for yii2, based on overtrue/easywechat
Installs: 196
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 2
Forks: 0
Open Issues: 0
Type:yii2-extension
Requires
- overtrue/wechat: ~4.0
- yiisoft/yii2: *
This package is auto-updated.
Last update: 2024-12-18 22:42:13 UTC
README
Wechat Sdk Extension for Yii 2
based on overtrue/wechat
安装
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
对应的处理方法是eventSubscribe
scan
对应的处理方法是eventScan