public static string GetUserId(string accessToken, string code) { string url = string.Format("https://oapi.dingtalk.com/user/getuserinfo?access_token={0}&code={1}", accessToken, code); try { string response = HttpRequestHelper.Get(url); GetUserInfoModel model = JsonConvert.DeserializeObject <GetUserInfoModel>(response); if (model != null) { if (model.errcode == 0) { return(model.userid); } else { throw new Exception(model.errmsg); } } } catch (Exception ex) { throw; } return(string.Empty); }
public async Task GetUserInfo_ShouldSuccess_WithExpectedParameters() { GetUserInfoModel model = new GetUserInfoModel { OpenID = OpenID }; IWeChatClient client = new DefaultClient(ServerUrl, AppId, AppSecret); var requestToken = new GetAccessTokenReqeust(); var resultToken = await client.GetAccessToken(requestToken); var token = resultToken.AccessToken; var request = new GetUserInfoRequest(); request.Parameters = model; var result = await client.Execute(request, token); Assert.True(result.ErrorCode == 0); }