鍍金池/ 問答/PHP  網(wǎng)絡(luò)營(yíng)銷  HTML/ 微信公眾號(hào)不能自動(dòng)回復(fù)是哪里寫的不對(duì)?

微信公眾號(hào)不能自動(dòng)回復(fù)是哪里寫的不對(duì)?

發(fā)送任何內(nèi)容也沒有任何回復(fù) 別的功能都正常 就是自動(dòng)回復(fù)不行

define("TOKEN", "weixin");
$wechatObj = new wechatCallbackapiTest();
$wechatObj->responseMsg();
//$wechatObj->valid();

class wechatCallbackapiTest
{
  public function valid()
    {
        $echoStr = $_GET["echostr"];
        //valid signature , option
        if($this->checkSignature()){
          echo $echoStr;
          exit;
        }
    }

    public function responseMsg()
    {
    $postStr = isset($GLOBALS['HTTP_RAW_POST_DATA']) ? $GLOBALS['HTTP_RAW_POST_DATA'] : file_get_contents("php://input");

    if (!empty($postStr)){
                libxml_disable_entity_loader(true);
                $postObj = simplexml_load_string($postStr, 'SimpleXMLElement', LIBXML_NOCDATA);
                $fromUsername = $postObj->FromUserName;
                $toUsername = $postObj->ToUserName;
                $keyword = trim($postObj->Content);
                $time = time();
                $textTpl ="<xml>
              <ToUserName><![CDATA[%s]]></ToUserName>
              <FromUserName><![CDATA[%s]]></FromUserName>
              <CreateTime>%s</CreateTime>
              <MsgType><![CDATA[%s]]></MsgType>
              <Content><![CDATA[%s]]></Content>
              </xml>";            
        if(!empty( $keyword ))
                {
                  $msgType = "text";
                  $contentStr = "<a ;
                  $resultStr = sprintf($textTpl, $fromUsername, $toUsername, $time, $msgType, $contentStr);
                  echo $resultStr;
                }else{
                  echo "嘿嘿";
                }
        }
    }
    
  private function checkSignature()
  {
        if (!defined("TOKEN")) {
            throw new Exception('TOKEN is not defined!');
        }
        
        $signature = $_GET["signature"];
        $timestamp = $_GET["timestamp"];
        $nonce = $_GET["nonce"];
            
    $token = TOKEN;
    $tmpArr = array($token, $timestamp, $nonce);
        // use SORT_STRING rule
    sort($tmpArr, SORT_STRING);
    $tmpStr = implode( $tmpArr );
    $tmpStr = sha1( $tmpStr );
    
    if( $tmpStr == $signature ){
      return true;
    }else{
      return false;
    }
  }
}
回答
編輯回答
愚念
  1. 驗(yàn)證服務(wù)器地址
  2. 記錄日志
  3. 查看微信服務(wù)器白名單:開發(fā)--基本配置--ip白名單
  4. 查看響應(yīng)頭信息
  5. 使用postman模擬微信請(qǐng)求
2018年5月18日 02:06
編輯回答
她愚我

可以發(fā)送xml到自己的地址調(diào)試,看看返回的是什么。

2018年4月28日 21:03
編輯回答
薔薇花

輸出前 加個(gè)頭試試

header("Content-type: text/xml");
2018年2月23日 17:29