微信公眾號開發xml:Xml fields error, please check your response xml!

來源:互聯網
上載者:User
php代碼如下 tp架構

responseMsg();      }    }    public function responseMsg()    {    //get post data, May be due to the different environments    $postStr = $GLOBALS["HTTP_RAW_POST_DATA"];    // $tmpstr = $postStr;    libxml_disable_entity_loader(true);    $postObj = simplexml_load_string($postStr,'SimpleXMLElement', LIBXML_NOCDATA);    //extract post data    if (strtolower( $postObj->MsgType ) == 'event'){                /* libxml_disable_entity_loader is to prevent XML eXternal Entity Injection,                   the best way is to check the validity of xml by yourself */                   if (strtolower( $postObj->Event == 'subscribe')) {                     $toUsername = $postObj->FromUserName;                     $fromUsername = $postObj->ToUserName;                     $time = time();                     $MsgType = 'text';                     $content = "歡迎訪問我的公眾號";                     $textTpl = "%s";                     $info = sprintf($textTpl,$toUsername,$fromUsername,$time,$MsgType,$content);                     echo $info;                   }        }    }}

測試結果如下:

http://120.27.115.59/wechat.php/Home/Index/wechat成功或失敗:Decrypt Fail!  錯誤原因:Xml fields error, please check your response xml! 狀態代碼:200    OK Headers:Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0Connection: Keep-AliveDate: Tue, 23 Aug 2016 10:23:34 GMTX-Powered-By: PHP/5.5.9-1ubuntu4.14Set-Cookie: PHPSESSID=4tlrj4jd7cgoo3ueaigc6753q7; path=/Pragma: no-cacheServer: Apache/2.4.7 (Ubuntu)Vary: Accept-EncodingExpires: Thu, 19 Nov 1981 08:52:00 GMTContent-Type: text/htmlContent-Length: 239 解密前xml:1471947814解密後xml:

回複內容:

php代碼如下 tp架構

responseMsg();      }    }    public function responseMsg()    {    //get post data, May be due to the different environments    $postStr = $GLOBALS["HTTP_RAW_POST_DATA"];    // $tmpstr = $postStr;    libxml_disable_entity_loader(true);    $postObj = simplexml_load_string($postStr,'SimpleXMLElement', LIBXML_NOCDATA);    //extract post data    if (strtolower( $postObj->MsgType ) == 'event'){                /* libxml_disable_entity_loader is to prevent XML eXternal Entity Injection,                   the best way is to check the validity of xml by yourself */                   if (strtolower( $postObj->Event == 'subscribe')) {                     $toUsername = $postObj->FromUserName;                     $fromUsername = $postObj->ToUserName;                     $time = time();                     $MsgType = 'text';                     $content = "歡迎訪問我的公眾號";                     $textTpl = "%s";                     $info = sprintf($textTpl,$toUsername,$fromUsername,$time,$MsgType,$content);                     echo $info;                   }        }    }}

測試結果如下:

http://120.27.115.59/wechat.php/Home/Index/wechat成功或失敗:Decrypt Fail!  錯誤原因:Xml fields error, please check your response xml! 狀態代碼:200    OK Headers:Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0Connection: Keep-AliveDate: Tue, 23 Aug 2016 10:23:34 GMTX-Powered-By: PHP/5.5.9-1ubuntu4.14Set-Cookie: PHPSESSID=4tlrj4jd7cgoo3ueaigc6753q7; path=/Pragma: no-cacheServer: Apache/2.4.7 (Ubuntu)Vary: Accept-EncodingExpires: Thu, 19 Nov 1981 08:52:00 GMTContent-Type: text/htmlContent-Length: 239 解密前xml:1471947814解密後xml:

解決了。。貌似是tp的問題

  • 相關文章

    聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.