@RequestMapping(path = "/v1/ht", produces = {"application/json;charset=UTF-8"})
@PostMapping("/htInsuredSubmit")
public ResultDTO<Map<String, String>> htInsuredSubmit(@RequestBody String strAppInfo,HttpServletRequest request){
try {
LogHelper.commoninfo("==========API==strAppInfo===="+strAppInfo);
// 针对url传递特殊字符转译问题
strAppInfo = strAppInfo.replaceAll("%","%25");
LogHelper.commoninfo("==========API==strAppInfo===="+strAppInfo);
String signature = MD5Util.MD5Encode(strAppInfo + ENCRYPT_VAL, "utf-8"); // 加密
// 发送数据,获取响应
String jsonStr = HttpClientConfig.requestService(htInsuredSubmitUrl, "json="+strAppInfo+"&channelCode="+CHANNELCODE+"&signature="+signature);
return new ResultDTO<>(ResultDTO.CODE_SUCCESS,jsonStr);
} catch (Exception e) {
LogHelper.commonerror("HrInsuredController.htInsuredSubmit:" + e.getMessage(), e);
return new ResultDTO<>(ResultDTO.CODE_DEFAULT_FAIL, "投保失败,请重试!");
}
public static String requestService(String toURL,String data) throws Exception {
StringBuffer bs = new StringBuffer();
URL url = new URL(toURL);
HttpURLConnection urlcon=null;
String proxyUrl="10.9.1.5";
int proxyProt=3128;
// 打开和URL之间的连接
if(isProxy){
Proxy proxy = new Proxy(Proxy.Type.DIRECT.HTTP, new InetSocketAddress(proxyUrl, proxyProt));
urlcon = (HttpURLConnection) url.openConnection(proxy);
}else{
urlcon = (HttpURLConnection) url.openConnection();
}
urlcon.setRequestMethod("POST");
urlcon.setUseCaches(false);
urlcon.setConnectTimeout(30000);
urlcon.setReadTimeout(30000);
urlcon.setDoInput(true);
urlcon.setDoOutput(true);
urlcon.setRequestProperty("accept", "*/*");
urlcon.setRequestProperty("Accept-Charset", "UTF-8");
urlcon.setRequestProperty("contentType", "UTF-8");
urlcon.setRequestProperty("Content-Type","application/x-www-form-urlencoded;charset=UTF-8");
OutputStream out = urlcon.getOutputStream();
out.write(data.getBytes("UTF-8"));
out.flush();
out.close();
urlcon.connect();
InputStream is = urlcon.getInputStream();
BufferedReader buffer = new BufferedReader(
new InputStreamReader(is,"UTF-8"));
String l = null;
while ((l = buffer.readLine()) != null) {
bs.append(l);
}
return bs.toString();
}