PHP code example of phpcxy / wechat-manager

1. Go to this page and download the library: Download phpcxy/wechat-manager 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/ */

    

phpcxy / wechat-manager example snippets


php artisan vendor:publish --tag=wechat-manager-migrations

php artisan migrate

$text = WechatManager::getReply('keyword');

$text = WechatManager::getWelcomeReply();


/**
 * 接收微信消息和事件
 * @param Request $request
 * @return
 */
public function server(Request $request)
{
    $wechat = app('wechat.official_account');
    $wechat->server->push(function($message) {
  
        $type = $message['MsgType'];
        
        switch ($type) {
            case 'text':
                $content = $message['Content'];
                $reply = WechatManager::getReply($content);
                if ($reply) {
                    return $reply;
                }
                break;
            case 'event':
                // 菜单的点击回复使用了CLICK事件,所以需要在事件这里获取下回复内容
                if ($message['Event'] === 'CLICK') {
                    $reply = WechatManager::getReply($message['EventKey'], 'menu');
                    if ($reply) {
                        return $reply;
                    }
                }
                
                break;
            
            default:
                return 'hello world';
                break;
                
        }
        
    });
    
    return $this->wechat->server->serve();
}