cn.hutool.json.JSONObject Java Examples

The following examples show how to use cn.hutool.json.JSONObject. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: OcrUtils.java    From tools-ocr with GNU Lesser General Public License v3.0 7 votes vote down vote up
private static String extractSogouResult(String html) {
    if (StrUtil.isBlank(html)) {
        return "";
    }
    JSONObject jsonObject = JSONUtil.parseObj(html);
    if (jsonObject.getInt("success", 0) != 1) {
        return "";
    }
    JSONArray jsonArray = jsonObject.getJSONArray("result");
    List<TextBlock> textBlocks = new ArrayList<>();
    boolean isEng;
    for (int i = 0; i < jsonArray.size(); i++) {
        JSONObject jObj = jsonArray.getJSONObject(i);
        TextBlock textBlock = new TextBlock();
        textBlock.setText(jObj.getStr("content").trim());
        //noinspection SuspiciousToArrayCall
        String[] frames = jObj.getJSONArray("frame").toArray(new String[0]);
        textBlock.setTopLeft(CommUtils.frameToPoint(frames[0]));
        textBlock.setTopRight(CommUtils.frameToPoint(frames[1]));
        textBlock.setBottomRight(CommUtils.frameToPoint(frames[2]));
        textBlock.setBottomLeft(CommUtils.frameToPoint(frames[3]));
        textBlocks.add(textBlock);
    }
    isEng = jsonObject.getStr("lang", "zh-Chs").equals("zh-Chs");
    return CommUtils.combineTextBlocks(textBlocks, isEng);
}
 
Example #2
Source File: ResponseUtil.java    From spring-boot-demo with MIT License 6 votes vote down vote up
/**
 * 往 response 写出 json
 *
 * @param response 响应
 * @param status   状态
 * @param data     返回数据
 */
public static void renderJson(HttpServletResponse response, IStatus status, Object data) {
    try {
        response.setHeader("Access-Control-Allow-Origin", "*");
        response.setHeader("Access-Control-Allow-Methods", "*");
        response.setContentType("application/json;charset=UTF-8");
        response.setStatus(200);

        // FIXME: hutool 的 BUG:JSONUtil.toJsonStr()
        //  将JSON转为String的时候,忽略null值的时候转成的String存在错误
        response.getWriter()
                .write(JSONUtil.toJsonStr(new JSONObject(ApiResponse.ofStatus(status, data), false)));
    } catch (IOException e) {
        log.error("Response写出JSON异常,", e);
    }
}
 
Example #3
Source File: MockFilterHandler.java    From v-mock with MIT License 6 votes vote down vote up
/**
 * 包装请求参数为json
 *
 * @param request 请求
 * @return requestJson
 */
@SneakyThrows
private String requestToJson(HttpServletRequest request) {
    JSONObject requestJsonObj = new JSONObject();
    // get all header
    Map<String, String> headerMap = ServletUtil.getHeaderMap(request);
    requestJsonObj.put("headers", headerMap);
    // get all param
    Map<String, String> paramMap = ServletUtil.getParamMap(request);
    requestJsonObj.put("params", paramMap);
    // body
    @Cleanup BufferedReader reader = request.getReader();
    String body = reader.lines().collect(Collectors.joining(System.lineSeparator()));
    requestJsonObj.put("body", body);
    return requestJsonObj.toString();
}
 
Example #4
Source File: SecurityTools.java    From jeecg-cloud with Apache License 2.0 6 votes vote down vote up
public static SecurityResp valid(SecurityReq req) {
    SecurityResp resp=new SecurityResp();
    String pubKey=req.getPubKey();
    String aesKey=req.getAesKey();
    String data=req.getData();
    String signData=req.getSignData();
    RSA rsa=new RSA(null, Base64Decoder.decode(pubKey));
    Sign sign= new Sign(SignAlgorithm.SHA1withRSA,null,pubKey);



    byte[] decryptAes = rsa.decrypt(aesKey, KeyType.PublicKey);
    //log.info("rsa解密后的秘钥"+ Base64Encoder.encode(decryptAes));
    AES aes = SecureUtil.aes(decryptAes);

    String dencrptValue =aes.decryptStr(data);
    //log.info("解密后报文"+dencrptValue);
    resp.setData(new JSONObject(dencrptValue));

    boolean verify = sign.verify(dencrptValue.getBytes(), Base64Decoder.decode(signData));
    resp.setSuccess(verify);
    return resp;
}
 
