//?我的本意是想做一個關(guān)注微信公眾號就自動回復(fù)一個welcome的效果,想了很多辦法,也查了很多資料,但是就是沒有用
//???調(diào)試也成功了,但是在手機上用的時候,關(guān)注就是沒反應(yīng),然后發(fā)送消息還顯示我的公眾號暫時停止服務(wù)
//???真的很疲倦。。。我是新手,這個問題卡了兩天了,快瘋了。求大神給指點,詳細(xì)一些,感激不盡!
<?php
public?function?index{
//獲得參數(shù)?signature?nonce?token?timestamp?echostr
$nonce?????=?$_GET['nonce'];
$token?????=?'paitson';
$timestamp?=?$_GET['timestamp'];
$echostr???=?$_GET['echostr'];
$signature?=?$_GET['signature'];
//形成數(shù)組,然后按字典序排序
$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?->?reponseMsg();
}
}
public?function?reponseMsg{
//收到數(shù)據(jù)
$postArr?=?$GLOBALS['HTTP_RAM_POST_DATA'];
//處理消息類型并設(shè)置回復(fù)內(nèi)容
?$postObj?=?simplexml_load_string(??$postArr??);
?if?(??strtolower?($postObj?->?MsgType)?=='event'??){
? if???(??strtolower?($postObj?->?Event?=='subscribe'??)?)??{
? $toUser??=??$postObj?->?FromUserName;
$fromUser??=??$postObj?->?toUserName;?
$time??=?time();
$msgtype??=??"text";
$content?=?'welcome!';
$template??=??"<xml>
??????????????????????????????????????????????????<ToUserName><![CDATA[%s]]></ToUserName>
??????????????????????????????????????????????????<FromUserName><![CDATA[%s]]></FromUserName>
??????????????????????????????????????????????????<CreateTime>12345678</CreateTime>
??????????????????????????????????????????????????<MsgType><![CDATA[%s]]></MsgType>
??????????????????????????????????????????????????<Content><![CDATA[%s]]></Content>
??????????????????????????????????</xml>"
$info?=??sprintf(?$template?,?$toUser?,?$fromUser?,?$time?,?$msgType?,?$content??);
? }
?}
}
?>
- 2 回答
- 0 關(guān)注
- 2653 瀏覽
添加回答
舉報
0/150
提交
取消