PHP Class PFinal\Wechat\SDK\WXBizMsgCrypt

Datei anzeigen Open project: pfinal/wechat Class Usage Examples

Public Methods

Method Description
__construct ( $token, $encodingAesKey, $appId ) 构造函数
decryptMsg ( $msgSignature, $timestamp = null, $nonce, $postData, &$msg ) : integer 检验消息的真实性,并且获取解密后的明文.
encryptMsg ( $replyMsg, $timeStamp, $nonce, &$encryptMsg ) : integer 将公众平台回复用户的消息加密打包.

Method Details

__construct() public method

构造函数
public __construct ( $token, $encodingAesKey, $appId )
$token string 公众平台上,开发者设置的token
$encodingAesKey string 公众平台上,开发者设置的EncodingAESKey
$appId string 公众平台的appId

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,失败返回对应的错误码

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,失败返回对应的错误码