要获取微信的敏感数据,需要先将加密的数据解密之后才能获取
class WXBizDataCrypt{ public static $OK = 0; public static $IllegalAesKey = -41001; public static $IllegalIv = -41002; public static $IllegalBuffer = -41003; public static $DecodeBase64Error = -41004; private $appid; private $sessionKey; public function __construct($params) { $this-sessionKey = $params["sessionKey"]; $this-appid = $params["appId"]; } public function decryptData( $encryptedData, $iv, &$data ) { if (strlen($this-sessionKey) != 24) { return self::$IllegalAesKey; } $aesKey=base64_decode($this-sessionKey); if (strlen($iv) != 24) { return self::$IllegalIv; } $aesIV=base64_decode($iv); $aesCipher=base64_decode($encryptedData); $result=openssl_decrypt( $aesCipher, "AES-128-CBC", $aesKey, 1, $aesIV); $dataObj=json_decode( $result ); if( $dataObj == NULL ) { return self::$IllegalBuffer; } if( $dataObj-watermark-appid != $this-appid ) { return self::$IllegalBuffer; } $data = $result; return self::$OK; }}