Example #5
Source File: ResponseUtil.java    From spring-boot-demo with MIT License 6 votes vote down vote up
/**
 * 往 response 写出 json
 *
 * @param response 响应
 * @param status   状态
 * @param data     返回数据
 */
public static void renderJson(HttpServletResponse response, IStatus status, Object data) {
    try {
        response.setHeader("Access-Control-Allow-Origin", "*");
        response.setHeader("Access-Control-Allow-Methods", "*");
        response.setContentType("application/json;charset=UTF-8");
        response.setStatus(200);

        // FIXME: hutool 的 BUG:JSONUtil.toJsonStr()
        //  将JSON转为String的时候,忽略null值的时候转成的String存在错误
        response.getWriter()
                .write(JSONUtil.toJsonStr(new JSONObject(ApiResponse.ofStatus(status, data), false)));
    } catch (IOException e) {
        log.error("Response写出JSON异常,", e);
    }
}
 
Example #6
Source File: ResponseUtil.java    From spring-boot-demo with MIT License 6 votes vote down vote up
/**
 * 往 response 写出 json
 *
 * @param response  响应
 * @param exception 异常
 */
public static void renderJson(HttpServletResponse response, BaseException exception) {
    try {
        response.setHeader("Access-Control-Allow-Origin", "*");
        response.setHeader("Access-Control-Allow-Methods", "*");
        response.setContentType("application/json;charset=UTF-8");
        response.setStatus(200);

        // FIXME: hutool 的 BUG:JSONUtil.toJsonStr()
        //  将JSON转为String的时候,忽略null值的时候转成的String存在错误
        response.getWriter()
                .write(JSONUtil.toJsonStr(new JSONObject(ApiResponse.ofException(exception), false)));
    } catch (IOException e) {
        log.error("Response写出JSON异常,", e);
    }
}
 
Example #7
Source File: SecurityTools.java    From jeecg-boot-with-activiti with MIT License 6 votes vote down vote up
public static SecurityResp valid(SecurityReq req) {
    SecurityResp resp=new SecurityResp();
    String pubKey=req.getPubKey();
    String aesKey=req.getAesKey();
    String data=req.getData();
    String signData=req.getSignData();
    RSA rsa=new RSA(null, Base64Decoder.decode(pubKey));
    Sign sign= new Sign(SignAlgorithm.SHA1withRSA,null,pubKey);



    byte[] decryptAes = rsa.decrypt(aesKey, KeyType.PublicKey);
    //log.info("rsa解密后的秘钥"+ Base64Encoder.encode(decryptAes));
    AES aes = SecureUtil.aes(decryptAes);

    String dencrptValue =aes.decryptStr(data);
    //log.info("解密后报文"+dencrptValue);
    resp.setData(new JSONObject(dencrptValue));

    boolean verify = sign.verify(dencrptValue.getBytes(), Base64Decoder.decode(signData));
    resp.setSuccess(verify);
    return resp;
}
 
Example #8
Source File: PictureServiceImpl.java    From yshopmall with Apache License 2.0 6 votes vote down vote up
@Override
public void synchronize() {
    //链式构建请求
    String result = HttpRequest.get(YshopConstant.Url.SM_MS_URL + "/v2/upload_history")
            //头信息,多个头信息多次调用此方法即可
            .header("Authorization", token)
            .timeout(20000)
            .execute().body();
    JSONObject jsonObject = JSONUtil.parseObj(result);
    List<Picture> pictures = JSON.parseArray(jsonObject.get("data").toString(), Picture.class);
    for (Picture picture : pictures) {
        if(this.getOne(new QueryWrapper<Picture>().eq("url",picture.getUrl()))==null){
            picture.setSize(FileUtil.getSize(Integer.parseInt(picture.getSize())));
            picture.setUsername("System Sync");
            picture.setMd5code(null);
            this.save(picture);
        }
    }
}
 
