search
HomeWeChat AppletMini Program DevelopmentDetailed explanation of WeChat applet message push PHP server verification example

This article mainly introduces the relevant information on the detailed explanation of the PHP server verification example of the WeChat applet message push. Friends in need can refer to

Detailed explanation of the PHP server verification example of the WeChat applet message push

WeChat documentation (there is an "Access Guide" at the bottom): 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 the server domain name

For example: https://hosts.com

Note the difference between http and https protocols.

2. Set up message push

2.1 Add the server interface test.php to your server. The content of the test.php interface is mainly to verify the message through token Whether it is sent from WeChat, the code refers to the official example:


define("TOKEN","xxxxx");/ 后台填写的token
$wechatObj = new wechatAPI();
$wechatObj->isValid();
class wechatAPI
{
public function isValid()//验证微信接口,如果确认是微信就返回它传来的echostr参数
{
 $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, SORT_STRING);
 $tmpStr = implode( $tmpArr );
 $tmpStr = sha1( $tmpStr );
 if( $tmpStr == $signature ){
 return true;
 }else{
 return false;
 }
}
};

2.2 Set up the background message push related information of the mini program

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 is only used for encryption and decryption)

Message encryption method: select plaintext for the time being, no need to consider encryption and decryption question.

Data format: Select according to needs.

Submit, if there are no problems, it will be successful. (If there is a problem you can use fake data to pass the browser test)

The above is the detailed content of Detailed explanation of WeChat applet message push PHP server verification example. For more information, please follow other related articles on the PHP Chinese website!

Statement
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 Tools

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft