WeChat public platform-php develops WeChat public accounts. After a user sends a message, the public account does not respond. How can this problem be debugged?

Source: Internet
Author: User
Tags php example
I developed it with thinkphp. This is the code of the message push address: {code...}. Actually, I want to know how to debug it. The code must be faulty... I developed it using thinkphp. This is the code of the message push address:


  SReqTimeStamp = I ('get. timestamp '); $ this-> sReqNonce = I ('get. nonce '); $ this-> sEncryptMsg = I ('get. msg_signature '); $ this-> wxcpt = new \ WXBizMsgCrypt ($ token, $ encodingaeskey, $ appid); $ sMsg = ""; // The parsed plaintext $ errCode = $ this-> wxcpt-> DecryptMsg ($ this-> sEncryptMsg, $ this-> sReqTimeStamp, $ this-> sReqNonce, $ content, $ sMsg); if ($ errCode! = 0) {exit () ;}else {// The decryption is successful. sMsg is the plain text in xml format $ content = $ sMsg ;}} $ data = new \ SimpleXMLElement ($ content); // $ data | die ('parameter acquisition failed'); foreach ($ data as $ key => $ value) {$ this-> data [$ key] = safe (strval ($ value) ;}$ this-> replyText (" ");} /* reply to text message */public function replyText ($ content) {$ msg ['content'] = $ Content; $ this-> _ replyData ($ msg, 'text');}/* send the reply message to the platform */private function _ replyData ($ msg, $ msgType) {$ msg ['tousername'] = $ this-> data ['fromusername']; $ msg ['fromusername'] = $ this-> data ['tousername']; $ msg ['createtime'] = NOW_TIME; $ msg ['msgtype'] = $ MsgType; if ($ _ REQUEST ['donotinit ']) {dump ($ msg ); exit () ;}$ xml = new \ SimpleXMLElement ('
  '); $ This-> _ data2xml ($ xml, $ msg); $ str = $ xml-> asXML (); if ($ _ GET ['encryption _ type'] = 'aes ') {$ sEncryptMsg = ""; // ciphertext in xml format $ errCode = $ this-> wxcpt-> EncryptMsg ($ str, $ this-> sReqTimeStamp, $ this-> sReqNonce, $ sEncryptMsg ); if ($ errCode = 0) {$ str = $ sEncryptMsg;} else {}} echo ($ str );} /* assemble xml data */public function _ data2xml ($ xml, $ data, $ item = 'item') {foreach ($ data as $ key => $ value) {is_numeric ($ key) & ($ key = $ item); if (is_array ($ value) | is_object ($ value )) {$ child = $ xml-> addChild ($ key); $ this-> _ data2xml ($ child, $ value, $ item );} else {if (is_numeric ($ value) {$ child = $ xml-> addChild ($ key, $ value );} else {$ child = $ xml-> addChild ($ key); $ node = dom_import_simplexml ($ child ); $ node-> appendChild ($ node-> ownerDocument-> createCDATASection ($ value ));}}}}}

In fact, I want to know how to debug the Code. The Code must be faulty...

Reply content:

I developed it using thinkphp. This is the code of the message push address:


  SReqTimeStamp = I ('get. timestamp '); $ this-> sReqNonce = I ('get. nonce '); $ this-> sEncryptMsg = I ('get. msg_signature '); $ this-> wxcpt = new \ WXBizMsgCrypt ($ token, $ encodingaeskey, $ appid); $ sMsg = ""; // The parsed plaintext $ errCode = $ this-> wxcpt-> DecryptMsg ($ this-> sEncryptMsg, $ this-> sReqTimeStamp, $ this-> sReqNonce, $ content, $ sMsg); if ($ errCode! = 0) {exit () ;}else {// The decryption is successful. sMsg is the plain text in xml format $ content = $ sMsg ;}} $ data = new \ SimpleXMLElement ($ content); // $ data | die ('parameter acquisition failed'); foreach ($ data as $ key => $ value) {$ this-> data [$ key] = safe (strval ($ value) ;}$ this-> replyText (" ");} /* reply to text message */public function replyText ($ content) {$ msg ['content'] = $ Content; $ this-> _ replyData ($ msg, 'text');}/* send the reply message to the platform */private function _ replyData ($ msg, $ msgType) {$ msg ['tousername'] = $ this-> data ['fromusername']; $ msg ['fromusername'] = $ this-> data ['tousername']; $ msg ['createtime'] = NOW_TIME; $ msg ['msgtype'] = $ MsgType; if ($ _ REQUEST ['donotinit ']) {dump ($ msg ); exit () ;}$ xml = new \ SimpleXMLElement ('
  '); $ This-> _ data2xml ($ xml, $ msg); $ str = $ xml-> asXML (); if ($ _ GET ['encryption _ type'] = 'aes ') {$ sEncryptMsg = ""; // ciphertext in xml format $ errCode = $ this-> wxcpt-> EncryptMsg ($ str, $ this-> sReqTimeStamp, $ this-> sReqNonce, $ sEncryptMsg ); if ($ errCode = 0) {$ str = $ sEncryptMsg;} else {}} echo ($ str );} /* assemble xml data */public function _ data2xml ($ xml, $ data, $ item = 'item') {foreach ($ data as $ key => $ value) {is_numeric ($ key) & ($ key = $ item); if (is_array ($ value) | is_object ($ value )) {$ child = $ xml-> addChild ($ key); $ this-> _ data2xml ($ child, $ value, $ item );} else {if (is_numeric ($ value) {$ child = $ xml-> addChild ($ key, $ value );} else {$ child = $ xml-> addChild ($ key); $ node = dom_import_simplexml ($ child ); $ node-> appendChild ($ node-> ownerDocument-> createCDATASection ($ value ));}}}}}

In fact, I want to know how to debug the Code. The Code must be faulty...

Debugging can be performed by writing files or databases. I usually write files! For example, the code entry begins to write files, record the user's openid and sent content, and so on. The most extreme case is that each line of code is followed by debugging information. Of course, this is not necessary! You just need to add it where you are interested and have questions! If the previous debugging information is available and the other debugging information is missing, it must be a problem with the intermediate code! In addition, remember to check whether the Code has syntax errors or the like. Open it in the editor.

Another php example in the public account development document first runs the example. Then, compare the example to debug your code at, and ensure that you have no problem with the connection.
Then, I made a client to simulate the user to send messages to the background and test my logic.

            
          Email                

Follow events

<Xml> <ToUserName> <! [CDATA [toUser]> </ToUserName> <FromUserName> <! [CDATA [mocker]> </FromUserName> <CreateTime> 1348831865 </CreateTime> <MsgType> <! [CDATA [event]> </MsgType> <Event> <! [CDATA [subscribe]> </Event> </xml>

Send

Text message

Send

Menu message

Send

Location event

<Xml> <ToUserName> <! [CDATA [toUser]> </ToUserName> <FromUserName> <! [CDATA [mocker]> </FromUserName> <CreateTime> 1351776365 </CreateTime> <MsgType> <! </MsgType> <Location_X> 23.134521 </Location_X> <Location_Y> 113.358803 </Location_Y> <Scale> 20 </Scale> <Label> <! [CDATA [location information]> </Label> <MsgId> 9876543210123456 </MsgId> </xml>

Send

QR code follow

Send

Scenario QR code

Send

Complete Group Sending

Send

Execution result

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.