Example #9
Source File: SecurityTools.java    From teaching with Apache License 2.0 6 votes vote down vote up
public static SecurityResp valid(SecurityReq req) {
    SecurityResp resp=new SecurityResp();
    String pubKey=req.getPubKey();
    String aesKey=req.getAesKey();
    String data=req.getData();
    String signData=req.getSignData();
    RSA rsa=new RSA(null, Base64Decoder.decode(pubKey));
    Sign sign= new Sign(SignAlgorithm.SHA1withRSA,null,pubKey);



    byte[] decryptAes = rsa.decrypt(aesKey, KeyType.PublicKey);
    //log.info("rsa解密后的秘钥"+ Base64Encoder.encode(decryptAes));
    AES aes = SecureUtil.aes(decryptAes);

    String dencrptValue =aes.decryptStr(data);
    //log.info("解密后报文"+dencrptValue);
    resp.setData(new JSONObject(dencrptValue));

    boolean verify = sign.verify(dencrptValue.getBytes(), Base64Decoder.decode(signData));
    resp.setSuccess(verify);
    return resp;
}
 
Example #10
Source File: ResponseUtil.java    From spring-boot-demo with MIT License 6 votes vote down vote up
/**
 * 往 response 写出 json
 *
 * @param response  响应
 * @param exception 异常
 */
public static void renderJson(HttpServletResponse response, BaseException exception) {
    try {
        response.setHeader("Access-Control-Allow-Origin", "*");
        response.setHeader("Access-Control-Allow-Methods", "*");
        response.setContentType("application/json;charset=UTF-8");
        response.setStatus(200);

        // FIXME: hutool 的 BUG:JSONUtil.toJsonStr()
        //  将JSON转为String的时候,忽略null值的时候转成的String存在错误
        response.getWriter()
                .write(JSONUtil.toJsonStr(new JSONObject(ApiResponse.ofException(exception), false)));
    } catch (IOException e) {
        log.error("Response写出JSON异常,", e);
    }
}
 
Example #11
Source File: ExComponentRich.java    From PicqBotX with MIT License 6 votes vote down vote up
/**
 * 转换为音乐分享富文本组件。
 */
public ExComponentRichMusic music()
{
    JSONObject json = JSONUtil.parseObj(content);
    if (json.containsKey("music"))
    {
        JSONObject d = json.getJSONObject("music");
        return new ExComponentRichMusic(
                d.getStr("title"),
                d.getStr("desc"),
                d.getStr("preview"),
                d.getStr("tag"),
                d.getStr("musicUrl"),
                d.getStr("jumpUrl")
        );
    }
    else
    {
        throw new UnsupportedOperationException();
    }
}
 
Example #12
Source File: ExComponentRich.java    From PicqBotX with MIT License 6 votes vote down vote up
/**
 * 转换为网页分享富文本组件。
 */
public ExComponentRichNews news()
{
    JSONObject json = JSONUtil.parseObj(content);
    if (json.containsKey("news"))
    {
        JSONObject d = json.getJSONObject("news");
        return new ExComponentRichNews(
                d.getStr("title"),
                d.getStr("desc"),
                d.getStr("preview"),
                d.getStr("tag"),
                d.getStr("jumpUrl")
        );
    }
    else
    {
        throw new UnsupportedOperationException();
    }
}
 
