Beispiel #1
0
        public async Task <IActionResult> WeChatUser(int acountId, string code)
        {
            if (string.IsNullOrEmpty(code))
            {
                throw new ApiException(-1, "code不能为空");
            }
            var wxConfig    = _config.WechatAccount.FirstOrDefault(x => x.AcountId == acountId);
            var accessToken = await _oauthService.GetWeChatAccessTokenAsync(wxConfig, code);

            if (accessToken == null)
            {
                throw new ApiException(-1, "code无效");
            }

            var result = await _oauthService.GetWeChatUserInfoAsync(accessToken.Access_Token, accessToken.OpenId);

            return(new ApiResult <WeChatUserInfo>(result));
        }