Exemplo n.º 1
0
        /// <summary>
        /// 订阅(关注)事件
        /// </summary>
        /// <returns></returns>
        public override IResponseMessageBase OnEvent_SubscribeRequest(RequestMessageEvent_Subscribe requestMessage)
        {
            Log4NetImpl.Write("关注事件触发:");
            MpUser fromUser = MpUserService.GetByOpenID(requestMessage.FromUserName);

            if (fromUser != null)
            {
                Log4NetImpl.Write("EventKey:" + requestMessage.EventKey);
                fromUser.IsSubscribe = true;
                if (!string.IsNullOrEmpty(requestMessage.EventKey))
                {
                    fromUser.SceneId = Convert.ToInt32(requestMessage.EventKey.Replace("qrscene_", ""));
                    Log4NetImpl.Write("OnEvent_SubscribeRequest:" + fromUser.SceneId.ToString());
                }
                fromUser.LastVisitDate = DateTime.Now;
                MpUserService.Update(fromUser);
            }
            var     responseMessage = ResponseMessageBase.CreateFromRequestMessage <ResponseMessageText>(requestMessage);
            MpReply reply           = MpReplyService.GetALL(k => k.Action == "beadded").FirstOrDefault();

            if (reply != null)
            {
                return(ResponseMsg(reply.MpMaterial));
            }
            return(responseMessage);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 处理链接消息请求
        /// </summary>
        /// <param name="requestMessage"></param>
        /// <returns></returns>
        public override IResponseMessageBase OnLinkRequest(RequestMessageLink requestMessage)
        {
            MpReply reply = MpReplyService.GetALL(k => k.Action == "autoreply").FirstOrDefault();

            if (reply != null)
            {
                return(ResponseMsg(reply.MpMaterial));
            }
            return(null);
        }
Exemplo n.º 3
0
        /// <summary>
        /// 处理文字请求
        /// </summary>
        /// <returns></returns>
        public override IResponseMessageBase OnTextRequest(RequestMessageText requestMessage)
        {
            MpReply reply    = MpReplyService.GetALL(k => k.KeywordName == requestMessage.Content.Trim()).FirstOrDefault();
            MpUser  fromUser = MpUserService.GetByOpenID(requestMessage.FromUserName);

            if (fromUser != null)
            {
                if (reply == null)
                {
                    reply = MpReplyService.GetALL(k => k.Action == "autoreply").FirstOrDefault();
                }
                if (reply != null)
                {
                    fromUser.LastVisitDate = DateTime.Now;
                    fromUser.IsSubscribe   = true;
                    MpUserService.Update(fromUser);
                    //用户接入
                    if (reply.MpMaterial.IsChat == 1)
                    {
                        Client.StartKfMeeting(fromUser.Id);
                        return(null);
                    }
                    //用户断开
                    if (reply.MpMaterial.IsChat == 2 || fromUser.LastVisitDate.AddMinutes(120) < DateTime.Now)
                    {
                        fromUser.UserState = 0;
                        Client.EndKfMeeting(fromUser.Id);
                        return(null);
                    }

                    if (fromUser.UserState == 1)
                    {
                        //发送消息给客服
                        Client.SendPrivateMessage(fromUser.Id, requestMessage.Content);
                        return(null);
                    }
                    return(ResponseMsg(reply.MpMaterial));
                }
            }

            return(null);
        }