首先准备好自己的url token,AESkey 等
我是tp6的环境
下载完之后,解压到app\common 文件夹内,这是我自己整理的 使用的企业微信团队官方的github 的包
然后在你需要调用的控制器
use app\common\WXBizMsgCrypt; //这个是必须引用的
use think\Response;//下面的是 为了给企业微信返回时引用的
这是自己写的一个方法
public function getpushdata(Request $request)
{
/**基本配置参数*/ $encodingAesKey = ''; //替换自己的参数
$token = '';//替换自己的参数
$corpId = Config::get('qyconfig.corpid');//替换自己的参数
$MsgSignature = $request->get('msg_signature');
$TimeStamp = $request->get('timestamp');
$Nonce = $request->get('nonce');
$Echostr = $request->get('echostr');
$sEchoStr = "";
$wxcpt = new WXBizMsgCrypt($token, $encodingAesKey, $corpId);
$errCode = $wxcpt->VerifyURL($MsgSignature, $TimeStamp, $Nonce, $Echostr, $sEchoStr);
if ($errCode == 0) {
/
$response = Response::create($sEchoStr)->contentType('text/plain');
return $response;
//
// 验证URL成功,将sEchoStr返回
} else {
print("ERR: " . $errCode . "\n\n");
}
}