|
@@ -45,6 +45,42 @@ public class ESignHttpUtil {
|
|
|
return json;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 根据E签宝的大部分返回值实体简单处理结果增加异常判断
|
|
|
+ * @param eurl
|
|
|
+ * @param param
|
|
|
+ * @param querys
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public JSONObject doGetGetJson(ESignUrl eurl, JSONObject param,String ...querys){
|
|
|
+ String url = eurl.getUrl(querys);
|
|
|
+ String str = doGet(url);
|
|
|
+ JSONObject json =JSONObject.parseObject(str);
|
|
|
+ int code = json.getInteger("code");
|
|
|
+ if(code!=0){
|
|
|
+ throw new ESignException(code,url,json.getString("message"));
|
|
|
+ }
|
|
|
+ return json;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据E签宝的大部分返回值实体简单处理结果增加异常判断
|
|
|
+ * @param eurl
|
|
|
+ * @param param
|
|
|
+ * @param querys
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public JSONObject doPutGetJson(ESignUrl eurl, JSONObject param,String ...querys){
|
|
|
+ String url = eurl.getUrl(querys);
|
|
|
+ String str = doPut(url,param.toJSONString());
|
|
|
+ JSONObject json =JSONObject.parseObject(str);
|
|
|
+ int code = json.getInteger("code");
|
|
|
+ if(code!=0){
|
|
|
+ throw new ESignException(code,url,json.getString("message"));
|
|
|
+ }
|
|
|
+ return json;
|
|
|
+ }
|
|
|
+
|
|
|
public String doPost(ESignUrl eurl, JSONObject param,String ...querys){
|
|
|
String url = eurl.getUrl(querys);
|
|
|
return doPost(url,param.toJSONString());
|
|
@@ -139,7 +175,95 @@ public class ESignHttpUtil {
|
|
|
return result.toString();
|
|
|
}
|
|
|
|
|
|
- public static String doGet(String url)
|
|
|
+ /**
|
|
|
+ * 向指定 URL 发送PUT方法的请求并添加E签宝所需的请求头
|
|
|
+ *
|
|
|
+ * @param url 发送请求的 URL
|
|
|
+ * @param json 请求参数,
|
|
|
+ * @return 所代表远程资源的响应结果
|
|
|
+ */
|
|
|
+ public String doPut(String url , String json)
|
|
|
+ {
|
|
|
+ PrintWriter out = null;
|
|
|
+ BufferedReader in = null;
|
|
|
+ StringBuilder result = new StringBuilder();
|
|
|
+ try
|
|
|
+ {
|
|
|
+
|
|
|
+ log.info("sendPost - {}", url);
|
|
|
+ // 打开和URL之间的连接
|
|
|
+ SSLContext sc = SSLContext.getInstance("SSL");
|
|
|
+ sc.init(null, new TrustManager[] { new TrustAnyTrustManager() }, new SecureRandom());
|
|
|
+ // 从上述SSLContext对象中得到SSLSocketFactory对象
|
|
|
+ SSLSocketFactory ssf = sc.getSocketFactory();
|
|
|
+
|
|
|
+ java.net.URL realUrl = new URL(url);
|
|
|
+
|
|
|
+ HttpsURLConnection conn = (HttpsURLConnection) realUrl.openConnection();
|
|
|
+
|
|
|
+ conn.setSSLSocketFactory(ssf);
|
|
|
+ conn.setRequestMethod("PUT");
|
|
|
+ conn.setRequestProperty("accept", "*/*");
|
|
|
+ conn.setRequestProperty("X-Tsign-Open-App-Id",eSignConfig.getAppId());
|
|
|
+ conn.setRequestProperty("X-Tsign-Open-Token",eSignConfig.geteSignToken().getAccessToken());
|
|
|
+ conn.setRequestProperty("connection", "Keep-Alive");
|
|
|
+ conn.setRequestProperty("Content-Type", "application/json;charset=UTF-8");
|
|
|
+ conn.setUseCaches(false);//设置不要缓存
|
|
|
+ conn.setDoOutput(true);
|
|
|
+ conn.setDoInput(true);
|
|
|
+ out = new PrintWriter(conn.getOutputStream());
|
|
|
+ out.write(json);
|
|
|
+ out.flush();
|
|
|
+ in = new BufferedReader( new InputStreamReader(conn.getInputStream()));
|
|
|
+ String line;
|
|
|
+ while ((line = in.readLine()) != null)
|
|
|
+ {
|
|
|
+ result.append(line);
|
|
|
+ }
|
|
|
+ log.info("recv - {}", result);
|
|
|
+ }
|
|
|
+ catch (ConnectException e)
|
|
|
+ {
|
|
|
+ log.error("调用ESignHttpUtil.doPost ConnectException, url=" + url + ",param_body=" + json, e);
|
|
|
+ throw new BusinessException("调用ESignHttpUtil.sendJsonPost ConnectException, url=" + url + ",param=" + json );
|
|
|
+ }
|
|
|
+ catch (SocketTimeoutException e)
|
|
|
+ {
|
|
|
+ log.error("调用ESignHttpUtil.doPost SocketTimeoutException, url=" + url + ",param=" + json, e);
|
|
|
+ throw new BusinessException("调用ESignHttpUtil.sendJsonPost SocketTimeoutException, url=" + url + ",param=" + json );
|
|
|
+ }
|
|
|
+ catch (IOException e)
|
|
|
+ {
|
|
|
+ log.error("调用ESignHttpUtil.doPost IOException, url=" + url + ",param=" + json, e);
|
|
|
+ throw new BusinessException("调用ESignHttpUtil.sendJsonPost IOException, url=" + url + ",param=" + json );
|
|
|
+ }
|
|
|
+ catch (Exception e)
|
|
|
+ {
|
|
|
+ log.error("调用HttpsUtil.doPost Exception, url=" + url + ",param=" + json, e);
|
|
|
+ throw new BusinessException("调用ESignHttpUtil.sendJsonPost Exception, url=" + url + ",param=" + json );
|
|
|
+ }
|
|
|
+ finally
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ if (out != null)
|
|
|
+ {
|
|
|
+ out.close();
|
|
|
+ }
|
|
|
+ if (in != null)
|
|
|
+ {
|
|
|
+ in.close();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch (IOException ex)
|
|
|
+ {
|
|
|
+ log.error("调用in.close Exception, url=" + url + ",param=" + json, ex);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return result.toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ public String doGet(String url)
|
|
|
{
|
|
|
StringBuilder result = new StringBuilder();
|
|
|
BufferedReader in = null;
|
|
@@ -151,6 +275,10 @@ public class ESignHttpUtil {
|
|
|
|
|
|
URLConnection connection = realUrl.openConnection();
|
|
|
connection.setRequestProperty("accept", "*/*");
|
|
|
+ connection.setRequestProperty("X-Tsign-Open-App-Id",eSignConfig.getAppId());
|
|
|
+ connection.setRequestProperty("X-Tsign-Open-Token",eSignConfig.geteSignToken().getAccessToken());
|
|
|
+ connection.setRequestProperty("Content-Type", "application/json;charset=UTF-8");
|
|
|
+ connection.setRequestProperty("connection", "Keep-Alive");
|
|
|
connection.connect();
|
|
|
in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
|
|
|
String line;
|