第一步登陆企业微信pc端管理后台设置好信息,先不要点击保存,会提示失败
随后根据填写的URL编写接口,接口代码如下:
//就是第一步图中的token
$token = 'xxx';
//就是第一步图中的EncodingAESKey
$encodingAESKey = 'xxx';
//企业微信corpid,前往我的企业->企业ID 内查看
$receiveid= 'xxx';
$signature = $_GET('msg_signature');
$timestamp = $_GET('timestamp');
$echostr = $_GET('echostr');
$nonce = $_GET('nonce');
$key = base64_decode($encodingAESKey . '=');
$iv = substr($key, 0, 16);
$array = array($echostr, $token, $timestamp, $nonce);
sort($array, SORT_STRING);
$str = implode($array);
$decryptSignature = sha1($str);
if ($signature != $decryptSignature){
return false;
}
$decrypted = openssl_decrypt($echostr, 'AES-256-CBC', $key, OPENSSL_ZERO_PADDING,$iv);
$pad = ord(substr($decrypted, -1));
$result = substr($decrypted, 0, (strlen($decrypted) - $pad));
//拆分
$content = substr($result, 16, strlen($result));
$len_list = unpack('N', substr($content, 0, 4));
$xml_len = $len_list[1];
$xml_content = substr($content, 4, $xml_len);
$from_receiveId = substr($content, $xml_len+ 4);
if($from_receiveId != $receiveid){
return false;
}
//返回验证内容
echo $xml_content;
第三步返回pc端界面点击保存,设置回调服务器成功