Table of Contents
教程四:调试公众号服务器,调试公众
Home php教程 php手册 教程四:调试公众号服务器,调试公众

教程四:调试公众号服务器,调试公众

Jun 13, 2016 am 08:38 AM
exist develop us master Tutorial server formal of debug Enter need

教程四:调试公众号服务器,调试公众

在进入正式的开发之前,我们还需要掌握微信公众号开发的调试方法.


如果我们完全依赖接收到的消息来进行调试,那我们将受到很多的限制,
比如我们只能返回指定格式的消息才能在微信应用中看到我们回复的内容,
如果我们的服务器报错,我们将无法知道确切的错误信息,
所以我们需要一个能代替微信服务器来给我们的公众号服务器发送消息并且能显示我们返回的任何消息格式的工具.


幸运的是我们在网上可以找到这样一个工具`webbot-cli`,
这个工具的地址是开源的,源码地址是: https://github.com/node-webot/webot-cli/blob/master/README.md


这是一个nodejs编写的工具,要安装这个工具我们首先需要安装nodejs开发环境.
这里是nodejs的官网 https://nodejs.org/, 按照官网的指示一步步安装就OK了.


安装完成后我们可以利用`npm`工具安装这个模拟开发调试工具.
安装命令是:

复制代码


安装这个工具需要管理员权限,所以mac和linux用户可能需要使用`sudo`.


安装完成后我们介绍一个这个工具的使用.
我们直接在命令行调用如下命令就会开始运行这个工具,

复制代码


其中`weixin` 为我们之前配置的token参数,
`http://weixinshow001.sinaapp.com` 为我们公众平台的服务器地址.
大家需要把这两个参数更改为自己的.


程序的运行界面长得是这个样子的:

                    
运行成功时会回显刚才传进去的url和token.
这里我们简单地测试一条text消息,
选中状态下回车会进入文本输入界面.

                   
我们随便输入一些文字,然后点击回车发送.
然后我们看到一个错误,这是为啥呢?

                           
原因是这样的,这个工具并未完全按照微信官方的消息格式发送,
微信官方的服务器在发送消息时并没有在GET字段中添加`echostr`项,
而这个工具会在任意一条消息发送`echostr`字段.


我们之前使用的wechat-php库是使用这个字段来判断是否是token验证特殊请求的,
如果是token验证特殊请求就会返回echostr字段并且终止后续操作,
于是造成了这个错误的产生.


现在我们修改一下我们的库来兼容这个测试库.


我们打开`Wechat.php`文件,在文件中找到`isValidateIncomingConn`函数,
这个函数是用来判断这一个请求是否是token验证请求的.
我们更改为一下内容:

复制代码


完成更高后上传到SAE的服务器使之生效,然后重新在`webot`中发送文本消息,我们就可以看到正确的回显了.
                            
基于这种调试方式,我们甚至可以再本地服务器上调试了!
基于这种调试方式,我们甚至可以再本地服务器上调试了!
基于这种调试方式,我们甚至可以再本地服务器上调试了!

只要把调试工具的url参数设置成本地url就ok了.

另外如果喜欢在外网服务器上写代码,微信官方提供的测试页也是不错的:http://mp.weixin.qq.com/debug

 

          感谢你的阅读,请用心感悟!希望可以帮到初学的您!!分享也是一种快乐!!!请接力。。。

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

In summer, you must try shooting a rainbow In summer, you must try shooting a rainbow Jul 21, 2024 pm 05:16 PM

After rain in summer, you can often see a beautiful and magical special weather scene - rainbow. This is also a rare scene that can be encountered in photography, and it is very photogenic. There are several conditions for a rainbow to appear: first, there are enough water droplets in the air, and second, the sun shines at a low angle. Therefore, it is easiest to see a rainbow in the afternoon after the rain has cleared up. However, the formation of a rainbow is greatly affected by weather, light and other conditions, so it generally only lasts for a short period of time, and the best viewing and shooting time is even shorter. So when you encounter a rainbow, how can you properly record it and photograph it with quality? 1. Look for rainbows. In addition to the conditions mentioned above, rainbows usually appear in the direction of sunlight, that is, if the sun shines from west to east, rainbows are more likely to appear in the east.

How to use LeakSanitizer to debug C++ memory leaks? How to use LeakSanitizer to debug C++ memory leaks? Jun 02, 2024 pm 09:46 PM

