接口文件
This commit is contained in:
@@ -0,0 +1,79 @@
|
||||
using System;
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
using Hncore.Infrastructure.Common;
|
||||
using Hncore.Infrastructure.Extension;
|
||||
using Hncore.Infrastructure.Serializer;
|
||||
using Hncore.Infrastructure.WebApi;
|
||||
using MsgCenterClient.WechatMpTplMsg;
|
||||
|
||||
namespace MsgCenterClient
|
||||
{
|
||||
public class MsgCenterHttpClient
|
||||
{
|
||||
private IHttpClientFactory _httpClientFactory;
|
||||
|
||||
internal static string _BaseUrl = "";
|
||||
|
||||
public string BaseUrl => _BaseUrl;
|
||||
|
||||
public MsgCenterHttpClient(IHttpClientFactory httpClientFactory)
|
||||
{
|
||||
_httpClientFactory = httpClientFactory;
|
||||
}
|
||||
|
||||
private HttpClient CreateHttpClient()
|
||||
{
|
||||
return _httpClientFactory.CreateClient();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 发送微信公众号模板消息
|
||||
/// </summary>
|
||||
/// <param name="msgBase"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<ApiResult> SendWechatMpTplMsg(MsgBase msgBase)
|
||||
{
|
||||
var body = msgBase.ToRequestObject();
|
||||
|
||||
try
|
||||
{
|
||||
var res = await CreateHttpClient()
|
||||
.PostAsJsonGetString(BaseUrl + "/api/msgcenter/v1/msg/SendMPTplMessage", body);
|
||||
|
||||
return res.FromJsonTo<ApiResult>();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
LogHelper.Error("发送微信公众号模板消息失败", e + "\n消息内容:\n" + body.ToJson(true));
|
||||
|
||||
return new ApiResult(ResultCode.C_UNKNOWN_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 发送微信小程序模板消息
|
||||
/// </summary>
|
||||
/// <param name="msgBase"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<ApiResult> SendMiniAppTplMsg(MiniAppMsgBase msgBase)
|
||||
{
|
||||
var body = msgBase.ToRequestObject();
|
||||
|
||||
try
|
||||
{
|
||||
var res = await CreateHttpClient()
|
||||
.PostAsJsonGetString(BaseUrl + "/api/msgcenter/v1/msg/SendMiniAppTplMessage", body);
|
||||
|
||||
return res.FromJsonTo<ApiResult>();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
LogHelper.Error("发送小程序模板消息失败", e + "\n消息内容:\n" + body.ToJson(true));
|
||||
|
||||
return new ApiResult(ResultCode.C_UNKNOWN_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user