Commit 353d295f by leiliangliang

Merge remote-tracking branch 'origin/working' into working

parents c3901137 3d271f76
...@@ -45,7 +45,10 @@ public class MaiMaiHotSearchCrawler { ...@@ -45,7 +45,10 @@ public class MaiMaiHotSearchCrawler {
JSONObject jsonObject = jsonArray.getJSONObject(i).getJSONObject("style35"); JSONObject jsonObject = jsonArray.getJSONObject(i).getJSONObject("style35");
if(jsonObject != null) { if(jsonObject != null) {
String name = jsonObject.getString("text"); String name = jsonObject.getString("text");
log.info(name); if (name.length()>750){
name = name.substring(0,750);
}
// log.info(name);
String maimaiUrl = jsonObject.getString("share_url"); String maimaiUrl = jsonObject.getString("share_url");
String icon = null; String icon = null;
if (jsonObject.containsKey("hot_type_card")) { if (jsonObject.containsKey("hot_type_card")) {
......
...@@ -6,12 +6,14 @@ import com.zhiwei.searchhotcrawler.bean.HotSearchList; ...@@ -6,12 +6,14 @@ import com.zhiwei.searchhotcrawler.bean.HotSearchList;
import com.zhiwei.searchhotcrawler.config.DBConfig; import com.zhiwei.searchhotcrawler.config.DBConfig;
import com.zhiwei.searchhotcrawler.crawler.WeiboHotSearchCrawler; import com.zhiwei.searchhotcrawler.crawler.WeiboHotSearchCrawler;
import com.zhiwei.searchhotcrawler.dbtemplate.MongoDBTemplate; import com.zhiwei.searchhotcrawler.dbtemplate.MongoDBTemplate;
import com.zhiwei.searchhotcrawler.util.MD5Util;
import lombok.extern.log4j.Log4j2; import lombok.extern.log4j.Log4j2;
import org.apache.logging.log4j.util.Strings; import org.apache.logging.log4j.util.Strings;
import org.bson.Document; import org.bson.Document;
import java.util.*; import java.util.*;
import static java.util.Objects.isNull;
import static java.util.Objects.nonNull; import static java.util.Objects.nonNull;
/** /**
...@@ -97,7 +99,12 @@ public class HotSearchCacheDAO { ...@@ -97,7 +99,12 @@ public class HotSearchCacheDAO {
String url = document.getString("url")!=null?document.getString("url"):null; String url = document.getString("url")!=null?document.getString("url"):null;
String topicResult = document.getString("topic_result")!=null?document.getString("topic_result"):null; String topicResult = document.getString("topic_result")!=null?document.getString("topic_result"):null;
String pictureUrl = document.getString("pictureUrl")!=null?document.getString("pictureUrl"):null; String pictureUrl = document.getString("pictureUrl")!=null?document.getString("pictureUrl"):null;
String id = name + "_" + type;
String id = document.getString("_id");
if (isNull(id)){
id = name + "_" + type;
}
boolean recommend = false; boolean recommend = false;
// Integer readCount = document.getInteger("comment_count"); // Integer readCount = document.getInteger("comment_count");
if("微博热搜".equals(type)){ if("微博热搜".equals(type)){
......
package com.zhiwei.searchhotcrawler.util;
import java.security.MessageDigest;
public class MD5Util {
private MD5Util() {
throw new IllegalStateException("Utility class");
}
/**
* @Title: MD5
* @Description: MD5后的字符串
* @param pwd
* @param @return
* 设定文件
* @return String 返回类型
*/
public static String getMD5(String pwd) {
return getString(pwd);
}
private static String getString(String pwd) {
char[] md5String = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
try {
// 使用平台的默认字符集将此 String 编码为 byte序列,并将结果存储到一个新的 byte数组中
byte[] btInput = pwd.getBytes();
// 信息摘要是安全的单向哈希函数,它接收任意大小的数据,并输出固定长度的哈希值。
MessageDigest mdInst = MessageDigest.getInstance("MD5");
// MessageDigest对象通过使用 update方法处理数据, 使用指定的byte数组更新摘要
mdInst.update(btInput);
// 摘要更新之后,通过调用digest()执行哈希计算,获得密文
byte[] md = mdInst.digest();
// 把密文转换成十六进制的字符串形式
int j = md.length;
char str[] = new char[j * 2];
int k = 0;
for (int i = 0; i < j; i++) { // i = 0
byte byte0 = md[i]; // 95
str[k++] = md5String[byte0 >>> 4 & 0xf]; // 5
str[k++] = md5String[byte0 & 0xf]; // F
}
// 返回经过加密后的字符串
return new String(str);
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment