/// <summary> /// 处理微信的POST请求 /// </summary> /// <param name="context"></param> /// <returns>返回xml响应</returns> private string HandlePost(HttpContext context) { RequestMessageHelper helper = new RequestMessageHelper(context.Request); if (helper.Message != null) { Message.Insert(new Message(MessageType.Request, helper.Message.ToString())); ResponseBaseMessage responseMessage = HandleRequestMessage(helper.Message); Message.Insert(new Message(MessageType.Response, responseMessage.ToString())); return(responseMessage.ToXml(helper.EncryptType)); } else { return(string.Empty); } }
/// <summary> /// 发送客服消息 /// </summary> /// <param name="responseMessage">响应消息</param> /// <param name="kfAccount">客服账号</param> /// <returns>返回发送是否成功</returns> public static ErrorMessage SendMessage(ResponseBaseMessage responseMessage, string kfAccount = "") { if (responseMessage == null) { return(new ErrorMessage(ErrorMessage.ExceptionCode, "响应消息不能为null。")); } if (!string.IsNullOrEmpty(kfAccount) && !CheckKfAccount(kfAccount)) { return(new ErrorMessage(ErrorMessage.ExceptionCode, "客服账号格式不正确。")); } string json = responseMessage.ToJson(); if (!string.IsNullOrWhiteSpace(kfAccount)) { string kfInfo = string.Format(",\"customservice\":{0}}", JsonConvert.SerializeObject(new { kf_account = kfAccount })); json = json.Remove(json.Length - 1) + kfInfo; } return(HttpHelper.RequestErrorMessage(urlForSendingMessage, responseMessage.FromUserName, null, httpMethodForSendingMessage, json)); }