1 | <?php |
||
20 | class WXBizMsgCrypt |
||
21 | { |
||
22 | private $token; |
||
23 | private $encodingAesKey; |
||
24 | private $appId; |
||
25 | |||
26 | /** |
||
27 | * 构造函数 |
||
28 | * |
||
29 | * @param $token string 公众平台上,开发者设置的token |
||
30 | * @param $encodingAesKey string 公众平台上,开发者设置的EncodingAESKey |
||
31 | * @param $appId string 公众平台的appId |
||
32 | */ |
||
33 | public function __construct($token, $encodingAesKey, $appId) |
||
39 | |||
40 | /** |
||
41 | * 将公众平台回复用户的消息加密打包. |
||
42 | * <ol> |
||
43 | * <li>对要发送的消息进行AES-CBC加密</li> |
||
44 | * <li>生成安全签名</li> |
||
45 | * <li>将消息密文和安全签名打包成xml格式</li> |
||
46 | * </ol> |
||
47 | * |
||
48 | * @param $replyMsg string 公众平台待回复用户的消息,xml格式的字符串 |
||
49 | * @param $timeStamp string 时间戳,可以自己生成,也可以用URL参数的timestamp |
||
50 | * @param $nonce string 随机串,可以自己生成,也可以用URL参数的nonce |
||
51 | * @param &$encryptMsg string 加密后的可以直接回复用户的密文,包括msg_signature, timestamp, nonce, encrypt的xml格式的字符串, |
||
52 | * 当return返回0时有效 |
||
53 | * |
||
54 | * @return int 成功0,失败返回对应的错误码 |
||
55 | */ |
||
56 | public function encryptMsg($replyMsg, $timeStamp = null, $nonce, &$encryptMsg) |
||
88 | |||
89 | /** |
||
90 | * 检验消息的真实性,并且获取解密后的明文. |
||
91 | * <ol> |
||
92 | * <li>利用收到的密文生成安全签名,进行签名验证</li> |
||
93 | * <li>若验证通过,则提取xml中的加密消息</li> |
||
94 | * <li>对消息进行解密</li> |
||
95 | * </ol> |
||
96 | * |
||
97 | * @param $msgSignature string 签名串,对应URL参数的msg_signature |
||
98 | * @param $timestamp string 时间戳 对应URL参数的timestamp |
||
99 | * @param $nonce string 随机串,对应URL参数的nonce |
||
100 | * @param $postData string 密文,对应POST请求的数据 |
||
101 | * @param &$msg string 解密后的原文,当return返回0时有效 |
||
102 | * |
||
103 | * @return int 成功0,失败返回对应的错误码 |
||
104 | */ |
||
105 | public function decryptMsg($msgSignature, $timestamp = null, $nonce, $postData, &$msg) |
||
152 | } |
||
153 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.