|
|
@@ -3,6 +3,10 @@ package com.uas.eis;
|
|
|
|
|
|
import com.deppon.dop.module.sdk.shared.util.SecurityUtil;
|
|
|
import com.uas.eis.dao.*;
|
|
|
+import com.uas.eis.entity.dop.DoPApiResp;
|
|
|
+import com.uas.eis.entity.dop.DoPResponseParam;
|
|
|
+import com.uas.eis.entity.ky.KYApiResp;
|
|
|
+import com.uas.eis.entity.ky.KYPirceData;
|
|
|
import com.uas.eis.entity.sf.*;
|
|
|
import com.uas.eis.service.ERPService;
|
|
|
import com.uas.eis.utils.*;
|
|
|
@@ -21,6 +25,7 @@ import java.io.InputStream;
|
|
|
import java.io.UnsupportedEncodingException;
|
|
|
import java.net.HttpURLConnection;
|
|
|
import java.net.URL;
|
|
|
+import java.text.DateFormat;
|
|
|
import java.util.*;
|
|
|
|
|
|
@RunWith(SpringRunner.class)
|
|
|
@@ -30,288 +35,6 @@ public class UasEisApplicationTests {
|
|
|
private BaseDao baseDao;
|
|
|
@Autowired
|
|
|
private ERPService erpService;
|
|
|
- /**
|
|
|
- 丰桥新沙箱测试顾客编码 Yg4Zf06w_sxZs3A5D
|
|
|
- 校验码 3Xdk1jqeG1Xod9nUXus8Op7DNOkchTnw
|
|
|
- **/
|
|
|
- private static final String CLIENT_CODE = "JYXKJWFFJ88E"; //此处替换为您在丰桥平台获取的顾客编码
|
|
|
- //此处替换为您在丰桥平台获取的校验码
|
|
|
- private static final String CHECK_WORD_PROD = "GgO0UoyQ5FssNLItii3olo63bQ80ErAE"; //生产校验码
|
|
|
- private static final String CHECK_WORD_BOX ="rMBhSYRa9OtUPkfX5mow01NlxDWtI411";//沙箱校验码
|
|
|
-
|
|
|
- //沙箱环境的地址 -PRO
|
|
|
- private static final String CALL_URL_BOX = "https://sfapi-sbox.sf-express.com/std/service";
|
|
|
- //生产环境的地址 -PRO
|
|
|
- private static final String CALL_URL_PROD = "https://sfapi.sf-express.com/std/service";
|
|
|
- @Test
|
|
|
- public void TestApi() throws UnsupportedEncodingException {
|
|
|
- /**ExpressServiceCodeEnum 对应速运类-快递APIs
|
|
|
- POSTServiceCodeEnum 对应速运类-驿站APIs
|
|
|
- YJTServiceCodeEnum 对应解决方案-医寄通APIs
|
|
|
- EPSServiceCodeEnum 对应解决方案-快递管家APIs
|
|
|
- HZTServiceCodeEnum 对应解决方案-函证通APIs 2022-2-24 新增
|
|
|
- 详情见code目录下枚举类,客户可自行修改引用的该类
|
|
|
- **/
|
|
|
- IServiceCodeStandard standardService = ExpressServiceCodeEnum.EXP_RECE_CREATE_ORDER; //下订单
|
|
|
- // 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());
|
|
|
- String msgData = tools.packageMsgData(standardService);
|
|
|
- SFCreatOrderReq sfOrder = new SFCreatOrderReq();
|
|
|
- sfOrder.setOrderId("SD24090018-2");
|
|
|
- sfOrder.setMonthlyCard("7551234567");
|
|
|
-// 1,寄件方信息 2,到件方信息
|
|
|
- List<SFContactInfo> contactInfoList = new ArrayList<>();
|
|
|
- SFContactInfo sendInfo = new SFContactInfo();
|
|
|
- sendInfo.setContactType(1);
|
|
|
- sendInfo.setCompany("深圳市佳毅兴科技有限公司");
|
|
|
- sendInfo.setContact("窦慧怡");
|
|
|
- sendInfo.setMobile("18128820006");
|
|
|
- sendInfo.setAddress("广东省深圳市宝安区大宝路51号新柯城业园1栋5楼");
|
|
|
- contactInfoList.add(sendInfo);
|
|
|
-
|
|
|
- SFContactInfo receiveInfo = new SFContactInfo();
|
|
|
- receiveInfo.setContactType(2);
|
|
|
- receiveInfo.setCompany("深圳市豪锦瑞科技有限公司");
|
|
|
- receiveInfo.setContact("刘洋");
|
|
|
- receiveInfo.setMobile("18688770976");
|
|
|
- receiveInfo.setAddress("深圳市宝安区71区万源商务大厦B栋606");
|
|
|
- contactInfoList.add(receiveInfo);
|
|
|
- sfOrder.setContactInfoList(contactInfoList);
|
|
|
-
|
|
|
- List<SFCargoDetail> cargoDetails = new ArrayList<>();
|
|
|
- sfOrder.setCargoDetails(cargoDetails);
|
|
|
- msgData = FlexJsonUtil.toJsonDeep(sfOrder);
|
|
|
- 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();
|
|
|
- SFCreatOrderResp sfApiRespData = FlexJsonUtil.fromJson(apiResultData, SFCreatOrderResp.class);
|
|
|
- if(sfApiRespData.isSuccess()){
|
|
|
- SFCreateOrder sfOrderResp = sfApiRespData.getMsgData();
|
|
|
- if(!CollectionUtil.isEmpty(sfOrderResp.getWaybillNoInfoList())){
|
|
|
- for (SFWaybillNoInfo sfWaybillNoInfoResp:sfOrderResp.getWaybillNoInfoList()){
|
|
|
- System.out.println("顺丰物流单号: ====="+sfWaybillNoInfoResp.getWaybillNo());
|
|
|
- }
|
|
|
- }
|
|
|
- }else {
|
|
|
- System.out.println("errorCode:"+sfApiRespData.getErrorCode()+"====errorMsg:"+sfApiRespData.getErrorMsg());
|
|
|
- }
|
|
|
- }else {
|
|
|
- System.out.println("code:"+sfApiResp.getApiResultCode()
|
|
|
- +"===apiResponseID:"+sfApiResp.getApiResponseID()
|
|
|
- +"===apiErrorMsg:"+sfApiResp.getApiErrorMsg());
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- @Test
|
|
|
- public void TestCreatSFOrder(){
|
|
|
- Map<String, Object> res = erpService.creatSFOrder("JYX_TEST", 50734879,"ADMIN");
|
|
|
- System.out.println("res==="+res.get("success")+":"+res.get("message"));
|
|
|
- }
|
|
|
-
|
|
|
- @Test
|
|
|
- public void TestCancelSFOrder(){
|
|
|
- Map<String, Object> res = erpService.cancelSFOrder("JYX_TEST", 50734879,"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();
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
|
|
|
@Test
|
|
|
public void TestSF_getprice(){
|