encryptMsg() public method

  1. 对要发送的消息进行AES-CBC加密
  2. 生成安全签名
  3. 将消息密文和安全签名打包成xml格式
public encryptMsg ( $replyMsg, $timeStamp, $nonce, &$encryptMsg ) : integer
$replyMsg string 公众平台待回复用户的消息,xml格式的字符串
$timeStamp string 时间戳,可以自己生成,也可以用URL参数的timestamp
$nonce string 随机串,可以自己生成,也可以用URL参数的nonce
return integer 成功0,失败返回对应的错误码
Beispiel #1
0
 /**
  * 解密
  * @param $replyMsg
  * @param $timestamp
  * @param $nonce
  * @return string
  * @throws WechatException
  */
 protected function encryptMsg($replyMsg, $timestamp, $nonce)
 {
     $msg = '';
     //传入公众号第三方平台的token(申请公众号第三方平台时填写的接收消息的校验token), 公众号第三方平台的appid, 公众号第三方平台的 EncodingAESKey(申请公众号第三方平台时填写的接收消息的加密symmetric_key)
     $pc = new WXBizMsgCrypt($this->token, $this->encodingAesKey, $this->appId);
     //第三方收到公众号平台发送的消息
     $errCode = $pc->encryptMsg($replyMsg, $timestamp, $nonce, $msg);
     if ($errCode == 0) {
         return $msg;
     }
     throw new WechatException('encrypt msg error. error code ' . $errCode);
 }