| | |
| | | import cn.hutool.http.HttpUtil; |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.xiaopeng.trafficControl.config.MinistryTransportProperties; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.stereotype.Component; |
| | |
| | | * |
| | | * 接口地址:https://wycapi.jtj.gz.gov.cn/api/app/common/binapi |
| | | */ |
| | | |
| | | private final String companyId = "4401XPQCB67N";//公司标识 |
| | | |
| | | private final String platform = "XPQC"; |
| | | |
| | | private final String key = "gEhROt7lg4DEBanR"; |
| | | |
| | | private final String url = "https://wycapi.jtj.gz.gov.cn/api/app/common/binapi"; |
| | | |
| | | @Value("${xp.file.path}") |
| | | private String filePath; |
| | | |
| | | private final MinistryTransportProperties ministryTransportProperties; |
| | | |
| | | public MinistryOfTransport(MinistryTransportProperties ministryTransportProperties) { |
| | | this.ministryTransportProperties = ministryTransportProperties; |
| | | } |
| | | |
| | | |
| | | /** |
| | |
| | | public String getToken(){ |
| | | //通过上传文件的方式获取token |
| | | String format = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmmssSSS")); |
| | | String fileName = platform + "_TOKEN_ACCESS_REQ_" + format + ".json"; |
| | | String fileName = ministryTransportProperties.getPlatform() + "_TOKEN_ACCESS_REQ_" + format + ".json"; |
| | | File file = FileUtil.file(filePath + fileName); |
| | | if(!file.exists()){ |
| | | file.getParentFile().mkdirs(); |
| | |
| | | JSONObject body = new JSONObject(); |
| | | JSONArray items = new JSONArray(); |
| | | JSONObject jsonObject = new JSONObject(); |
| | | jsonObject.put("platform", platform); |
| | | jsonObject.put("key", key); |
| | | jsonObject.put("platform", ministryTransportProperties.getPlatform()); |
| | | jsonObject.put("key", ministryTransportProperties.getKey()); |
| | | items.add(jsonObject); |
| | | body.put("items", items); |
| | | log.info("获取token请求参数 {}", body.toJSONString()); |
| | | log.info("获取token请求参数已生成"); |
| | | file = FileUtil.writeUtf8String(body.toJSONString(), file); |
| | | String md5 = MD5.create().digestHex(file); |
| | | HttpRequest post = HttpUtil.createPost(url); |
| | | HttpRequest post = HttpUtil.createPost(ministryTransportProperties.getUrl()); |
| | | post.contentType("multipart/form-data;boundary=inputstream"); |
| | | post.header("binfile-md5", md5); |
| | | post.header("binfile-gzip", "false"); |
| | |
| | | post.form("filename", fileName); |
| | | HttpResponse execute = post.execute(); |
| | | if(!execute.isOk()){ |
| | | log.info("获取token失败:{}", execute.body()); |
| | | log.info("获取token失败,status={}", execute.getStatus()); |
| | | return execute.body(); |
| | | } |
| | | InputStream inputStream = execute.bodyStream(); |
| | |
| | | resultFile.getParentFile().mkdirs(); |
| | | FileUtil.writeFromStream(inputStream, resultFile); |
| | | String responseContent = FileUtil.readUtf8String(resultFile); |
| | | log.info("获取token成功 {}", responseContent); |
| | | log.info("获取token成功"); |
| | | return responseContent; |
| | | } |
| | | |