How to solve the problem of php weixin configuration failure

藏色散人
Release: 2023-03-14 12:02:01
Original
2073 people have browsed it

php Weixin configuration failure solution: 1. Create a PHP sample file; 2. Use the "function checkWeixin() {...}" method to verify whether the parameters come from WeChat.

How to solve the problem of php weixin configuration failure

#The operating environment of this article: Windows 7 system, PHP version 7.4, Dell G3 computer.

How to solve the problem of php weixin configuration failure?

php WeChat public account development verification token prompts configuration failure

<?php
// //最简单的验证方式
// echo $_GET["echostr"];
 
//验证是否来自于微信
function checkWeixin() {
//微信会发送4个参数到我们的服务器后台 签名 时间戳 随机字符串 随机数
 
$signature = $_GET["signature"];
$timestamp = $_GET["timestamp"];
$nonce = $_GET["nonce"];
$echostr = $_GET["echostr"];
$token = "zchare861230";
 
// 1、将token、timestamp、nonce三个参数进行字典序排序
$tmpArr = array($nonce,$token,$timestamp);
sort($tmpArr,SORT_STRING);
// 2、将三个参数字符串拼接成一个字符串进行sha1加密
$str = implode($tmpArr);
$sign = sha1($str);
// 3、开发者获得加密后的字符串可与signature对比,标识该请求来源于微信
if ($sign == $signature) {
echo $echostr;
}
}
checkWeixin();
?>
Copy after login

Recommended study: "PHP video tutorial

The above is the detailed content of How to solve the problem of php weixin configuration failure. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
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