微信公众号服务器配置Token验证失败如何php验证

by 少年2021-08-05
  • 0 赞
  • 0 收藏
  • 技术
  • 48262 评论
  • 174500 阅读
© 本文 by 少年 版权所有,作者未对本笔记声明转载限制,转载时请注明本文标题和链接。
笔记

很多微信公众号开发者,在配置服务器配置时可能会遇到Token验证失败的情况,那到底该怎么操作呢?


首先,我们要了解各个配置项的含义



URL:必须以http://或https://开头,分别支持80端口和443端口。这里要特别说明的是,需要填写具体做响应的地址,比如:(https/http)://域名/wechat/index.php 这个index.php不要略去,略去可能会导致验证失败。

Token:这个设置可以自定义。比如设置成:‘ideashu’。

EncodingAESKey:点击随机生成就可以。

消息加解密方式:既然来看教程,就直接选明文模式。


这时提交肯定是token验证失败


之后,我们需要告诉微信我有目标地址的使用权


怎么来验证你的权限呢?


其实我们点击提交时,微信就会向你说的目标地址发送验证信息,这时我们在服务器的响应地址文件作出响应的响应就可以了


我们打开服务器,找到我们设置的目录,比如我们设置的URL是:(https/http)://域名/wechat/index.php;我们就在服务器根目录下创建wechat文件夹,并创建文件index.php文件,这个index.php文件就能接收微信发来的信息(GET方式)。


我们对接收的信息进行一系列的操作后就可以,具体操作见 index.php 代码:


<?php
//获得参数 signature nonce token timestamp echostr
$nonce     = $_GET['nonce'];
$token     = '你设置的token';
$timestamp = $_GET['timestamp'];
$echostr   = $_GET['echostr'];
$signature = $_GET['signature'];
//形成数组,然后按字典序排序
$array = array($nonce, $timestamp, $token);
sort($array);
//拼接成字符串,sha1加密 ,然后与signature进行校验
$str = sha1( implode( $array ) );
if( $str == $signature && $echostr ){
	echo  $echostr;//第一次接入weixin api接口的时候
	exit;
}
?>

保存代码后,回到微信公众号服务器配置页面点击验证即可通过验证。


这个代码只需要验证时使用,验证通过后就可以改成其他代码了。


---

转载请注明本文标题和链接:《 微信公众号服务器配置Token验证失败如何php验证
TAG: php
评论
Rvqrvi
olmesartan 20mg without prescription verapamil over the counter buy depakote without a prescription

2023-05-29 19:57:18回复

Seergy
Fqfhord Dkioct topiramate tablets spc Nzhxtv Yhdduz

2023-05-27 20:24:31回复

Thoeic
generic ivermectin cheap stromectol deltasone cost

2023-05-23 16:24:33回复

Zumngv
buy azipro 250mg sale neurontin over the counter cheap neurontin generic

2023-05-23 00:17:24回复

Vidalistaer
Wyrzpg vidalista black 80 mg tablets Jodacs

2023-05-22 10:39:19回复

12345678 ... 9653(有 48262 条评论)