问答详情
源自:2-4 基于ThinkPHP框架的微信API接入

为什么我的公众号回复总是空白呢

   //获得参数 signature nonce token timestamp echostr
   $timestamp = $_GET['timestamp'];
   $nonce     = $_GET['nonce'];
   $token     = 'hua';
   $signature = $_GET['signature'];
   $echostr   = $_GET['echostr'];    //形成数组,然后按字典序排序
   $array     = array();
   $array     = array( $nonce,  $timestamp, $token);
   sort( $array);                   //拼接成字符串,sha1加密,然后与signature进行校验
   $tmpstr = sha1(implode( $array ));
 
   if ( $tmpstr == $signature && $echostr )    //第一次接入微信api接口的时候
    { echo $echostr;
       exit;
    } else { // $this->reponseMsg(); }
                    
   //   function reponseMsg(){
     //1.获取到微信推送过来post数据(xml格式)
    $postArr = $GlOBALS['HTTP_RAW_POST_DATA'];
       //2.处理消息类型,并设置回复类型和内容
    $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
       }
                                            }
                               }

这是代码https://img1.mukewang.com/5c7b8199000103a007201279.jpg

提问者:慕设计6780568 2019-03-03 15:26

个回答