微信公众号服务器配置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
评论
Etpowc
buy metronidazole 200mg generic cephalexin 125mg pills buy keflex 250mg

2023-05-11 04:40:22回复

Mqreei
estradiol online buy estradiol no prescription buy prazosin 2mg online cheap

2023-05-10 17:09:10回复

cialfrance
prix cialis 20mg pharmacie belgique tadalafil biogaran 5 mg prix cialis generique en france

2023-05-10 12:52:43回复

synthroidvbo
buy synthroid cheap Patients who are taking Synthroid should inform their healthcare provider if they have a history of adrenal gland disorders, as the medication can affect adrenal function.

2023-05-09 12:52:43回复

cialfrancecom
cialis livraison rapide internet equivalent cialis sans ordonnance pharmacie en ligne belgique cialis

2023-05-08 23:00:18回复

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