//当客户的渠道为0时,随机自动分配一个渠道编号(优先未锁定用户的),sendtype= 当为1的时候 有渠道也发送,一般是点击我的顾问时候发送,0=则是留言的时候变更渠道发送 public static int GetFenpeiChannel(int comid, string openid, int sendtype = 1, int companyid = 0, int channleid = 0) { var crmdata = new B2bCrmData(); MemberCardData carddata = new MemberCardData(); var channeldata = new MemberChannelData();//读取渠道信息 decimal idcard = 0; decimal channelid = 0; var userinfo_auto = carddata.GetMemberCardByOpenId(openid);;//获取微信操作账户 if (userinfo_auto != null) { idcard = userinfo_auto.Cardcode;; channelid = userinfo_auto.IssueCard;//获取渠道ID } //判断对 微信注册,网站注册渠道进行归0 var channeltype = channeldata.GetChannelDetail(int.Parse(channelid.ToString())); if (channeltype != null) { if (channeltype.Issuetype == 3 || channeltype.Issuetype == 4 || channeltype.Name == "默认渠道") {//如果渠道时微信注册或网站注册,渠道ID归0,下面自动重新分配有效渠道 channelid = 0; } } return(int.Parse(channelid.ToString())); }
//当客户的渠道为0时,随机自动分配一个渠道编号(优先未锁定用户的),sendtype= 当为1的时候 有渠道也发送,一般是点击我的顾问时候发送,0=则是留言的时候变更渠道发送 public static int AutoFenpeiChannel(int comid, string openid, int sendtype = 1, int companyid = 0, int channleid = 0) { var crmdata = new B2bCrmData(); MemberCardData carddata = new MemberCardData(); var channeldata = new MemberChannelData();//读取渠道信息 decimal idcard = 0; decimal channelid = 0; var userinfo_auto = carddata.GetMemberCardByOpenId(openid);;//获取微信操作账户 if (userinfo_auto != null) { idcard = userinfo_auto.Cardcode;; channelid = userinfo_auto.IssueCard;//获取渠道ID } //判断对 微信注册,网站注册渠道进行归0 var channeltype = channeldata.GetChannelDetail(int.Parse(channelid.ToString())); if (channeltype != null) { if (channeltype.Issuetype == 3 || channeltype.Issuetype == 4 || channeltype.Name == "默认渠道") {//如果渠道时微信注册或网站注册,渠道ID归0,下面自动重新分配有效渠道 channelid = 0; } } if (channelid == 0) { //查询在线渠道列表, int totalcount = 0; //在线数量 var channellist = channeldata.GetChannelListByComid(comid, companyid, 2, out totalcount, channleid); //先查询渠道列表 锁定客户为空的 if (channellist != null) { if (totalcount > 0) { //随机选择一个渠道 Random rand = new Random(); var channel_temp = channellist[rand.Next(0, totalcount - 1)]; var channelid_temp = channel_temp.Id; //绑定渠道 int upchannel = new MemberCardData().upCardcodeChannel(idcard.ToString(), channelid_temp); channelid = channelid_temp; } } //只有变更时才发送顾问信息 Sendweixinchient(openid, comid); } else { //点击顾问也发送 if (sendtype == 1) { Sendweixinchient(openid, comid); } } return(int.Parse(channelid.ToString())); }
//给客户发送顾问的信息 public static void Sendweixinchient(string openid, int comid) { WeiXinBasic basic = new WeiXinBasicData().GetWxBasicByComId(comid); string company = ""; string channelname = ""; string name = ""; WxMessageLogData messagelogdata = new WxMessageLogData(); //var messageinfo = messagelogdata.GetWxMessageLogSendTime(comid, openid);//查询2小时内是否给渠道发送过消息 //if (messageinfo == 0) //{ //会员 MemberCardData carddata = new MemberCardData(); var userdata = new B2bCrmData(); var userinfo = userdata.GetB2bCrm(openid, comid); if (userinfo != null) { name = userinfo.Name; } var cardinfo = carddata.GetMemberCardByOpenId(openid); if (cardinfo != null) { //获取渠道 var channeldata = new MemberChannelData(); var channelinfo = channeldata.GetChannelDetail(int.Parse(cardinfo.IssueCard.ToString())); if (channelinfo != null) { channelname = channelinfo.Name; //渠道名称 if (channelinfo.Companyid == 0) //内部渠道 { B2bCompanyData comdata = new B2bCompanyData(); var cominfo = comdata.GetCompanyBasicById(comid); if (cominfo != null) { company = cominfo.Com_name; } } else { //外部合作单位,调取合作单位名称 var channelcompanydata = new MemberChannelcompanyData(); var channelcominfo = channelcompanydata.GetChannelCompany(channelinfo.Companyid.ToString()); if (channelcominfo != null) { company = channelcominfo.Companyname; } } } } if (channelname != "" && channelname != "默认渠道" && channelname != "微信注册" && channelname != "网站注册") { //微信客服 文本消息 string data = SendWxMsg(comid, openid, 1, "", name + "你好,我是您的服务顾问" + company + "的 " + channelname + " ,\n请直接在微信上给我语音或文字留言,我会在手机微信上看到留言并很快回复。您不信? 现在就试试…", "", basic.Weixinno); //微信模板消息 new Weixin_tmplmsgManage().WxTmplMsg_SubscribeActReward(comid, openid, name + "你好,我是您的服务顾问" + company + "的 " + channelname + " , \\n请直接在微信上给我语音或文字留言,我会在手机微信上看到留言并很快回复。您不信? 现在就试试…\\n", "向《我的服务顾问:" + channelname + "》微信咨询", DateTime.Now.ToString(), ""); WxMessageLog messagelog = new WxMessageLog(); messagelog.Comid = comid; messagelog.Weixin = openid; var messageedit = messagelogdata.EditWxMessageLog(messagelog);//插入日志 //顾问录入的 问候语音 int isreplymediasuc = 0;//发送语音消息状态:0失败;1成功 WXAccessToken m_accesstoken = WeiXinManage.GetAccessToken(basic.Comid, basic.AppId, basic.AppSecret); //根据用户微信得到其顾问微信,然后根据微信和标记得到最新的一条保存路径(注:已经上传过语音的即mediaid!="") Wxmedia_updownlog udlog = new Wxmedia_updownlogData().GetWxmedia_updownlog(openid, (int)Clientuptypemark.DownGreetVoice, basic.Comid); if (udlog == null) { isreplymediasuc = 0; } else { string media_id = new WxUploadDownManage().UploadMultimedia(m_accesstoken.ACCESS_TOKEN, "voice", udlog.savepath); if (media_id != "") { Wxmedia_updownlog uplog = new Wxmedia_updownlog { id = 0, mediaid = media_id, mediatype = "voice", savepath = udlog.savepath, created_at = ConvertDateTimeInt(DateTime.Now).ToString(), createtime = DateTime.Now, opertype = "up", operweixin = openid, clientuptypemark = (int)Clientuptypemark.DownGreetVoice,//上传多媒体信息 comid = basic.Comid, relativepath = udlog.relativepath, txtcontent = "", isfinish = 1 }; int uplogresult = new Wxmedia_updownlogData().Edituploadlog(uplog); if (uplogresult == 0) { isreplymediasuc = 0; } else { //resxml = "<xml><ToUserName><![CDATA[" + requestXML.FromUserName + "]]></ToUserName><FromUserName><![CDATA[" + requestXML.ToUserName + "]]></FromUserName><CreateTime>" + ConvertDateTimeInt(DateTime.Now) + "</CreateTime><MsgType><![CDATA[voice]]></MsgType><Voice><MediaId><![CDATA[" + media_id + "]]></MediaId></Voice></xml>"; isreplymediasuc = 1; SendWxMsg(comid, openid, 2, "", "", media_id, basic.Weixinno); } } else { isreplymediasuc = 0; } } ////如果发送语音失败,则发送客服消息 //if (isreplymediasuc == 0) //{ //} } //} }