package com.xiaopeng.vehicleConvoy.util; import java.io.ByteArrayInputStream; import java.io.InputStream; import java.security.MessageDigest; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; import java.util.Base64; import java.util.concurrent.TimeUnit; import com.alibaba.fastjson2.JSONArray; import com.alibaba.fastjson2.JSON; import com.alibaba.fastjson2.JSONObject; import com.xiaopeng.common.core.utils.StringUtils; import com.xiaopeng.common.redis.service.RedisService; import com.xiaopeng.vehicleConvoy.config.MinistryTransportProperties; import com.xiaopeng.vehicleConvoy.model.dto.*; import lombok.extern.slf4j.Slf4j; import org.apache.http.HttpResponse; import org.apache.http.client.config.RequestConfig; import org.apache.http.client.methods.HttpPost; import org.apache.http.entity.ContentType; import org.apache.http.entity.mime.MultipartEntityBuilder; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClientBuilder; import org.apache.http.util.EntityUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.core.io.ClassPathResource; import org.springframework.stereotype.Component; import javax.annotation.PostConstruct; /** * 交通部接口对接 */ @Slf4j @Component public class MinistryOfTransport { /** * 公司名称:广州易点智慧出行科技有限公司 * * 平台简称:“有鹏出行” * 标识:XPQCB67N * key:gEhROt7lg4DEBanR * * 对接ip:127.0.0.1,125.71.236.64,47.98.173.145,116.62.136.48,39.108.249.22,47.105.208.135,47.112.126.81,114.55.179.11,39.170.77.50,120.26.242.215 * * 接口地址:https://wycapi.jtj.gz.gov.cn/api/app/common/binapi */ public static String DEFAULT_COMPANY_ID = "4401XPQCB67N"; public static String DEFAULT_SYMBOL = "XPQCB67N_S0612018007357G"; public static String DEFAULT_PROTOCOL_VERSION = "V2.0"; private static final DateTimeFormatter FILE_TIME_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-ddHHmmssSSS"); public static final DateTimeFormatter DATA_TIME_FORMATTER = DateTimeFormatter.ofPattern("yyyyMMddHHmmss"); private static final String TOKEN_CACHE_KEY = "ministry_of_transport:token"; private static final long TOKEN_EXPIRE_SECONDS = 20 * 60; private static final long TOKEN_REFRESH_THRESHOLD_SECONDS = 5 * 60; @Autowired private RedisService redisService; @Autowired private MinistryTransportProperties ministryTransportProperties; @PostConstruct public void initDefaultConstants() { DEFAULT_COMPANY_ID = defaultIfBlank(ministryTransportProperties.getCompanyId(), DEFAULT_COMPANY_ID); DEFAULT_SYMBOL = defaultIfBlank(ministryTransportProperties.getSymbol(), DEFAULT_SYMBOL); DEFAULT_PROTOCOL_VERSION = defaultIfBlank(ministryTransportProperties.getProtocolVersion(), DEFAULT_PROTOCOL_VERSION); } /** * 获取token * @return */ public String getToken(){ try { String cachedToken = redisService.getCacheObject(TOKEN_CACHE_KEY); if (StringUtils.isNotBlank(cachedToken)) { Long expireTime = redisService.getExpire(TOKEN_CACHE_KEY); if (expireTime > TOKEN_REFRESH_THRESHOLD_SECONDS) { return cachedToken; } else { log.info("token即将过期,剩余{}秒,开始刷新", expireTime); } } else { log.info("未找到缓存token,开始获取新token"); } String format = LocalDateTime.now().format(FILE_TIME_FORMATTER); String filename = ministryTransportProperties.getPlatform() + "_TOKEN_ACCESS_REQ_" + format + ".json"; JSONObject body = new JSONObject(); body.put("platform", ministryTransportProperties.getPlatform()); body.put("key", ministryTransportProperties.getKey()); String response = uploadJsonFile(filename, body.toJSONString(), ministryTransportProperties.getPlatform()); String token = parseToken(response); redisService.setCacheObject(TOKEN_CACHE_KEY, token, TOKEN_EXPIRE_SECONDS, TimeUnit.SECONDS); log.info("成功获取新token并缓存,有效期{}秒", TOKEN_EXPIRE_SECONDS); return token; }catch (Exception e){ log.error("获取交通部token失败", e); } return null; } private String defaultIfBlank(String value, String defaultValue) { return StringUtils.isBlank(value) ? defaultValue : value; } /** * 报送网约车平台公司基本信息(PTJB) * * @return 监管平台原始响应 */ public String pushPlatformBaseInfo() { JSONObject item = buildPlatformBaseInfo(); return pushBasicReqInfo(item,"PTJB"); } /** * 报送网约车平台公司运营规模信息(PTYYGM) * * @return 监管平台原始响应 */ public String pushPlatformOperationScaleInfo() { JSONObject item = buildPlatformOperationScaleInfo(); return pushBasicReqInfo(item,"PTYYGM"); } /** * 报送网约车车辆基本信息(CLJB) * * @param dto 车辆基本信息 * @return 监管平台原始响应 */ public String pushVehicleBaseInfo(RegulationVehicleBaseInfoDTO dto) { JSONObject item = buildVehicleBaseInfo(dto); return pushBasicReqInfo(item, "CLJB"); } /** * 报送网约车车辆保险信息(CLBX) * * @param dto 车辆保险信息 * @return 监管平台原始响应 */ public String pushVehicleInsuranceInfo(RegulationVehicleInsuranceInfoDTO dto) { JSONObject item = buildVehicleInsuranceInfo(dto); return pushBasicReqInfo(item, "CLBX"); } /** * 报送网约车车辆里程信息(CLLC) * * @param dto 车辆里程信息 * @return 监管平台原始响应 */ public String pushVehicleMileageInfo(RegulationVehicleMileageInfoDTO dto) { JSONObject item = buildVehicleMileageInfo(dto); return pushBasicReqInfo(item, "CLLC"); } /** * 报送网约车驾驶员基本信息(JSYJB) * * @param dto 驾驶员基本信息 * @return 监管平台原始响应 */ public String pushDriverBaseInfo(RegulationDriverBaseInfoDTO dto) { JSONObject item = buildDriverBaseInfo(dto); return pushBasicReqInfo(item, "JSYJB"); } /** * 报送网约车驾驶员培训信息(JSYPX) * * @param dto 驾驶员培训信息 * @return 监管平台原始响应 */ public String pushDriverTrainingInfo(RegulationDriverTrainingInfoDTO dto) { JSONObject item = buildDriverTrainingInfo(dto); return pushBasicReqInfo(item, "JSYPX"); } /** * 报送网约车驾驶员移动终端信息(JSYYDZD) * * @param dto 驾驶员移动终端信息 * @return 监管平台原始响应 */ public String pushDriverMobileTerminalInfo(RegulationDriverMobileTerminalInfoDTO dto) { JSONObject item = buildDriverMobileTerminalInfo(dto); return pushBasicReqInfo(item, "JSYYDZD"); } /** * 报送网约车驾驶员统计信息(JSYTJ) * * @param dto 驾驶员统计信息 * @return 监管平台原始响应 */ public String pushDriverStatisticsInfo(RegulationDriverStatisticsInfoDTO dto) { JSONObject item = buildDriverStatisticsInfo(dto); return pushBasicReqInfo(item, "JSYTJ"); } /** * 报送网约车乘客基本信息(CKJB) * * @param dto 乘客基本信息 * @return 监管平台原始响应 */ public String pushPassengerBaseInfo(RegulationPassengerBaseInfoDTO dto) { JSONObject item = buildPassengerBaseInfo(dto); return pushBasicReqInfo(item, "CKJB"); } /** * 报送网约车平台投资人信息(PTTZR) * * @param dto 平台投资人信息 * @return 监管平台原始响应 */ public String pushPlatformInvestorInfo(RegulationPlatformInvestorInfoDTO dto) { JSONObject item = buildPlatformInvestorInfo(dto); return pushBasicReqInfo(item, "PTTZR"); } /** * 报送驾驶员合同信息(GTJSYHT) * * @param dto 驾驶员合同信息 * @return 监管平台原始响应 */ public String pushDriverContractInfo(RegulationDriverContractInfoDTO dto) { JSONObject item = buildDriverContractInfo(dto); return pushBasicReqInfo(item, "GTJSYHT"); } /** * 报送订单发起(DDFQ) * * @param dto 订单发起信息 * @return 监管平台原始响应 */ public String pushOrderCreateInfo(RegulationOrderCreateInfoDTO dto) { JSONObject item = buildOrderCreateInfo(dto); return pushOrderReqInfo(item, "DDFQ"); } /** * 报送订单成功(DDCG) * * @param dto 订单成功信息 * @return 监管平台原始响应 */ public String pushOrderMatchInfo(RegulationOrderMatchInfoDTO dto) { JSONObject item = buildOrderMatchInfo(dto); return pushOrderReqInfo(item, "DDCG"); } /** * 报送订单撤销(DDCX) * * @param dto 订单撤销信息 * @return 监管平台原始响应 */ public String pushOrderCancelInfo(RegulationOrderCancelInfoDTO dto) { JSONObject item = buildOrderCancelInfo(dto); return pushOrderReqInfo(item, "DDCX"); } /** * 报送订单违约(DDWY) * * @param dto 订单违约信息 * @return 监管平台原始响应 */ public String pushOrderViolationInfo(RegulationOrderViolationInfoDTO dto) { JSONObject item = buildOrderViolationInfo(dto); return pushOrderReqInfo(item, "DDWY"); } /** * 报送车辆营运上线(CLYYSX) * * @param dto 车辆营运上线信息 * @return 监管平台原始响应 */ public String pushVehicleOperateLoginInfo(RegulationVehicleOperateLoginInfoDTO dto) { JSONObject item = buildVehicleOperateLoginInfo(dto); return pushOperationReqInfo(item, "CLYYSX"); } /** * 报送车辆营运下线(CLYYXX) * * @param dto 车辆营运下线信息 * @return 监管平台原始响应 */ public String pushVehicleOperateLogoutInfo(RegulationVehicleOperateLogoutInfoDTO dto) { JSONObject item = buildVehicleOperateLogoutInfo(dto); return pushOperationReqInfo(item, "CLYYXX"); } /** * 报送营运出发(YYCF) * * @param dto 营运出发信息 * @return 监管平台原始响应 */ public String pushOperateDepartInfo(RegulationOperateDepartInfoDTO dto) { JSONObject item = buildOperateDepartInfo(dto); return pushOperationReqInfo(item, "YYCF"); } /** * 报送营运到达(YYDD) * * @param dto 营运到达信息 * @return 监管平台原始响应 */ public String pushOperateArriveInfo(RegulationOperateArriveInfoDTO dto) { JSONObject item = buildOperateArriveInfo(dto); return pushOperationReqInfo(item, "YYDD"); } /** * 报送营运支付(YYZF) * * @param dto 营运支付信息 * @return 监管平台原始响应 */ public String pushOperatePayInfo(RegulationOperatePayInfoDTO dto) { JSONObject item = buildOperatePayInfo(dto); return pushOperationReqInfo(item, "YYZF"); } /** * 报送驾驶员定位信息(JSYDW) * * @param dto 驾驶员定位信息 * @return 监管平台原始响应 */ public String pushDriverPositionInfo(RegulationDriverPositionInfoDTO dto) { JSONObject item = buildDriverPositionInfo(dto); return pushGpsReqInfo(item, "JSYDW"); } /** * 报送乘客评价信息(CKPJ) * * @param dto 乘客评价信息 * @return 监管平台原始响应 */ public String pushPassengerEvaluateInfo(RegulationPassengerEvaluateInfoDTO dto) { JSONObject item = buildPassengerEvaluateInfo(dto); return pushEvaluateReqInfo(item, "CKPJ"); } /** * 报送乘客投诉处理信息(CKTSCL) * * @param dto 乘客投诉处理信息 * @return 监管平台原始响应 */ public String pushPassengerComplaintInfo(RegulationPassengerComplaintInfoDTO dto) { JSONObject item = buildPassengerComplaintInfo(dto); return pushEvaluateReqInfo(item, "CKTSCL"); } /** * 报送车辆注销报备(CLZXBB) * * @param dto 车辆注销报备信息 * @return 监管平台原始响应 */ public String pushVehicleCancelReportInfo(RegulationVehicleCancelReportInfoDTO dto) { JSONObject item = buildVehicleCancelReportInfo(dto); return pushRegistReqInfo(item, "CLZXBB"); } /** * 报送驾驶员处罚信息(JSYCF) * * @param dto 驾驶员处罚信息 * @return 监管平台原始响应 */ public String pushDriverPunishInfo(RegulationDriverPunishInfoDTO dto) { JSONObject item = buildDriverPunishInfo(dto); return pushEvaluateReqInfo(item, "JSYCF"); } /** * 报送驾驶员信誉信息(JSYXY) * * @param dto 驾驶员信誉信息 * @return 监管平台原始响应 */ public String pushDriverReputationInfo(RegulationDriverReputationInfoDTO dto) { JSONObject item = buildDriverReputationInfo(dto); return pushEvaluateReqInfo(item, "JSYXY"); } /** * 报送人车对应关系信息(RCDYGX) * * @param dto 人车对应关系信息 * @return 监管平台原始响应 */ public String pushDriverVehicleRelationInfo(RegulationDriverVehicleRelationInfoDTO dto) { JSONObject item = buildDriverVehicleRelationInfo(dto); return pushRelationshipReqInfo(item, "RCDYGX"); } /** * 报送平台营运报备(PTYYBB) * * @param dto 平台营运报备信息 * @return 监管平台原始响应 */ public String pushPlatformOperationRegisterInfo(RegulationPlatformOperationRegisterInfoDTO dto) { JSONObject item = buildPlatformOperationRegisterInfo(dto); return pushRegistReqInfo(item, "PTYYBB"); } /** * 报送平台暂停营运报备(PTZTYYBB) * * @param dto 平台暂停营运报备信息 * @return 监管平台原始响应 */ public String pushPlatformPauseOperationRegisterInfo(RegulationPlatformPauseOperationRegisterInfoDTO dto) { JSONObject item = buildPlatformPauseOperationRegisterInfo(dto); return pushRegistReqInfo(item, "PTZTYYBB"); } /** * 报送合作聚合平台信息(PTJHPTXX) * * @param dto 合作聚合平台信息 * @return 监管平台原始响应 */ public String pushPlatformAggregationInfo(RegulationPlatformAggregationInfoDTO dto) { JSONObject item = buildPlatformAggregationInfo(dto); return pushRegistReqInfo(item, "PTJHPTXX"); } /** * 报送车辆营运报备(CLYYBB) * * @param dto 车辆营运报备信息 * @return 监管平台原始响应 */ public String pushVehicleOperationRegisterInfo(RegulationVehicleOperationRegisterInfoDTO dto) { JSONObject item = buildVehicleOperationRegisterInfo(dto); return pushRegistReqInfo(item, "CLYYBB"); } /** * 报送驾驶员注册报备(JSYZCBB) * * @param dto 驾驶员注册报备信息 * @return 监管平台原始响应 */ public String pushDriverRegisterInfo(RegulationDriverRegisterInfoDTO dto) { JSONObject item = buildDriverRegisterInfo(dto); return pushRegistReqInfo(item, "JSYZCBB"); } /** * 报送驾驶员注销注册(JSYZXZC) * * @param dto 驾驶员注销注册信息 * @return 监管平台原始响应 */ public String pushDriverCancelRegisterInfo(RegulationDriverCancelRegisterInfoDTO dto) { JSONObject item = buildDriverCancelRegisterInfo(dto); return pushRegistReqInfo(item, "JSYZXZC"); } /** * 报送网约车平台公司支付信息(PTZF) * * @return 监管平台原始响应 */ public String pushPlatformPayInfo(RegulationPlatformPayInfoDTO dto) { JSONObject item = buildPlatformPayInfo(dto); return pushBasicReqInfo(item,"PTZF"); } /** * 网约车平台公司服务机构(PTFWJG) * @return 监管平台原始响应 */ public String pushPlatformServiceInfo(RegulationPlatformServiceInfoDTO dto) { JSONObject item = buildPlatformServiceInfo(dto); return pushBasicReqInfo(item,"PTFWJG"); } /** * 网约车平台公司经营许可(CPTJYXK) * @return 监管平台原始响应 */ public String pushPlatformLicenseInfo(RegulationPlatformLicenseInfoDTO dto) { JSONObject item = buildPlatformLicenseInfo(dto); return pushBasicReqInfo(item,"CPTJYXK"); } /** * 网约车平台公司计程计价方式(PTYJ) * @return 监管平台原始响应 */ public String pushPlatformPriceInfo(RegulationPlatformPriceInfoDTO dto) { JSONObject item = buildPlatformPriceInfo(dto); return pushBasicReqInfo(item,"PTYJ"); } /** * 推送基础信息 * @param item 推送基础信息 * @param command 推送基础信息类型 * @return 监管平台原始响应 */ private String pushBasicReqInfo(JSONObject item,String command) { return pushReqInfo(item,"BASIC",command); } /** * 推送订单信息 * @param item 推送基础信息 * @param command 推送基础信息类型 * @return 监管平台原始响应 */ private String pushOrderReqInfo(JSONObject item,String command) { return pushReqInfo(item,"ORDER",command); } /** * 推送营运信息 * @param item 推送营运信息 * @param command 推送营运信息类型 * @return 监管平台原始响应 */ private String pushOperationReqInfo(JSONObject item,String command) { return pushReqInfo(item,"OPERATION",command); } /** * 推送服务质量信息 * @param item 推送服务质量信息 * @param command 推送服务质量信息类型 * @return 监管平台原始响应 */ private String pushEvaluateReqInfo(JSONObject item, String command) { return pushReqInfo(item,"EVALUATE",command); } /** * 推送注册报备信息 * @param item 推送注册报备信息 * @param command 推送注册报备信息类型 * @return 监管平台原始响应 */ private String pushRegistReqInfo(JSONObject item,String command) { return pushReqInfo(item,"REGIST",command); } /** * 推送GPS信息 * @param item 推送信息 * @param command 推送信息关键字 * @return 监管平台原始响应 */ private String pushGpsReqInfo(JSONObject item,String command) { return pushReqInfo(item,"GPS",command); } /** * 推送人车关系信息 * @param item 推送信息 * @param command 推送信息关键字 * @return 监管平台原始响应 */ private String pushRelationshipReqInfo(JSONObject item,String command) { return pushReqInfo(item,"RELATIONSHIP",command); } /** * 推送信息 * @param item 推送信息 * @param type 推送信息类型 * @param command 推送信息关键字 * @return 监管平台原始响应 */ private String pushReqInfo(JSONObject item,String type,String command) { String token = parseToken(getToken()); JSONObject body = new JSONObject(); JSONArray items = new JSONArray(); items.add(item); body.put("items", items); String format = LocalDateTime.now().format(FILE_TIME_FORMATTER); String filename = ministryTransportProperties.getPlatform() + "_"+ type +"_"+ command +"_REQ_" + format + ".json"; return uploadJsonFile(filename, body.toJSONString(), token); } private JSONObject buildPlatformBaseInfo() { JSONObject item = new JSONObject(); item.put("symbol", ministryTransportProperties.getSymbol()); item.put("companyId", ministryTransportProperties.getCompanyId()); item.put("companyName", ministryTransportProperties.getCompanyName()); item.put("identifier", ministryTransportProperties.getIdentifier()); item.put("contactPhone", ministryTransportProperties.getContactPhone()); item.put("address", ministryTransportProperties.getPlatformAddressCode()); item.put("businessScope", ministryTransportProperties.getBusinessScope()); item.put("contactAddress", ministryTransportProperties.getContactAddress()); item.put("economicType", ministryTransportProperties.getEconomicType()); item.put("regCapital", ministryTransportProperties.getRegCapital()); item.put("legalName", ministryTransportProperties.getLegalName()); item.put("legalId", ministryTransportProperties.getLegalId()); item.put("legalPhone", ministryTransportProperties.getLegalPhone()); item.put("legalPhoto", encodePdf(ministryTransportProperties.getLegalPhotoFile())); item.put("legalPhotoId", ministryTransportProperties.getLegalPhotoId()); item.put("identifierPhoto", encodePdf(ministryTransportProperties.getIdentifierPhotoFile())); item.put("state", ministryTransportProperties.getPlatformState()); item.put("flag", "1"); item.put("updateTime", LocalDateTime.now().format(DATA_TIME_FORMATTER)); item.put("serviceItem", ministryTransportProperties.getServiceItem()); item.put("servicePromise", ministryTransportProperties.getServicePromise()); item.put("protocolVersion", ministryTransportProperties.getProtocolVersion()); return item; } private JSONObject buildPlatformOperationScaleInfo() { JSONObject item = new JSONObject(); item.put("symbol", ministryTransportProperties.getSymbol()); item.put("companyId", ministryTransportProperties.getCompanyId()); item.put("vehicleNum", ministryTransportProperties.getOperationScaleVehicleNum()); item.put("driverNum", ministryTransportProperties.getOperationScaleDriverNum()); item.put("flag", "1"); item.put("updateTime", LocalDateTime.now().format(DATA_TIME_FORMATTER)); item.put("protocolVersion", ministryTransportProperties.getProtocolVersion()); return item; } private JSONObject buildVehicleBaseInfo(RegulationVehicleBaseInfoDTO dto) { if (dto == null) { throw new RuntimeException("网约车车辆基本信息不能为空"); } return (JSONObject) JSON.toJSON(dto); } private JSONObject buildVehicleInsuranceInfo(RegulationVehicleInsuranceInfoDTO dto) { if (dto == null) { throw new RuntimeException("网约车车辆保险信息不能为空"); } return (JSONObject) JSON.toJSON(dto); } private JSONObject buildVehicleMileageInfo(RegulationVehicleMileageInfoDTO dto) { if (dto == null) { throw new RuntimeException("网约车车辆里程信息不能为空"); } return (JSONObject) JSON.toJSON(dto); } private JSONObject buildDriverBaseInfo(RegulationDriverBaseInfoDTO dto) { if (dto == null) { throw new RuntimeException("网约车驾驶员基本信息不能为空"); } return (JSONObject) JSON.toJSON(dto); } private JSONObject buildDriverTrainingInfo(RegulationDriverTrainingInfoDTO dto) { if (dto == null) { throw new RuntimeException("网约车驾驶员培训信息不能为空"); } return (JSONObject) JSON.toJSON(dto); } private JSONObject buildDriverMobileTerminalInfo(RegulationDriverMobileTerminalInfoDTO dto) { if (dto == null) { throw new RuntimeException("网约车驾驶员移动终端信息不能为空"); } return (JSONObject) JSON.toJSON(dto); } private JSONObject buildDriverStatisticsInfo(RegulationDriverStatisticsInfoDTO dto) { if (dto == null) { throw new RuntimeException("网约车驾驶员统计信息不能为空"); } return (JSONObject) JSON.toJSON(dto); } private JSONObject buildPassengerBaseInfo(RegulationPassengerBaseInfoDTO dto) { if (dto == null) { throw new RuntimeException("网约车乘客基本信息不能为空"); } return (JSONObject) JSON.toJSON(dto); } private JSONObject buildPlatformInvestorInfo(RegulationPlatformInvestorInfoDTO dto) { if (dto == null) { throw new RuntimeException("网约车平台投资人信息不能为空"); } return (JSONObject) JSON.toJSON(dto); } private JSONObject buildDriverContractInfo(RegulationDriverContractInfoDTO dto) { if (dto == null) { throw new RuntimeException("驾驶员合同信息不能为空"); } return (JSONObject) JSON.toJSON(dto); } private JSONObject buildOrderCreateInfo(RegulationOrderCreateInfoDTO dto) { if (dto == null) { throw new RuntimeException("订单发起信息不能为空"); } return (JSONObject) JSON.toJSON(dto); } private JSONObject buildOrderMatchInfo(RegulationOrderMatchInfoDTO dto) { if (dto == null) { throw new RuntimeException("订单成功信息不能为空"); } return (JSONObject) JSON.toJSON(dto); } private JSONObject buildOrderCancelInfo(RegulationOrderCancelInfoDTO dto) { if (dto == null) { throw new RuntimeException("订单撤销信息不能为空"); } return (JSONObject) JSON.toJSON(dto); } private JSONObject buildOrderViolationInfo(RegulationOrderViolationInfoDTO dto) { if (dto == null) { throw new RuntimeException("订单违约信息不能为空"); } return (JSONObject) JSON.toJSON(dto); } private JSONObject buildVehicleOperateLoginInfo(RegulationVehicleOperateLoginInfoDTO dto) { if (dto == null) { throw new RuntimeException("车辆营运上线信息不能为空"); } return (JSONObject) JSON.toJSON(dto); } private JSONObject buildVehicleOperateLogoutInfo(RegulationVehicleOperateLogoutInfoDTO dto) { if (dto == null) { throw new RuntimeException("车辆营运下线信息不能为空"); } return (JSONObject) JSON.toJSON(dto); } private JSONObject buildOperateDepartInfo(RegulationOperateDepartInfoDTO dto) { if (dto == null) { throw new RuntimeException("营运出发信息不能为空"); } return (JSONObject) JSON.toJSON(dto); } private JSONObject buildOperateArriveInfo(RegulationOperateArriveInfoDTO dto) { if (dto == null) { throw new RuntimeException("营运到达信息不能为空"); } return (JSONObject) JSON.toJSON(dto); } private JSONObject buildOperatePayInfo(RegulationOperatePayInfoDTO dto) { if (dto == null) { throw new RuntimeException("营运支付信息不能为空"); } return (JSONObject) JSON.toJSON(dto); } private JSONObject buildDriverPositionInfo(RegulationDriverPositionInfoDTO dto) { if (dto == null) { throw new RuntimeException("驾驶员定位信息不能为空"); } return (JSONObject) JSON.toJSON(dto); } private JSONObject buildPassengerEvaluateInfo(RegulationPassengerEvaluateInfoDTO dto) { if (dto == null) { throw new RuntimeException("乘客评价信息不能为空"); } return (JSONObject) JSON.toJSON(dto); } private JSONObject buildPassengerComplaintInfo(RegulationPassengerComplaintInfoDTO dto) { if (dto == null) { throw new RuntimeException("乘客投诉处理信息不能为空"); } return (JSONObject) JSON.toJSON(dto); } private JSONObject buildVehicleCancelReportInfo(RegulationVehicleCancelReportInfoDTO dto) { if (dto == null) { throw new RuntimeException("车辆注销报备信息不能为空"); } return (JSONObject) JSON.toJSON(dto); } private JSONObject buildDriverPunishInfo(RegulationDriverPunishInfoDTO dto) { if (dto == null) { throw new RuntimeException("驾驶员处罚信息不能为空"); } return (JSONObject) JSON.toJSON(dto); } private JSONObject buildDriverReputationInfo(RegulationDriverReputationInfoDTO dto) { if (dto == null) { throw new RuntimeException("驾驶员信誉信息不能为空"); } return (JSONObject) JSON.toJSON(dto); } private JSONObject buildDriverVehicleRelationInfo(RegulationDriverVehicleRelationInfoDTO dto) { if (dto == null) { throw new RuntimeException("人车对应关系信息不能为空"); } return (JSONObject) JSON.toJSON(dto); } private JSONObject buildPlatformOperationRegisterInfo(RegulationPlatformOperationRegisterInfoDTO dto) { if (dto == null) { throw new RuntimeException("平台营运报备信息不能为空"); } return (JSONObject) JSON.toJSON(dto); } private JSONObject buildPlatformPauseOperationRegisterInfo(RegulationPlatformPauseOperationRegisterInfoDTO dto) { if (dto == null) { throw new RuntimeException("平台暂停营运报备信息不能为空"); } return (JSONObject) JSON.toJSON(dto); } private JSONObject buildPlatformAggregationInfo(RegulationPlatformAggregationInfoDTO dto) { if (dto == null) { throw new RuntimeException("合作聚合平台信息不能为空"); } return (JSONObject) JSON.toJSON(dto); } private JSONObject buildVehicleOperationRegisterInfo(RegulationVehicleOperationRegisterInfoDTO dto) { if (dto == null) { throw new RuntimeException("车辆营运报备信息不能为空"); } return (JSONObject) JSON.toJSON(dto); } private JSONObject buildDriverRegisterInfo(RegulationDriverRegisterInfoDTO dto) { if (dto == null) { throw new RuntimeException("驾驶员注册报备信息不能为空"); } return (JSONObject) JSON.toJSON(dto); } private JSONObject buildDriverCancelRegisterInfo(RegulationDriverCancelRegisterInfoDTO dto) { if (dto == null) { throw new RuntimeException("驾驶员注销注册信息不能为空"); } return (JSONObject) JSON.toJSON(dto); } private JSONObject buildPlatformPayInfo(RegulationPlatformPayInfoDTO dto) { if (dto == null) { throw new RuntimeException("网约车平台公司支付信息不能为空"); } return (JSONObject) JSON.toJSON(dto); } private JSONObject buildPlatformServiceInfo(RegulationPlatformServiceInfoDTO dto) { if (dto == null) { throw new RuntimeException("网约车平台公司服务机构信息不能为空"); } return (JSONObject) JSON.toJSON(dto); } private JSONObject buildPlatformLicenseInfo(RegulationPlatformLicenseInfoDTO dto) { if (dto == null) { throw new RuntimeException("网约车平台公司经营许可信息不能为空"); } return (JSONObject) JSON.toJSON(dto); } private JSONObject buildPlatformPriceInfo(RegulationPlatformPriceInfoDTO dto) { if (dto == null) { throw new RuntimeException("网约车平台公司计程计价方式信息不能为空"); } return (JSONObject) JSON.toJSON(dto); } private String encodePdf(String filename) { if (filename == null || filename.trim().isEmpty()) { return ""; } String resourcePath = "files/" + filename.trim(); ClassPathResource resource = new ClassPathResource(resourcePath); try { long contentLength = resource.contentLength(); if (contentLength > 10 * 1024 * 1024) { throw new RuntimeException("文件超过10M: " + filename); } try (InputStream inputStream = resource.getInputStream()) { byte[] bytes = new byte[(int) contentLength]; int offset = 0; int read; while (offset < bytes.length && (read = inputStream.read(bytes, offset, bytes.length - offset)) != -1) { offset += read; } if (offset != bytes.length) { throw new RuntimeException("文件读取不完整: " + filename); } return Base64.getEncoder().encodeToString(bytes); } } catch (Exception e) { throw new RuntimeException("读取PDF文件失败: " + filename, e); } } private String uploadJsonFile(String filename, String jsonBody, String auth) { try { byte[] bytes = jsonBody.getBytes("UTF-8"); String md5 = hash(new ByteArrayInputStream(bytes)); HttpPost post = new HttpPost(ministryTransportProperties.getUrl()); MultipartEntityBuilder builder = MultipartEntityBuilder.create(); post.addHeader("binfile-md5", md5); post.addHeader("binfile-auth", auth); post.addHeader("binfile-gzip", "false"); post.addHeader("binfile-reqlen", String.valueOf(bytes.length)); builder.addBinaryBody("binFile", new ByteArrayInputStream(bytes), ContentType.DEFAULT_BINARY, filename); builder.addTextBody("filename", filename, ContentType.create(ContentType.DEFAULT_TEXT.getMimeType(), "UTF-8")); post.setEntity(builder.build()); HttpClientBuilder clientBuilder = HttpClientBuilder.create(); RequestConfig requestConfig = RequestConfig.custom() .setConnectTimeout(10000) .build(); clientBuilder.setDefaultRequestConfig(requestConfig); clientBuilder.disableContentCompression(); try (CloseableHttpClient client = clientBuilder.build()) { HttpResponse response = client.execute(post); String responseBody = response.getEntity() == null ? "" : EntityUtils.toString(response.getEntity(), "UTF-8"); log.info("交通部接口响应 status={}, filename={}, responseLength={}", response.getStatusLine().getStatusCode(), filename, responseBody.length()); return responseBody; } } catch (Exception e) { throw new RuntimeException("上传交通部接口文件失败: " + filename, e); } } private String parseToken(String tokenResponse) { if (StringUtils.isBlank(tokenResponse)) { throw new RuntimeException("交通部token响应为空"); } try { JSONObject response = JSON.parseObject(tokenResponse); String token = response.getString("token"); if (StringUtils.isNotBlank(token)) { return token; } JSONArray items = response.getJSONArray("items"); if (items != null && !items.isEmpty()) { token = items.getJSONObject(0).getString("token"); if (StringUtils.isNotBlank(token)) { return token; } } } catch (Exception e) { throw new RuntimeException("解析交通部token失败: " + tokenResponse, e); } throw new RuntimeException("交通部token响应中未找到token: " + tokenResponse); } private static char[] commonDigit = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' }; public static String hash(InputStream in) { try { byte[] buffer = new byte[1024]; MessageDigest md5 = MessageDigest.getInstance("MD5"); int numRead = 0; while ((numRead = in.read(buffer)) > 0) { md5.update(buffer, 0, numRead); } in.close(); return toHexString(md5.digest()); } catch (Exception e) { return ""; } } private static String toHexString(byte[] b) { StringBuilder sb = new StringBuilder(b.length * 2); for (int i = 0; i < b.length; i++) { sb.append(commonDigit[(b[i] & 0xf0) >>> 4]); sb.append(commonDigit[b[i] & 0x0f]); } return sb.toString(); } }