Esempio n. 1
0
        /// <summary>
        /// 根据微信小程序平台提供的解密算法解密数据,推荐直接使用此方法
        /// </summary>
        /// <param name="loginInfo">登陆信息</param>
        /// <returns>用户信息</returns>
        public static WechatUserInfo Decrypt(WechatLoginInfo loginInfo)
        {
            if (loginInfo == null)
            {
                return(null);
            }

            if (String.IsNullOrEmpty(loginInfo.code))
            {
                return(null);
            }

            OpenIdAndSessionKey oiask = DecodeOpenIdAndSessionKey(loginInfo);

            if (oiask == null)
            {
                return(null);
            }

            if (!VaildateUserInfo(loginInfo, oiask))
            {
                return(null);
            }

            WechatUserInfo userInfo = Decrypt(loginInfo.encryptedData, loginInfo.iv, oiask.session_key);

            return(userInfo);
        }
Esempio n. 2
0
        /// <summary>
        /// 反序列化包含OpenId和SessionKey的Json数据包
        /// </summary>
        /// <param name="code">Json数据包</param>
        /// <returns>包含OpenId和SessionKey的类</returns>
        public static OpenIdAndSessionKey DecodeOpenIdAndSessionKey(WechatLoginInfo loginInfo)
        {
            OpenIdAndSessionKey oiask = JsonConvert.DeserializeObject <OpenIdAndSessionKey>(GetOpenIdAndSessionKeyString(loginInfo.code));

            if (!String.IsNullOrEmpty(oiask.errcode))
            {
                return(null);
            }
            return(oiask);
        }
Esempio n. 3
0
 /// <summary>
 /// 根据微信小程序平台提供的签名验证算法验证用户发来的数据是否有效
 /// </summary>
 /// <param name="loginInfo">登陆信息</param>
 /// <param name="idAndKey">包含OpenId和SessionKey的类</param>
 /// <returns>True:资料有效,False:资料无效</returns>
 public static bool VaildateUserInfo(WechatLoginInfo loginInfo, OpenIdAndSessionKey idAndKey)
 {
     return(VaildateUserInfo(loginInfo, idAndKey.session_key));
 }