Exemplo n.º 1
0
        SmallApp_UserInfo IWeChatSmallApp.GetUserInfo(SmallApp_InfoData data, string session_key)
        {
            if (_info == null)
            {
                throw new WeChatError("请先调用init初始化");
            }
            //签名验证
            var sign = StringEncyptionHelper.sha1(data.rawData + session_key);

            if (sign.ToLower() != data.signature.ToLower())
            {
                throw new WeChatError("签名验证不通过");
            }

            //解密开始
            try
            {
                var user = JsonHelper.jsonToModel <SmallApp_UserInfo>(StringEncyptionHelper.aesDecrypt(data.encryptedData, session_key, data.iv, CipherMode.CBC));
                //水印验证
                if (user.watermark.appid != _info.smallapp_appid)
                {
                    throw new Exception("水印验证不通过");
                }
                return(user);
            }
            catch
            {
                throw new Exception("解密失败");
            }
        }
Exemplo n.º 2
0
        public SmallApp_UserInfo GetUserInfo(SmallApp_InfoData data, string session_key)
        {
            //签名验证
            var sign = FrequentlyEncrypt.Sha1(data.rawData + session_key);

            if (sign.ToLower() != data.signature.ToLower())
            {
                throw new Exception("签名验证不通过");
            }

            //解密开始
            try
            {
                var user = JsonConvert.DeserializeObject <SmallApp_UserInfo>(FrequentlyEncrypt.AesDecrypt(data.encryptedData, session_key, data.iv, CipherMode.CBC));
                //水印验证
                if (user.watermark.appid != _setting.appid)
                {
                    throw new Exception("水印验证不通过");
                }
                return(user);
            }
            catch
            {
                throw new Exception("解密失败");
            }
        }