基于盛派SDK开发(配置篇一):企业号充当服务号多客服功能

背景:

由于服务号不支持手机版多客服,可以通过企业号来实现此功能。

效果图:

1,服务号:

 

2,企业号:

 

 

服务号配置:

 

   其中WeChatController代码如下:

   

  /// <summary>
    /// 与微信服务器通讯
    /// </summary>
    public class WeChatController : Controller
    {        
        [HttpGet]
        [ActionName("Index")]
        public ActionResult Get(string signature, string timestamp, string nonce, string echostr)
        {
            if (CheckSignature.Check(signature, timestamp, nonce, WeChatParameter._weiXinToken))
            {
                return Content(echostr); //返回随机字符串则表示验证通过
            }
            else
            {
                return Content("failed:" + signature + "," + CheckSignature.GetSignature(timestamp, nonce, WeChatParameter._weiXinToken) + "。如果您在浏览器中看到这条信息,表明此Url可以填入微信后台。");
            }
        }

        /// <summary>
        /// 用户发送消息后,微信平台自动Post一个请求到这里,并等待响应XML。
        ///
        /// 
        /// </summary>
        [HttpPost]
        [ActionName("Index")]
        public ActionResult Post(PostModel postModel)
        {
            if (!CheckSignature.Check(postModel.Signature, postModel.Timestamp, postModel.Nonce, WeChatParameter._weiXinToken))
            {
                return Content("参数错误!");
            }

            postModel.Token =WeChatParameter._weiXinToken;//根据自己后台的设置保持一致
            postModel.EncodingAESKey = WeChatParameter._encodingAESKey;//根据自己后台的设置保持一致
            postModel.AppId = WeChatParameter._appID;//根据自己后台的设置保持一致

            //自定义MessageHandler,对微信请求的详细判断操作都在这里面。

            var messageHandler = new CustomMessageHandler(Request.InputStream, postModel);
            messageHandler.Execute();//执行微信处理过程

            return new FixWeixinBugWeixinResult(messageHandler);//返回结果

        }
    }

  

企业号配置:

1,进去企业号后台 》服务中心 》企业客服 。如图:

  

2,设置内部成员客服

    

 

3,外部成员客服接口

    

注意:内部客服与外部客服配置一致

多客服回调接口代码如下:

 /// <summary>
    /// 多客服回掉接口
    /// </summary>
    public class QyKFController : Controller
    {
        public static readonly string Token = WeChatParameter._weChatQY_Msg_Token;
        public static readonly string EncodingAESKey = WeChatParameter._weChatQY_Msg_EncodingAESKey;
        public static readonly string CorpId = WeChatParameter._weChatQY_CorpId;


        /// <summary>
        /// 微信后台验证地址(使用Post),微信企业后台应用的“修改配置”的Url填写如:http://sdk.weixin.senparc.com/qy
        /// </summary>
        [HttpPost]
        [ActionName("Index")]
        public ActionResult Post(PostModel postModel)
        {

            postModel.Token = Token;
            postModel.EncodingAESKey = EncodingAESKey;
            postModel.CorpId = CorpId;

            try
            {
                var packageId = "";
                KFMessageHandler.SendMessage(Request.InputStream, postModel, out packageId);
                return Content(packageId);

            }
            catch (Exception ex)
            {
                using (TextWriter tw = new StreamWriter(Server.MapPath("~/App_Data/KF_Error/" + DateTime.Now.Ticks + ".txt")))
                {
                    tw.WriteLine("ExecptionMessage:" + ex.Message);
                    tw.WriteLine(ex.Source);
                    tw.WriteLine(ex.StackTrace);

                    tw.Flush();
                    tw.Close();
                }
                return Content("");
            }

        }
    }

  

 

posted @ 2017-05-09 17:43  厦门_成  阅读(429)  评论(0编辑  收藏  举报