using System.Threading.Tasks;
using GxPress.Common.Http;
using Newtonsoft.Json;
using GxPress.Repository.Interface;
using GxPress.Service.Interface.WeChat;
namespace GxPress.Service.Implement.WeChat
{
///
/// 微信开发平台
///
public class WeChatOpen:IWeChatOpen
{
private readonly IUserRepository userRepository;
public WeChatOpen(IUserRepository userRepository)
{
this.userRepository = userRepository;
}
public async Task GetWeChatOpenUserInfoAsync(string code)
{
var url = $@"https://api.weixin.qq.com/sns/oauth2/access_token?appid=wx7f8c16978c2ab126&secret=d157ee6a4b2c9d437dab4ebc37fd2fa8&code={code}&grant_type=authorization_code";
var response = await HttpClientHelper.GetHeadersAsync(url, null);
if (response.IsSuccessStatusCode)
{
var content = await response.Content.ReadAsStringAsync();
var data = JsonConvert.DeserializeObject(content);
if (string.IsNullOrEmpty(data.errmsg))
{
return data.openid;
}
}
return string.Empty;
}
}
//如果好用,请收藏地址,帮忙分享。
public class WeChatOpenResult
{
///
///
///
public string access_token { get; set; }
///
///
///
public int expires_in { get; set; }
///
///
///
public string refresh_token { get; set; }
///
///
///
public string openid { get; set; }
///
///
///
public string scope { get; set; }
///
///
///
public string unionid { get; set; }
///
///
///
public int errcode { get; set; }
///
///
///
public string errmsg { get; set; }
}
}