Search in sources :

Example 56 with JSONObject

use of net.sf.json.JSONObject in project pmph by BCSquad.

the class WechatAccessToken method getWXjsTicket.

/**
 * <pre>
 * 功能描述:获取wx_js_ticket
 * 使用示范:
 *
 * @param accessToken access_token
 * @return
 * </pre>
 */
public static WXjsTicket getWXjsTicket(String accessToken) {
    WXjsTicket wXjsTicket = null;
    String requestUrl = WXURLUtil.JSAPIURL.replace("ACCESS_TOKEN", accessToken);
    // 发起GET请求获取凭证
    JSONObject jsonObject = HttpRequestUtil.httpRequest(requestUrl, "GET", null);
    System.out.println("CommonUtil.java 调用了一次getWXjsTicket接口");
    if (null != jsonObject) {
        try {
            wXjsTicket = new WXjsTicket();
            wXjsTicket.setJsTicket(jsonObject.getString("ticket"));
            wXjsTicket.setJsTicketExpiresIn(jsonObject.getInt("expires_in"));
        } catch (JSONException e) {
            wXjsTicket = null;
            // 获取wXjsTicket失败
            log.error("获取wXjsTicket失败 errcode:{} errmsg:{}", jsonObject.getInt("errcode"), jsonObject.getString("errmsg"));
        }
    }
    return wXjsTicket;
}
Also used : WXjsTicket(com.bc.pmpheep.wechat.po.WXjsTicket) JSONObject(net.sf.json.JSONObject) JSONException(net.sf.json.JSONException)

Example 57 with JSONObject

use of net.sf.json.JSONObject in project topcom-cloud by 545314690.

the class EtlController method commentsEtl.

@ApiOperation("commentsEtl")
@RequestMapping(value = "/commentsEtl", method = RequestMethod.GET, produces = "application/json")
@ResponseBody
public Object commentsEtl(@RequestParam Integer limit) {
    long count = 0;
    long count1 = 0;
    SearchResponse searchResponse = scanComments("", limit);
    while (searchResponse.getHits().getHits().length > 0) {
        SearchHit[] hits = searchResponse.getHits().hits();
        List<JSONObject> commentsList = new ArrayList<>();
        for (int i = 0; i < hits.length; i++) {
            JSONObject jsonObject = JSONObject.fromObject(hits[i].sourceAsMap());
            commentsList.add(jsonObject);
        }
        // String path = "D:\\data\\comments\\"+"comments"+(count1/50000)+".txt";
        String path = "/home/yuqing/data/esFile/comments/" + "comments" + (count1 / 50000) + ".txt";
        save2File(commentsList, path);
        dleteCommentsDoc("yuqing", "comment", commentsList);
        count1 = count1 + commentsList.size();
        count = count + searchResponse.getHits().getHits().length;
        logger.error("删除comments条数:" + count1);
        logger.error("处理comments条数:" + count + "\n 完成度" + (double) count * 100 / searchResponse.getHits().getTotalHits() + "%");
        searchResponse = scanComments(searchResponse.getScrollId(), limit);
    }
    return "done";
}
Also used : SearchHit(org.elasticsearch.search.SearchHit) JSONObject(net.sf.json.JSONObject) ArrayList(java.util.ArrayList) SearchResponse(org.elasticsearch.action.search.SearchResponse) ApiOperation(io.swagger.annotations.ApiOperation)

Example 58 with JSONObject

use of net.sf.json.JSONObject in project topcom-cloud by 545314690.

the class EtlController method saveJson.

private void saveJson(String yuqing, String article, List<JSONObject> jsonObjects) {
    Client client = elasticsearchTemplate.getClient();
    BulkRequestBuilder bulkRequestBuilder = client.prepareBulk();
    for (int i = 0; i < jsonObjects.size(); i++) {
        JSONObject jsonObject = jsonObjects.get(i);
        IndexRequestBuilder indexRequestBuilder = client.prepareIndex("yuqing", "article").setSource(jsonObject.toString()).setId(jsonObject.get("id").toString());
        bulkRequestBuilder.add(indexRequestBuilder);
    }
    bulkRequestBuilder.execute().actionGet();
}
Also used : IndexRequestBuilder(org.elasticsearch.action.index.IndexRequestBuilder) JSONObject(net.sf.json.JSONObject) BulkRequestBuilder(org.elasticsearch.action.bulk.BulkRequestBuilder) Client(org.elasticsearch.client.Client)

