/// <summary>
        /// 根据微信小程序平台提供的解密算法解密数据,推荐直接使用此方法
        /// </summary>
        /// <param name="loginInfo">登陆信息</param>
        /// <returns>用户信息</returns>
        public 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);

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

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