上海征信涉农接口

This commit is contained in:
majintao
2024-07-29 15:33:31 +08:00
parent 1ed853d041
commit 7344e0d3f5
@@ -23,12 +23,14 @@ import com.google.gson.JsonObject;
import net.sf.json.JSONObject;
import org.apache.commons.lang.StringUtils;
import org.apache.http.HttpEntity;
import org.apache.http.HttpHost;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.impl.conn.DefaultProxyRoutePlanner;
import org.apache.http.util.EntityUtils;
import org.sothis.core.util.Pager;
import sun.misc.BASE64Encoder;
@@ -288,12 +290,6 @@ public class AddrSvcController {
return mav;
}
<<<<<<< HEAD
public static void main(String[] args) {
String address = "江西省南康市蓉江街道办事处麻田村石桥19号";
String townShip = "蓉江街道";
System.out.println(address.substring(address.indexOf(townShip)+townShip.length()));
=======
public Object avgPriceAction(AddressModel model) {
RestfulModelAndView mav = new RestfulModelAndView();
if (StringUtils.isBlank(model.getAddress())) {
@@ -492,6 +488,98 @@ public class AddrSvcController {
}
return mav;
}
/**
* 涉农识别-新规则-上海征信
*
* @param model
* @return
*/
public Object shzxVillageIdentifyAction(AddressModel model) {
RestfulModelAndView mav = new RestfulModelAndView();
if (StringUtils.isBlank(model.getAddress())) {
mav.setModel(BasicModel.buildBadRequestModel("地址不能为空"));
return mav;
}
HttpRequest request = new HttpRequest();
JSONObject json = null;
Map<String, String> params = new HashMap<String, String>();
params.put("city", StringUtils.isNotBlank(model.getCity()) ? model.getCity() : null);
String address = model.getAddress();
params.put("address", address);
String type = StringUtils.isNotBlank(model.getType()) ? model.getType() : null;
params.put("type", type);
try {
json = request.getJsonContent("http://192.168.0.100:32080/FangJiaAddressService/shzxVillageIdentify", params, "UTF-8");
} catch (Exception e) {
try {
json = request.getJsonContent("http://192.168.0.100:32080/FangJiaAddressService/shzxVillageIdentify", params, "UTF-8");
} catch (Exception ex) {
ex.printStackTrace();
}
}
if (json != null) {
int code = json.getInt("msgCode");
String msg = json.getString("msg");
BasicModel basicModel = new BasicModel(code, msg);
if (json.containsKey("result")) {
//我们的结果
JSONObject result = json.getJSONObject("result");
//我们省级及以上有开发区,直接用我们的结果
if (result.containsKey("devDistrictName")) {
basicModel.setResult(result);
} else {
try {
//如果是江苏省或者浙江省 调用齐梁的结果
if ("江苏省".equals(result.getString("province")) || "浙江省".equals(result.getString("province"))) {
//结果比较,如果涉农结果不一致
//调用齐梁 type :1 对公 0 对私
//我们 type :1 对私 2 对共
String qltype = "2".equals(type) ? "1" : "0";
Map<String, String> map = senRequest(address, qltype);
// 涉农结果不一样
if (!map.get("verifyFlag").equals(result.get("verifyFlag"))) {
//城市不一样 用我们
if (result.containsKey("city")) {
if ((!result.get("city").equals(map.get("city")) && StringUtils.isNotBlank(result.getString("city")))) {
basicModel.setResult(result);
} else {
map.put("addrVerify", "地址有效");
map.put("typeName", areaMap.get(map.get("typeCode")));
basicModel.setResult(map);
}
} else {
map.put("addrVerify", "地址有效");
map.put("typeName", areaMap.get(map.get("typeCode")));
basicModel.setResult(map);
}
} else {
basicModel.setResult(result);
}
} else {
basicModel.setResult(result);
}
} catch (Exception e) {
e.printStackTrace();
basicModel.setResult(result);
}
}
}
mav.setModel(basicModel);
} else {
mav.setModel(BasicModel.buildServerErrorModel().setMsg("服务升级中..."));
}
return mav;
}
/**
@@ -636,9 +724,12 @@ public class AddrSvcController {
String auth = authKey + ":" + password;
String authHeader = "Basic " + new BASE64Encoder().encode(auth.getBytes(Charset.forName("UTF-8")));
CloseableHttpClient httpClient = HttpClients.createDefault();
HttpHost proxy = new HttpHost(proxyHost, proxyPort);
DefaultProxyRoutePlanner routePlanner = new DefaultProxyRoutePlanner(proxy);
CloseableHttpClient httpClient = HttpClients.custom()
.setRoutePlanner(routePlanner)
.build();
HttpPost httpPost = new HttpPost(targetURL);
Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(proxyHost, proxyPort));
Authenticator.setDefault(new Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(proxyUsername, proxyPassword.toCharArray());
@@ -837,6 +928,5 @@ public class AddrSvcController {
public void setVillageIdentifyService(VillageIdentifyService villageIdentifyService) {
this.villageIdentifyService = villageIdentifyService;
>>>>>>> c7c2bae298951f01848f2b654c4c5e7fdba454c0
}
}