From 5e7b0ed4a154ad067cbcf4aa1a1c7cce32f9864c Mon Sep 17 00:00:00 2001
From: admin <weikou2014>
Date: 星期五, 26 四月 2024 18:02:17 +0800
Subject: [PATCH] 唯品会链接解析升级
---
fanli/src/main/java/com/yeshi/fanli/util/ShamHongBaoUtil.java | 307 ++++++++++++++++++++++++---------------------------
1 files changed, 145 insertions(+), 162 deletions(-)
diff --git a/fanli/src/main/java/com/yeshi/fanli/util/ShamHongBaoUtil.java b/fanli/src/main/java/com/yeshi/fanli/util/ShamHongBaoUtil.java
index 0c03803..72d46d7 100644
--- a/fanli/src/main/java/com/yeshi/fanli/util/ShamHongBaoUtil.java
+++ b/fanli/src/main/java/com/yeshi/fanli/util/ShamHongBaoUtil.java
@@ -1,162 +1,145 @@
-package com.yeshi.fanli.util;
-
-import java.io.File;
-import java.io.IOException;
-import java.text.DecimalFormat;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.UUID;
-
-import javax.annotation.Resource;
-
-import org.apache.commons.httpclient.HttpClient;
-import org.apache.commons.httpclient.HttpMethod;
-import org.apache.commons.httpclient.NameValuePair;
-import org.apache.commons.httpclient.methods.PostMethod;
-import org.springframework.stereotype.Component;
-
-import com.yeshi.fanli.entity.bus.user.HongBaoMessage;
-import com.yeshi.fanli.entity.bus.user.ShamUser;
-import com.yeshi.fanli.entity.bus.user.UserInfo;
-import com.yeshi.fanli.service.inter.hongbao.HongBaoMessageService;
-import com.yeshi.fanli.service.inter.user.ShamUserService;
-import com.yeshi.fanli.service.inter.user.UserInfoService;
-
-import jxl.Cell;
-import jxl.Sheet;
-import jxl.Workbook;
-import jxl.read.biff.BiffException;
-import net.sf.json.JSONArray;
-import net.sf.json.JSONObject;
-
-@Component
-public class ShamHongBaoUtil {
-
- @Resource
- private ShamUserService shamUserService;
-
- @Resource
- private UserInfoService userInfoService;
-
- @Resource
- private HongBaoMessageService hongBaoMessageService;
-
- public void addShamUserInfo(){
- List<ShamUser> list =shamUserService.getAll();
- for (ShamUser shamUser : list) {
- UserInfo form = new UserInfo();
- form.setNickName(shamUser.getName());
- form.setPortrait(shamUser.getPicUrl());
- form.setLoginType(-1);
- form.setOpenid(UUID.randomUUID().toString().replaceAll("-", "")+"-1");
- userInfoService.addUser(form, "23649898");
- }
- }
-
- public void deleteShamUser(String path){
- try {
- Workbook workbook = Workbook.getWorkbook(new File(path));
- Sheet sheet = workbook.getSheet(0);
- for (int ii=0;ii<sheet.getRows();ii++) {
- Cell cell = sheet.getCell(0,ii);
- if(cell.getContents()==null || "".equals(cell.getContents().trim())){
- continue;
- }
- shamUserService.delete(Long.parseLong(cell.getContents()));
- }
- } catch (BiffException e) {
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- }
-
- }
-
- private void addHongBaoMessage(){
- List<ShamUser> all = shamUserService.getAll();
- List<HongBaoMessage> list = new ArrayList<HongBaoMessage>();
- HongBaoMessage message;
- DecimalFormat df = new DecimalFormat("######0.00");
- for (ShamUser shamUser : all) {
- message = new HongBaoMessage();
- message.setName(shamUser.getName());
- message.setPicUrl(shamUser.getPicUrl());
- double random = (Math.random()+0.01)*20;
- String format = df.format(random);
- message.setContent("鎮勬倓棰嗗彇浜�"+format+"鍏冪孩鍖�");
- list.add(message);
- }
- hongBaoMessageService.add(list);
- }
-
- public void addShamUser(String pid) throws Exception{
- HttpClient client = new HttpClient();
- HttpMethod method = getPostMethod(pid);
- client.executeMethod(method);
- java.lang.System.out.println(method.getStatusLine()); //鎵撳嵃缁撴灉椤甸潰
- String response=new String(method.getResponseBodyAsString().getBytes("UTF-8"));
- //鎵撳嵃杩斿洖鐨勪俊鎭�
- method.releaseConnection();
- List<ShamUser> list = parseQQresult(response);
- for (ShamUser shamUser : list) {
- shamUserService.addShamUser(shamUser);
- }
- }
-
- private static List<ShamUser> parseQQresult(String response) throws Exception {
- JSONObject json = JSONObject.fromObject(response);
- List<ShamUser> list = new ArrayList<ShamUser>();
- String code = String.valueOf(json.opt("retcode"));
- if("0".equals(code)){
- JSONArray jsonArray = json.optJSONObject("result").optJSONObject("buddy").optJSONArray("info_list");
- ShamUser user = null;
- String patterns = "[^\u4e00-\u9fa5\\w\\s]+";
- if(jsonArray==null){
- return list;
- }
- for (Object object : jsonArray) {
- JSONObject data = (JSONObject)object;
- String name = (String) data.opt("nick");
- name=name.replaceAll(patterns, "").replaceAll(" ", "");
- if(name.length() < 2){
- continue;
- }
- String picUrl = (String) data.opt("url");
- user = new ShamUser();
- user.setName(new String(name.getBytes(),"utf-8"));
- if(picUrl.contains("pub.idqqimg.com")){
- picUrl="https://gw.alicdn.com/tps/i3/TB1yeWeIFXXXXX5XFXXuAZJYXXX-210-210.png_160x160.jpg";
- }
- user.setPicUrl(picUrl);
- list.add(user);
- }
- }
- return list;
- }
-
- private static HttpMethod getPostMethod(String pid) {
- PostMethod post = new PostMethod( "http://cgi.find.qq.com/qqfind/buddy/search_v3" ); //recommendDetails voteGoods recommendReplys makePublic replys
- NameValuePair num = new NameValuePair( "num" , "100" );
- NameValuePair page = new NameValuePair( "page" , "0" );
- NameValuePair sessionid = new NameValuePair( "sessionid" , "0" );
- NameValuePair agerg = new NameValuePair( "agerg" , "13" );
- NameValuePair sex = new NameValuePair( "sex" , "0" );
- NameValuePair firston = new NameValuePair( "firston" , "0" );
- NameValuePair video = new NameValuePair( "video" , "0" );
- NameValuePair country = new NameValuePair( "country" , "1" );
- NameValuePair province = new NameValuePair( "province" , pid );
- NameValuePair city = new NameValuePair( "city" , "0" );
- NameValuePair district = new NameValuePair( "district" , "0" );
- NameValuePair hcountry = new NameValuePair( "hcountry" , "1" );
- NameValuePair hprovince = new NameValuePair( "hprovince" , "0" );
- NameValuePair hcity = new NameValuePair( "hcity" , "0" );
- NameValuePair hdistrict = new NameValuePair( "hdistrict" , "0" );
- NameValuePair online = new NameValuePair( "online" , "0" );
- NameValuePair ldw = new NameValuePair( "ldw" , "814539287" );
- post.setRequestHeader("Cookie", "RK=7dVSTqdaSf; pt2gguin=o0424539852; ptisp=ctc; ptcz=555762bb1a6cef860451fe47677c82eaf80a1388eee045b8cf2d546ed1c96534; _qpsvr_localtk=tk70; pgv_info=ssid=s852802188; pgv_pvid=9584824304; uin=o424539852; skey=Z9PWyiIOuI; itkn=2002088896");
- post.setRequestBody( new NameValuePair[] {num,page,sessionid,agerg,sex,firston,video,country,province,city,
- district,hcountry,hprovince,hcity,hdistrict,online,ldw});
- return post;
- }
-
-}
+package com.yeshi.fanli.util;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.UUID;
+
+import javax.annotation.Resource;
+
+import com.yeshi.fanli.entity.SystemEnum;
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.HttpMethod;
+import org.apache.commons.httpclient.NameValuePair;
+import org.apache.commons.httpclient.methods.PostMethod;
+import org.springframework.stereotype.Component;
+
+import com.yeshi.fanli.entity.bus.user.ShamUser;
+import com.yeshi.fanli.entity.bus.user.UserInfo;
+import com.yeshi.fanli.service.inter.user.ShamUserService;
+import com.yeshi.fanli.service.inter.user.UserInfoService;
+
+import jxl.Cell;
+import jxl.Sheet;
+import jxl.Workbook;
+import jxl.read.biff.BiffException;
+import net.sf.json.JSONArray;
+import net.sf.json.JSONObject;
+
+@Component
+public class ShamHongBaoUtil {
+
+ @Resource
+ private ShamUserService shamUserService;
+
+ @Resource
+ private UserInfoService userInfoService;
+
+ public void addShamUserInfo() {
+ List<ShamUser> list = shamUserService.getAll();
+ for (ShamUser shamUser : list) {
+ UserInfo form = new UserInfo();
+ form.setNickName(shamUser.getName());
+ form.setPortrait(shamUser.getPicUrl());
+ form.setLoginType(-1);
+ form.setOpenid(UUID.randomUUID().toString().replaceAll("-", "") + "-1");
+ userInfoService.addUser(form, SystemEnum.blks);
+ }
+ }
+
+ public void deleteShamUser(String path) {
+ try {
+ Workbook workbook = Workbook.getWorkbook(new File(path));
+ Sheet sheet = workbook.getSheet(0);
+ for (int ii = 0; ii < sheet.getRows(); ii++) {
+ Cell cell = sheet.getCell(0, ii);
+ if (cell.getContents() == null || "".equals(cell.getContents().trim())) {
+ continue;
+ }
+ shamUserService.deleteByPrimaryKey(Long.parseLong(cell.getContents()));
+ }
+ } catch (BiffException e) {
+ e.printStackTrace();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+
+ }
+
+ public void addShamUser(String pid) throws Exception {
+ HttpClient client = new HttpClient();
+ HttpMethod method = getPostMethod(pid);
+ client.executeMethod(method);
+ java.lang.System.out.println(method.getStatusLine()); // 鎵撳嵃缁撴灉椤甸潰
+ String response = new String(method.getResponseBodyAsString().getBytes("UTF-8"));
+ // 鎵撳嵃杩斿洖鐨勪俊鎭�
+ method.releaseConnection();
+ List<ShamUser> list = parseQQresult(response);
+ for (ShamUser shamUser : list) {
+ shamUserService.addShamUser(shamUser);
+ }
+ }
+
+ private static List<ShamUser> parseQQresult(String response) throws Exception {
+ JSONObject json = JSONObject.fromObject(response);
+ List<ShamUser> list = new ArrayList<ShamUser>();
+ String code = String.valueOf(json.opt("retcode"));
+ if ("0".equals(code)) {
+ JSONArray jsonArray = json.optJSONObject("result").optJSONObject("buddy").optJSONArray("info_list");
+ ShamUser user = null;
+ String patterns = "[^\u4e00-\u9fa5\\w\\s]+";
+ if (jsonArray == null) {
+ return list;
+ }
+ for (Object object : jsonArray) {
+ JSONObject data = (JSONObject) object;
+ String name = (String) data.opt("nick");
+ name = name.replaceAll(patterns, "").replaceAll(" ", "");
+ if (name.length() < 2) {
+ continue;
+ }
+ String picUrl = (String) data.opt("url");
+ user = new ShamUser();
+ user.setName(new String(name.getBytes(), "utf-8"));
+ if (picUrl.contains("pub.idqqimg.com")) {
+ picUrl = "https://gw.alicdn.com/tps/i3/TB1yeWeIFXXXXX5XFXXuAZJYXXX-210-210.png_160x160.jpg";
+ }
+ user.setPicUrl(picUrl);
+ list.add(user);
+ }
+ }
+ return list;
+ }
+
+ private static HttpMethod getPostMethod(String pid) {
+ PostMethod post = new PostMethod("http://cgi.find.qq.com/qqfind/buddy/search_v3"); // recommendDetails
+ // voteGoods
+ // recommendReplys
+ // makePublic
+ // replys
+ NameValuePair num = new NameValuePair("num", "100");
+ NameValuePair page = new NameValuePair("page", "0");
+ NameValuePair sessionid = new NameValuePair("sessionid", "0");
+ NameValuePair agerg = new NameValuePair("agerg", "13");
+ NameValuePair sex = new NameValuePair("sex", "0");
+ NameValuePair firston = new NameValuePair("firston", "0");
+ NameValuePair video = new NameValuePair("video", "0");
+ NameValuePair country = new NameValuePair("country", "1");
+ NameValuePair province = new NameValuePair("province", pid);
+ NameValuePair city = new NameValuePair("city", "0");
+ NameValuePair district = new NameValuePair("district", "0");
+ NameValuePair hcountry = new NameValuePair("hcountry", "1");
+ NameValuePair hprovince = new NameValuePair("hprovince", "0");
+ NameValuePair hcity = new NameValuePair("hcity", "0");
+ NameValuePair hdistrict = new NameValuePair("hdistrict", "0");
+ NameValuePair online = new NameValuePair("online", "0");
+ NameValuePair ldw = new NameValuePair("ldw", "814539287");
+ post.setRequestHeader("Cookie",
+ "RK=7dVSTqdaSf; pt2gguin=o0424539852; ptisp=ctc; ptcz=555762bb1a6cef860451fe47677c82eaf80a1388eee045b8cf2d546ed1c96534; _qpsvr_localtk=tk70; pgv_info=ssid=s852802188; pgv_pvid=9584824304; uin=o424539852; skey=Z9PWyiIOuI; itkn=2002088896");
+ post.setRequestBody(new NameValuePair[] { num, page, sessionid, agerg, sex, firston, video, country, province,
+ city, district, hcountry, hprovince, hcity, hdistrict, online, ldw });
+ return post;
+ }
+
+}
--
Gitblit v1.8.0