Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to solve the problem of Token verification failure or request URL timeout in the development of Wechat for php

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article is about how to solve the problem of Token verification failure or request URL timeout in the development of Wechat for php. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

1.Token verification failed

This is to check the configuration file, the most basic is

Define ("TOKEN", "weixin"); weixin is the ID behind your Wechat development.

Solution to the problem of Token verification failure or request URL timeout in Wechat development

two。 Request URL timed out

There is no way to submit this a few more times, and this is that the server installed software such as a security dog to block Wechat IP, you can check it.

3. Officially download a wechatCallbackapiTest class and do some operations, as shown below:

Define ("TOKEN", "weixin"); $wechatObj = new wechatCallbackapiTest (); if (isset ($_ GET ['echostr'])) {$wechatObj- > valid ();} else {$wechatObj- > responseMsg ();}

The code for the wechatCallbackapiTest class is as follows:

Class wechatCallbackapiTest {public function valid () {$echoStr = $_ GET ["echostr"]; if ($this- > checkSignature ()) {echo $echoStr; exit;} private function checkSignature () {$signature = $_ GET ["signature"]; $timestamp = $_ GET ["timestamp"]; $nonce = $_ GET ["nonce"]; $token = TOKEN; $tmpArr = array ($token, $timestamp, $nonce); sort ($tmpArr) $tmpStr = implode ($tmpArr); $tmpStr = sha1 ($tmpStr); if ($tmpStr = = $signature) {return true;} else {return false;}} public function responseMsg () {$postStr = $GLOBALS ["HTTP_RAW_POST_DATA"]; if (! emptyempty ($postStr)) {$postObj = simplexml_load_string ($postStr, 'SimpleXMLElement', LIBXML_NOCDATA); $fromUsername = $postObj- > FromUserName; $toUsername = $postObj- > ToUserName $keyword = trim ($postObj- > Content); $time = time (); $textTpl = "% s 0"; if ($keyword! = "" | |! emptyempty ($keyword)) {msgType = "text"; / / $contentStr. = date ("Y-m-d H:i:s", time ()) $resultStr = sprintf ($textTpl, $fromUsername, $toUsername, $time, $msgType, $contentStr); echo $resultStr;}} else {echo "; exit;}} thank you for reading! On "how to solve the php version of Wechat development Token verification failure or request URL timeout problem," this article is shared here, I hope the above content can be of some help to you, so that you can learn more knowledge, if you think the article is good, you can share it out for more people to see it!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report