微信公众号接入

xiaoxiao2021-02-28  32

// 校验是否接入成功 public function index(){ $echoStr = $_GET["echostr"]; if(!$echoStr) { echo $this -> responseMsg(); }else { if($this -> checkSignature()) { echo $echoStr; exit; } } } /** * 检测消息是否来自微信 */ public function checkSignature(){ $echoStr = $_GET["echostr"]; $signature = $_GET["signature"]; //微信发过来的东西 $timestamp = $_GET["timestamp"]; $nonce = $_GET["nonce"]; $token = $this -> token; //定义你在微信公众号开发者模式里面定义的token $tmpArr = array($token,$timestamp,$nonce); sort($tmpArr, SORT_STRING); $tmpStr = sha1(implode($tmpArr)); if ($tmpStr == $signature) { return true; } else { return false; } }

写好这两个方法以后把微信公众号里的基本配置地址改成你的地址即可。记住http的域名就写http,https的就写https,如果https写成了http,就会导致接入失败

转载请注明原文地址: https://www.6miu.com/read-2620526.html

最新回复(0)