/// <summary> /// 定时推送消息 /// </summary> /// <param name="push"></param> /// <param name="baseMsg"></param> /// <param name="apMsgType"></param> /// <param name="user"></param> /// <returns></returns> private async Task SendAutoPushMsg(WxAutoPushShow push, PubKfBaseMsg baseMsg, Enum_ApMsgType apMsgType, WxUserInfo user) { // 文本消息 昵称赋值 if (apMsgType == Enum_ApMsgType.Text) { var txt = push.TextContent.Replace("{nickname}", user.NickName); baseMsg = new PubKfTextMsg { text = new PubKfTextContent { content = txt } }; } // 红包单独发送 if (apMsgType == Enum_ApMsgType.RedBag) { var apiRes = await wxAutoConvertHelper.SendAutoPushRedPack(push, user.OpenId); logHelper.Debug("AutoPushJob:发送红包用户:" + user.OpenId + " 结果:" + apiRes); } else { // 非红包消息发送 var apiRes = PubKfApi.SendMsg(baseMsg, user.OpenId); if (apiRes.IsSuss) { await wxAutoConvertHelper.SaveAutoPushHis(push.Id, user.OpenId); } else { logHelper.Error("AutoPushJob:发送消息给" + user.OpenId + "失败:" + apiRes.errcode + " " + apiRes.errmsg); } logHelper.Debug("AutoPushJob:发送消息用户:" + user.OpenId + " 结果:" + apiRes.JsonSerialize()); } }
/// <summary> /// 定时推送(客服消息) /// </summary> /// <param name="item"></param> /// <param name="openId"></param> /// <returns></returns> public async Task <Result <string> > AutoRespond(WxAutoPushShow item, string openId) { try { // 自动推送类型 var type = ComHelper.GetEnumValueByStr <Enum_ApMsgType>(item.ContentType); // 发送客服消息预览 var apiRes = new PubApiResult(); switch (type) { case Enum_ApMsgType.Text: item.TextContent = item.TextContent.Replace("{nickname}", string.Empty); apiRes = PubKfApi.SendTextMsg(openId, item.TextContent); break; case Enum_ApMsgType.Image: apiRes = PubKfApi.SendImageMsg(openId, item.MediaId); break; case Enum_ApMsgType.Voice: apiRes = PubKfApi.SendVoiceMsg(openId, item.MediaId); break; case Enum_ApMsgType.News: apiRes = PubKfApi.SendMpNewsMsg(openId, item.MediaId); break; case Enum_ApMsgType.Video: apiRes = PubKfApi.SendVideoMsg(openId, item.MediaId, item.VideoThumbMediaId, item.VideoTitle, item.VideoDescription); break; case Enum_ApMsgType.BackNews: var lstArts = await wxAutoConvertHelper.GetAutoPushBackNews(item); apiRes = PubKfApi.SendNewsMsg(openId, lstArts); break; case Enum_ApMsgType.RedBag: return(await wxAutoConvertHelper.SendAutoPushRedPack(item, openId)); default: break; } logHelper.Debug("PrevKeyword:预览返回结果:" + ComHelper.JsonSerialize(apiRes)); if (!apiRes.IsSuss) { var msg = "预览出错:" + apiRes.errcode + " " + apiRes.errmsg; logHelper.Error("PrevKeyword:" + msg); return(new Result <string> { Message = msg }); } return(new Result <string> { IsSucc = true, Message = "发送预览消息成功!" }); } catch (Exception ex) { logHelper.Error("PrevKeyword:发送预览消息失败:" + ex.Message + " " + ex.StackTrace); } return(new Result <string> { Message = "发送预览消息失败!" }); }