Example #13
Source File: SecurityTools.java    From jeecg-boot with Apache License 2.0 6 votes vote down vote up
public static SecurityResp valid(SecurityReq req) {
    SecurityResp resp=new SecurityResp();
    String pubKey=req.getPubKey();
    String aesKey=req.getAesKey();
    String data=req.getData();
    String signData=req.getSignData();
    RSA rsa=new RSA(null, Base64Decoder.decode(pubKey));
    Sign sign= new Sign(SignAlgorithm.SHA1withRSA,null,pubKey);



    byte[] decryptAes = rsa.decrypt(aesKey, KeyType.PublicKey);
    //log.info("rsa解密后的秘钥"+ Base64Encoder.encode(decryptAes));
    AES aes = SecureUtil.aes(decryptAes);

    String dencrptValue =aes.decryptStr(data);
    //log.info("解密后报文"+dencrptValue);
    resp.setData(new JSONObject(dencrptValue));

    boolean verify = sign.verify(dencrptValue.getBytes(), Base64Decoder.decode(signData));
    resp.setSuccess(verify);
    return resp;
}
 
Example #14
Source File: ResponseUtil.java    From spring-boot-demo with MIT License 6 votes vote down vote up
/**
 * 往 response 写出 json
 *
 * @param response 响应
 * @param status   状态
 * @param data     返回数据
 */
public static void renderJson(HttpServletResponse response, IStatus status, Object data) {
    try {
        response.setHeader("Access-Control-Allow-Origin", "*");
        response.setHeader("Access-Control-Allow-Methods", "*");
        response.setContentType("application/json;charset=UTF-8");
        response.setStatus(200);

        // FIXME: hutool 的 BUG:JSONUtil.toJsonStr()
        //  将JSON转为String的时候,忽略null值的时候转成的String存在错误
        response.getWriter()
                .write(JSONUtil.toJsonStr(new JSONObject(ApiResponse.ofStatus(status, data), false)));
    } catch (IOException e) {
        log.error("Response写出JSON异常,", e);
    }
}
 
Example #15
Source File: ResponseUtil.java    From spring-boot-demo with MIT License 6 votes vote down vote up
/**
 * 往 response 写出 json
 *
 * @param response  响应
 * @param exception 异常
 */
public static void renderJson(HttpServletResponse response, BaseException exception) {
    try {
        response.setHeader("Access-Control-Allow-Origin", "*");
        response.setHeader("Access-Control-Allow-Methods", "*");
        response.setContentType("application/json;charset=UTF-8");
        response.setStatus(200);

        // FIXME: hutool 的 BUG:JSONUtil.toJsonStr()
        //  将JSON转为String的时候,忽略null值的时候转成的String存在错误
        response.getWriter()
                .write(JSONUtil.toJsonStr(new JSONObject(ApiResponse.ofException(exception), false)));
    } catch (IOException e) {
        log.error("Response写出JSON异常,", e);
    }
}
 
Example #16
Source File: OauthResourceTokenConfig.java    From spring-boot-demo with MIT License 6 votes vote down vote up
/**
 * 本地没有公钥的时候,从服务器上获取
 * 需要进行 Basic 认证
 *
 * @return public key
 */
private String getKeyFromAuthorizationServer() {
    ObjectMapper objectMapper = new ObjectMapper();
    HttpHeaders httpHeaders = new HttpHeaders();
    httpHeaders.add(HttpHeaders.AUTHORIZATION, encodeClient());
    HttpEntity<String> requestEntity = new HttpEntity<>(null, httpHeaders);
    String pubKey = new RestTemplate()
        .getForObject(resourceServerProperties.getJwt().getKeyUri(), String.class, requestEntity);
    try {
        JSONObject body = objectMapper.readValue(pubKey, JSONObject.class);
        log.info("Get Key From Authorization Server.");
        return body.getStr("value");
    } catch (IOException e) {
        log.error("Get public key error: {}", e.getMessage());
    }
    return null;
}
 
