You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
|
using Ds.Module.WeChat.Models;
|
|
|
|
|
using Ds.Module.WeChat.Service;
|
|
|
|
|
using DS.Module.Nuget;
|
|
|
|
|
using MediatR;
|
|
|
|
|
using SKIT.FlurlHttpClient.Wechat.Api;
|
|
|
|
|
using SKIT.FlurlHttpClient.Wechat.Work.Events;
|
|
|
|
|
|
|
|
|
|
namespace Ds.Module.WeChat.Mediator
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 表示 TEXT 事件的数据
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class TextMessageEventCommand : IRequest<WeChatApiCallBack>
|
|
|
|
|
{
|
|
|
|
|
public TextMessageEvent EventObj { get; set; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 处理TEXT 事件的数据-以被动回复文本消息为例
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class TextMessageEventCommandHandler : IRequestHandler<TextMessageEventCommand, WeChatApiCallBack>
|
|
|
|
|
{
|
|
|
|
|
private readonly IWeChatApiHttpClientFactory _weChatApiHttpClientFactory;
|
|
|
|
|
|
|
|
|
|
public TextMessageEventCommandHandler(IWeChatApiHttpClientFactory weChatApiHttpClientFactory)
|
|
|
|
|
{
|
|
|
|
|
_weChatApiHttpClientFactory = weChatApiHttpClientFactory;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task<WeChatApiCallBack> Handle(TextMessageEventCommand request, CancellationToken cancellationToken)
|
|
|
|
|
{
|
|
|
|
|
var jm = new WeChatApiCallBack() { Status = true };
|
|
|
|
|
|
|
|
|
|
if (request.EventObj != null)
|
|
|
|
|
{
|
|
|
|
|
var client = _weChatApiHttpClientFactory.CreateWxOpenClient();
|
|
|
|
|
var replyModel = new SKIT.FlurlHttpClient.Wechat.Api.Events.TransferCustomerServiceReply()
|
|
|
|
|
{
|
|
|
|
|
ToUserName = request.EventObj.FromUserName,
|
|
|
|
|
FromUserName = request.EventObj.ToUserName,
|
|
|
|
|
CreateTimestamp = CommonHelper.GetTimeStampByTotalSeconds()
|
|
|
|
|
};
|
|
|
|
|
var replyXml = client.SerializeEventToXml(replyModel);
|
|
|
|
|
jm.Data = replyXml;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return await Task.FromResult(jm);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|