Example #1
0
        /// <summary>
        /// 执行处理。
        /// </summary>
        public override void Process()
        {
            RequestSubscribeEventMessage requestMessage = base.GetRequestMessage <RequestSubscribeEventMessage>();

            ResponseTextMessage responseMessage = new ResponseTextMessage()
            {
                Content = requestMessage.EventKey
            };

            base.ResponseMessage = responseMessage;
        }
Example #2
0
        /// <summary>
        /// 执行处理。
        /// </summary>
        public override void Process()
        {
            RequestTextMessage requestMessage = base.GetRequestMessage <RequestTextMessage>();

            ResponseTextMessage responseMessage = new ResponseTextMessage()
            {
                Content = requestMessage.Content
            };

            base.ResponseMessage = responseMessage;
        }
Example #3
0
        /// <summary>
        /// 处理请求消息,返回响应消息
        /// </summary>
        /// <returns>返回响应消息</returns>
        private ResponseBaseMessage HandleRequestMessage(RequestBaseMessage requestMessage)
        {
            ResponseTextMessage response = new ResponseTextMessage(requestMessage.FromUserName, requestMessage.ToUserName,
                                                                   DateTime.Now, string.Format("自动回复,请求内容如下:\r\n{0}", requestMessage));

            response.Content += "\r\n科峰微信测试";
            ErrorMessage errorMessage = CustomerService.SendMessage(new ResponseTextMessage(requestMessage.FromUserName, requestMessage.ToUserName, DateTime.Now, string.Format("自动回复客服消息,请求内容如下:\r\n{0}", requestMessage.ToString())));

            if (!errorMessage.IsSuccess)
            {
                Message.Insert(new Message(MessageType.Exception, errorMessage.ToString()));
            }
            return(response);
        }
Example #4
0
        public ResponseMessage Post([FromBody] RequestMessage request)
        {
            var textRequest = request as RequestTextMessage;
            var response    = new ResponseTextMessage(textRequest)
            {
                Content = textRequest?.Content
            };

            _logger.LogInformation("[Recive a Message]\r\n request is :{0} \r\n response:{1}",
                                   JsonConvert.SerializeObject(request),
                                   JsonConvert.SerializeObject(response));

            return(response);
        }
        public async Task <IActionResult> Post([FromBody] Update update)
        {
            response = await updateservice.Update(update);

            if (response != null)
            {
                await client.SendTextMessageAsync(
                    chatId : response.ChatId,
                    text : response.text,
                    replyMarkup : response.keyboardMarkup
                    );
            }

            return(Ok());
        }
Example #6
0
        public ResponseMessage Post([FromBody] RequestMessage request)
        {
            var textRequest = request as RequestTextMessage;
            var response    = new ResponseTextMessage
            {
                FromUserName = "******",
                ToUserName   = "******",
                Content      = textRequest?.Content ?? "this is a test!",
                CreateTime   = DateTime.Now.Ticks,
            };

            _logger.LogInformation("[Recive a Message]\r\n request is :{0} \r\n response:{1}",
                                   JsonConvert.SerializeObject(request),
                                   JsonConvert.SerializeObject(response));

            return(response);
        }
Example #7
0
 /// <summary>
 /// 处理数据
 /// </summary>
 public HandlerResult HandlerData(string openId, DataTypes intputType, object rawData)
 {
     if (rawData == null || rawData is string == false)
     {
         this.FailResponseResult = new ResponseTextMessage("您剛才輸入的資訊不是文字類型。");
         return(HandlerResult.Fail);
     }
     else if (rawData.ToString().Length > 6)
     {
         this.FailResponseResult = new ResponseTextMessage("您剛才輸入的文字超過6位元長度。");
         return(HandlerResult.Fail);
     }
     else
     {
         this.SuccessResponseResult = new ResponseTextMessage(String.Format("設置成功,新的昵稱為:{0}", rawData));
         return(HandlerResult.Success);
     }
 }
        /// <summary>
        /// 处理数据
        /// </summary>
        public HandlerResult HandlerData(string openId, DataTypes intputType, object rawData)
        {
            try
            {
                //根据不同的类型,进行rawData的转换,以及数据的存储处理
                switch (intputType)
                {
                case DataTypes.Text:
                {
                    var data = rawData as String;
                    if (data != null)
                    {
                        TextBL control_Text = TransactionAOP.newInstance(typeof(TextBL)) as TextBL;
                        control_Text.NewText(openId, data);

                        this.SuccessResponseResult = new ResponseTextMessage("您發送的文字內容分享成功!");
                        return(HandlerResult.Success);
                    }
                }
                break;

                case DataTypes.Image:
                {
                    var data = rawData as ImageCan;
                    if (data != null)
                    {
                        MediaBL control_Media = TransactionAOP.newInstance(typeof(MediaBL)) as MediaBL;
                        control_Media.NewMedia(openId, data.MediaID, Senparc.Weixin.MP.UploadMediaFileType.image);

                        this.SuccessResponseResult = new ResponseTextMessage("您發送的圖片內容分享成功!");
                        return(HandlerResult.Success);
                    }
                }
                break;

                case DataTypes.Voice:
                {
                    var data = rawData as VoiceCan;
                    if (data != null)
                    {
                        MediaBL control_Media = TransactionAOP.newInstance(typeof(MediaBL)) as MediaBL;
                        control_Media.NewMedia(openId, data.MediaID, Senparc.Weixin.MP.UploadMediaFileType.voice);

                        this.SuccessResponseResult = new ResponseTextMessage("您發送的語音內容分享成功!");
                        return(HandlerResult.Success);
                    }
                }
                break;

                case DataTypes.Video:
                {
                    var data = rawData as VideoCan;
                    if (data != null)
                    {
                        MediaBL control_Media = TransactionAOP.newInstance(typeof(MediaBL)) as MediaBL;
                        control_Media.NewMedia(openId, data.MediaID, Senparc.Weixin.MP.UploadMediaFileType.video);

                        this.SuccessResponseResult = new ResponseTextMessage("您發送的視頻內容分享成功!");
                        return(HandlerResult.Success);
                    }
                }
                break;

                default:
                {
                    this.FailResponseResult = new ResponseTextMessage("目前未支持此內容類型。\n請重新分享,類型要求為:文本或圖片、語音、視頻。");
                    return(HandlerResult.Fail);
                }
                }

                //没有合适处理时返回失败
                this.FailResponseResult = new ResponseTextMessage("分享失敗。");
                return(HandlerResult.Fail);
            }
            catch (Exception ex)
            {
                this.SuccessResponseResult = new ResponseTextMessage("抱歉,服務故障!");
                Logger.Log4Net.Error("CustomHandler_ShareMessage异常。", ex);
                return(HandlerResult.Success);
            }
        }
        //---------Control--------

        #region 构造函数
        /// <summary>
        ///  构造函数
        /// </summary>
        public CustomHandler_ShareMessage()
        {
            ReadyMessage = new ResponseTextMessage("歡迎參與“精彩生活,我愛分享”活動!\n請回復 文本类型或圖片类型、語音类型、視頻类型的内容,進行分享。");
        }