亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

訂閱號關注后沒有推送事件, 除了檢查代碼還需要檢查哪里?

?<?php
namespace?app\wechat\controller;

class?Index
{
????public?function?index(){
//1)將token、timestamp、nonce三個參數進行字典序排序?
$token ???=?'weixin';
$timestamp?=?$_GET['timestamp'];
$nonce?????=?$_GET['nonce'];
$signature?=?$_GET['signature'];
$echostr???=?$_GET['echostr'];
//2)將三個參數字符串拼接成一個字符串進行sha1加密?
$array?=?array($token,?$timestamp,?$nonce);
sort($array);
$str?=?sha1(implode('',?$array));
//3)開發者獲得加密后的字符串可與signature對比,標識該請求來源于微信
if($str?==?$signature?&&?$echostr){
//第一次接入微信api接口的時候
echo?$echostr;
exit;
}else{
$this->reponseMsg();
}
}
public?function?reponseMsg(){
$postArr?=?file_get_contents("php://input");
$postObj?=?simplexml_load_string($postArr);
//判斷數據包是否是訂閱號推送
if(strtolower($postObj->MsgType)?==?'event'){
//如果關注?subscribe?事件
if(strtolower($postObj->Event)?==?'subscribe'){
//回復用戶消息
$toUser???=?$postObj->FromUserName;
$fromUser?=?$postObj->ToUserName;
$time?????=?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,?$time,?$msgType,?$content);
echo?$info;
}
}
}
}


正在回答

舉報

0/150
提交
取消

訂閱號關注后沒有推送事件, 除了檢查代碼還需要檢查哪里?

我要回答 關注問題
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號