StringBuilder msg = new StringBuilder();
msg.Append("【客戶消費訂單消息提醒】"+ OrderType);
switch (OrderType)
{
case "汽車售后申請":
var returnSaleOrder= GetReturnSaleOrder(orderNo);
if (returnSaleOrder!= null)
{
var orgName = GetAreaName((returnSaleOrder.AreaGid));
msg.Append("新增汽車售后申請,");
msg.Append("售后片區:" + AreaName + ",");
msg.Append("售后訂單: " + returnSaleOrder.ReturnNo + ",");
msg.Append("發起時間:" + returnSaleOrder.CreateDate);
}
break;
case "汽車購買訂單":
var order = GetOrder(orderNo);
if (order != null)
{
var orgName = GetAreaName(DataConvertHelper.GetGuid(order.AreaGid));
msg.Append("汽車銷售訂單,");
msg.Append("銷售片區:" + AreaName + ",");
msg.Append("銷售訂單號: " + order.OrderNo + ",");
msg.Append("購買交易時間:" + order.PayDate);
}
break;
}
var sendMsg = msg.ToString(); //向不同配置企業微信人員發送服務通知消息 foreach (var item in IPAddressNotice.Split(",")) { var info = new MessageHelper(); info.Touser = item ; info.QyWxSend(sendMsg); } public MessageHelper() { var config = GetConfig("QyWx"); if (config != null) { this.Identify = config["Identify"]; //商戶名稱 this.Agentid = config["Agentid"];//企業應用ID this.Touser = config["Touser"]; //商戶企業微信號成員 this.ServiveUrl = config["ServiveUrl"]; //商戶企業微信服務地址 } } /// <summary> /// 發送企業微信 /// </summary> /// <param name="Message"></param> /// <returns></returns> public string QyWxSend(string Message) { string responseString = string.Empty; var requestData = new StringBuilder(); requestData.Append("<?xml version=\"1.0\" encoding=\"utf-8\"?>"); requestData.Append("<soap12:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap12=\"http://www.w3.org/2003/05/soap-envelope\">"); requestData.Append("<soap12:Body>"); requestData.Append("<SendMessage xmlns=\"http://gongsi.com/\">"); requestData.Append("<identify>" + this.Identify + "</identify>"); requestData.Append("<agentid>" + this.Agentid + "</agentid>"); requestData.Append("<touser>" + this.Touser + "</touser>"); requestData.Append("<content>" + Message + "</content>"); requestData.Append("</SendMessage>"); requestData.Append("</soap12:Body>"); requestData.Append("</soap12:Envelope>"); WebClient webClient = new WebClient(); byte[] postData = Encoding.UTF8.GetBytes(requestData.ToString()); string serviveUrl = this.ServiveUrl; webClient.Headers.Add("Content-Type", "application/soap+xml"); webClient.Headers.Add("ContentLength", postData.Length.ToString()); try { byte[] responseData = webClient.UploadData(serviveUrl, "POST", postData); responseString= Encoding.UTF8.GetString(responseData); } catch (Exception ex) { var response = new DataResponse { Exception = new ExceptionModel(ex) }; responseString= JsonHelper.SerializeObject(response); } return responseString } /// <summary> /// 發送企業微信消息 可多人 逗號間隔 /// </summary> /// <param name="Message"></param> /// <returns></returns> public string QyWxSendMore(string Users,string Message) { string responseString = string.Empty; var requestData = new StringBuilder(); requestData.Append("<?xml version=\"1.0\" encoding=\"utf-8\"?>"); requestData.Append("<soap12:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap12=\"http://www.w3.org/2003/05/soap-envelope\">"); requestData.Append("<soap12:Body>"); requestData.Append("<SendMessageList xmlns=\"http://gongsi.com/\">"); requestData.Append("<identify>" + this.Identify + "</identify>"); requestData.Append("<agentid>" + this.Agentid + "</agentid>"); requestData.Append("<TouserList>" + Users + "</TouserList>"); requestData.Append("<content>" + Message + "</content>"); requestData.Append("</SendMessageList>"); requestData.Append("</soap12:Body>"); requestData.Append("</soap12:Envelope>"); WebClient webClient = new WebClient(); byte[] postData = Encoding.UTF8.GetBytes(requestData.ToString()); string serviveUrl = this.ServiveUrl; webClient.Headers.Add("Content-Type", "application/soap+xml"); webClient.Headers.Add("ContentLength", postData.Length.ToString()); try { byte[] responseData = webClient.UploadData(serviveUrl, "POST", postData); responseString = Encoding.UTF8.GetString(responseData); } catch (Exception ex) { var response = new DataResponse { Exception = new ExceptionModel(ex) }; responseString =JsonHelper.SerializeObject(response); } return responseString; }