慕桂英6468770
2018-08-12 22:53
// 接收事件推送并回复
public function reponseMsg()
{
$postArr = $GLOBALS['HTTP_RAW_POST_DATA'];
$postObj = simplexml_load_string($postArr);
if (strtolower($postObj->MsgType) == 'event') {
if (strtolower($postObj->Event) == 'subscribe') {
$toUser = $postObj->FromUserName;
$fromUser = $postObj->ToUserName;
$createTime = time();
$msgType = 'text';
$content = '斯是陋室,惟吾德馨';
$template = '<xml><ToUserName><![CDATA[%s]]></ToUserName><FromUserName><![CDATA[%s]]></FromUserName><CreateTime>%s</CreateTime><MsgType><![CDATA[%s]]></MsgType><Content><![CDATA[%s]]></Content></xml>';
$info = sprintf($template,$toUser,$fromUser,$createTime,$msgType,$Content);
echo $info;
}
}
}
看下php版本 7.0$postArr = $GLOBALS['HTTP_RAW_POST_DATA'];就获取不到xml了
还是不行
public function index()
{
if (isset($_GET['echostr'])) {
//获得参数 signature nonce token timestamp echostr
$nonce = $_GET['nonce'];
$token = 'weixin';
$timestamp = $_GET['timestamp'];
$echostr = $_GET['echostr'];
$signature = $_GET['signature'];
//形成数组,然后按字典序排序
$array = array();
$array = array($nonce, $timestamp, $token);
sort($array);
//拼接成字符串,sha1加密 ,然后与signature进行校验
$str = sha1(implode($array));
if ($str == $signature && $echostr) {
//第一次接入weixin api接口的时候
echo $echostr;
exit;
}
} else {
$this->responseMsg();
}
}拿去吧 少年
$content 第一个字母大写了。
PHP实现微信公众平台开发—提升篇
64952 学习 · 371 问题
相似问题