How to use LeakSanitizer to debug C++ memory leaks? Install LeakSanitizer. Enable LeakSanitizer via compile flag. Run the application and analyze the LeakSanitizer report. Identify memory allocation types and allocation locations. Fix memory leaks and ensure all dynamically allocated memory is released.

Shortcut to golang function debugging and analysis Shortcut to golang function debugging and analysis May 06, 2024 pm 10:42 PM

This article introduces shortcuts for Go function debugging and analysis, including: built-in debugger dlv, which is used to pause execution, check variables, and set breakpoints. Logging, use the log package to record messages and view them during debugging. The performance analysis tool pprof generates call graphs and analyzes performance, and uses gotoolpprof to analyze data. Practical case: Analyze memory leaks through pprof and generate a call graph to display the functions that cause leaks.

How to conduct concurrency testing and debugging in Java concurrent programming? How to conduct concurrency testing and debugging in Java concurrent programming? May 09, 2024 am 09:33 AM

Concurrency testing and debugging Concurrency testing and debugging in Java concurrent programming are crucial and the following techniques are available: Concurrency testing: Unit testing: Isolate and test a single concurrent task. Integration testing: testing the interaction between multiple concurrent tasks. Load testing: Evaluate an application's performance and scalability under heavy load. Concurrency Debugging: Breakpoints: Pause thread execution and inspect variables or execute code. Logging: Record thread events and status. Stack trace: Identify the source of the exception. Visualization tools: Monitor thread activity and resource usage.

How to debug PHP asynchronous code How to debug PHP asynchronous code May 31, 2024 am 09:08 AM

Tools for debugging PHP asynchronous code include: Psalm: a static analysis tool that can find potential errors. ParallelLint: A tool that inspects asynchronous code and provides recommendations. Xdebug: An extension for debugging PHP applications by enabling a session and stepping through the code. Other tips include using logging, assertions, running code locally, and writing unit tests.

How to retrieve the wrong chain of virtual currency? Tutorial on retrieving the wrong chain of virtual currency transfer How to retrieve the wrong chain of virtual currency? Tutorial on retrieving the wrong chain of virtual currency transfer Jul 16, 2024 pm 09:02 PM

The expansion of the virtual market is inseparable from the circulation of virtual currency, and naturally it is also inseparable from the issue of virtual currency transfers. A common transfer error is the address copy error, and another error is the chain selection error. The transfer of virtual currency to the wrong chain is still a thorny problem, but due to the inexperience of transfer operations, novices often transfer the wrong chain. So how to recover the wrong chain of virtual currency? The wrong link can be retrieved through a third-party platform, but it may not be successful. Next, the editor will tell you in detail to help you better take care of your virtual assets. How to retrieve the wrong chain of virtual currency? The process of retrieving virtual currency transferred to the wrong chain may be complicated and challenging, but by confirming the transfer details, contacting the exchange or wallet provider, importing the private key to a compatible wallet, and using the cross-chain bridge tool

Equipped with AMD EPYC 4004 series processors, ASUS launches a variety of server and workstation products Equipped with AMD EPYC 4004 series processors, ASUS launches a variety of server and workstation products Jul 23, 2024 pm 09:34 PM

According to news from this website on July 23, ASUS has launched a variety of server and workstation-level products powered by AMD EPYC 4004 series processors. Note from this site: AMD launched the AM5 platform and Zen4 architecture EPYC 4004 series processors in May, offering up to 16-core 3DV-Cache specifications. ASUSProER100AB6 server ASUSProER100AB6 is a 1U rack server product equipped with EPYC Xiaolong 4004 series processor, suitable for the needs of IDC and small and medium-sized enterprises. ASUSExpertCenterProET500AB6 workstation ASUSExpertCenterProET500AB6 is a

PHP Debugging Errors: A Guide to Common Mistakes PHP Debugging Errors: A Guide to Common Mistakes Jun 05, 2024 pm 03:18 PM

Common PHP debugging errors include: Syntax errors: Check the code syntax to make sure there are no errors. Undefined variable: Before using a variable, make sure it is initialized and assigned a value. Missing semicolons: Add semicolons to all code blocks. Function is undefined: Check that the function name is spelled correctly and make sure the correct file or PHP extension is loaded.

See all articles