Home > Backend Development > PHP Tutorial > Tutorial 4: Debugging the public account server, debugging the public_PHP tutorial

Tutorial 4: Debugging the public account server, debugging the public_PHP tutorial

WBOY
Release: 2016-07-12 08:51:26
Original
960 people have browsed it

Tutorial 4: Debugging the public account server, debugging the public

Before entering the formal development, we also need to master the debugging method of WeChat public account development.


If we rely entirely on received messages for debugging, we will be subject to many restrictions.
For example, we can only return messages in a specified format to see our replies in the WeChat application content,
If our server reports an error, we will not be able to know the exact error message,
so we need a server that can replace WeChat to send messages to our official account server and can display any message format we return. Tool.


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


This is a tool written in nodejs. To install this tool we first need to install the nodejs development environment.
Here It is the official website of nodejs https://nodejs.org/. Follow the instructions on the official website to install it step by step.


After the installation is completed, we can use the `npm` tool to install this simulation development and debugging tool.
The installation command is:

Copy code


Installing this tool requires administrator rights, so mac and linux users may need to use `sudo`.


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

Copy code


Among them `weixin` is the token parameter we configured before,
`http://weixinshow001.sinaapp.com` is the server address of our public platform.
Everyone needs to put this Change the two parameters to your own.


The running interface of the program looks like this:

When successful, the url and token just passed in will be echoed. Here we simply test a text message.
Press Enter when selected to enter the text input interface.
                        >
We just enter some text and click Enter to send.
Then we see an error, why is this?
                                   
The reason is that this tool does not completely follow the official message format of WeChat.
The official WeChat server does not add the `echostr` item in the GET field when sending the message.
And this tool will send the `echostr` field in any message.
The wechat-php library we used before used this field to determine whether it is a token verification special request,If it is a special request for token verification, the echostr field will be returned and subsequent operations will be terminated,
thus causing this error.


Now we modify our library to be compatible with this test library.


We open the `Wechat.php` file and find the `isValidateIncomingConn` function in the file.
This function is used to determine whether this request is a token verification request.
We Change to the following content:


Copy code


After completing the above steps, upload it to the SAE server to make it effective, and then re-send the text message in `webot`, and we can see the correct echo.


Based on this debugging method, we can even debug on the local server! Based on this debugging method, we can even debug on the local server! Based on this debugging method, we can even debug on the local server!
Just set the url parameter of the debugging tool to the local url.
In addition, if you like to go out To write code on the web server, the test page provided by WeChat is also good: http://mp.weixin.qq.com/debug





Thank you for reading, please understand with your heart! Hope this helps you as a beginner! ! Sharing is also a joy! ! ! Please pass on. . .

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1130486.htmlTechArticleTutorial 4: Debugging the public account server, debugging the public Before entering the formal development, we also need to master the WeChat public account Developed debugging method. If we rely entirely on received messages...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template