求助 自動推送不顯示 測不出來哪出問題
<?php
namespace Home\Controller;
use Think\Controller;
class IndexController extends Controller {
??? public function index(){
??? //獲得參數(shù) signature? nance? token? timestamp echostr
?? ??? ?$nonce = $_GET['nonce'];
?? ??? ?$token = 'cyts';
??????? $timestamp = $_GET['timestamp'];
??????? $echostr = $_GET['echostr'];
??????? $signature = $_GET['signature'];
??????? //形成數(shù)組然后用字典排序
??????? $array = array($nonce,$token,$timestamp);
??????? sort($array);
??????? //拼接字符串,加密,然后與sigature進行校驗
??????? $str = sha1(implode($array));
??????? if ($str == $signature && $echostr) {
??????????? //第一次介入weixin API接口的時候驗證
?????? ??? ? echo $echostr;
?????? ??? ? exit;
??????? }else{
??????????? $this->reponseMsg();
??????? }
??? }
??? //接收時間推送并回復
??? public function reponseMsg(){
??????? //1.獲取到微信推送過來POST數(shù)據(jù)(xml格式)
?? ??? ?$postArr = $GLOBALS['HTTP_RAW_POST_DATA'];
?? ??? ?//2處理消息類型,并設置回復類型和內(nèi)容
??????? // <xml>
??????? // <ToUserName><![CDATA[toUser]]></ToUserName>
??????? // <FromUserName><![CDATA[FromUser]]></FromUserName>
??????? // <CreateTime>123456789</CreateTime>
??????? // <MsgType><![CDATA[event]]></MsgType>
??????? // <Event><![CDATA[subscribe]]></Event>
??????? // </xml>?? ?
??????? // $postObj = simplexml_load_string($postar);
??????? // $postObj->ToUseName = '';
??????? // $postObj->FromUserName = '';
??????? // $postObj->CreateTime = '';
??????? // $postObj->MsgType = '';
??????? // $postObj->Event = '';
??????? //判斷該數(shù)據(jù)包是否是訂閱的事件推送
??????? if(strtolower($postObj->MsgType) == 'event'){
??????????? //如果是關注subscribe事件
??????????? if (strtolower($postObj->Event == 'subscribe') ){
??????????????? //回復用戶消息
??????????????? $toUser?? = $postObj->FromUserName;
??????????????? $fromUser = $postObj->ToUserName;
??????????????? $time???? = time();
??????????????? $msgType? = 'text';
??????????????? $content? = '歡迎關注我的微信公眾賬號';
??????????????? file_put_contents('1.php', $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;
??????????? }
??????? }???? ?
??? }
?? ?
}
2016-11-03
?if (strtolower($postObj->Event == 'subscribe') ){
?file_put_contents('1.php', $content);
你看是不是這兩句中的一句