using BBWY.Common.Http; using BBWY.Common.Models; using Newtonsoft.Json; using System.Net.Http; namespace BBWY.Server.Business { public class QYMessageCenterBusiness : IDenpendency { private RestApiService restApiService; public QYMessageCenterBusiness(RestApiService restApiService) { this.restApiService = restApiService; } public void SendMessage(string channel, string teamId, string shopId, string appCode, string title, string content, string senderId, string recevierId) { SendMessage(channel, teamId, shopId, appCode, title, content, string.Empty, senderId, recevierId, false); } public void SendMessage(string channel, string teamId, string shopId, string appCode, string title, string content, string customTypeCode, string senderId, string recevierId) { SendMessage(channel, teamId, shopId, appCode, title, content, customTypeCode, senderId, recevierId, false); } public void SendMessage(string channel, string teamId, string shopId, string appCode, string title, object jsonContent, string customTypeCode, string senderId, string recevierId) { SendMessage(channel, teamId, shopId, appCode, title, JsonConvert.SerializeObject(jsonContent), customTypeCode, senderId, recevierId, true); } private void SendMessage(string channel, string teamId, string shopId, string appCode, string title, string content, string customTypeCode, string senderId, string recevierId, bool isJsonMsg) { var httpResult = restApiService.SendRequest("http://api.msg.qiyue666.com", "api/message/send", new { appCode, channel, teamId, shopId, title, content, customTypeCode, senderId, recevierId, isJsonMsg }, null, HttpMethod.Post); if ((httpResult.StatusCode != System.Net.HttpStatusCode.OK)) throw new BusinessException($"QYMessageCenterBusiness SendMessage HttpCode {httpResult.StatusCode}"); var response = JsonConvert.DeserializeObject(httpResult.Content); if (!response.Success) throw new BusinessException($"QYMessageCenterBusiness SendMessage {response.Msg}"); } } }