PHP code example of luoyt / wechat
1. Go to this page and download the library: Download luoyt/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/ */
luoyt / wechat example snippets
php
$options['token'] = "123456";
$options['appid'] = '';
$options['secret'] = '';
$options['access_token'] = '';
$wechat = new Wechat($options);
if(isset($_GET['echostr'])){
$wechat->valid(); //检验signature代码
}else{
$request = $wechat->request();
// 自动回复处理
if($request['msgtype']=='event'){ //事件处理
$openid = $request['fromusername'];
if($request['event']=='subscribe'){ //关注事件
}elseif($request['event']=='unsubscribe'){ //取消关注事件
}elseif($request['event']=='SCAN'){ //扫码事件
}elseif($request['event']=='CLICK'){ //菜单点击事件
}
}else if($request['msgtype']=='text'){ //文本回复
}else if($request['msgtype']=='voice'){ //语音回复
}