Exemplo n.º 1
0
        /// <summary>
        /// 20200629 用户授权 通过解密获取unionid  再查询是否是泰便利注册用户
        /// </summary>

        public UserInfoResModel EasyDecryptByDE(WeChatCodeDEModel codeModel, string appId, string appSecret)
        {
            UserInfoResModel resModel = new UserInfoResModel();
            BaseViewModel    model    = new BaseViewModel();

            Dtol.Easydtol.UserInfo user = new Dtol.Easydtol.UserInfo();

            if (codeModel.code == null || codeModel.code == "")
            {
                model.ResponseCode = 9;
                model.Message      = "参数为空";
            }

            WeChatInfoModel oiask = JsonConvert.DeserializeObject <WeChatInfoModel>(GetOpenIdAndSessionKeyString(codeModel.code, appId, appSecret));

            if (!string.IsNullOrEmpty(oiask.session_key))
            {
                WechatUserInfoResModel res = new WechatUserInfoResModel();

                res = Decrypt(codeModel.encryptedData, codeModel.iv, oiask.session_key);
                if (!string.IsNullOrEmpty(res.unionId))
                {
                    V_OpenidUnionid v_Openid = new V_OpenidUnionid();
                    v_Openid.openid  = oiask.openid;
                    v_Openid.unionid = res.unionId;
                    v_OpenidUnionidRepository.Add(v_Openid);
                    v_OpenidUnionidRepository.SaveChanges();

                    user = GetEasyUser(res.unionId);

                    if (!String.IsNullOrEmpty(user.ID))
                    {
                        model.ResponseCode = 5;
                        model.Message      = "unionid不为空,已注册泰便利";
                    }
                    else
                    {
                        model.ResponseCode = 6;
                        model.Message      = "unionid不为空,未注册泰便利";
                    }
                }
                else
                {
                    model.ResponseCode = 7;
                    model.Message      = "授权未获取unionid";
                }
            }
            else
            {
                model.ResponseCode = 8;
                model.Message      = "授权未获取session_key";
            }
            resModel.baseView = model;
            resModel.userInfo = user;

            return(resModel);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 20200629  用户授权 通过解密获取unionid  再查询是否是泰便利注册用户
        /// </summary>
        public UserInfoResModel GetWeChartUserInfoByDE(WeChatCodeDEModel model)
        {
            UserInfoResModel resModel = new UserInfoResModel();

            resModel = _IWeChatClientRepository.EasyDecryptByDE(model, _IOptions.Value.appid, _IOptions.Value.secret);
            //判断 是否注册泰便利
            if (resModel.userInfo != null)
            {
                if (resModel.userInfo.ID != null)
                {
                    DEncrypt encrypt       = new DEncrypt();
                    string   Name          = encrypt.Decrypt(resModel.userInfo.Name);
                    string   CertificateID = encrypt.Decrypt(resModel.userInfo.CertificateID);
                    string   Mobile        = encrypt.Decrypt(resModel.userInfo.Mobile);

                    resModel.userInfo.Name          = Name;
                    resModel.userInfo.CertificateID = CertificateID;
                    resModel.userInfo.Mobile        = Mobile;
                }
            }


            return(resModel);
        }
        public ActionResult <UserInfoResModel> GetWeChartUserInfoByDE(WeChatCodeDEModel codeModel)
        {
            UserInfoResModel resModel = _weChatHttpClientService.GetWeChartUserInfoByDE(codeModel);

            return(resModel);
        }