Example #17
Source File: PictureServiceImpl.java    From sk-admin with Apache License 2.0 6 votes vote down vote up
@Override
public void synchronize() {
    //链式构建请求
    String result = HttpRequest.get(CommonConstant.SM_MS_URL + "/v2/upload_history")
            //头信息,多个头信息多次调用此方法即可
            .header("Authorization", token)
            .timeout(20000)
            .execute().body();
    JSONObject jsonObject = JSONUtil.parseObj(result);
    List<Picture> pictures = JSON.parseArray(jsonObject.get("data").toString(), Picture.class);
    for (Picture picture : pictures) {
        if (!pictureDao.existsByUrl(picture.getUrl())) {
            picture.setSize(FileUtils.getSize(Integer.parseInt(picture.getSize())));
            picture.setUsername("System Sync");
            picture.setMd5Code("");
            pictureDao.save(picture);
        }
    }
}
 
Example #18
Source File: PictureServiceImpl.java    From eladmin with Apache License 2.0 6 votes vote down vote up
@Override
public void synchronize() {
    //链式构建请求
    String result = HttpRequest.get(ElAdminConstant.Url.SM_MS_URL + "/v2/upload_history")
            //头信息,多个头信息多次调用此方法即可
            .header("Authorization", token)
            .timeout(20000)
            .execute().body();
    JSONObject jsonObject = JSONUtil.parseObj(result);
    List<Picture> pictures = JSON.parseArray(jsonObject.get("data").toString(), Picture.class);
    for (Picture picture : pictures) {
        if(!pictureRepository.existsByUrl(picture.getUrl())){
            picture.setSize(FileUtil.getSize(Integer.parseInt(picture.getSize())));
            picture.setUsername("System Sync");
            picture.setMd5Code(null);
            pictureRepository.save(picture);
        }
    }
}
 
Example #19
Source File: ApiController.java    From SubTitleSearcher with Apache License 2.0 5 votes vote down vote up
/**
 * 下载字幕
 */
public void zimu_down() {
	HttpRequest request = getRequest();
	HttpResponse response = getResponse();
	String data = request.getParaToStr("data");
	if(data == null) {
		outJsonpMessage(request,response, 1, "请求数据错误");
		return;
	}
	
	JSONObject dataJson = JSONUtil.parseObj(data);
	JSONArray items = dataJson.getJSONArray("items");
	if(items == null || items.size()==0) {
		outJsonpMessage(request,response, 1, "请选择字幕文件");
		return;
	}
	//System.out.println(data);
	
	DownParm downParm;
	JSONObject row;
	int item_id;
	for(int i = 0; i < items.size(); i++) {
		row = items.getJSONObject(i);
		item_id = row.getInt("id");
		downParm = new DownParm();
		downParm.charset = row.getStr("charset", "");
		downParm.simplified = row.getBool("simplified", false);
		downParm.filenameType = row.getInt("filenameType", 1);

		try {
			DownZIMu.down(item_id, downParm);
		}catch(Exception e) {
			logger.error(e);
		}
		
	}
	outJsonpMessage(request,response, 0, "OK");
}
 
Example #20
Source File: DownZIMu.java    From SubTitleSearcher with Apache License 2.0 5 votes vote down vote up
/**
 * 射手、迅雷
 * 
 * @param row
 * @param filename
 * @param url
 * @param charset
 * @param simplified
 * @return
 */
public static boolean downAndSave(int index, JSONObject row,JSONObject fileRow,  String filename, String url, DownParm downParm) {
	try {
		byte[] data = HtHttpUtil.http.getBytes(url, null, url);
		if (data == null || data.length < 100) {
			return false;
		}
		if(downParm.filenameType == DownParm.filenameType_BAT) {
			filename += (".chn" + (index+1)) + "." + fileRow.getStr("Ext");
		}else {
			filename += "." + fileRow.getStr("Ext");
		}
		
		
		logger.info("save=" + filename);
		// Vector<Object> colData = MainWin.getSubTableData(row.getStr("key"));
		// String charset = (String)colData.get(5);
		if (downParm.simplified) {
			String dataStr = new String(data, downParm.charset);
			dataStr = ChineseHelper.convertToSimplifiedChinese(dataStr);
			MyFileUtil.fileWrite(filename, dataStr, "UTF-8", "");
		} else {
			MyFileUtil.fileWriteBin(filename, data);
		}
		return true;
	} catch (Exception e) {
		logger.error(e);
	}
	return false;
}
 
