Beispiel #1
0
        public override void OnHttpStatusOK(QQHttpResponse response)
        {
            // {'ret':0,'msg':'5F7E31F0001EF4310865F1FF4549B12B.jPg'}
            Regex     rex = new Regex(QQConstants.REGXP_JSON_SINGLE_RESULT);
            Match     m   = rex.Match(response.GetResponseString());
            CFaceItem pic = new CFaceItem();
            JObject   obj = null;

            if (m.Success)
            {
                try
                {
                    string regResult = Regex.Replace(Regex.Replace(m.Groups[0].Value, "[\\r]?[\\n]", " "), "[\r]?[\n]", " ");
                    obj = JObject.Parse(regResult);

                    int retcode = obj["ret"].ToObject <int>();
                    if (retcode == 0)
                    {
                        pic.IsSuccess = true;
                        pic.FileName  = obj["msg"].ToString();
                        NotifyActionEvent(QQActionEventType.EVT_OK, pic);

                        Context.Store.AddPicItem(pic);
                        return;
                    }
                    else if (retcode == 4)
                    {
                        // {'ret':4,'msg':'D81AB7A7627ED673FDCD4DD24220C192.jPg
                        // -6102 upload cface failed'}
                        string prefix = "\"msg\":\"";
                        string suffix = ".jPg";

                        rex = new Regex(prefix + "([\\s\\S]*)" + suffix, RegexOptions.IgnoreCase);
                        m   = rex.Match(obj.ToString());

                        if (m.Success)
                        {
                            string r = Regex.Replace(m.Groups[0].Value, prefix, "");
                            //LOG.debug("ret 4: " + r);
                            pic.IsSuccess = true;
                            pic.FileName  = r;
                            NotifyActionEvent(QQActionEventType.EVT_OK, pic);
                            return;
                        }
                    }
                    else
                    {
                        MyLogger.Default.Debug($"ret: {retcode}");
                    }
                }
                catch (Exception e)
                {
                    MyLogger.Default.Warn(e.Message, e);
                }
            }
            // 失败后返回路径
            pic.FileName  = file;
            pic.IsSuccess = false;
            NotifyActionEvent(QQActionEventType.EVT_ERROR, new QQException(QQErrorCode.UNEXPECTED_RESPONSE, "CFace: " + response.GetResponseString()));
        }
Beispiel #2
0
 /**
  * <p>Constructor for GetGroupPicAction.</p>
  *
  * @param context a {@link iqq.im.core.QQContext} object.
  * @param listener a {@link iqq.im.QQActionListener} object.
  * @param cface a {@link iqq.im.bean.content.CFaceItem} object.
  * @param msg a {@link iqq.im.bean.QQMsg} object.
  * @param picOut a {@link java.io.OutputStream} object.
  */
 public GetGroupPicAction(QQContext context, QQActionListener.OnActionEvent listener,
                          CFaceItem cface, QQMsg msg, byte[] picOut) : base(context, listener)
 {
     this.cface  = cface;
     this.msg    = msg;
     this.picOut = picOut;
 }
Beispiel #3
0
        /// <summary>
        /// 获取群聊天图片
        /// </summary>
        /// <param name="cface"></param>
        /// <param name="msg"></param>
        /// <param name="picout"></param>
        /// <param name="listener"></param>
        /// <returns></returns>
        public QQActionFuture GetGroupPic(CFaceItem cface, QQMsg msg,
                                          Stream picout, QQActionEventHandler listener)
        {
            var mod = GetModule <ChatModule>(QQModuleType.CHAT);

            return(mod.GetGroupPic(cface, msg, picout, listener));
        }
Beispiel #4
0
 /**
  * <p>Constructor for GetGroupPicAction.</p>
  *
  * @param context a {@link iqq.im.core.QQContext} object.
  * @param listener a {@link iqq.im.IQQActionListener} object.
  * @param cface a {@link iqq.im.bean.content.CFaceItem} object.
  * @param msg a {@link iqq.im.bean.QQMsg} object.
  * @param picOut a {@link java.io.OutputStream} object.
  */
 public GetGroupPicAction(QQContext context, QQActionEventHandler listener,
                          CFaceItem cface, QQMsg msg, Stream picOut)
     : base(context, listener)
 {
     this.cface  = cface;
     this.msg    = msg;
     this.picOut = picOut;
 }
