想要开启回调模式吗?来跟我看齐喽!
一、在其微信企业号里面的应用中创建自己的应用,创建时会用到你主页的url和CroupID
二、进入回调模式开启页面,此页面的URL为你回调模式的访问路径
接下来,重点来了!写你的回调方法,懒人请复制哦
<?php
namespace app\index\controller;
use think\Controller;
use TimeCheer\Weixin\QYAPI\Crypt\WXBizMsgCrypt;
class Index extends Controller{
private $encodingAesKey = "";
private $token = "";
private $corpId = "";
private $sVerifyMsgSig;
private $sVerifyTimeStamp;
private $sVerifyNonce;
public function __construct(){
$this -> sVerifyMsgSig = $_GET["msg_signature"];
$this -> sVerifyTimeStamp = $_GET["timestamp"];
$this -> sVerifyNonce = $_GET["nonce"];
}
//回调模式
public function valid(){
$wxcpt = new WXBizMsgCrypt($this -> token, $this -> encodingAesKey, $this -> corpId);
$sVerifyEchoStr = $_GET["echostr"];
$errCode = $wxcpt->VerifyURL($this -> sVerifyMsgSig, $this -> sVerifyTimeStamp, $this -> sVerifyNonce, $sVerifyEchoStr, $sEchoStr);
if ($errCode == 0) {
echo $sEchoStr;
} else {
print("ERR: " . $errCode . "\n\n");
}
}
}
其中用到的encodingAesKey、token、corpId一定要填写最真实的!不要糊弄微信服务器哦!他不傻~
然后最后一步跟重要!!!!!!!
点击保存!!!!!!!
是不是成功了?没有成功就再试几次,也可能跟网有关系~