Пример #1
0
        public IResponseMessageBase SendMessage(string openId, IResponseMessageBase responseMessage)
        {
            var messageQueue = new SenparcMessageQueue();

            if (responseMessage is ResponseMessageText)
            {
                {
                    var mqKey = SenparcMessageQueue.GenerateKey("MessageHandlerSendMessageAsync", responseMessage.GetType(), Guid.NewGuid().ToString(), "SendMessage");
                    messageQueue.Add(mqKey, () =>
                    {
                        var asyncResponseMessage      = responseMessage as ResponseMessageText;
                        asyncResponseMessage.Content += "\r\n\r\n - 这条消息来自客服接口-1";

                        //发送客服消息
                        CustomApi.SendText(Config.AppId, openId, asyncResponseMessage.Content);
                    });
                }
                {
                    var mqKey = SenparcMessageQueue.GenerateKey("MessageHandlerSendMessageAsync", responseMessage.GetType(), Guid.NewGuid().ToString(), "SendMessage");
                    messageQueue.Add(mqKey, () =>
                    {
                        var asyncResponseMessage      = responseMessage as ResponseMessageText;
                        asyncResponseMessage.Content += "\r\n\r\n - 这条消息来自客服接口-2";

                        //发送客服消息
                        CustomApi.SendText(Config.AppId, openId, asyncResponseMessage.Content);
                    });
                }


                return(new ResponseMessageNoResponse());
            }
            //else if ()
            //{
            //    //...
            //}

            return(responseMessage);
        }
Пример #2
0
        /// <summary>
        /// 客服消息返回用户信息
        /// </summary>
        /// <param name="openId"></param>
        /// <param name="responseMessage"></param>
        /// <returns></returns>
        public IResponseMessageBase SendKfMessage(string openId, IResponseMessageBase responseMessage)
        {
            var messageQueue = new SenparcMessageQueue();

            if (responseMessage is ResponseMessageText)
            {
                {
                    var myKey = SenparcMessageQueue.GenerateKey("MessageHandlerSendMessageAsync", responseMessage.GetType(),
                                                                Guid.NewGuid().ToString(), "SendMessage");

                    messageQueue.Add(myKey, () =>
                    {
                        var kfResponseMessage = responseMessage as ResponseMessageText;
                        if (kfResponseMessage != null)
                        {
                            kfResponseMessage.Content += "\r\n【客服消息队列-1】";

                            //在队列中发送消息
                            CustomApi.SendText(Config.AppId, openId, kfResponseMessage.Content);
                        }
                    });
                }
                {
                    var myKey = SenparcMessageQueue.GenerateKey("MessageHandlerSendMessageAsync", responseMessage.GetType(),
                                                                Guid.NewGuid().ToString(), "SendMessage");

                    messageQueue.Add(myKey, () =>
                    {
                        var kfResponseMessage = responseMessage as ResponseMessageText;
                        if (kfResponseMessage != null)
                        {
                            kfResponseMessage.Content += "\r\n【客服消息队列-2】";

                            //在队列中发送消息
                            CustomApi.SendText(Config.AppId, openId, kfResponseMessage.Content);
                        }
                    });
                }
            }

            return(new ResponseMessageNoResponse());
        }
Пример #3
0
        public async Task <IResponseMessageBase> SendMessage(string appid, string openid, IResponseMessageBase responseMessage)
        {
            var messageQueue = new SenparcMessageQueue();

            if (!(responseMessage is ResponseMessageText responseMessagea))
            {
                return(responseMessage);
            }
            return(await Task.Run(() =>
            {
                {
                    var key = SenparcMessageQueue.GenerateKey("MessageHandlerSendMessageAsync", responseMessage.GetType(), Guid.NewGuid().ToString(), "SendMessage");
                    messageQueue.Add(key, () =>
                    {
                        responseMessagea.Content += "\r\n[消息超时后客服发送的消息1]";
                        // 发送客服消息 在队列里面就可以不用 async await 了
                        CustomApi.SendText(appid, openid, responseMessagea.Content);
                    });
                }

                {
                    var key = SenparcMessageQueue.GenerateKey("MessageHandlerSendMessageAsync", responseMessage.GetType(), Guid.NewGuid().ToString(), "SendMessage");
                    messageQueue.Add(key, () =>
                    {
                        responseMessagea.Content += "\r\n[消息超时后客服发送的消息2]";
                        // 发送客服消息 在队列里面就可以不用 async await 了
                        CustomApi.SendText(appid, openid, responseMessagea.Content);
                    });
                }
                return new ResponseMessageNoResponse();
            }));
        }
        public static readonly string AppId = ConfigurationManager.AppSettings["WeixinAppId"];// Config.SenparcWeixinSetting.WeixinAppId;//与微信公众账号后台的AppId设置保持一致,区分大小写。


        public IResponseMessageBase SendMessage(string openId, IResponseMessageBase ResponseMessage)
        {
            var senparcMessageQueue = new SenparcMessageQueue();

            if (ResponseMessage is ResponseMessageText)
            {
                string strResponseMsg = "";

                //以下是:把同一用户的多个消息内容,加入到队列中

                //myKey 加入队列排序执行
                var myKey = SenparcMessageQueue.GenerateKey("MessageQueueHandlerAsync", ResponseMessage.GetType(),
                                                            Guid.NewGuid().ToString(), "SendMessage");

                senparcMessageQueue.Add(myKey, () =>
                {
                    //把需要回复的消息,整理一下
                    var asyncResponseMessage = ResponseMessage as ResponseMessageText;
                    if (asyncResponseMessage != null)
                    {
                        asyncResponseMessage.Content += "\r\n【1-执行超过5秒,以客服消息回复】";

                        strResponseMsg = asyncResponseMessage.Content;
                    }
                });

                //Thread.Sleep(10);

                //myKey2 加入队列排序执行
                var myKey2 = SenparcMessageQueue.GenerateKey("MessageQueueHandlerAsync", ResponseMessage.GetType(),
                                                             Guid.NewGuid().ToString(), "SendMessage");
                senparcMessageQueue.Add(myKey2, () =>
                {
                    //把需要回复的消息,整理一下
                    var asyncResponseMessage = ResponseMessage as ResponseMessageText;
                    if (asyncResponseMessage != null)
                    {
                        asyncResponseMessage.Content += "\r\n【2-执行超过5秒,以客服消息回复】";

                        strResponseMsg = asyncResponseMessage.Content;
                    }
                });

                //执行队列,把需要回复的消息整理
                SenparcMessageQueue.OperateQueue();

                //通过客服消息的方式,下发给用户
                CustomApi.SendText(AppId, openId, strResponseMsg);


                //不再给用户回复消息
                return(new ResponseMessageNoResponse());
            }
            return(ResponseMessage);
        }