/// <summary> /// 群发微信消息 /// </summary> /// <param name="msgtype"></param> /// <param name="userdesc"></param> /// <param name="mediaid"></param> /// <param name="labelids"></param> /// <param name="sex"></param> /// <param name="msgcontent"></param> /// <param name="region"></param> /// <returns></returns> public JsonResult SendWXGroupMessage(string msgtype, string userdesc, string mediaid = "", string labelids = "", string sex = "", string msgcontent = "", string region = "") { WXMsgType type; if (Enum.TryParse <WXMsgType>(msgtype, out type)) { Entities.SendToUserLabel query = new Entities.SendToUserLabel(); string toUserDesc = string.Empty; if (!string.IsNullOrWhiteSpace(labelids)) { query.LabelIds = labelids.Split(',').Select(e => long.Parse(e)).ToArray(); } if (!string.IsNullOrWhiteSpace(sex)) { query.Sex = (Himall.CommonModel.SexType)Convert.ToInt32(sex); } if (!string.IsNullOrWhiteSpace(region)) { query.ProvinceId = long.Parse(region); } Entities.SendMsgInfo model = new Entities.SendMsgInfo() { AppId = this.SiteSettings.WeixinAppId, AppSecret = this.SiteSettings.WeixinAppSecret, Content = msgcontent, MediaId = mediaid, MsgType = type, ToUserLabel = query, ToUserDesc = userdesc }; var result = _iWXMsgTemplateService.SendWXMsg(model); if (result.errCode == "0") { return(Json(new { success = true })); } else { if (result.errMsg.Contains("success")) { return(Json(new { success = true })); } else { Log.Error("SendWXGroupMessage: " + result.errCode); return(Json(new { success = false, msg = result.errCode })); } } } return(Json(new { success = false, msg = "微信消息类型异常" })); }
/// <summary> /// 群发送消息 /// </summary> /// <param name="info"></param> /// <returns></returns> public static Entities.SendInfoResult SendWXMsg(Entities.SendMsgInfo info) { return(_iWXMsgTemplateService.SendWXMsg(info)); }