|
|
@@ -15,7 +15,11 @@ import com.sf.csim.express.service.HttpClientUtil;
|
|
|
import com.sf.csim.express.service.IServiceCodeStandard;
|
|
|
import com.sf.csim.express.service.code.ExpressServiceCodeEnum;
|
|
|
|
|
|
+import java.io.FileOutputStream;
|
|
|
+import java.io.InputStream;
|
|
|
import java.io.UnsupportedEncodingException;
|
|
|
+import java.net.HttpURLConnection;
|
|
|
+import java.net.URL;
|
|
|
import java.util.*;
|
|
|
|
|
|
@RunWith(SpringRunner.class)
|
|
|
@@ -136,13 +140,175 @@ public class UasEisApplicationTests {
|
|
|
|
|
|
@Test
|
|
|
public void TestCreatSFOrder(){
|
|
|
- Map<String, Object> res = erpService.creatSFOrder("JYX_TEST", 50734826,"ADMIN");
|
|
|
+ Map<String, Object> res = erpService.creatSFOrder("JYX_TEST", 50734919,"ADMIN");
|
|
|
System.out.println("res==="+res.get("success")+":"+res.get("message"));
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
public void TestCancelSFOrder(){
|
|
|
- Map<String, Object> res = erpService.cancelSFOrder("JYX_TEST", 50734826,"ADMIN");
|
|
|
+ Map<String, Object> res = erpService.cancelSFOrder("JYX_TEST", 50734919,"ADMIN");
|
|
|
System.out.println("res==="+res.get("success")+":"+res.get("message"));
|
|
|
}
|
|
|
+ @Test
|
|
|
+ public void TestPrintPDF() throws UnsupportedEncodingException {
|
|
|
+ /**ExpressServiceCodeEnum 对应速运类-快递APIs
|
|
|
+ POSTServiceCodeEnum 对应速运类-驿站APIs
|
|
|
+ YJTServiceCodeEnum 对应解决方案-医寄通APIs
|
|
|
+ EPSServiceCodeEnum 对应解决方案-快递管家APIs
|
|
|
+ HZTServiceCodeEnum 对应解决方案-函证通APIs 2022-2-24 新增
|
|
|
+ 详情见code目录下枚举类,客户可自行修改引用的该类
|
|
|
+ **/
|
|
|
+ IServiceCodeStandard standardService = ExpressServiceCodeEnum.COM_RECE_CLOUD_PRINT_WAYBILLS; //下订单
|
|
|
+ // IServiceCodeStandard standardService = ExpressServiceCodeEnum.EXP_RECE_SEARCH_ORDER_RESP; //查订单
|
|
|
+ // IServiceCodeStandard standardService = ExpressServiceCodeEnum.EXP_RECE_UPDATE_ORDER;//订单取消
|
|
|
+ // IServiceCodeStandard standardService = ExpressServiceCodeEnum.EXP_RECE_FILTER_ORDER_BSP;//订单筛选
|
|
|
+ // IServiceCodeStandard standardService = ExpressServiceCodeEnum.EXP_RECE_SEARCH_ROUTES;//查路由
|
|
|
+ // IServiceCodeStandard standardService = ExpressServiceCodeEnum.EXP_RECE_GET_SUB_MAILNO;//子单号
|
|
|
+ // IServiceCodeStandard standardService = ExpressServiceCodeEnum.EXP_RECE_QUERY_SFWAYBILL;//查运费
|
|
|
+ // IServiceCodeStandard standardService = ExpressServiceCodeEnum.EXP_RECE_REGISTER_ROUTE;//注册路由
|
|
|
+ // IServiceCodeStandard standardService = ExpressServiceCodeEnum.EXP_RECE_CREATE_REVERSE_ORDER;//退货下单
|
|
|
+ // IServiceCodeStandard standardService = ExpressServiceCodeEnum.EXP_RECE_CANCEL_REVERSE_ORDER;//退货消单
|
|
|
+ // IServiceCodeStandard standardService = ExpressServiceCodeEnum.EXP_RECE_WANTED_INTERCEPT;//截单转寄
|
|
|
+ // IServiceCodeStandard standardService = ExpressServiceCodeEnum.EXP_RECE_QUERY_DELIVERTM;//时效标准及价格查询
|
|
|
+ // IServiceCodeStandard standardService = ExpressServiceCodeEnum.COM_RECE_CLOUD_PRINT_WAYBILLS;//面单打印
|
|
|
+ // IServiceCodeStandard standardService = ExpressServiceCodeEnum.EXP_RECE_UPLOAD_ROUTE;//路由上传
|
|
|
+ // IServiceCodeStandard standardService = ExpressServiceCodeEnum.EXP_RECE_SEARCH_PROMITM;//预计派送时间查询
|
|
|
+ // IServiceCodeStandard standardService = ExpressServiceCodeEnum.EXP_EXCE_CHECK_PICKUP_TIME;//揽件服务时间查询
|
|
|
+ // IServiceCodeStandard standardService = ExpressServiceCodeEnum.EXP_RECE_VALIDATE_WAYBILLNO;//运单号合法性校验
|
|
|
+
|
|
|
+
|
|
|
+ CallExpressServiceTools tools=CallExpressServiceTools.getInstance();
|
|
|
+ Map<String, String> params = new HashMap<String, String>();
|
|
|
+ String timeStamp = String.valueOf(System.currentTimeMillis());
|
|
|
+ Map<String, Object> msgDataMap = new HashMap<>();
|
|
|
+ msgDataMap.put("templateCode","fm_76130_standard_JYXKJWFFJ88E");
|
|
|
+ msgDataMap.put("version","2.0");
|
|
|
+ msgDataMap.put("fileType","pdf");
|
|
|
+ msgDataMap.put("sync","true");
|
|
|
+ List<Map<String,Object>> docList = new ArrayList<>();
|
|
|
+ Map<String,Object> doc = new HashMap<>();
|
|
|
+ doc.put("masterWaybillNo","SF7444488564898");
|
|
|
+ docList.add(doc);
|
|
|
+ doc = new HashMap<>();
|
|
|
+ doc.put("masterWaybillNo","SF7444488606478");
|
|
|
+ docList.add(doc);
|
|
|
+ msgDataMap.put("documents",docList);
|
|
|
+ String msgData = FlexJsonUtil.toJsonDeep(msgDataMap);
|
|
|
+ params.put("partnerID", CLIENT_CODE); // 顾客编码 ,对应丰桥上获取的clientCode
|
|
|
+ params.put("requestID", UUID.randomUUID().toString().replace("-", ""));
|
|
|
+ params.put("serviceCode",standardService.getCode());// 接口服务码
|
|
|
+ params.put("timestamp", timeStamp);
|
|
|
+ params.put("msgData", msgData);
|
|
|
+ params.put("msgDigest", tools.getMsgDigest(msgData,timeStamp,CHECK_WORD_BOX));
|
|
|
+ long startTime = System.currentTimeMillis();
|
|
|
+// System.out.println("====调用请求:" + params.get("msgData"));
|
|
|
+ System.out.println("====调用实际请求:" + params);
|
|
|
+ String result = HttpClientUtil.post(CALL_URL_BOX, params);
|
|
|
+ System.out.println("====调用丰桥的接口服务代码:" + String.valueOf(standardService.getCode()) + " 接口耗时:"+ String.valueOf(System.currentTimeMillis()-startTime)+"====");
|
|
|
+ System.out.println("===调用地址 ==="+CALL_URL_BOX);
|
|
|
+ System.out.println("===顾客编码 ==="+CLIENT_CODE);
|
|
|
+ System.out.println("===返回结果:" +result);
|
|
|
+// Map<String,Object> resData = JacksonUtil.fromJson(result);
|
|
|
+ SFApiResp sfApiResp = FlexJsonUtil.fromJson(result, SFApiResp.class);
|
|
|
+ if(sfApiResp!=null){
|
|
|
+ if("A1000".equals(sfApiResp.getApiResultCode())){
|
|
|
+ String apiResultData = sfApiResp.getApiResultData();
|
|
|
+ SFPrintToPDFResp sfPrintToPDFResp = FlexJsonUtil.fromJson(apiResultData, SFCreatOrderResp.class);
|
|
|
+ if(sfPrintToPDFResp.isSuccess()){
|
|
|
+ SFPrintFileResp sfPrintFileResp = sfPrintToPDFResp.getObj();
|
|
|
+ List<SFPrintFile> files = sfPrintFileResp.getFiles();
|
|
|
+ if(!CollectionUtil.isEmpty(files)){
|
|
|
+ files.stream().sorted(Comparator.comparingInt(SFPrintFile::getSeqNo));
|
|
|
+ for (SFPrintFile file : files) {
|
|
|
+ pdfDownLoad(file.getUrl(),file.getToken(),file.getWaybillNo());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ System.out.println("errorCode:"+sfPrintToPDFResp.getErrorCode()+"====errorMsg:"+sfPrintToPDFResp.getErrorMessage());
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ System.out.println("code:"+sfApiResp.getApiResultCode()
|
|
|
+ +"===apiResponseID:"+sfApiResp.getApiResponseID()
|
|
|
+ +"===apiErrorMsg:"+sfApiResp.getApiErrorMsg());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void TestpdfDownLoad(){
|
|
|
+ String fileUrl="https://eos-scp-core-shenzhen-futian1-oss.sf-express.com:443/v1.2/AUTH_EOS-SCP-CORE/print-file-sbox/AAABkcBBzkdSfT1fJRhKjpLt-VFNcr-a_SF7444488607870_fm_76130_standard_JYXKJWFFJ88E_1_1.pdf";
|
|
|
+ String token="AUTH_tkv12_f146d1855480549d262b5c46ab0ab597ff20a97d9d0db45c16bedeb4fabd112b012deadd477ee524b1d690ce01baa3cdffbb125a6ccf69b73778dba2eb5157eb29d9b3c970d295a3ca38c86f265339b4e7673f13379eb30a5b06511e78f70544cc4cdfc6c2876b2b6b012fdd1261d4dc0a993336de84ff3d3ef08dcf6775c715ea8f1ccf7c6c82a84ac370b171a5ac5311e398d02ff8a80d4a3a5acb161165ebbbfe1b7a686c5f0c6fb838db2b8c7625d1d8540df26f87d4f8e135ecce42d062";
|
|
|
+ String fileName="SF7444488607870";
|
|
|
+ pdfDownLoad(fileUrl,token,fileName);
|
|
|
+ }
|
|
|
+ private void pdfDownLoad(String fileUrl,String token,String fileName){
|
|
|
+ //下载地址
|
|
|
+// String fileUrl = ioList.getGeneralString("ei_pdfurl"); // "https://inv.jss.com.cn/fp2/2zpnwyKkdvu9dWzE8BhmSnER0Iux3xQRMLidDJhiIE2PziVXY4lL3k83OsK0K06YctW5cf1FFHxraffj-bf16A.pdf";
|
|
|
+ // 定义要保存的文件的路径
|
|
|
+// String fileName = ioList.getGeneralString("cu_name")+ioList.getGeneralString("ei_refno")+".pdf";//
|
|
|
+ String fileBasePath = "C:\\jyxsf\\"+fileName+".pdf";
|
|
|
+// fileBasePath = String.valueOf(obs[5])+fileName;//发票储存路径
|
|
|
+ try {//X-Auth-token
|
|
|
+ // 创建URL对象
|
|
|
+ URL url = new URL(fileUrl);
|
|
|
+ HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
|
|
|
+ // 设置请求方法为GET
|
|
|
+ httpURLConnection.setRequestMethod("GET");
|
|
|
+ // 添加请求头
|
|
|
+ httpURLConnection.setRequestProperty("X-Auth-token", token); // 假设你的token是通过Bearer模式传递的
|
|
|
+ // 连接服务器
|
|
|
+ httpURLConnection.connect();
|
|
|
+ // 检查响应码
|
|
|
+ int responseCode = httpURLConnection.getResponseCode();
|
|
|
+ if (responseCode == HttpURLConnection.HTTP_OK) {
|
|
|
+ // 读取输入流
|
|
|
+ InputStream inputStream = httpURLConnection.getInputStream();
|
|
|
+ // 写入文件
|
|
|
+ FileOutputStream fileOutputStream = new FileOutputStream(fileBasePath);
|
|
|
+ byte[] buffer = new byte[4096];
|
|
|
+ int bytesRead = -1;
|
|
|
+ while ((bytesRead = inputStream.read(buffer)) != -1) {
|
|
|
+ fileOutputStream.write(buffer, 0, bytesRead);
|
|
|
+ }
|
|
|
+ // 关闭流
|
|
|
+ fileOutputStream.close();
|
|
|
+ inputStream.close();
|
|
|
+
|
|
|
+ System.out.println("下载成功");
|
|
|
+ } else {
|
|
|
+ System.out.println("下载失败 : " + responseCode);
|
|
|
+ }
|
|
|
+ // 断开连接
|
|
|
+ httpURLConnection.disconnect();
|
|
|
+ // 打开连接
|
|
|
+// URLConnection conn = url.openConnection();
|
|
|
+// // 获取输入流
|
|
|
+// InputStream in = conn.getInputStream();
|
|
|
+// // 创建输出流
|
|
|
+// FileOutputStream out = new FileOutputStream(fileBasePath);
|
|
|
+// // 创建缓冲区
|
|
|
+// byte[] buffer = new byte[104857600];
|
|
|
+// // 读取并写入数据
|
|
|
+// int len;
|
|
|
+// while ((len = in.read(buffer)) != -1) {
|
|
|
+// out.write(buffer, 0, len);
|
|
|
+// }
|
|
|
+// long size = out.getChannel().size();
|
|
|
+// // 关闭流
|
|
|
+// in.close();
|
|
|
+// out.close();
|
|
|
+// System.out.println("size:"+size);
|
|
|
+ //存文件 filepath
|
|
|
+// int id = commonService.saveFilePath(fileBasePath, (int) size, fileName, "管理员");
|
|
|
+// baseDao.execute("update ELECINVOICE set ei_pdfattach ='"+id+";' where ei_id = "+ioList.getGeneralInt("ei_id"));
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ String errMsg = "文件转存异常";
|
|
|
+ if(StringUtil.hasText(e.getMessage())){
|
|
|
+ errMsg = e.getMessage();
|
|
|
+ }else if(e.getCause()!=null&&StringUtil.hasText(e.getCause().getMessage())){
|
|
|
+ errMsg = e.getCause().getMessage();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|