1
This commit is contained in:
28
Services/WeChatHttpClient.cs
Normal file
28
Services/WeChatHttpClient.cs
Normal file
@@ -0,0 +1,28 @@
|
||||
using System.Text;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace WeChatSharp.Services;
|
||||
|
||||
public class WeChatHttpClient
|
||||
{
|
||||
private readonly WeChatAccessTokenService _accessTokenService;
|
||||
private readonly HttpClient _httpClient;
|
||||
|
||||
public WeChatHttpClient(WeChatAccessTokenService accessTokenService, HttpClient httpClient)
|
||||
{
|
||||
_accessTokenService = accessTokenService;
|
||||
_httpClient = httpClient;
|
||||
}
|
||||
public async Task<string> PostJsonAsync<T>(string url,T model)
|
||||
{
|
||||
var json = JsonConvert.SerializeObject(model);
|
||||
var jsonContent = new StringContent(json, Encoding.UTF8, "application/json");
|
||||
return await PostAsync(url, jsonContent);
|
||||
}
|
||||
public async Task<string> PostAsync(string url,HttpContent content)
|
||||
{
|
||||
url += $"?{WeChatAccessTokenService._AccessToken}={await _accessTokenService.GetAccessTokenAsync()}";
|
||||
var responseMessage = await _httpClient.PostAsync(url, content);
|
||||
return await responseMessage.Content.ReadAsStringAsync();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user