Example #21
Source File: ZIMuKuCommon.java    From SubTitleSearcher with Apache License 2.0 5 votes vote down vote up
/**
 * 获取下载网址列表
 * @return
 */
public static JSONArray getDetailList(String url) {
	String result = httpGet(baseUrl+url);
	//System.out.println(result);
	Document doc = Jsoup.parse(result);
	Elements matchList = doc.select("#subtb tbody tr");
	if(matchList.size() == 0)return new JSONArray();
	//System.out.println(matchList.html());
	JSONArray resList = new JSONArray();
	for(int i  = 0 ; i < matchList.size(); i++) {
		Element row = matchList.get(i);
		JSONObject resRow = new JSONObject();
		resRow.put("url", row.selectFirst("a").attr("href"));
		resRow.put("title", row.selectFirst("a").attr("title"));
		resRow.put("ext", row.selectFirst(".label-info").text());
		Elements authorInfos = row.select(".gray");
		StringBuffer authorInfo = new StringBuffer();
		authorInfos.forEach(element ->{
			authorInfo.append(element.text() + ",");
		});
		if(authorInfo.length() > 0) {
			resRow.put("authorInfo", authorInfo.toString().substring(0, authorInfo.length()-1));
		}else {
			resRow.put("authorInfo", "");
		}
		
		resRow.put("lang", row.selectFirst("img").attr("alt"));
		resRow.put("rate", row.selectFirst(".rating-star").attr("title").replace("字幕质量:", ""));
		resRow.put("downCount", row.select("td").get(3).text());
		resList.add(resRow);
	}
	return resList;
}
 
Example #22
Source File: SecurityToolsTest.java    From teaching with Apache License 2.0 5 votes vote down vote up
@Test
public void Test(){
    MyKeyPair mkeyPair = SecurityTools.generateKeyPair();

    JSONObject msg = new JSONObject();
    msg.put("name", "党政辉");
    msg.put("age", 50);
    JSONObject identity = new JSONObject();
    identity.put("type", "01");
    identity.put("no", "210882165896524512");
    msg.put("identity", identity);

    // 签名加密部分
    SecuritySignReq signReq = new SecuritySignReq();
    // data为要加密的报文字符串
    signReq.setData(msg.toString());
    // 为rsa私钥
    signReq.setPrikey(mkeyPair.getPriKey());
    // 调用签名方法
    SecuritySignResp sign = SecurityTools.sign(signReq);
    // 打印出来加密数据
    // signData为签名数据
    // data为aes加密数据
    // asekey为ras加密过的aeskey
    System.out.println(new JSONObject(sign).toStringPretty());

    // 验签解密部分
    SecurityReq req = new SecurityReq();
    //对方传过来的数据一一对应
    req.setAesKey(sign.getAesKey());
    req.setData(sign.getData());
    req.setSignData(sign.getSignData());
    //我们的公钥
    req.setPubKey(mkeyPair.getPubKey());
    //验签方法调用
    SecurityResp securityResp = SecurityTools.valid(req);
    //解密报文data为解密报文
    //sucess 为验签成功失败标志 true代码验签成功,false代表失败
    System.out.println(new JSONObject(securityResp).toStringPretty());
}
 
Example #23
Source File: ApiController.java    From SubTitleSearcher with Apache License 2.0 5 votes vote down vote up
/**
 * 下载字幕
 */
