decryptMsg() public method

  1. 利用收到的密文生成安全签名,进行签名验证
  2. 若验证通过,则提取xml中的加密消息
  3. 对消息进行解密
public decryptMsg ( $msgSignature, $timestamp = null, $nonce, $postData, &$msg ) : integer
$msgSignature string 签名串,对应URL参数的msg_signature
$timestamp string 时间戳 对应URL参数的timestamp
$nonce string 随机串,对应URL参数的nonce
$postData string 密文,对应POST请求的数据
return integer 成功0,失败返回对应的错误码
Beispiel #1
0
 /**
  * 解密
  * @param string $msgSignature
  * @param string $timestamp
  * @param string $nonce
  * @param string $encryptMsg
  * @return string
  * @throws WechatException
  */
 protected function decryptMsg($msgSignature, $timestamp, $nonce, $encryptMsg)
 {
     $msg = '';
     //传入公众号第三方平台的token(申请公众号第三方平台时填写的接收消息的校验token), 公众号第三方平台的appid, 公众号第三方平台的 EncodingAESKey(申请公众号第三方平台时填写的接收消息的加密symmetric_key)
     $pc = new WXBizMsgCrypt($this->token, $this->encodingAesKey, $this->appId);
     // 第三方收到公众号平台发送的消息
     $errCode = $pc->decryptMsg($msgSignature, $timestamp, $nonce, $encryptMsg, $msg);
     if ($errCode == 0) {
         Log::debug((string) $msg);
         return $msg;
     }
     throw new WechatException('decrypt msg error. error code ' . $errCode);
 }