Beispiel #5
0
 public GetUserPicAction(IQQContext context, QQActionListener listener,
                         CFaceItem cface, QQMsg msg, Stream picOut)
     : base(context, listener)
 {
     this.cface  = cface;
     this.msg    = msg;
     this.picOut = picOut;
 }
Beispiel #6
0
 /**
  * <p>Constructor for GetGroupPicAction.</p>
  *
  * @param context a {@link iqq.im.core.IQQContext} object.
  * @param listener a {@link iqq.im.IQQActionListener} object.
  * @param cface a {@link iqq.im.bean.content.CFaceItem} object.
  * @param msg a {@link iqq.im.bean.QQMsg} object.
  * @param picOut a {@link java.io.OutputStream} object.
  */
 public GetGroupPicAction(IQQContext context, QQActionListener listener,
                          CFaceItem cface, QQMsg msg, Stream picOut)
     : base(context, listener)
 {
     _cface  = cface;
     _msg    = msg;
     _picOut = picOut;
 }
        public override void OnHttpStatusOK(QQHttpResponse response)
        {
            // {'ret':0,'msg':'5F7E31F0001EF4310865F1FF4549B12B.jPg'}
            var rex = new Regex(QQConstants.REGXP_JSON_SINGLE_RESULT);
            var str = response.GetResponseString();
            var m   = rex.Match(str);
            var pic = new CFaceItem();

            if (m.Success)
            {
                var regResult = Regex.Replace(Regex.Replace(m.Groups[0].Value, "[\\r]?[\\n]", " "), "[\r]?[\n]", " ");
                var obj       = JObject.Parse(regResult);

                var retcode = obj["ret"].ToObject <int>();
                if (retcode == 0)
                {
                    pic.IsSuccess = true;
                    pic.FileName  = obj["msg"].ToString();
                    NotifyActionEvent(QQActionEventType.EvtOK, pic);

                    Context.Store.AddPicItem(pic);
                    return;
                }
                else if (retcode == 4)
                {
                    // {'ret':4,'msg':'D81AB7A7627ED673FDCD4DD24220C192.jPg
                    // -6102 upload cface failed'}
                    var prefix = "\"msg\":\"";
                    var suffix = ".jPg";

                    rex = new Regex(prefix + "([\\s\\S]*)" + suffix, RegexOptions.IgnoreCase);
                    m   = rex.Match(obj.ToString());

                    if (m.Success)
                    {
                        var r = Regex.Replace(m.Groups[0].Value, prefix, "");
                        //LOG.debug("ret 4: " + r);
                        pic.IsSuccess = true;
                        pic.FileName  = r;
                        NotifyActionEvent(QQActionEventType.EvtOK, pic);
                        return;
                    }
                }
                else
                {
                    Context.Logger.LogDebug($"ret: {retcode}");
                }
            }

            throw new QQException(QQErrorCode.UnexpectedResponse, "CFace: " + str);
        }
Beispiel #8
0
        public IQQActionFuture GetUserPic(CFaceItem cface, QQMsg msg, Stream picout, QQActionListener listener)
        {
            var mod = GetModule <ChatModule>(QQModuleType.CHAT);

            return(mod.GetUserPic(cface, msg, picout, listener));
        }
Beispiel #9
0
 public QQActionFuture GetGroupPic(CFaceItem cface, QQMsg msg, Stream picout, QQActionEventHandler listener)
 {
     return(PushHttpAction(new GetGroupPicAction(this.Context, listener, cface, msg, picout)));
 }
Beispiel #10
0
 /**
  * <p>getGroupPic.</p>
  *
  * @param cface a {@link iqq.im.bean.content.CFaceItem} object.
  * @param msg a {@link iqq.im.bean.QQMsg} object.
  * @param picout a {@link java.io.OutputStream} object.
  * @param listener a {@link iqq.im.QQActionListener.OnActionEvent} object.
  * @return a {@link iqq.im.evt.AbstractActionFuture} object.
  */
 public AbstractActionFuture getGroupPic(CFaceItem cface, QQMsg msg,
                                         byte[] picout, QQActionListener.OnActionEvent listener)
 {
     return(pushHttpAction(new GetGroupPicAction(getContext(), listener, cface, msg, picout)));
 }
Beispiel #11
0
 public IQQActionFuture GetUserPic(CFaceItem cface, QQMsg msg, Stream picout, QQActionListener listener)
 {
     return(PushHttpAction(new GetUserPicAction(Context, listener, cface, msg, picout)));
 }