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())); }
public GetUserPicAction(IQQContext context, QQActionListener listener, CFaceItem cface, QQMsg msg, Stream picOut) : base(context, listener) { this.cface = cface; this.msg = msg; this.picOut = picOut; }
/** * <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; }
/** * <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; }
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); }
public IQQActionFuture GetUserPic(CFaceItem cface, QQMsg msg, Stream picout, QQActionListener listener) { return PushHttpAction(new GetUserPicAction(Context, listener, cface, msg, picout)); }
public QQActionFuture GetGroupPic(CFaceItem cface, QQMsg msg, Stream picout, QQActionEventHandler listener) { return PushHttpAction(new GetGroupPicAction(this.Context, listener, cface, msg, picout)); }