예제 #1
0
        /// <summary>
        /// 处理图片请求
        /// </summary>
        /// <param name="requestMessage"></param>
        /// <returns></returns>
        public override IResponseMessageBase OnImageRequest(RequestMessageImage requestMessage)
        {
            var content = new
            {
                msgType = "image",
                mediaId = requestMessage.MediaId
            };

            var data = new RequestMsgData();

            data.MsgId        = requestMessage.MsgId;
            data.Content      = Newtonsoft.Json.JsonConvert.SerializeObject(content);
            data.CreateTime   = requestMessage.CreateTime;
            data.FromUserName = requestMessage.FromUserName;
            data.ToUserName   = requestMessage.ToUserName;
            data.MsgType      = requestMessage.MsgType;
            db.AddToRequestMsgData(data);
            db.SaveChanges();

            var accessToken = Senparc.Weixin.MP.Containers.AccessTokenContainer.TryGetAccessToken(appId, appSecret);
            var fileName    = CustomerMessage.GetCachePathForTemporaryMedia(requestMessage.MediaId);

            using (FileStream fs = new FileStream(fileName, FileMode.Create))
            {
                MediaApi.Get(accessToken, requestMessage.MediaId, fs);
            }

            return(null);
        }
예제 #2
0
        public static RequestMsgData AddToRequestMsgData(this DbContext db, RequestMsgData model)
        {
            db.Set <RequestMsgData>().Add(model);
            //判断接入表
            var session = db.QueryCustomerSession()
                          .Where(m => m.OpenId == model.FromUserName)
                          .FirstOrDefault();

            if (session == null)
            {
                //未接入
                //添加一条接入纪录
                session = new CustomerSession()
                {
                    OpenId = model.FromUserName,
                    Time   = model.CreateTime,
                    Worker = "",
                    Status = CustomerSessionStatus.未接入
                };
                db.AddToCustomerSession(session);
            }
            //更新时间
            session.Time = DateTime.Now;
            //插入到客服的聊天纪录中
            var msg = new CustomerMessage()
            {
                FromUser = model.FromUserName,
                Time     = model.CreateTime,
                ToUser   = session.Worker,    //如果为关闭或者未接入,这里是空
                Content  = model.Content,
                ChatFlag = model.FromUserName //这里使用OpenId作为交流的标识
            };

            db.AddToCustomerMessage(msg);

            //客服接入
            if (session.Status == CustomerSessionStatus.客服接入)
            {
            }
            else if (session.Status == CustomerSessionStatus.序接入)
            {
                //暂时未实现
            }
            else if (session.Status == CustomerSessionStatus.未接入)
            {
                //暂时未实现
            }
            else if (session.Status == CustomerSessionStatus.关闭)
            {
                //重启为未接入
                session.Status = CustomerSessionStatus.未接入;
            }
            //程序接入
            return(model);
        }
예제 #3
0
 public static CustomerMessage AddToCustomerMessage(this DbContext context, CustomerMessage model)
 {
     context.Set <CustomerMessage>().Add(model);
     return(model);
 }