|
@@ -4,6 +4,7 @@ package kd.imc.rim.utils;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
+import javassist.Loader;
|
|
|
import kd.bos.script.annotations.KSObject;
|
|
|
import org.apache.http.HttpEntity;
|
|
|
import org.apache.http.client.methods.CloseableHttpResponse;
|
|
@@ -18,6 +19,8 @@ import java.io.OutputStream;
|
|
|
import java.net.HttpURLConnection;
|
|
|
import java.net.URL;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
import java.util.Base64;
|
|
|
import java.util.Date;
|
|
|
import java.util.Iterator;
|
|
@@ -33,35 +36,33 @@ public class ApiHttpUtils {
|
|
|
//设置请求路径
|
|
|
HttpPost httpPost = new HttpPost(url);
|
|
|
httpPost.setHeader("Content-type", "application/json;charset=utf-8");
|
|
|
- httpPost.setHeader("mesgtype", "bills_crop_base64");
|
|
|
- httpPost.setHeader("channelcode", "JSX");
|
|
|
+ JSONObject object = new JSONObject();
|
|
|
+ JSONObject head = new JSONObject();
|
|
|
+ head.put("mesgtype","bills_crop_base64");
|
|
|
+ head.put("channelcode","JSX");
|
|
|
Date date = new Date();
|
|
|
- SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
+ SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");
|
|
|
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", "");
|
|
|
- httpPost.setHeader("App_key", "XYK_DPJ_KEY");
|
|
|
- httpPost.setHeader("App_secret", "XYK_DPJ_SECRET");
|
|
|
- JSONObject object = new JSONObject();
|
|
|
- object.put("file_base64",Params);
|
|
|
+ head.put("channeldate",formatDate);
|
|
|
+ LocalDateTime now = LocalDateTime.now();
|
|
|
+ DateTimeFormatter hHmmss = DateTimeFormatter.ofPattern("HHmmss");
|
|
|
+ DateTimeFormatter yyyyMMddHHmmssSSSS = DateTimeFormatter.ofPattern("yyyyMMddHHmmssSSSS");
|
|
|
+ String channeltime = now.format(hHmmss);
|
|
|
+ String hHmmssSSS1 = now.format(yyyyMMddHHmmssSSSS);
|
|
|
+ head.put("channeltime",channeltime);
|
|
|
+ head.put("channelserno",hHmmssSSS1);
|
|
|
+ head.put("bron","");
|
|
|
+ head.put("tellerno","");
|
|
|
+ head.put("reserve","");
|
|
|
+ head.put("dealcode","");
|
|
|
+ head.put("dealmsg","");
|
|
|
+ head.put("App_key","XYK_DEJ_Key");
|
|
|
+ head.put("APP_secret","XYK_DEJ_SECRET");
|
|
|
+ JSONObject body = new JSONObject();
|
|
|
+ body.put("file_base64",Params);
|
|
|
+ object.put("head",head);
|
|
|
+ object.put("body",body);
|
|
|
StringEntity entity = new StringEntity(object.toString(), ContentType.APPLICATION_JSON);
|
|
|
- // post请求是将参数放在请求体里面传过去的;这里将entity放入post请求体中
|
|
|
- // 设置编码格式
|
|
|
-// entity.setContentEncoding("UTF-8");
|
|
|
- // 发送Json格式的数据请求
|
|
|
-// entity.setContentType("application/json");
|
|
|
httpPost.setEntity(entity);
|
|
|
// 响应模型(发送post请求)
|
|
|
CloseableHttpResponse response = httpClient.execute(httpPost);
|
|
@@ -109,23 +110,43 @@ public class ApiHttpUtils {
|
|
|
catch (Exception e) { e.printStackTrace(); }
|
|
|
return null;
|
|
|
}
|
|
|
- public static String toJsonString(String Params) throws Exception {
|
|
|
+ public static String toFiledata(String Params) throws Exception {
|
|
|
if("".equals(Params)){return null;};
|
|
|
JSONArray objects = JSONArray.parseArray(Params);
|
|
|
- Object object = objects.get(0);
|
|
|
- JSONObject respenjson = (JSONObject) JSONObject.toJSON(object);
|
|
|
- JSONArray itemList = respenjson.getJSONArray("item_list");
|
|
|
- JSONObject item_list = new JSONObject();
|
|
|
- for (int i=0;i<itemList.size();i++){
|
|
|
- Object obj = itemList.get(i);
|
|
|
- net.sf.json.JSONObject respenjsons = (net.sf.json.JSONObject) JSONObject.toJSON(obj);
|
|
|
- Iterator it = respenjsons.keys();
|
|
|
- while(it.hasNext()){
|
|
|
- String key = (String) it.next();// 获得key
|
|
|
- String value = respenjsons.getString(key);// 获得value
|
|
|
+ for(int a=0;a<objects.size();a++){
|
|
|
+ Object object = objects.get(a);
|
|
|
+ JSONObject respenjson = (JSONObject) JSONObject.toJSON(object);
|
|
|
+ String type_description = respenjson.getString("type_description");//增值税电子普通发票 行程单 通用定额发票 火车票
|
|
|
+ if("".equals(type_description)){return null;};
|
|
|
+ JSONArray itemList = respenjson.getJSONArray("item_list");
|
|
|
+ JSONObject item_list = new JSONObject();
|
|
|
+ for (int i=0;i<itemList.size();i++){
|
|
|
+ Object obj = itemList.get(i);
|
|
|
+ JSONObject respenjsons = (JSONObject) JSONObject.toJSON(obj);
|
|
|
+ String key = respenjsons.get("key").toString();// 获得key
|
|
|
+ String value = respenjsons.get("value").toString();// 获得value
|
|
|
item_list.put(key,value);
|
|
|
}
|
|
|
+ if("增值税电子普通发票".equals(type_description)){
|
|
|
+ String zzsdzptfp = zzsdzptfp(item_list);
|
|
|
+ return zzsdzptfp;
|
|
|
+ }else if("行程单".equals(type_description)){
|
|
|
+ String jpxcd = jpxcd(item_list);
|
|
|
+ return jpxcd;
|
|
|
+ } else if ("火车票".equals(type_description)) {
|
|
|
+ String hcp = hcp(item_list);
|
|
|
+ return hcp;
|
|
|
+ } else if ("通用定额发票".equals(type_description)) {
|
|
|
+ String tydefp = tydefp(item_list);
|
|
|
+ return tydefp;
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ //增值税电子普通发票
|
|
|
+ public static String zzsdzptfp(JSONObject item_list) throws Exception {
|
|
|
//组装发票数据结构 !
|
|
|
JSONObject json = new JSONObject();//返回最外层json
|
|
|
json.put("errcode","0000");
|
|
@@ -136,17 +157,19 @@ public class ApiHttpUtils {
|
|
|
JSONArray recoginitionData = new JSONArray();//数据层数组
|
|
|
JSONObject fileObj = new JSONObject();//实际数据json
|
|
|
fileObj.put("canBeDeduction","");//0
|
|
|
- fileObj.put("salerName","");//销售方名称 ocr字段:vat_invoice_seller_name
|
|
|
- fileObj.put("invoiceMoney","");//金额明细 ocr字段:vat_invoice_price_list
|
|
|
+ fileObj.put("salerName",item_list.getString("vat_invoice_seller_name"));//销售方名称 ocr字段:vat_invoice_seller_name
|
|
|
+ fileObj.put("invoiceMoney",item_list.getString("vat_invoice_price_list"));//金额明细 ocr字段:vat_invoice_price_list
|
|
|
fileObj.put("signStatus","");//0
|
|
|
fileObj.put("downloadUrl","");//下载地址链接
|
|
|
fileObj.put("fileHash","");//文件哈希值
|
|
|
- fileObj.put("invoiceAmount","");//合计金额 ocr字段:vat_invoice_total
|
|
|
+ fileObj.put("invoiceAmount",item_list.getString("vat_invoice_total"));//合计金额 ocr字段:vat_invoice_total
|
|
|
fileObj.put("localUrl","");//预览链接
|
|
|
fileObj.put("deductionStatus",1);//扣除
|
|
|
- fileObj.put("salerTaxNo","");//纳税人识别号 ocr字段:vat_invoice_seller_id_invoice_seal
|
|
|
+ fileObj.put("salerTaxNo",item_list.getString("vat_invoice_seller_id_seal"));//纳税人识别号 ocr字段:vat_invoice_seller_id_seal
|
|
|
+
|
|
|
fileObj.put("invoiceType",1);//发票类型 ocr字段:type 1="增值税发票"
|
|
|
- fileObj.put("invoiceNo","");//发票号码 ocr字段:vat_invoice_haoma_large_size
|
|
|
+
|
|
|
+ fileObj.put("invoiceNo",item_list.getString("vat_invoice_haoma_large_size"));//发票号码 ocr字段:vat_invoice_haoma_large_size
|
|
|
fileObj.put("isRepeat",false);//是否重复
|
|
|
fileObj.put("pixel","");//3962978 未知字段
|
|
|
fileObj.put("oriImageSize","");//base64编码长度
|
|
@@ -154,38 +177,38 @@ public class ApiHttpUtils {
|
|
|
fileObj.put("orientation","0");//0
|
|
|
fileObj.put("batchNo",null);//null
|
|
|
fileObj.put("clientId","Vfz636yVhmk9HEu1QTAp");//客户端id
|
|
|
- fileObj.put("buyerTaxNo","");//购买方纳税人识别号 ocr字段:vat_invoice_rate_payer_id
|
|
|
+ fileObj.put("buyerTaxNo",item_list.getString("vat_invoice_rate_payer_id"));//购买方纳税人识别号 ocr字段:vat_invoice_rate_payer_id
|
|
|
fileObj.put("warningCode","");//警告数量
|
|
|
fileObj.put("originalState",0);//原始状态0
|
|
|
fileObj.put("companySeal","1");//未知字段
|
|
|
fileObj.put("originalUrl","");//地址链接
|
|
|
- fileObj.put("invoiceDate","");//开票日期 ocr字段:vat_invoice_issue_dat_print
|
|
|
- fileObj.put("buyerName","");//购买方名称 ocr字段:vat_invoice_payer_name
|
|
|
- fileObj.put("invoiceCode","");//发票代码 ocr字段: vat_invoice_daima
|
|
|
+ fileObj.put("invoiceDate",item_list.getString("vat_invoice_issue_date"));//开票日期 ocr字段:vat_invoice_issue_date
|
|
|
+ fileObj.put("buyerName",item_list.getString("vat_invoice_payer_name"));//购买方名称 ocr字段:vat_invoice_payer_name
|
|
|
+ fileObj.put("invoiceCode",item_list.getString("vat_invoice_daima"));//发票代码 ocr字段: vat_invoice_daima
|
|
|
fileObj.put("serialNo","");//未知字段
|
|
|
- fileObj.put("totalAmount","");//价税合计 ocr字段: vat_invoice_total_cover_tax_digits
|
|
|
- fileObj.put("taxRate","");//税率 ocr字段 vat_invoice_tax_rate
|
|
|
+ fileObj.put("totalAmount",item_list.getString("vat_invoice_total_cover_tax_digits"));//价税合计 ocr字段: vat_invoice_total_cover_tax_digits
|
|
|
+ fileObj.put("taxRate",item_list.getString("vat_invoice_tax_rate"));//税率 ocr字段 vat_invoice_tax_rate
|
|
|
fileObj.put("oriOrientation","0");//未知字段
|
|
|
fileObj.put("oriRegion","");//什么地区....
|
|
|
fileObj.put("rotationAngle","0");//未知字段
|
|
|
fileObj.put("snapshotUrl","");//图片地址
|
|
|
fileObj.put("imageSerialNo","");//图片编码?
|
|
|
fileObj.put("recognitionSerialNo","");//未知字段
|
|
|
- fileObj.put("totalTaxAmount","");//税额合计 ocr字段 vat_invoice_tax_total
|
|
|
- fileObj.put("taxAmount","");//税额 ocr字段 vat_invoice_tax_list
|
|
|
+ fileObj.put("totalTaxAmount",item_list.getString("vat_invoice_tax_total"));//税额合计 ocr字段 vat_invoice_tax_total
|
|
|
+ fileObj.put("taxAmount",item_list.getString("vat_invoice_tax_list"));//税额 ocr字段 vat_invoice_tax_list
|
|
|
fileObj.put("region","");//未知字段
|
|
|
fileObj.put("isExpend","");//""
|
|
|
fileObj.put("expendStatus",null);//null
|
|
|
fileObj.put("fileType",1);//附件类型
|
|
|
JSONArray items = new JSONArray();//数据明细层数组
|
|
|
JSONObject mxFileObj = new JSONObject();//明细数据json
|
|
|
- mxFileObj.put("unitPrice","");//合计金额 oct字段: vat_invoice_total
|
|
|
- mxFileObj.put("taxRate","");//税率明细 vat_invoice_tax_rate_list
|
|
|
+ mxFileObj.put("unitPrice",item_list.getString("vat_invoice_total"));//合计金额 oct字段: vat_invoice_total
|
|
|
+ mxFileObj.put("taxRate",item_list.getString("vat_invoice_tax_rate_list"));//税率明细 vat_invoice_tax_rate_list
|
|
|
mxFileObj.put("unit","");
|
|
|
mxFileObj.put("num","1");
|
|
|
- mxFileObj.put("detailAmount","");//金额明细 ocr字段:vat_invoice_price_list
|
|
|
- mxFileObj.put("taxAmount","");//税额明细 ocr字段 vat_invoice_tax_list
|
|
|
- mxFileObj.put("goodsName","");//服务名称/项目名称 ocr字段 vat_invoice_goods_list
|
|
|
+ mxFileObj.put("detailAmount",item_list.getString("vat_invoice_price_list"));//金额明细 ocr字段:vat_invoice_price_list
|
|
|
+ mxFileObj.put("taxAmount",item_list.getString("vat_invoice_tax_list"));//税额明细 ocr字段 vat_invoice_tax_list
|
|
|
+ mxFileObj.put("goodsName",item_list.getString("vat_invoice_goods_list"));//服务名称/项目名称 ocr字段 vat_invoice_goods_list
|
|
|
//值拼接完成后开始set数据结构
|
|
|
items.add(mxFileObj);
|
|
|
fileObj.put("items",items);
|
|
@@ -194,4 +217,68 @@ public class ApiHttpUtils {
|
|
|
json.put("data",data);
|
|
|
return json.toJSONString();
|
|
|
}
|
|
|
+ //机票行程单
|
|
|
+ public static String jpxcd(JSONObject item_list) throws Exception {
|
|
|
+
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ //火车票
|
|
|
+ public static String hcp(JSONObject item_list) throws Exception {
|
|
|
+ //组装发票数据结构 !
|
|
|
+ JSONObject json = new JSONObject();//返回最外层json
|
|
|
+ json.put("errcode","0000");
|
|
|
+ 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","");//0
|
|
|
+ fileObj.put("stationGetOn",item_list.getString("departure_station"));//出发站 ocr字段:departure_station
|
|
|
+ fileObj.put("passengerName",item_list.getString("passenger_name"));//乘客 ocr字段:passenger_name
|
|
|
+ fileObj.put("signStatus","");//0
|
|
|
+ fileObj.put("downloadUrl","");//下载地址链接
|
|
|
+ fileObj.put("fileHash","");//文件哈希值
|
|
|
+ fileObj.put("seatNumber",item_list.getString("seat_number"));//座位 ocr字段:seat_number
|
|
|
+ fileObj.put("localUrl","");//预览链接
|
|
|
+ fileObj.put("trainNum",item_list.getString("train_number"));//车次编号 ocr字段:train_number
|
|
|
+ fileObj.put("trainTime","");//
|
|
|
+ fileObj.put("stationGetOff",item_list.getString("arrival_station"));//目的地 ocr字段:arrival_station
|
|
|
+ fileObj.put("deductionStatus",1);
|
|
|
+ fileObj.put("invoiceType","9");//发票类型
|
|
|
+ fileObj.put("isRepeat",false);//是否重复
|
|
|
+ fileObj.put("pixel","");//未知
|
|
|
+ fileObj.put("oriImageSize","");//未知
|
|
|
+ fileObj.put("pdfToImgSnapshotUrl","");//“”
|
|
|
+ fileObj.put("orientation","0");//null
|
|
|
+ fileObj.put("batchNo","");//
|
|
|
+ fileObj.put("warningCode","1");//
|
|
|
+ fileObj.put("originalState",0);//
|
|
|
+ fileObj.put("originalUrl","");//""
|
|
|
+ fileObj.put("invoiceDate",item_list.getString("departure_date"));//乘车日期 ocr字段:departure_date
|
|
|
+ fileObj.put("serialNo","");//
|
|
|
+ fileObj.put("seat",item_list.getString("class"));//几等座 ocr字段:class
|
|
|
+ fileObj.put("totalAmount",item_list.getString("price"));//票价 ocr字段:price
|
|
|
+ fileObj.put("taxRate","");//
|
|
|
+ fileObj.put("customerIdentityNum",item_list.getString("passenger_id"));//身份证 ocr字段 passenger_id
|
|
|
+ fileObj.put("oriOrientation","0");//
|
|
|
+ fileObj.put("oriRegion","0");//
|
|
|
+ fileObj.put("rotationAngle","");//未知字段
|
|
|
+ fileObj.put("snapshotUrl","");//
|
|
|
+ fileObj.put("imageSerialNo","");//未知字段
|
|
|
+ fileObj.put("printingSequenceNo",item_list.getString("number"));//发票号码 ocr字段 number
|
|
|
+ fileObj.put("recognitionSerialNo","");//
|
|
|
+ fileObj.put("businessType",1);//未知字段
|
|
|
+ fileObj.put("region","");//
|
|
|
+ //值拼接完成后开始set数据结构e
|
|
|
+ recoginitionData.add(fileObj);
|
|
|
+ data.put("recoginitionData",recoginitionData);
|
|
|
+ json.put("data",data);
|
|
|
+ return json.toJSONString();
|
|
|
+ }
|
|
|
+ //通用定额发票
|
|
|
+ public static String tydefp(JSONObject item_list) throws Exception {
|
|
|
+
|
|
|
+ return null;
|
|
|
+ }
|
|
|
}
|