| | |
| | | using Azure.Core; |
| | | using Furion.FriendlyException; |
| | | using Furion.HttpRemote; |
| | | using Furion.JsonSerialization; |
| | | using Mapster; |
| | | using Microsoft.Extensions.Caching.Distributed; |
| | | using Microsoft.Extensions.Options; |
| | |
| | | using System.Net.Http.Json; |
| | | using System.Text; |
| | | using System.Text.Json.Nodes; |
| | | using System.Text.Unicode; |
| | | using System.Threading; |
| | | using System.Threading.Tasks; |
| | | using static System.Net.Mime.MediaTypeNames; |
| | | |
| | | namespace ApiTools.Core |
| | | { |
| | |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 该接口用于发送订阅消息 |
| | | /// 发送订阅消息 |
| | | /// </summary> |
| | | /// <param name="command"></param> |
| | | /// <returns></returns> |
| | | public async Task<string> WxSend(SendRequest command) |
| | | public async Task WxmpSendSubscribMessage(WxmpSendSubscribMessageRequest command) |
| | | { |
| | | var option = options.Value.Items.FirstOrDefault(it => it.Code == command.WxmpCode); |
| | | if (option == null || option.AppId.IsNull() || option.AppSecret.IsNull()) |
| | | throw Oops.Oh(EnumErrorCodeType.s400, "获取小程序码失败,缺失配置:WxmpOptions"); |
| | | throw Oops.Oh(EnumErrorCodeType.s400, "发送订阅消息失败,缺失配置:WxmpOptions"); |
| | | command.EnvVersion = option.EnvVersion; |
| | | if (!options.Value.SubscribMessageTemplates.ContainsKey(command.TemplateId)) |
| | | throw Oops.Oh(EnumErrorCodeType.s400, "发送订阅消息失败,模板不存在"); |
| | | var template = options.Value.SubscribMessageTemplates[command.TemplateId]; |
| | | command.TemplateId = template.TemplateId; |
| | | if (command.Page.IsNull()) command.Page = template.Page; |
| | | var accessToken = await GetAccessToken(command.WxmpCode); |
| | | var request = command.Adapt<SendRequest>(); |
| | | var jsonContent = JsonConvert.SerializeObject(request, new JsonSerializerSettings |
| | | var jsonContent = JsonConvert.SerializeObject(command, new JsonSerializerSettings |
| | | { |
| | | NullValueHandling = NullValueHandling.Ignore |
| | | }); |
| | |
| | | if (response.Content.Headers.ContentType.ToString() == "application/json; charset=UTF-8") |
| | | { |
| | | var jsonResult = await response.Content.ReadAsStringAsync(); |
| | | var callback = jsonResult.JsonTo<SendResponse>(); |
| | | var callback = jsonResult.JsonTo<WxmpSendSubscribMessageResponse>(); |
| | | if (callback == null || callback.ErrorCode != 0) |
| | | //throw Oops.Oh(EnumErrorCodeType.s510, $"获取小程序码失败:{callback.errmsg},请联系管理员"); |
| | | return jsonResult; |
| | | throw Oops.Oh(EnumErrorCodeType.s510, $"发送订阅消息失败:{callback.ErrorMessage},请联系管理员"); |
| | | } |
| | | //var stream = await response.Content.ReadAsStreamAsync(); |
| | | //var result = AliyunOSSUtils.Upload(command, stream, command.OssFileName); |
| | | return ""; |
| | | } |
| | | |
| | | |
| | | } |
| | | } |