Get the App
SLTechnology News&Howtos  ›  Development  › 

How to implement the verification of WeChat Mini Programs message push php server

Shulou Source: shulou.com Published: 2022-06-03 08:52:10 11月15日 Update

This article introduces the relevant knowledge of "how to implement WeChat Mini Programs message push php server verification". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Detailed explanation of WeChat Mini Programs message push php server verification example

Wechat document (there is a "access guide" below): https://mp.weixin.qq.com/debug/wxadoc/dev/api/custommsg/callback_help.html

Settings page (Settings > Development Settings):

Https://mp.weixin.qq.com/wxopen/initprofile?action=home&lang=zh_CN

1. Set server domain name

For example: https://hosts.com

Note the difference between http and https protocols.

two。 Set up message push

2.1 adding server interface test.php,test.php to your server mainly verifies whether the message is sent by Wechat through token. The code refers to the official example:

Define ("TOKEN", "xxxxx"); / token$wechatObj = new wechatAPI () filled in at backend; $wechatObj- > isValid (); class wechatAPI {public function isValid () / / verify Wechat API. If confirmed as Wechat, return its echostr parameter {$echoStr = $_ GET ["echostr"]; if ($this- > checkSignature ()) {echo $echoStr; exit;}} private function checkSignature () / / official verification function {$signature = $_ GET ["signature"] $timestamp = $GET ["timestamp"]; $nonce = $_ GET ["nonce"]; $token = TOKEN; $tmpArr = array ($token, $timestamp, $nonce); sort ($tmpArr, SORT_STRING); $tmpStr = implode ($tmpArr); $tmpStr = sha1 ($tmpStr); if ($tmpStr = = $signature) {return true;} else {return false;}

2.2 set Mini Program background message push related information

URL (server address): https://hosts.com/xx/test.php

Token: any string that conforms to the specification, such as "xxxxx" defined above

EncodingAESKey (message encryption key): (randomly generated, just save it yourself, this encryption and decryption only)

Message encryption: choose plaintext for the time being, without thinking about encryption and decryption.

Data format: choose according to the demand.

Submit, if there is no problem, it will be successful. (if there is a problem, you can pass the browser test with fake data.)

This is the end of the content of "how to implement WeChat Mini Programs message push php server authentication". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Tags: Message server service authentication push program content interface problem encryption background official data more knowledge choice different practical successful next Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Microsoft OPPO Reno Apple MariaDB Linux