protected void onHttpStatusOK(QQHttpResponse response) throws QQException, JSONException {
// {'ret':0,'msg':'5F7E31F0001EF4310865F1FF4549B12B.jPg'}
Pattern p = Pattern.compile(QQConstants.REGXP_JSON_SINGLE_RESULT);
Matcher m = p.matcher(response.getResponseString());
CFaceItem pic = new CFaceItem();
JSONObject obj = null;
if (m.find()) {
try {
String regResult = m.group().replaceAll("[\\r]?[\\n]", " ").replaceAll("[\r]?[\n]", " ");
obj = new JSONObject(regResult);
LOG.debug("cface result: " + obj.toString());
int retcode = obj.getInt("ret");
if (retcode == 0) {
pic.setSuccess(true);
pic.setFileName(obj.getString("msg"));
notifyActionEvent(QQActionEvent.Type.EVT_OK, pic);
getContext().getStore().addPicItem(pic);
return;
} else if (retcode == 4) {
// {'ret':4,'msg':'D81AB7A7627ED673FDCD4DD24220C192.jPg
// -6102 upload cface failed'}
String prefix = "\"msg\":\"";
String suffix = ".jPg";
Pattern p4 = Pattern.compile(prefix + "([\\s\\S]*)" + suffix, Pattern.CASE_INSENSITIVE);
Matcher m4 = p4.matcher(obj.toString());
if (m4.find()) {
String r = m4.group().replaceAll(prefix, "");
LOG.debug("ret 4: " + r);
pic.setSuccess(true);
pic.setFileName(r);
notifyActionEvent(QQActionEvent.Type.EVT_OK, pic);
return;
}
} else {
LOG.debug("ret: " + retcode);
}
} catch (Exception e) {
LOG.warn(e.getMessage(), e);
}
}
// 失败后返回路径
pic.setFileName(file.getPath());
pic.setSuccess(false);
notifyActionEvent(QQActionEvent.Type.EVT_ERROR, new QQException(QQErrorCode.UNEXPECTED_RESPONSE));
LOG.debug("CFace: " + response.getResponseString());
}