/// <summary> /// 小程序获取手机号 需要认证的公众号才有权限 /// </summary> /// <param name="input"></param> /// <returns></returns> public async Task <PhoneNumModel> GetDecryptPhoneNumAsync(EncryptedPhoneNumModel input) { if (input == null) { throw new Exception("获取手机号请求数据不能为空"); } OpenIdAndSessionKeyModel model = await GetOpenIdAndSessionKeyAsync(input.code); if (model.errcode != 0) { throw new Exception($"获取session_key失败,code:{model.errcode} 信息:{model.errmsg}"); } string result = SecurityHelper.AESDecryptString(input.encryptedData, input.iv, model.session_key); return(result.ToObject <PhoneNumModel>()); }
/// <summary> ///小程序登录第一步 小程序直接拉去加密的用户信息 根据微信小程序平台提供的解密算法解密数据,推荐直接使用此方法 /// </summary> /// <param name="loginInfo">登陆信息</param> /// <returns>用户信息</returns> public async Task <WechatUserInfoModel> GetDecryptUserInfoAsync(EncryptedLoginInfoModel input) { if (input == null) { throw new Exception("获取登录信息请求数据不能为空"); } OpenIdAndSessionKeyModel model = await GetOpenIdAndSessionKeyAsync(input.code); if (model.errcode != 0) { throw new Exception($"获取session_key失败,code:{model.errcode} 信息:{model.errmsg}"); } if (!VaildateSignature(input.rawData, input.signature, model.session_key)) { throw new Exception("signature校验失败"); } string result = SecurityHelper.AESDecryptString(input.encryptedData, input.iv, model.session_key); //反序列化结果,生成用户信息实例 return(result.ToObject <WechatUserInfoModel>()); }