微信公众号服务器配置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
评论
Estbpz
order tadalafil 40mg tadalafil brand viagra 50mg pills

2023-05-08 22:43:08回复

Gbeejs
buy duricef 500mg without prescription purchase epivir pills propecia order

2023-05-08 06:58:03回复

Fchzvc
purchase carbamazepine for sale order carbamazepine online cheap buy lincomycin 500mg sale

2023-05-07 23:28:52回复

Mzphel
zocor 20mg sale buy zocor tablets purchase sildenafil pills

2023-05-06 21:22:18回复

synthroiduuu
thyroid medication over the counter Patients who are considering natural thyroid hormone supplements should discuss their options with their healthcare provider and undergo regular monitoring to ensure appropriate dosing and effectiveness.

2023-05-06 10:27:39回复

1 ... 3456789 ... 9653(有 48262 条评论)