示例#1
0
        public async Task <ActionResult> SimLogin([FromBody] SimLoginRequestDTO request)
        {
            LoginResponseDTO res = new LoginResponseDTO();

            try
            {
                IPlatformSession session = ClusterClient.GetGrain <IPlatformSession>(request.user_name);
                Account          account = await session.VerifyAccount(Platform.Sim, request.user_name);

                if (account == null)
                {
                    throw new Exception($"VerifyAccount cant found {request.user_name}");
                }

                string access_token = JWT.GetAccessToken(account);
                await session.RefreshToken(access_token);

                res.data   = access_token;
                res.result = LoginResult.Success;
            }
            catch (Exception ex)
            {
                res.result = LoginResult.None;
                res.data   = ex.ToString();
                Logger.LogError(ex.ToString());
            }

            return(Json(res));
        }
示例#2
0
        public async Task <ActionResult> WeChatLogin([FromBody] WeChatLoginRequestDTO request)
        {
            LoginResponseDTO res = new LoginResponseDTO();

            try
            {
                string app_id      = Configuration.GetSection("WeChat")["AppId"];
                string app_secrect = Configuration.GetSection("WeChat")["AppSecret"];
                string url         = $"https://api.weixin.qq.com/sns/jscode2session?appid={app_id}&secret={app_secrect}&js_code={request.code}&grant_type=authorization_code";

                var client = HttpClients.CreateClient();
                var json   = await client.GetStringAsync(url);

                dynamic response = JsonConvert.DeserializeObject <dynamic>(json);

                if (response.errcode == 0)
                {
                    string unionid = (string)response.unionid;

                    IPlatformSession session = ClusterClient.GetGrain <IPlatformSession>(unionid);
                    Account          account = await session.VerifyAccount(Platform.WeChat, unionid);

                    if (account == null)
                    {
                        throw new Exception($"VerifyAccount cant found {unionid}");
                    }

                    string access_token = JWT.GetAccessToken(account);
                    await session.RefreshToken(access_token);

                    res.data   = access_token;
                    res.result = LoginResult.Success;
                }
                else
                {
                    res.result = LoginResult.WeChatLoginFaild;
                    res.data   = (string)response.errmsg;
                }
            }
            catch (Exception ex)
            {
                res.result = LoginResult.WeChatLoginFaild;
                res.data   = ex.ToString();
                Logger.LogError(ex.ToString());
            }

            return(Json(res));
        }