| | |
| | | if (option == null || option.AppId.IsNull() || option.AppSecret.IsNull()) |
| | | 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 jsonContent = JsonConvert.SerializeObject(command, new JsonSerializerSettings |
| | | { |
| | |
| | | .WithQueryParameter("access_token", accessToken) |
| | | .SetJsonContent(jsonContent)); |
| | | response.EnsureSuccessStatusCode(); |
| | | if (response.Content.Headers.ContentType.ToString() == "application/json; charset=UTF-8") |
| | | { |
| | | var jsonResult = await response.Content.ReadAsStringAsync(); |
| | | var callback = jsonResult.JsonTo<WxmpSendSubscribMessageResponse>(); |
| | | if (callback == null || callback.ErrorCode != 0) |
| | | throw Oops.Oh(EnumErrorCodeType.s510, $"发送订阅消息失败:{callback.ErrorMessage},请联系管理员"); |
| | | } |
| | | var jsonResult = await response.Content.ReadAsStringAsync(); |
| | | var callback = jsonResult.JsonTo<WxmpSendSubscribMessageResponse>(); |
| | | if (callback == null || callback.ErrorCode != 0) |
| | | throw Oops.Oh(EnumErrorCodeType.s510, $"发送订阅消息失败:{callback.ErrorMessage},请联系管理员"); |
| | | } |
| | | } |
| | | } |