微信开发服务器的验证程序

时间:2018-03-11 00:19:29 类型:PHP
字号:    

在将微信公众号启用开发模式时,这里分享给大家

1.  配置服务器信息如图

   2.  一步骤中配置的地址里面加签名认证代码如下:

    

$signature = $this->request->param("signature");
		$timestamp = $this->request->param("timestamp");
		$nonce     = $this->request->param("nonce");
		$echostr   = $this->request->get("echostr");

		$token = $this->config["wx"]["token"];
		
		$array = array($token, $timestamp, $nonce); //放到一个数组里
		sort($array, SORT_STRING); // 将三人参数进行字典排序
		$str = implode($array); // 将三个参数拼接成一个字符串
		$str = sha1($str); // 进行 sha1加密
		if($signature == $str){
			echo $echostr;
			exit();
		}
		else{
			return false;
		}
3. 启用服务器配置, 便可提交成功!