Ecology-Dev-chaofa/盛虹化纤/interface/shhq/tb_qys.jsp

154 lines
5.5 KiB
Plaintext

<%@ page language="java" contentType="text/html; charset=utf-8" %>
<%@ page import="java.util.Map" %>
<%@ page import="java.util.HashMap" %>
<%@ page import="org.apache.http.impl.client.*" %>
<%@ page import="org.apache.http.impl.client.CloseableHttpClient" %>
<%@ page import="org.apache.http.client.methods.HttpPost" %>
<%@ page import="org.apache.http.client.methods.CloseableHttpResponse" %>
<%@ page import="org.apache.http.entity.*" %>
<%@ page import="org.apache.http.HttpEntity" %>
<%@ page import="org.apache.http.util.EntityUtils" %>
<%@ page import="java.io.IOException" %>
<%@ page import="weaver.conn.RecordSet" %>
<%@ page import="com.alibaba.fastjson.JSONObject" %>
<%@ page import="org.apache.commons.codec.digest.DigestUtils" %>
<%@ page import="java.net.URL" %>
<%@ page import="com.wbi.util.Util" %>
<%@ page import="com.alibaba.fastjson.JSONArray" %>
<jsp:useBean id="rs" class="weaver.conn.RecordSet" scope="page" />
<%
int sum = 0;
boolean flag = false;
String message = "";
JSONObject result = new JSONObject();
String name = Util.null2String(request.getParameter("name"));
String mobile = Util.null2String(request.getParameter("mobile"));
String cardNo = Util.null2String(request.getParameter("cardNo"));
Map<String,String> headers = new HashMap<>();
String qys_auth_url = rs.getPropValue("hrm_shhq","qys_auth_url");
String qys_auth_url2 = rs.getPropValue("hrm_shhq","qys_auth_url2");
String qys_auth_apptoken = rs.getPropValue("hrm_shhq","qys_auth_apptoken");
String qys_auth_appsecret = rs.getPropValue("hrm_shhq","qys_auth_appsecret");
long timestamp = System.currentTimeMillis();
headers.put("Host", String.valueOf(new URL(qys_auth_url).getPort()));
headers.put("Accept", "text/plain,application/json");
headers.put("User-Agent", "privateapp-java-api-client");
headers.put("x-qys-accesstoken", qys_auth_apptoken);
headers.put("x-qys-timestamp", String.valueOf(timestamp));
headers.put("x-qys-signature", DigestUtils.md5Hex(qys_auth_apptoken+qys_auth_appsecret+timestamp));
headers.put("Content-Type", "application/json");
JSONObject jsonObject = new JSONObject();
jsonObject.put("name",name);
jsonObject.put("mobile",mobile);
jsonObject.put("cardNo",cardNo);
jsonObject.put("repeat","true");
jsonObject.put("successPage","http://172.30.18.86:8090/interface/shhq/realAuthResult.jsp?code=1");
JSONArray array2 = new JSONArray();
array2.add("NONE");
jsonObject.put("modifyFields",array2);
rs.writeLog(cardNo+ " =========== 实名认证结果 请求参数 =============== "+ jsonObject.toString());
String map = pushInfoSubmit(qys_auth_url2,headers,jsonObject.toString(),"UTF-8");
result.put("flag",flag);
result.put("message",message);
sum++;
%>
<%!
/**
* 提交
* @param url
* @param headers
* @param stringJson
* @param encode
* @return
*/
public static String pushInfoSubmit(String url, Map<String,String> headers, String stringJson, String encode){
String result = "";
if(encode == null){
encode = "utf-8";
}
RecordSet rs = new RecordSet();
String content = null;
CloseableHttpResponse httpResponse = null;
CloseableHttpClient closeableHttpClient = null;
rs.writeLog( " =========== 实名认证结果 url =============== "+ url);
rs.writeLog( " =========== 实名认证结果 headers =============== "+ headers);
rs.writeLog( " =========== 实名认证结果 stringJson =============== "+ stringJson);
try {
closeableHttpClient = HttpClients.createDefault();
HttpPost httpost = new HttpPost(url);
//设置header
httpost.setHeader("Content-type", "application/json");
if (headers != null && headers.size() > 0) {
for (Map.Entry<String, String> entry : headers.entrySet()) {
httpost.setHeader(entry.getKey(),entry.getValue());
}
}
//组织请求参数
StringEntity stringEntity = new StringEntity(stringJson, encode);
httpost.setEntity(stringEntity);
//响应信息
httpResponse = closeableHttpClient.execute(httpost);
if(httpResponse != null) {
HttpEntity entity = httpResponse.getEntity();
content = EntityUtils.toString(entity, encode);
if (content != null && !"".equals(content)) {
JSONObject jsonObject = JSONObject.parseObject(content);
rs.writeLog("============= pushInfo jsonObject =================== " + jsonObject);
int code = (int) jsonObject.get("code");
if(code == 0){
result = jsonObject.get("result").toString();
}
}
}
} catch (Exception e) {
e.printStackTrace();
rs.writeLog(e);
}finally{
try {
httpResponse.close();
} catch (IOException e) {
e.printStackTrace();
}
}
try { //关闭连接、释放资源
closeableHttpClient.close();
} catch (IOException e) {
e.printStackTrace();
}
return result;
}
%>
<HEAD>
</HEAD>
<BODY>
<h1>Congratulation Mode 666666 !</h1>
<h1> 对接契约锁人脸识别的 </h1>
<h1> 返回结果 <%=map%></h1>
<h1> 返回结果 <%=result%></h1>
<h1> sum <%=sum%> </h1>
</BODY>