public async Task <WxUser> GetSnsApiUserInfo(string code) { var token = await AccessTokenFactory.GetTokenAsync(code); if (token == null) { return(null); } string url = $"{WxConstants.SNSAPI_USERINFO_URL}?access_token={token.AccessToken}&openid={token.OpenId}&lang=zh_CN"; return(await WxClient.GetAsync <WxUser>(url)); }
public async Task SendTempMsg(string toUser, string tempId, object data, string url = "", string color = null) { var token = await AccessTokenFactory.GetTokenAsync(); if (token == null) { return; } var msg = new { touser = toUser, template_id = tempId, data, url, color }; string uri = $"{WxConstants.CGI_BIN_TEMPLATE_URL}?access_token={token.AccessToken}"; var content = new StringContent(msg.ToJsonString(), System.Text.Encoding.UTF8, "application/json"); await WxClient.PostAsync(uri, content); }
public WxService(IOptions <WxOptions> options, HttpClient client, IMemoryCache cache) { _options = options.Value; WxClient.Init(client, cache, _options); }