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