/// <summary>
        /// 联系客服(菜单)
        /// </summary>
        /// <param name="recMsg"></param>
        /// <returns></returns>
        public async Task <string> ContactKf(PubReceiveMsg recMsg)
        {
            try
            {
                var timeStamp = ComHelper.ConvertDateTimeInt(DateTime.Now);
                if (!IsWorkTime())
                {
                    var msg = "您好!现在非客服上班时间,请您在每天9-22点联系我们的客服美眉!";
                    return(await wxAutoComResponse.SendWxText(recMsg.FromUserName, recMsg.ToUserName, timeStamp, msg));
                }
                else
                {
                    PubKfApi.SendTextMsg(recMsg.FromUserName, "正在为你转接在线客服,请稍后.....");
                    var msg = PubMsgApi.BuildKfTransferMsg(recMsg.FromUserName, recMsg.ToUserName, timeStamp);
                    logHelper.Debug("ContactKf:msg:" + msg.JsonSerialize());
                    // 发送客服消息提醒
                    return(await wxAutoComResponse.AutoMsgResponse(msg));
                }
            }
            catch (Exception ex)
            {
                logHelper.Error("ContactKf:联系客服失败:" + ex.Message + "        " + ex.StackTrace);
            }

            return(wxAutoComResponse.ResponseOK());;
        }
Exemple #2
0
        public async Task <Result <string> > UpdWxKfImg([FromBody] WxKfInfoShow item)
        {
            try
            {
                // 转换路径
                if (string.IsNullOrEmpty(item.KfHeadUpVir))
                {
                    return(new Result <string> {
                        Message = "请先上传客服头像!"
                    });
                }

                // 头像物理路径
                var phyPath = ComHelper.GetPhyWWWRoot(item.KfHeadUpVir);
                var apiRes  = PubKfApi.SetKFHeadImg(phyPath, item.KfAccount);
                logHelper.Debug("UpdWxKfImg:修改客服头像结果:" + apiRes.JsonSerialize());
                if (!apiRes.IsSuss)
                {
                    var msg = "修改客服头像:错误代码:" + apiRes.errcode + "     信息:" + apiRes.errmsg;
                    logHelper.Error("UpdWxKfImg:" + msg);
                    return(new Result <string> {
                        Message = msg
                    });
                }

                // 保存客服信息
                item.Updater    = currentUser.UserName;
                item.UpdateTime = DateTime.Now;
                var upRes = await repo.UpdateAsync(item, new List <string> {
                    "KfHeadUpVir", "Updater", "UpdateTime"
                });

                return(new Result <string> {
                    IsSucc = upRes, Message = $"更新微信客服头像{(upRes ? "成功!" : "失败!")}"
                });
            }
            catch (Exception ex)
            {
                logHelper.Error("UpdWxKfImg:更新微信客服头像失败:" + ex.Message + "     " + ex.StackTrace);
            }

            return(new Result <string> {
                Message = "更新微信客服头像失败!"
            });
        }
Exemple #3
0
        public async Task <Result <string> > InviteWxKf([FromBody] WxKfInfoShow item)
        {
            try
            {
                if (string.IsNullOrEmpty(item.InviteWx))
                {
                    return(new Result <string> {
                        Message = "请先输入客服微信号!"
                    });
                }

                var apiRes = PubKfApi.SendKfInvite(item.KfAccount, item.InviteWx);
                logHelper.Debug("InviteWxKf:邀请微信客服结果:" + apiRes.JsonSerialize());
                if (!apiRes.IsSuss)
                {
                    var msg = "邀请微信客服:错误代码:" + apiRes.errcode + "     信息:" + apiRes.errmsg;
                    logHelper.Error("InviteWxKf:" + msg);
                    return(new Result <string> {
                        Message = msg
                    });
                }

                // 保存客服信息
                item.InviteWx     = item.InviteWx;
                item.InviteStatus = "waiting";
                item.Updater      = currentUser.UserName;
                item.UpdateTime   = DateTime.Now;
                var upRes = await repo.UpdateAsync(item, new List <string> {
                    "InviteWx", "InviteStatus", "Updater", "UpdateTime"
                });

                return(new Result <string> {
                    IsSucc = upRes, Message = $"邀请微信客服{(upRes ? "成功!" : "失败!")}"
                });
            }
            catch (Exception ex)
            {
                logHelper.Error("InviteWxKf:邀请微信客服失败:" + ex.Message + "     " + ex.StackTrace);
            }

            return(new Result <string> {
                Message = "邀请微信客服失败!"
            });
        }
