PHP code example of muxin / wechat
1. Go to this page and download the library: Download muxin/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/ */
muxin / wechat example snippets
//继承公众号类实现自己的功能
class test extends \Muxin\weixin\wechat{
//重载 接收文本消息
public function msg_text($data){
//服务器下发的信息
$开发者 = $data->ToUserName;
$用户ID = $data->FromUserName;
$信息创建时间 = $data->CreateTime;
$信息内容 = $data->Content;
$信息ID = $data->MsgId;
/*
在这里添加您的代码
*/
//回复给用户的信息
$回复内容='您给我发了信息:'.$信息内容;
//调用回复文本消息函数回复用户信息
return $this->ret_text($用户ID,$开发者,$回复内容);
}
//重载 接收用户关注事件
public function event_subscribe($data){
$开发者ID = $data->ToUserName;
$用户ID = $data->FromUserName;
$信息创建时间 = $data->CreateTime;
$事件KEY值 = $data->EventKey;
$二维码ticket = $data->Ticket;
/*
您的代码
*/
$ret_text = "感谢您的关注";
return $this->ret_text($开发者ID,$用户ID,$ret_text);
}
//重载 接收用户取消关注事件
public function event_unsubscribe($data){
$开发者ID = $data->ToUserName;
$用户ID = $data->FromUserName;
$信息创建时间 = $data->CreateTime;
/*
您的代码
*/
}
}
//配置公众号参数
$config=array(
'APPID'=>'公众号的APPID',
'AppSecret'=>'公众号的AppSecret',
'TOKEN'=>'公众号TOKEN',
'encodingAesKey'=>'公众号encodingAesKey',
);
//实例化业务对象
$t = new test($config['APPID'],$config['TOKEN'],$config['encodingAesKey'],1);
// 启动服务器,并返回或者输出数据
return $t->server();
// echo $t->server();
//继承公众号类实现自己的功能
class test extends \Muxin\weixin\wechat{
}
//配置公众号参数
$config=array(
'APPID'=>'公众号的APPID',
'AppSecret'=>'公众号的AppSecret',
'TOKEN'=>'公众号TOKEN',
'encodingAesKey'=>'公众号encodingAesKey',
);
//实例化业务对象
$t = new test($config['APPID'],$config['TOKEN'],$config['encodingAesKey'],1);
//获取用户列表
$data=[
'next_openid' => 0, //第一个拉取的OPENID,不填默认从头开始拉取
];
$r = $t->api('/cgi-bin/user/get',0,$data);
var_dump($r);
//
$data=[
'user_list' =>[
[
"openid" => "otvxTs4dckWG7imySrJd6jSi0CWE",
"lang" => "zh_CN"
],
[
"openid" => "otvxTs4dckWG7imySrJd6jSi0CWE",
"lang" => "zh_CN"
],
]
];
//获取用户基本信息
$r = $t->api('/cgi-bin/user/info/batchget',1,$data);
var_dump($r);