Example 59 with JSONObject

use of net.sf.json.JSONObject in project topcom-cloud by 545314690.

the class EtlController method weiboEtl.

/**
 * 微博id->weiboId
 * md5(id)->微博id
 * @param limit
 * @return
 */
@ApiOperation("weiboEtl")
@RequestMapping(value = "/weiboEtl", method = RequestMethod.GET, produces = "application/json")
@ResponseBody
public Object weiboEtl(@RequestParam Integer limit) {
    long count = 0;
    SearchResponse searchResponse = scanWeibo("", limit);
    while (searchResponse.getHits().getHits().length > 0) {
        SearchHit[] hits = searchResponse.getHits().hits();
        List<JSONObject> commentsList = new ArrayList<>();
        for (int i = 0; i < hits.length; i++) {
            JSONObject jsonObject = JSONObject.fromObject(hits[i].sourceAsMap());
            jsonObject.put("weiboId", jsonObject.get("id"));
            jsonObject.put("id", MD5Utils.md5(jsonObject.get("id").toString()));
            commentsList.add(jsonObject);
        }
        updateJson("yuqing", "article", commentsList);
        count = count + searchResponse.getHits().getHits().length;
        logger.error(searchResponse.getHits().getTotalHits());
        logger.error("处理微博条数:" + count + "\n 完成度" + (double) count * 100 / searchResponse.getHits().getTotalHits() + "%");
        searchResponse = scanWeibo(searchResponse.getScrollId(), limit);
    }
    return "done";
}
Also used : SearchHit(org.elasticsearch.search.SearchHit) JSONObject(net.sf.json.JSONObject) ArrayList(java.util.ArrayList) SearchResponse(org.elasticsearch.action.search.SearchResponse) ApiOperation(io.swagger.annotations.ApiOperation)

Example 60 with JSONObject

use of net.sf.json.JSONObject in project topcom-cloud by 545314690.

the class EtlController method etlSimHash.

public List<JSONObject> etlSimHash(SearchHit[] hits) {
    List<JSONObject> commentsList = new ArrayList<>();
    for (int i = 0; i < hits.length; i++) {
        JSONObject jsonObject = JSONObject.fromObject(hits[i].sourceAsString());
        jsonObject.put("textSimHash", SimHasher.analysis(jsonObject.getString("title") + jsonObject.getString("content")).toString());
        jsonObject.put("titleSimHash", SimHasher.analysis(jsonObject.getString("title")).toString());
        commentsList.add(jsonObject);
    }
    return commentsList;
}
Also used : JSONObject(net.sf.json.JSONObject) ArrayList(java.util.ArrayList)

Aggregations

JSONObject (net.sf.json.JSONObject)493 Test (org.junit.Test)99 JSONArray (net.sf.json.JSONArray)94 IOException (java.io.IOException)49 HashMap (java.util.HashMap)48 ArrayList (java.util.ArrayList)36 JSON (net.sf.json.JSON)26 PrintWriter (java.io.PrintWriter)25 Map (java.util.Map)23 File (java.io.File)21 InputStream (java.io.InputStream)18 URISyntaxException (java.net.URISyntaxException)15 UnsupportedEncodingException (java.io.UnsupportedEncodingException)14 JsonConfig (net.sf.json.JsonConfig)14 FreeStyleBuild (hudson.model.FreeStyleBuild)13 URI (java.net.URI)13 URL (java.net.URL)13 JSONException (net.sf.json.JSONException)13 Context (org.zaproxy.zap.model.Context)12 Transactional (org.springframework.transaction.annotation.Transactional)11