Exemple #4
0
        public async Task <Result <string> > DelWxKfImg([FromBody] WxKfInfoShow item)
        {
            try
            {
                if (string.IsNullOrEmpty(item.KfAccount))
                {
                    return(new Result <string> {
                        Message = "请先输入客服账号!"
                    });
                }

                var apiRes = PubKfApi.DeleteKF(item.KfAccount);
                logHelper.Debug("DelWxKfImg:删除微信客服结果:" + apiRes.JsonSerialize());
                if (!apiRes.IsSuss)
                {
                    var msg = "删除微信客服:错误代码:" + apiRes.errcode + "     信息:" + apiRes.errmsg;
                    logHelper.Error("DelWxKfImg:" + msg);
                    return(new Result <string> {
                        Message = msg
                    });
                }

                // 保存客服信息
                item.IsDel      = 1;
                item.Updater    = currentUser.UserName;
                item.UpdateTime = DateTime.Now;
                var upRes = await repo.UpdateAsync(item, new List <string> {
                    "IsDel", "Updater", "UpdateTime"
                });

                return(new Result <string> {
                    IsSucc = upRes, Message = $"删除微信客服{(upRes ? "成功!" : "失败!")}"
                });
            }
            catch (Exception ex)
            {
                logHelper.Error("DelWxKfImg:删除微信客服失败:" + ex.Message + "     " + ex.StackTrace);
            }

            return(new Result <string> {
                Message = "删除微信客服失败!"
            });
        }
        /// <summary>
        /// 联系客服
        /// </summary>
        /// <param name="recMsg"></param>
        /// <returns></returns>
        public Result <string> ChatWithKf(PubReceiveMsgCData recMsg)
        {
            try
            {
                if (IsWorkTime() && IsIn5Min(recMsg.FromUserName) && IsKfMsg(recMsg))
                {
                    PubKfApi.SendTextMsg(recMsg.FromUserName, "正在为你转接在线客服,请稍后.....");
                    var msg = PubMsgApi.BuildKfTransferMsg(recMsg.FromUserName, recMsg.ToUserName, recMsg.CreateTime);
                    return(new Result <string> {
                        IsSucc = true, Data = msg
                    });
                }
            }
            catch (Exception ex)
            {
                logHelper.Error("ChatWithKf:联系客服失败:" + ex.Message + "     " + ex.StackTrace);
            }

            return(new Result <string> {
                Message = "联系客服失败!"
            });
        }
        /// <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(WxAutoKeywordShow item, string openId)
        {
            try
            {
                // 自动推送类型
                Enum_ApMsgType type = ComHelper.GetEnumValueByStr <Enum_ApMsgType>(item.ContentType);
                // 发送客服消息预览
                PubApiResult 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.GetAutoKeywordBackNews(item);

                    apiRes = PubKfApi.SendNewsMsg(openId, lstArts);
                    break;

                case Enum_ApMsgType.RedBag:
                    return(await wxAutoConvertHelper.SendAutoKeywordRedPack(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 = "发送预览消息失败!"
            });
        }
Exemple #8
0
        public async Task <Result <string> > SyncWxKf([FromBody] WxKfInfoShow item)
        {
            try
            {
                var apiRes = PubKfApi.GetKFList();
                logHelper.Debug("SyncWxKf:同步微信客服信息结果:" + apiRes.JsonSerialize());
                if (!apiRes.IsSuss)
                {
                    var msg = "同步微信客服信息:错误代码:" + apiRes.errcode + "     信息:" + apiRes.errmsg;
                    logHelper.Error("SyncWxKf:" + msg);
                    return(new Result <string> {
                        Message = msg
                    });
                }

                var lstKf = apiRes.kf_list;
                // 保存客服列表信息
                var dtNow        = DateTime.Now;
                var userName     = currentUser.UserName;
                var lstKfAcounts = new List <string>();
                foreach (var kf in lstKf)
                {
                    var exist = await repo.FirstOrDefaultAsync <WxKfInfoShow>(x => x.KfAccount == kf.kf_account);

                    if (exist == null)
                    {
                        exist            = new WxKfInfoShow();
                        exist.Creater    = userName;
                        exist.CreateTime = dtNow;
                    }

                    exist.KfAccount        = kf.kf_account;
                    exist.KfNick           = kf.kf_nick;
                    exist.KfId             = kf.kf_id;
                    exist.KfHeadimgurl     = kf.kf_headimgurl;
                    exist.KfWx             = kf.kf_wx;
                    exist.InviteWx         = kf.invite_wx;
                    exist.InviteExpireTime = kf.invite_expire_time;
                    exist.InviteStatus     = kf.invite_status;
                    exist.IsDel            = 0;
                    exist.Updater          = userName;
                    exist.UpdateTime       = dtNow;
                    var saveRes = await repo.SaveAsync(exist);

                    lstKfAcounts.Add(exist.KfAccount);
                }

                // 删除不用的客服
                if (lstKfAcounts.Count > 0)
                {
                    var delRes = await repo.ExecuteCommandAsync(" UPDATE WxKfInfo SET IsDel = 1, Updater = @userName, UpdateTime = @dtNow WHERE KfAccount NOT IN (@lstKfAcounts) ",
                                                                new { userName, dtNow, lstKfAcounts });
                }

                return(new Result <string> {
                    IsSucc = true, Message = "同步微信客服信息成功!"
                });
            }
            catch (Exception ex)
            {
                logHelper.Error("SyncWxKf:同步微信客服信息失败:" + ex.Message + "     " + ex.StackTrace);
            }

            return(new Result <string> {
                Message = "同步微信客服信息失败!"
            });
        }
Exemple #9
0
        public async Task <Result <string> > SaveWxKf([FromBody] WxKfInfoShow item)
        {
            try
            {
                var dtNow    = DateTime.Now;
                var userName = currentUser.UserName;
                // 客服信息
                var kfInfo = new PubKf();
                // 客服账号名称
                var kfSuffix = cacheHelper.GetDbConfValByKey("kfsuffix");
                var accName  = item.KfAccount;
                if (!accName.EndsWith(kfSuffix))
                {
                    item.KfAccount = string.Format("{0}@{1}", accName, kfSuffix);
                }

                kfInfo.kf_account = item.KfAccount;
                kfInfo.nickname   = item.KfNick;
                kfInfo.password   = ComHelper.MD5Sign("ramikf");
                if (!item.CreateTime.HasValue)
                {
                    // 创建客服
                    var addRes = PubKfApi.AddKF(kfInfo);
                    logHelper.Debug("SaveWxKf:创建客服结果:" + addRes.JsonSerialize());
                    if (!addRes.IsSuss)
                    {
                        var msg = "创建客服失败:错误代码:" + addRes.errcode + "     信息:" + addRes.errmsg;
                        logHelper.Error("SaveWxKf:" + msg);
                        return(new Result <string> {
                            Message = msg
                        });
                    }

                    // 保存客服信息
                    item.Creater    = userName;
                    item.Updater    = userName;
                    item.CreateTime = dtNow;
                    item.UpdateTime = dtNow;
                    await repo.AddAsync(item);

                    return(new Result <string> {
                        IsSucc = true, Message = "创建客服成功!"
                    });
                }
                else
                {
                    // 修改客服
                    var editRes = PubKfApi.UpdateKF(kfInfo);
                    logHelper.Debug("SaveWxKf:更新客服结果:" + editRes.JsonSerialize());
                    if (!editRes.IsSuss)
                    {
                        var msg = "更新客服失败:错误代码:" + editRes.errcode + "     信息:" + editRes.errmsg;
                        logHelper.Error("SaveWxKf:" + msg);
                        return(new Result <string> {
                            Message = msg
                        });
                    }

                    // 保存客服信息
                    item.Updater    = userName;
                    item.UpdateTime = dtNow;
                    var upRes = repo.Update(item, new List <string> {
                        "KfNick", "Updater", "UpdateTime"
                    });

                    return(new Result <string> {
                        IsSucc = upRes, Message = $"更新客服{(upRes ? "成功!" : "失败!")}"
                    });
                }
            }
            catch (Exception ex)
            {
                logHelper.Error("SaveWxKf:更新微信客服信息失败:" + ex.Message + "     " + ex.StackTrace);
            }

            return(new Result <string> {
                Message = "更新微信客服信息失败!"
            });
        }