public void zimu_down() {
	HttpRequest request = getRequest();
	HttpResponse response = getResponse();
	String data = request.getParaToStr("data");
	if(data == null) {
		outJsonpMessage(request,response, 1, "请求数据错误");
		return;
	}
	
	JSONObject dataJson = JSONUtil.parseObj(data);
	JSONArray items = dataJson.getJSONArray("items");
	if(items == null || items.size()==0) {
		outJsonpMessage(request,response, 1, "请选择字幕文件");
		return;
	}
	//System.out.println(data);
	
	DownParm downParm;
	JSONObject row;
	int item_id;
	for(int i = 0; i < items.size(); i++) {
		row = items.getJSONObject(i);
		item_id = row.getInt("id");
		downParm = new DownParm();
		downParm.charset = row.getStr("charset", "");
		downParm.simplified = row.getBool("simplified", false);
		downParm.filenameType = row.getInt("filenameType", 1);

		try {
			DownZIMu.down(item_id, downParm);
		}catch(Exception e) {
			logger.error(e);
		}
		
	}
	outJsonpMessage(request,response, 0, "OK");
}
 
Example #24
Source File: DownZIMu.java    From SubTitleSearcher with Apache License 2.0 5 votes vote down vote up
public static void addRow(String key, String title, String rate, JSONObject data, String from) {
	JSONObject dataRow = new JSONObject();
	dataRow.put("key", key);
	dataRow.put("title", title);
	dataRow.put("rate", rate);
	dataRow.put("data", data);
	dataRow.put("from", from);
	dataArr.add(dataRow);
}
 
Example #25
Source File: ExtractApiController.java    From SubTitleSearcher with Apache License 2.0 5 votes vote down vote up
/**
 * 下载压缩文件中的字幕
 * @param data
 * @return
 */
public void down_archive_file() {
	HttpRequest request = getRequest();
	HttpResponse response = getResponse();
	String data = request.getParaToStr("data");
	if(data == null) {
		outJsonpMessage(request,response, 1, "请求数据错误");
		return;
	}
	logger.info("data="+data);
	if(data == null || data.length() < 10) {
		logger.error("data=null");
		outJsonpMessage(request,response, 1, "参数错误");
		return;
	}
	JSONObject dataJson = JSONUtil.parseObj(data);
	JSONArray items = dataJson.getJSONArray("items");
	if(items == null || items.size() == 0) {
		logger.error("items=null");
		outJsonpMessage(request,response, 1, "参数错误");
		return;
	}
	
	JSONObject resp = new JSONObject();
	resp.put("saveSelected", ExtractDialog.extractDialog.saveSelected(items));
	outJsonpMessage(request,response, 0, "OK", resp);
}
 
Example #26
Source File: Base.java    From SubTitleSearcher with Apache License 2.0 5 votes vote down vote up
protected JSONObject getAjaxMessage(int result, String message, JSONObject data) {
	JSONObject json = new JSONObject();
	json.put("result", result);
	json.put("message", message);

	if (data != null) {
		json.putAll(data);
	}

	return json;
}
 
Example #27
Source File: XunLeiCommon.java    From SubTitleSearcher with Apache License 2.0 5 votes vote down vote up
public static JSONArray DownList(String fileName) throws Exception {
	String cid = getCid(fileName);
	String result = HtHttpUtil.http.get(String.format("http://sub.xmp.sandai.net:8000/subxl/%s.json", cid));
	if(result == null) {
		logger.error("未查询到结果");
		return null;
	}
	//System.out.println(result);
	JSONObject json = JSONUtil.parseObj(result);
	return json.getJSONArray("sublist");
}
 
Example #28
Source File: SubHDCommon.java    From SubTitleSearcher with Apache License 2.0 5 votes vote down vote up
/**
 * 下载字幕
 * @param url
 * @return
 */
