PHP code example of thanatosxia / yii2-wechat

1. Go to this page and download the library: Download thanatosxia/yii2-wechat library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

thanatosxia / yii2-wechat example snippets



'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();

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()
     {

     }

}