微信公众号token的设置和接入步骤
发布于 3 年前 作者 xiangwei 825 次浏览 来自 分享

1、首先接入token
登录微信公众账号 -》开发 -》基本设置 -》基本配置
设置一下
(1) IP白名单
(2)服务器地址(URL)
(3)令牌(Token)
(4)消息加解密密钥(EncodingAESKey)
(5)消息加密方式 (明文模式)

设置 成功之后会提示:

设置 失败之后提示:

需要在原来的代码上加上:
ob_clean ();

public function index() {
    ob_clean ();
	//1. 将timestamp , nonce , token 按照字典排序  
	$timestamp = $_GET['timestamp'];
	$nonce = $_GET['nonce'];
	$token = "";
	//token
	$signature = $_GET['signature'];
	$array = array($timestamp,$nonce,$token);
	sort($array);
	//2.将排序后的三个参数拼接后用sha1加密  
	$tmpstr = implode('',$array);
	$tmpstr = sha1($tmpstr);
	//3. 将加密后的字符串与 signature 进行对比, 判断该请求是否来自微信  
	if($tmpstr == $signature) {
		echo $_GET['echostr'];
		exit;
	}
}

2、开启
接入成功之后,在服务器配置(未启动)设置一下开启,
如图:

3、创建菜单栏

菜单栏创建成功之后,会提示:

{"errcode":0,"errmsg":"ok"}

4、关注对应的公账号

温馨提示:
按照以上步骤开发哦!

接口开发参考地址:

接入指南 接口文档:
https://developers.weixin.qq.com/doc/offiaccount/Basic_Information/Access_Overview.html

access_token接口文档:
https://developers.weixin.qq.com/doc/offiaccount/Basic_Information/Get_access_token.html

创建菜单栏接口文档:
https://developers.weixin.qq.com/doc/offiaccount/Custom_Menus/Creating_Custom-Defined_Menu.html

微信公众平台接口调试工具
http://mp.weixin.qq.com/debug/

微信token PHP示例代码下载:
https://res.wx.qq.com/op_res/-serEQ6xSDVIjfoOHcX78T1JAYX-pM_fghzfiNYoD8uHVd3fOeC0PC_pvlg4-kmP

作者:Ams

回到顶部