|
@@ -0,0 +1,141 @@
|
|
|
+package kd.imc.rim.utils;
|
|
|
+
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import kd.bos.script.annotations.KSObject;
|
|
|
+import org.apache.http.HttpEntity;
|
|
|
+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 java.text.SimpleDateFormat;
|
|
|
+import java.util.Date;
|
|
|
+
|
|
|
+@KSObject
|
|
|
+public class ApiHttpUtils {
|
|
|
+
|
|
|
+ public static String Posthttp(String url, String Params) throws Exception {
|
|
|
+ // 获得Http客户端
|
|
|
+ CloseableHttpClient httpClient = HttpClientBuilder.create().build();
|
|
|
+ // 创建Post请求
|
|
|
+ //设置请求路径
|
|
|
+ HttpPost httpPost = new HttpPost(url);
|
|
|
+ httpPost.setHeader("Content-type", "application/json;charset=utf-8");
|
|
|
+ httpPost.setHeader("mesgtype", "bills_crop_base64");
|
|
|
+ httpPost.setHeader("channelcode", "JSX");
|
|
|
+ Date date = new Date();
|
|
|
+ SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
+ String formatDate = dateFormat.format(date);
|
|
|
+ httpPost.setHeader("channeldate", formatDate);
|
|
|
+ long time = new Date().getTime();
|
|
|
+ String channeltime = Long.toString(time);
|
|
|
+ httpPost.setHeader("channeltime",channeltime);
|
|
|
+ long l = System.currentTimeMillis();
|
|
|
+ String channelserno = Long.toString(l);
|
|
|
+ httpPost.setHeader("channelserno", channelserno);
|
|
|
+ httpPost.setHeader("brno", "");
|
|
|
+ httpPost.setHeader("tellerno", "*DMY");
|
|
|
+ httpPost.setHeader("terminalno", "");
|
|
|
+ httpPost.setHeader("APP_", "");
|
|
|
+ httpPost.setHeader("reserve", "");
|
|
|
+ httpPost.setHeader("dealcode", "");
|
|
|
+ httpPost.setHeader("dealmsg", "");
|
|
|
+ StringEntity entity = new StringEntity(Params,"UTF-8");
|
|
|
+ // post请求是将参数放在请求体里面传过去的;这里将entity放入post请求体中
|
|
|
+ // 设置编码格式
|
|
|
+ entity.setContentEncoding("UTF-8");
|
|
|
+ // 发送Json格式的数据请求
|
|
|
+ entity.setContentType("application/json");
|
|
|
+ httpPost.setEntity(entity);
|
|
|
+ // 响应模型(发送post请求)
|
|
|
+ CloseableHttpResponse response = httpClient.execute(httpPost);
|
|
|
+ // 从响应模型中获取响应实体
|
|
|
+ HttpEntity responseEntity = response.getEntity();
|
|
|
+ com.alibaba.fastjson.JSONObject jsonObject = new com.alibaba.fastjson.JSONObject();
|
|
|
+ if (responseEntity != null) {
|
|
|
+ jsonObject = JSON.parseObject(EntityUtils.toString(response.getEntity()));
|
|
|
+ return jsonObject.toJSONString();
|
|
|
+ }
|
|
|
+ // 释放资源
|
|
|
+ if (httpClient != null) {
|
|
|
+ httpClient.close();
|
|
|
+ }
|
|
|
+ if (response != null) {
|
|
|
+ response.close();
|
|
|
+ }
|
|
|
+ return "";
|
|
|
+ }
|
|
|
+ public static String toJsonString(String Params) throws Exception {
|
|
|
+ JSONObject json = new JSONObject();//返回最外层json
|
|
|
+ json.put("errcode","");
|
|
|
+ json.put("traceId","");
|
|
|
+ json.put("description","");
|
|
|
+ JSONObject data = new JSONObject();//数据层json
|
|
|
+ json.put("batchNo","");
|
|
|
+ JSONArray recoginitionData = new JSONArray();//数据层数组
|
|
|
+ JSONObject fileObj = new JSONObject();//实际数据json
|
|
|
+ fileObj.put("canBeDeduction","");
|
|
|
+ fileObj.put("salerName","");
|
|
|
+ fileObj.put("invoiceMoney","");
|
|
|
+ fileObj.put("signStatus","");
|
|
|
+ fileObj.put("downloadUrl","");
|
|
|
+ fileObj.put("fileHash","");
|
|
|
+ fileObj.put("invoiceAmount","");
|
|
|
+ fileObj.put("localUrl","");
|
|
|
+ fileObj.put("deductionStatus","");
|
|
|
+ fileObj.put("salerTaxNo","");
|
|
|
+ fileObj.put("invoiceType","");
|
|
|
+ fileObj.put("invoiceNo","");
|
|
|
+ fileObj.put("isRepeat","");
|
|
|
+ fileObj.put("pixel","");
|
|
|
+ fileObj.put("oriImageSize","");
|
|
|
+ fileObj.put("pdfToImgSnapshotUrl","");
|
|
|
+ fileObj.put("orientation","");
|
|
|
+ fileObj.put("batchNo","");
|
|
|
+ fileObj.put("clientId","");
|
|
|
+ fileObj.put("buyerTaxNo","");
|
|
|
+ fileObj.put("warningCode","");
|
|
|
+ fileObj.put("originalState","");
|
|
|
+ fileObj.put("companySeal","");
|
|
|
+ fileObj.put("originalUrl","");
|
|
|
+ fileObj.put("invoiceDate","");
|
|
|
+ fileObj.put("buyerName","");
|
|
|
+ fileObj.put("invoiceCode","");
|
|
|
+ fileObj.put("serialNo","");
|
|
|
+ fileObj.put("totalAmount","");
|
|
|
+ fileObj.put("taxRate","");
|
|
|
+ fileObj.put("oriOrientation","");
|
|
|
+ fileObj.put("oriRegion","");
|
|
|
+ fileObj.put("rotationAngle","");
|
|
|
+ fileObj.put("snapshotUrl","");
|
|
|
+ fileObj.put("imageSerialNo","");
|
|
|
+ fileObj.put("recognitionSerialNo","");
|
|
|
+ fileObj.put("totalTaxAmount","");
|
|
|
+ fileObj.put("taxAmount","");
|
|
|
+ fileObj.put("region","");
|
|
|
+ fileObj.put("isExpend","");
|
|
|
+ fileObj.put("expendStatus","");
|
|
|
+ fileObj.put("fileType","");
|
|
|
+ JSONArray items = new JSONArray();//数据明细层数组
|
|
|
+ JSONObject mxFileObj = new JSONObject();//明细数据json
|
|
|
+ mxFileObj.put("unitPrice","");
|
|
|
+ mxFileObj.put("taxRate","");
|
|
|
+ mxFileObj.put("unit","");
|
|
|
+ mxFileObj.put("num","");
|
|
|
+ mxFileObj.put("detailAmount","");
|
|
|
+ mxFileObj.put("taxAmount","");
|
|
|
+ mxFileObj.put("goodsName","");
|
|
|
+ //值拼接完成后开始set数据结构
|
|
|
+ items.add(mxFileObj);
|
|
|
+ fileObj.put("items",items);
|
|
|
+ recoginitionData.add(fileObj);
|
|
|
+ data.put("recoginitionData",recoginitionData);
|
|
|
+ json.put("data",data);
|
|
|
+ return json.toJSONString();
|
|
|
+ }
|
|
|
+}
|