d909fd4410551a824157041d8d4e0424cc3c3f79.svn-base
11.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
package com.thinkgem.jeesite.modules.reg.web.httprest.httpRestService;
import java.io.IOException;
import java.net.URLEncoder;
import java.util.Iterator;
import java.util.Map;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.util.EntityUtils;
import org.codehaus.jackson.JsonParser.Feature;
import org.codehaus.jackson.map.ObjectMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.google.common.collect.Maps;
import com.thinkgem.jeesite.common.config.Global;
import com.thinkgem.jeesite.common.mapper.JsonMapper;
import com.thinkgem.jeesite.common.service.ServiceException;
import com.thinkgem.jeesite.common.utils.DateUtils;
import com.thinkgem.jeesite.common.utils.JsonUtil;
import com.thinkgem.jeesite.common.utils.StringUtils;
import com.thinkgem.jeesite.modules.reg.service.qjxt.InterfacelogService;
import com.thinkgem.jeesite.modules.reg.utils.Base64;
import com.thinkgem.jeesite.modules.ycsl.entity.token.YcslToken;
import com.thinkgem.jeesite.modules.ycsl.service.token.YcslTokenService;
@Service
public class HttpactivityService {
@Autowired
private YcslTokenService ycslTokenService;
@Autowired
private InterfacelogService interfacelogService;
Logger logger = LoggerFactory.getLogger(getClass());
public Map postRequest(Map data,String bj) throws ClientProtocolException, IOException {
String resjson = "";
logger.info("*******请求数据信息:"+JsonUtil.toJsonString(data));
if(StringUtils.isNotBlank(bj)){
if("sendDb".equals(bj)){
//2.1.6 不动产登簿信息接收接口 登薄结果推送
resjson = getReturnResByUrl(JsonMapper.toJsonString(data),"一窗受理平台",Global.POST_YCSL_URL_FZ,null);
}else if("bhSqxx".equals(bj)){
//退件删除请求
resjson = getReturnResByUrl(JsonMapper.toJsonString(data),"一窗受理平台",Global.POST_YCSL_URL_XTTJ,null);
}else if("updateYwzt".equals(bj)){
//业务办结状态请求
resjson = getReturnResByUrl(JsonMapper.toJsonString(data),"一窗受理平台",Global.POST_YCSL_URL_YWZT,null);
}else if("downTradeFiles".equals(bj)){
//2.1.5 房产交易附件下载
resjson = getReturnResByUrl(JsonMapper.toJsonString(data),"一窗受理平台",Global.POST_YCSL_URL_downTradeFiles,null);
}else if("queryTradeWj".equals(bj)){
//2.1.4 获取交易业务办结信息
resjson = getReturnResByUrl(JsonMapper.toJsonString(data),"一窗受理平台",Global.POST_YCSL_URL_queryTradeWj,null);
}else if("insertSL".equals(bj)){
//2.1.1 新增受理信息到中间库
resjson = getReturnResByUrl(JsonMapper.toJsonString(data),"一窗受理平台",Global.POST_YCSL_URL_insertSL,null);
}else if("updateSL".equals(bj)){
//2.1.2 修改受理信息到中间库
resjson = getReturnResByUrl(JsonMapper.toJsonString(data),"一窗受理平台",Global.POST_YCSL_URL_updateSL,null);
}else if("deleteSL".equals(bj)){
//2.1.3 删除受理信息到中间库
resjson = getReturnResByUrl(JsonMapper.toJsonString(data),"一窗受理平台",Global.POST_YCSL_URL_deleteSL,null);
}else if("queryTradeYw".equals(bj)){
//2.1.8 不动产获取交易业务办结信息
resjson = getReturnResByUrl(JsonMapper.toJsonString(data),"一窗受理平台",Global.POST_YCSL_URL_queryTradeYw,null);
}else if("queryTradeEstate".equals(bj)){
//2.1.9 查询房产交易信息
resjson = getReturnResByUrl(JsonMapper.toJsonString(data),"一窗受理平台",Global.POST_YCSL_URL_queryTradeEstate,null);
}else if("saveHookRelation".equals(bj)){
//2.1.10 不动产新增挂接关系
resjson = getReturnResByUrl(JsonMapper.toJsonString(data),"一窗受理平台",Global.POST_YCSL_URL_saveHookRelation,null);
}else if("removeHookRelation".equals(bj)){
//2.1.11 不动产删除挂接关系
resjson = getReturnResByUrl(JsonMapper.toJsonString(data),"一窗受理平台",Global.POST_YCSL_URL_removeHookRelation,null);
}else if("saveHouseStatus".equals(bj)){
//2.1.12 新增房屋状态
resjson = getReturnResByUrl(JsonMapper.toJsonString(data),"一窗受理平台",Global.POST_YCSL_URL_saveHouseStatus,null);
}else if("modifyHouseStatus".equals(bj)){
//2.1.13 修改房屋状态
resjson = getReturnResByUrl(JsonMapper.toJsonString(data),"一窗受理平台",Global.POST_YCSL_URL_modifyHouseStatus,null);
}else if("terminateInfo".equals(bj)){
//2.1.14 不动产办结信息接收接口
resjson = getReturnResByUrl(JsonMapper.toJsonString(data),"一窗受理平台",Global.POST_YCSL_URL_terminateInfo,null);
}else if("findLicenseInfo".equals(bj)){
//2.1.15 是否挂牌信息查询接口
resjson = getReturnResByUrl(JsonMapper.toJsonString(data),"一窗受理平台",Global.POST_YCSL_URL_findLicenseInfo,null);
}else if("wsqk".equals(bj)){
//4.3 完税接口
resjson = getReturnResByUrl(JsonMapper.toJsonString(data),"一窗受理平台",Global.POST_YCSL_URL_wsqk,null);
}else if("downDealFiles".equals(bj)){
//2.1.17 房产合同下载
resjson = getReturnResByUrl(JsonMapper.toJsonString(data),"一窗受理平台",Global.POST_YCSL_URL_downDealFiles,null);
}
}
if(!StringUtils.isBlank(resjson)) {
ObjectMapper mapper = new ObjectMapper();
mapper.configure(Feature.ALLOW_UNQUOTED_CONTROL_CHARS, true);
mapper.configure(Feature.ALLOW_UNQUOTED_FIELD_NAMES, true);
mapper.configure(Feature.ALLOW_SINGLE_QUOTES, true);
mapper.configure(Feature.ALLOW_UNQUOTED_CONTROL_CHARS, true);
mapper.configure(Feature.INTERN_FIELD_NAMES, true);
mapper.configure(Feature.CANONICALIZE_FIELD_NAMES, true);
Map json = mapper.readValue(resjson, Map.class);
return json;
}else {
return null;
}
}
/**
* @param url
* post方式请求
* @return url返回的数据,以字符串显示
* @throws ClientProtocolException
* @throws IOException
*/
private String getReturnResByUrl(String in_json,String servername,String urls,Map<String ,String> header) throws IOException {
logger.info("url:{}",urls);
logger.info("http request header:" + JsonUtil.toJsonString(header));
logger.info("http request data:" + in_json);
// URL访问超时时间
String url = urls;
Integer URLOUTTIME = 1000 * 60;
String json = Base64.encryptBASE64(in_json);
String res = "";
HttpPost httppost = null;
CloseableHttpClient client = null;
CloseableHttpResponse response = null;
Exception exception = null;
try {
client = HttpClientBuilder.create().build();
httppost = new HttpPost(url);
RequestConfig requestConfig = RequestConfig.custom().setConnectionRequestTimeout(URLOUTTIME)
.setConnectTimeout(URLOUTTIME).setSocketTimeout(URLOUTTIME).build();
httppost.setConfig(requestConfig);
StringEntity entity = new StringEntity(in_json, "utf-8");
httppost.setEntity(entity);
if(header != null && header.size() >0) {
Iterator<String> it = header.keySet().iterator();
while(it.hasNext()){
String key = it.next();
httppost.setHeader(key,header.get(key));
}
}
httppost.setHeader("ContentType", "application/json;charset=UTF-8");
response = client.execute(httppost);
int code = response.getStatusLine().getStatusCode();
if (code == 200) {
res = EntityUtils.toString(response.getEntity(), "utf-8");
} else {
throw new ServiceException("返回状态代码" + code);
}
} catch (Exception s) {
exception = s;
throw new ServiceException(" http请求发生错误," + s.getMessage());
} finally {
if (httppost != null) {
httppost.releaseConnection();
}
if (response != null) {
response.close();
}
if (client != null) {
client.close();
}
interfacelogService.saveAskByProperty(url, servername,in_json,res, exception);
}
logger.info("http post back:" + res);
return res;
}
/**
* @param url
* post方式请求
* @return url返回的数据,以字符串显示
* @throws ClientProtocolException
* @throws IOException
*/
public String getrzsbByUrl(String rzsbxml) throws IOException {
// URL访问超时时间
String url = Global.getCommonLogUrl();
Integer URLOUTTIME = 1000 * 60;
String res = "";
HttpPost httppost = null;
CloseableHttpClient client = null;
CloseableHttpResponse response = null;
Exception exception = null;
try {
client = HttpClientBuilder.create().build();
httppost = new HttpPost(url);
RequestConfig requestConfig = RequestConfig.custom().setConnectionRequestTimeout(URLOUTTIME)
.setConnectTimeout(URLOUTTIME).setSocketTimeout(URLOUTTIME).build();
httppost.setConfig(requestConfig);
StringEntity entity = new StringEntity(rzsbxml, "utf-8");
httppost.setEntity(entity);
httppost.setHeader("ContentType", "application/json;charset=UTF-8");
response = client.execute(httppost);
int code = response.getStatusLine().getStatusCode();
if (code == 200) {
res = EntityUtils.toString(response.getEntity(), "utf-8");
} else {
throw new ServiceException("返回状态代码" + code);
}
} catch (Exception s) {
exception = s;
throw new ServiceException(" http请求发生错误," + s.getMessage());
} finally {
if (httppost != null) {
httppost.releaseConnection();
}
if (response != null) {
response.close();
}
if (client != null) {
client.close();
}
}
logger.info("http post back:" + res);
return res;
}
public Map hzpostRequest(Map data) throws ClientProtocolException, IOException {
Map resmap = Maps.newHashMap();
Map head = Maps.newHashMap();
head.put("regionCode", "0000");
head.put("orgid", "");
resmap.put("head", head);
resmap.put("data", data);
System.out.println("*******返回登记结果信息:"+resmap);
String resjson = getReturnResByUrl(JsonMapper.toJsonString(resmap),"数据汇总复核",Global.POST_SJHZ_URL_FH,null);
ObjectMapper mapper = new ObjectMapper();
mapper.configure(Feature.ALLOW_UNQUOTED_CONTROL_CHARS, true);
mapper.configure(Feature.ALLOW_UNQUOTED_FIELD_NAMES, true);
mapper.configure(Feature.ALLOW_SINGLE_QUOTES, true);
mapper.configure(Feature.ALLOW_UNQUOTED_CONTROL_CHARS, true);
mapper.configure(Feature.INTERN_FIELD_NAMES, true);
mapper.configure(Feature.CANONICALIZE_FIELD_NAMES, true);
Map json = mapper.readValue(resjson, Map.class);
String success = json.get("success").toString();
if("false".equals(success)){
throw new ServiceException("响应失败,错误信息:"+(json.get("resultMsg")) == null?"错误信息未返回":json.get("resultMsg").toString().toString());
}
return json;
}
// public static void main(String[] args) {
// HttpactivityService service = new HttpactivityService();
// Map data = Maps.newHashMap();
// data.put("proid", "Adfsdgwew");
// data.put("bdcdyh", "Adfsdgwew");
// data.put("cqzh", "陕(2017)汉中市不动产权第0000010号");
// data.put("xml", "此处放xml报文");
//
// try {
// Map map = service.postRequest(data);
// System.out.println("返回信息head" + map.get("head"));
// } catch (ClientProtocolException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// } catch (IOException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
// }
}