Tutorial 4: debug the public account server and debug the public _ PHP Tutorial

Source: Internet
Author: User
Tutorial 4: debug the public account server and the public account. Tutorial 4: debug the public account server. before debugging the public, we need to know how to debug the public account development. if we fully rely on the received message tutorial 4: debug the public account server and debug the public

Before entering the formal development stage, we also need to master the debugging methods for public account development.


If we rely entirely on the received message for debugging, we will be subject to a lot of restrictions,
For example, only messages in the specified format can be returned to view the reply content in the application,
If an error is reported on our server, we cannot know the exact error message,
Therefore, we need a tool that can replace the server to send messages to our public account server and display any message formats we return.


Fortunately, we can find such a tool 'webbot-cli 'on the Internet ',
The address of this tool is open source, source address is: https://github.com/node-webot/webot-cli/blob/master/README.md


This is a tool written by nodejs. to install this tool, we must first install the nodejs development environment.
Here is nodejs official website https://nodejs.org/, according to the instructions of the official website step by step install OK.


After installation, we can use the 'npm 'tool to install the simulated development and debugging tool.
The installation command is:


The administrator privilege is required to install this tool. Therefore, mac and linux users may need to use 'sudo '.


After the installation is complete, we will introduce the use of this tool.
We can directly call the following command on the command line to start running this tool,


Here, 'weixin' is the token parameter we configured earlier,
'Http: // weixinshow001.sinaapp.com 'is the server address of our public platform.
You need to change these two parameters to your own.


The running interface of the program looks like this:

When the operation is successful, the uploaded url and token are displayed.
Here we test a text message,
Press enter to enter the text input page.

Enter some text and press enter to send it.
Then we see an error. why?

The reason is that this tool is not completely sent in the official message format,
The official server did not add the 'echostr' item to the GET field when sending the message,
This tool sends the 'chostr' field in any message.


The wechat-php library we used previously used this field to determine whether it was a token to verify the special request,
For a special token verification request, the echostr field is returned and subsequent operations are terminated,
This error is caused.


Now let's modify our library to be compatible with this test Library.


Open the 'WeChat. php' file and find the 'isvalidateincomingconn' function in the file,
This function is used to determine whether the request is a token verification request.
Let's change it to the following content:


After the image is uploaded to the server of SAE to make it take effect, and then send a text message in 'webot 'again, we can see the correct echo.

Based on this debugging method, we can even debug it on the local server!
Based on this debugging method, we can even debug it on the local server!
Based on this debugging method, we can even debug it on the local server!

You only need to set the url parameter of the debugging tool to the local url.

In addition, if you like to write code on the Internet server, the official test page is also good: http://mp.weixin.qq.com/debug

Thank you for reading this article! Hope you can help beginners !! Sharing is also a pleasure !!! Please relay...

Before entering the formal development stage, we also need to master the debugging method for public account development. if we rely entirely on the received message...

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.