public static JSONObject downContent(String url) {
	String result = HtHttpUtil.http.get(baseUrl+url, HtHttpUtil.http.default_charset, HtHttpUtil.http._ua, baseUrl+url);
	Document doc = Jsoup.parse(result);
	Elements matchList = doc.select("#down");
	if(matchList.size() == 0)return null;
	Element down = matchList.get(0);
	Map<String, Object> postData = new HashMap<String, Object>();
	postData.put("sub_id", matchList.attr("sid"));
	postData.put("dtoken", down.attr("dtoken"));
	result = HtHttpUtil.http.post(baseUrl+"/ajax/down_ajax", postData);
	if(result == null || !result.contains("}"))return null;
	JSONObject resultJson = JSONUtil.parseObj(result);
	if(resultJson == null || !resultJson.getBool("success"))return null;
	String downUrl = resultJson.getStr("url");
	String filename = StringUtil.basename(downUrl);
	//HtHttpUtil.http.debug=true;
	byte[] data = HtHttpUtil.http.getBytes(downUrl, HtHttpUtil.http._ua, baseUrl+url);
	
	JSONObject resp = new JSONObject();
	resp.put("filename", filename);
	resp.put("ext", StringUtil.extName(filename).toLowerCase());
	resp.put("data", Base64.encode(data));

	
	return resp;
}
 
Example #29
Source File: ZIMuKuCommon.java    From SubTitleSearcher with Apache License 2.0 5 votes vote down vote up
/**
 * 下载字幕
 * @param url
 * @return
 */
public static JSONObject downContent(String url) {
	String result = httpGet(baseUrl+url);
	String downUrl = RegexUtil.getMatchStr(result, 
			"<a\\s+id=\"down1\"\\s+href=\"([^\"]*/dld/[\\w]+\\.html)\""
			, Pattern.DOTALL);
	if(downUrl == null)return null;
	if(!downUrl.startsWith("http")) {
		downUrl = baseUrl + downUrl;
	}
	
	result = httpGet(downUrl);
	if(result == null)return null;
	//System.out.println(result);
	JSONArray resList = RegexUtil.getMatchList(result, 
			"<li><a\\s+rel=\"nofollow\"\\s+href=\"([^\"]*/download/[^\"]+)\"", Pattern.DOTALL);
	if(resList == null || resList.size() == 0 || resList.getJSONArray(0).size() == 0)return null;
	//HtHttpUtil.http.debug=true;
	HttpResponse httpResp = HtHttpUtil.http.getResponse(addBaseUrl(resList.getJSONArray(0).getStr(0)), null, downUrl);
	int i = 0;
	while(httpResp == null && resList.size() > ++i) {
		httpResp = HtHttpUtil.http.getResponse(addBaseUrl(resList.getJSONArray(1).getStr(0)), null, downUrl);
	}
	//System.out.println(httpResp);
	if(httpResp == null)return null;
	String filename = HtHttpUtil.getFileName(httpResp);
	byte[] data = httpResp.bodyBytes();
	//System.out.println(filename);
	JSONObject resp = new JSONObject();
	resp.put("filename", filename);
	resp.put("ext", StringUtil.extName(filename).toLowerCase());
	resp.put("data", Base64.encode(data));
	
	return resp;
}
 
Example #30
Source File: ExtractApiController.java    From SubTitleSearcher with Apache License 2.0 5 votes vote down vote up
/**
 * 获取初始化数据
 */
public void get_init_data() {
	JSONObject resp = new JSONObject();
	JSONArray list = new JSONArray();
	for (int i = 0; i < ExtractDialog.extractDialog.archiveFiles.size(); i++) {
		File file = ExtractDialog.extractDialog.archiveFiles.get(i);
		String title = file.getName();
		
		if(!ArrayUtil.contains(AppConfig.subExtNames, StringUtil.extName(file).toLowerCase())){
			continue;
		}
		
		String key = title;
		JSONObject row = new JSONObject();
		row.put("key", key);
		row.put("title", title);
		row.put("size", file.length());
		row.put("sizeF", StringUtil.getPrintSize(file.length()));
		
		list.add(row);
	}
	resp.put("list", list);
	resp.put("title", ExtractDialog.extractDialog.title);
	resp.put("archiveExt", ExtractDialog.extractDialog.archiveExt);
	resp.put("archiveSize", ExtractDialog.extractDialog.archiveData.length);
	resp.put("archiveSizeF", StringUtil.getPrintSize(ExtractDialog.extractDialog.archiveData.length));
	
	outJsonpMessage(request,response, 0, "OK", resp);
}