Skip to content

Commit

Permalink
add verifyUrl
Browse files Browse the repository at this point in the history
  • Loading branch information
maojindao55 committed Dec 29, 2022
1 parent 5450b91 commit 5b092d7
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions WXBizMsgCrypt.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,44 @@ public function __construct($token, $encodingAesKey, $appId)
$this->encodingAesKey = $encodingAesKey;
$this->appId = $appId;
}
/*
*验证URL
*@param sMsgSignature: 签名串,对应URL参数的msg_signature
*@param sTimeStamp: 时间戳,对应URL参数的timestamp
*@param sNonce: 随机串,对应URL参数的nonce
*@param sEchoStr: 随机串,对应URL参数的echostr
*@param sReplyEchoStr: 解密之后的echostr,当return返回0时有效
*@return:成功0,失败返回对应的错误码
*/
public function VerifyURL($sMsgSignature, $sTimeStamp, $sNonce, $sEchoStr, &$sReplyEchoStr)
{
if (strlen($this->m_sEncodingAesKey) != 43) {
return ErrorCode::$IllegalAesKey;
}

$pc = new Prpcrypt($this->m_sEncodingAesKey);
//verify msg_signature
$sha1 = new SHA1;
$array = $sha1->getSHA1($this->m_sToken, $sTimeStamp, $sNonce, $sEchoStr);
$ret = $array[0];

if ($ret != 0) {
return $ret;
}

$signature = $array[1];
if ($signature != $sMsgSignature) {
return ErrorCode::$ValidateSignatureError;
}

$result = $pc->decrypt($sEchoStr, $this->m_sReceiveId);
if ($result[0] != 0) {
return $result[0];
}
$sReplyEchoStr = $result[1];

return ErrorCode::$OK;
}
/**
* 将公众平台回复用户的消息加密打包.
* <ol>
Expand Down

0 comments on commit 5b092d7

Please sign in to comment.