This commit is contained in:
2021-11-20 17:35:06 +08:00
parent 399e90b4dd
commit 88bbfb9ba0
2 changed files with 197 additions and 3 deletions
@@ -167,9 +167,9 @@ public class RegionData implements PriorityOrdered {
ret = format(cityRegionMap, region);
}
if (null == ret) {
return region;
}
// if (null == ret) {
// return region;
// }
return ret;
}
@@ -0,0 +1,194 @@
package com.fangjia.script.bhapitest
import com.fangjia.core.util.HttpRequest
import com.fangjia.core.util.MD5Util
import com.fangjia.script.lixue.util.RequestUtil
import com.fangjia.script.util.ABuYunUtil
import com.fangjia.script.util.DateUtils
import com.fangjia.script.weilei.spider.HttpClientUtils
import com.fangjia.script.yinjihaun.util.HttpClient
import net.sf.json.JSONArray
import net.sf.json.JSONObject
import org.apache.commons.lang.StringUtils
import org.jsoup.Jsoup
import org.yaml.snakeyaml.util.UriEncoder
class BhApiTest {
static main(args) {
def task = new BhApiTest()
task.run()
}
def run(){
def md5str1 = MD5Util.encrypt("bohaifangjiatest1632387715123456","utf-8")
def token = "bohaifangjiatest"
// def curDate = DateUtils.formatDateByPattern(new Date(), "yyyy-MM-dd HH:mm:ss")
// def date1 = DateUtils.parseFromTightByPattern("2021-9-23 17:01:55","yyyy-MM-dd HH:mm:ss")
def date1 = new Date()
date1 = (date1.getTime()/1000).toInteger()
def nonce = 123456
def str = token + date1.toString()+nonce
def md5str2 = MD5Util.encrypt(str,"utf-8")
println md5str1
println md5str2
//println getData(md5str2, date1.toString(), nonce)
// getData2(date1.toString(), nonce)
getData3(date1.toString(), nonce)
}
def getData2(timestamp, nonce){
List<JSONObject> list = new ArrayList<JSONObject>();
Map params = new HashMap();
def queryFullAddr = "叶联路699弄"
params.put("queryFullAddr",queryFullAddr);
params.put("preCode", "sh1190323");
params.put("preName", "南山雨果/西郊水岸馨苑(公寓)");
params.put("countryCode", "310118000000");
params.put("buildName", "叶联路666弄/叶联路699弄");
params.put("floor", "2");
params.put("totalFloor", "11");
// params.put("houseNo",ev.getRoomNum());
params.put("groundArea", "88.71");
params.put("orientName", "南");
params.put("buildYear", "2014");
params.put("dealPriceTotal", "5500000");
params.put("userName", "test");
// params.put("userPhone", "17740818975");
// params.put("userMail", "");
params.put("groupName", "测试");
def lists = ["queryFullAddr", "preCode", "preName", "countryCode", "buildName", "unitCode","floor","totalFloor","houseNo","groundArea","undergroundArea","orientName","buildYear","dealPriceTotal","specialNo","userName","userPhone","userMail","groupName"]
def s = ""
for(def key : lists){
def value = params.get(key)
if(value){
s = s + value
}
}
println s
def s1 = URLEncoder.encode(s,"utf-8")
println s1
Integer date1 = (int)(new Date().getTime()/1000);
String str = "bohaifangjiatest" + date1.toString()+nonce+ s1
println "拼接: "+str
String md5str2 = MD5Util.encrypt(str,"utf-8");
println "md5:"+md5str2
Map headers = new HashMap();
headers.put("timestamp", date1.toString());
headers.put("sign", md5str2);
headers.put("nonce", nonce.toString());
HttpRequest request = new HttpRequest();
String content = null;
try {
content = request.post("http://topen.shbrea.com.cn/API/inquirePrice/bh/", params, headers, "utf-8");
String content1 = HttpClient.post("http://topen.shbrea.com.cn/API/inquirePrice/bh/", params, headers, "utf-8", false)
if(StringUtils.isNotBlank(content)){
JSONObject jsonObj = JSONObject.fromObject(content);
JSONArray data = (JSONArray) jsonObj.get("data");
if(data.size()>0){
for(int i=0;i<data.size();i++){
JSONObject obj = (JSONObject) data.get(i);
list.add(obj);
}
}
}
}catch (Exception e){
e.printStackTrace();
}
}
def getData(md5str, timestamp, nonce){
def params = [:]
// params.put("keyword",URLEncoder.encode("中潭路99弄", "UTF-8"))
params.put("keyword","中山二路125弄")
def headers = [:]
headers.put("timestamp", timestamp)
headers.put("sign", md5str)
headers.put("nonce", nonce.toString())
// String result = RequestUtil.doGet("http://topen.shbrea.com.cn/API/searchAddr/bh/", headers);
def ret = ABuYunUtil.doGet("http://topen.shbrea.com.cn/API/searchAddr/bh/", params, headers, "utf-8");
def rets = HttpClient.get("http://topen.shbrea.com.cn/API/searchAddr/bh/", params, headers)
JSONObject jsonObj = JSONObject.fromObject(rets);
def data = jsonObj.data
println data
}
public String decode(String input) {
StringBuffer out = new StringBuffer(); // Used to hold the output.
char current; // Used to reference the current character.
if(input == null || ("".equals(input)))
return ""; // vacancy test.
for (int i = 0; i < input.length(); i++) {
current = input.charAt(i);
if ((current == 0x9) || (current == 0xA) || (current == 0xD)
|| ((current > 0x20) && (current <= 0xD7FF))
|| ((current >= 0xE000) && (current <= 0xFFFD))
|| ((current >= 0x10000) && (current <= 0x10FFFF))
|| (current < 0x0))
out.append(current);
}
return out.toString().trim();
}
def getData3(timestamp, nonce){
List<JSONObject> list = new ArrayList<JSONObject>();
Map params = new HashMap();
params.put("queryId","cdadc441-8917-33b6-8787-8d894bf088b4");
params.put("userName", "测试");
def lists = ["queryId", "userName"]
def s = ""
for(def key : lists){
def value = params.get(key)
if(value){
s = s + value
}
}
println s
def s1 = URLEncoder.encode(s,"utf-8")
println s1
Integer date1 = (int)(new Date().getTime()/1000);
String str = "bohaifangjiatest" + date1.toString()+nonce+ s1
println "拼接: "+str
String md5str2 = MD5Util.encrypt(str,"utf-8");
println "md5:"+md5str2
Map headers = new HashMap();
headers.put("timestamp", date1.toString());
headers.put("sign", md5str2);
headers.put("nonce", nonce.toString());
HttpRequest request = new HttpRequest();
String content = null;
try {
content = request.post("http://topen.shbrea.com.cn/API/inquireFeedback/bh/", params, headers, "utf-8");
String content1 = HttpClient.post("http://topen.shbrea.com.cn/API/inquireFeedback/bh/", params, headers, "utf-8", false)
if(StringUtils.isNotBlank(content)){
JSONObject jsonObj = JSONObject.fromObject(content);
JSONArray data = (JSONArray) jsonObj.get("data");
if(data.size()>0){
for(int i=0;i<data.size();i++){
JSONObject obj = (JSONObject) data.get(i);
list.add(obj);
}
}
}
}catch (Exception e){
e.printStackTrace();
}
}
}