Example #1
0
        public async Task <AppletUserSessionDTO> AddOrUpdateAppletUserSession(AppletUserSessionDTO model)
        {
            AppletUserSessionDTO result = null;

            using (var client = new HttpClient())
            {
                client.DefaultRequestHeaders.Add("gooiosapikey", "6de960be9183367800160026c7e9f3d2");

                var reqUrl  = $"http://authservice.gooios.com/api/user/appletusersession";
                var data    = JsonConvert.SerializeObject(model);
                var content = new StringContent(data, Encoding.UTF8, "application/json");

                var res = await client.PostAsync(reqUrl, content);

                if (res.IsSuccessStatusCode)
                {
                    var resContent = await res.Content.ReadAsStringAsync();

                    result = JsonConvert.DeserializeObject <AppletUserSessionDTO>(resContent);
                }
                return(result);
            }
        }
Example #2
0
        public async Task <OpenIDSessionKeyDTO> GetSessionKey(string code, string organizationId = null, string applicationId = null)
        {
            WeChatOpenIdResponseDTO result = null;

            BaseGateway gateway = null;

            if (string.IsNullOrEmpty(organizationId))
            {
                gateway = _gateways.Get <WechatpayGateway>();
            }
            else
            {
                WeChatAppConfiguration appConfig = _wechatAppConfigurationRepository.GetFiltered(o => o.OrganizationId == organizationId).FirstOrDefault();
                if (appConfig != null)
                {
                    var wechatpayMerchant = new PaySharp.Wechatpay.Merchant
                    {
                        AppId           = appConfig.AppId,
                        MchId           = appConfig.MchId,
                        Key             = appConfig.Key,
                        AppSecret       = appConfig.AppSecret,
                        SslCertPath     = appConfig.SslCertPath,
                        SslCertPassword = appConfig.SslCertPassword,
                        NotifyUrl       = appConfig.NotifyUrl
                    };

                    gateway = new WechatpayGateway(wechatpayMerchant);
                }
                else
                {
                    gateway = _gateways.Get <WechatpayGateway>();
                }
            }

            var reqModel = new WeChatOpenIdRequestDTO {
                AppId = gateway.Merchant.AppId, Code = code, Secret = _configuration.WeChatAppSecret
            };

            result = await _wechatApiProxy.CheckAuthCode(reqModel);

            //TODO:验签

            AppletUserSessionDTO dto = null;

            if (result != null)
            {
                await _authServiceProxy.AddOrUpdateAppletUser(new AppletUserDTO
                {
                    ApplicationId  = applicationId,
                    Channel        = UserChannel.WeChat,
                    NickName       = "",
                    OpenId         = result.OpenId,
                    OrganizationId = organizationId,
                    UserId         = "",
                    UserPortrait   = ""
                });

                dto = await _authServiceProxy.AddOrUpdateAppletUserSession(new AppletUserSessionDTO
                {
                    UserId     = "",
                    OpenId     = result.OpenId,
                    SessionKey = result.SessionKey
                });
            }

            return(new OpenIDSessionKeyDTO {
                GooiosSessionKey = dto.GooiosSessionKey, OpenId = dto.OpenId
            });
        }