From 392b42c4891cf2e6beda57ab32c51598f290f4b7 Mon Sep 17 00:00:00 2001 From: mitao <2763622819@qq.com> Date: 星期五, 14 三月 2025 20:56:27 +0800 Subject: [PATCH] bug修改 --- ruoyi-modules/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/LogisticsServiceImpl.java | 137 +++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 137 insertions(+), 0 deletions(-) diff --git a/ruoyi-modules/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/LogisticsServiceImpl.java b/ruoyi-modules/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/LogisticsServiceImpl.java index 3abea27..994ab03 100644 --- a/ruoyi-modules/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/LogisticsServiceImpl.java +++ b/ruoyi-modules/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/LogisticsServiceImpl.java @@ -1,10 +1,35 @@ package com.ruoyi.order.service.impl; + +import com.alibaba.nacos.shaded.com.google.gson.Gson; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.toolkit.StringUtils; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.kuaidi100.sdk.api.QueryTrack; +import com.kuaidi100.sdk.core.IBaseClient; +import com.kuaidi100.sdk.pojo.HttpResult; +import com.kuaidi100.sdk.request.QueryTrackParam; +import com.kuaidi100.sdk.request.QueryTrackReq; +import com.kuaidi100.sdk.utils.SignUtils; import com.ruoyi.order.mapper.LogisticsMapper; +import com.ruoyi.order.mapper.OrderMapper; import com.ruoyi.order.service.ILogisticsService; import com.ruoyi.system.api.domain.Logistics; +import com.ruoyi.system.api.domain.dto.LogisticsDTO; +import com.ruoyi.system.api.domain.vo.Express100VO; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.net.HttpURLConnection; +import java.net.URL; +import java.net.URLEncoder; +import java.util.HashMap; +import java.util.Map; +import java.util.Objects; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import org.springframework.web.client.RestTemplate; /** * <p> @@ -18,4 +43,116 @@ public class LogisticsServiceImpl extends ServiceImpl<LogisticsMapper, Logistics> implements ILogisticsService { + private static final String key = "BltjQodT7186"; + + private static final String kye1 = "GMtjjhxp9pdEpfz37M"; + private static final String customer = "56DE8E9E3D58CE73C60755C8B7483043"; + + private static final String AUTONUMBER_AUTO_URL = "http://www.kuaidi100.com/autonumber/auto?num=NUM&key=KEY"; + + @Autowired + private RestTemplate restTemplate; + @Autowired + private OrderMapper orderMapper; + + @Override + public Express100VO getLogisticsList(LogisticsDTO logisticsDTO) { + QueryTrackReq queryTrackReq = new QueryTrackReq(); + QueryTrackParam queryTrackParam = new QueryTrackParam(); + queryTrackParam.setCom(logisticsDTO.getCompany()); + queryTrackParam.setNum(logisticsDTO.getPostid()); + if ((logisticsDTO.getCompany().equals("shunfeng") || logisticsDTO.getCompany() + .equals("shunfengkuaiyun")) && StringUtils.isNotBlank( + logisticsDTO.getReceiverPhone())) { + queryTrackParam.setPhone(logisticsDTO.getReceiverPhone()); + } + String param = new Gson().toJson(queryTrackParam); + + queryTrackReq.setParam(param); + queryTrackReq.setCustomer(customer); + queryTrackReq.setSign(SignUtils.querySign(param ,key,customer)); + + IBaseClient baseClient = new QueryTrack(); + HttpResult execute = null; + try { + execute = baseClient.execute(queryTrackReq); + } catch (Exception e) { + throw new RuntimeException(e); + } + // 对返回的数据进行反序列化处理 + Gson gson = new Gson(); + String responseBody = execute.getBody(); + Express100VO response = gson.fromJson(responseBody, Express100VO.class); + LambdaQueryWrapper<Logistics> wrapper= Wrappers.lambdaQuery(); + wrapper.eq(Logistics::getLogisticsNum,logisticsDTO.getCompany()); + Logistics one = this.getOne(wrapper); + if (Objects.nonNull(one)) { + response.setLogisticsName(one.getLogisticsName()); + } + return response; + } + + @Override + public Boolean isLogisticsOne(LogisticsDTO logisticsDTO) { + Boolean b=false; + + + + Map<String,String> params=new HashMap(); + params.put("secret_key", "GMtjjhxp9pdEpfz37M"); + params.put("secret_code", "53514ac63f0447d188423221550b0c3e"); + params.put("secret_sign", "8265A3C04DDA73E5B899F7F750099BB0"); + params.put("num", logisticsDTO.getPostid()); + String string=post(params); + if (string.equals("[]")){ + return b; + }else{ + return b=true; + } + + } + + public String post(Map<String,String> params){ + StringBuilder response=new StringBuilder(""); + BufferedReader reader = null; + try { + StringBuilder builder =new StringBuilder(); + for(Map.Entry param:params.entrySet()){ + if(builder.length()>0){ + builder.append('&'); + } + builder.append(URLEncoder.encode(param.getKey().toString(),"UTF-8")); + builder.append('='); + builder.append(URLEncoder.encode(String.valueOf(param.getValue()),"UTF-8")); + } + byte[]bytes=builder.toString().getBytes("UTF-8"); + URL url=new URL("http://cloud.kuaidi100.com/api"); + HttpURLConnection conn = (HttpURLConnection) url.openConnection(); + conn.setConnectTimeout(5000); + conn.setReadTimeout(5000); + conn.setRequestMethod("POST"); + conn.setRequestProperty("accept","*/*"); + conn.setRequestProperty("connection","Keep-Alive"); + conn.setRequestProperty("Content-Type","application/x-www-form-urlencoded"); + conn.setRequestProperty("Content-Length",String.valueOf(bytes.length)); + conn.setDoOutput(true); + conn.getOutputStream().write(bytes); + reader=new BufferedReader(new InputStreamReader(conn.getInputStream(),"UTF-8")); + String line = ""; + while ((line =reader.readLine())!=null){ + response.append(line); + } + }catch(Exception e){ + e.printStackTrace(); + }finally{ + try{ + if (null!=reader){ + reader.close(); + } + }catch(IOException e){ + e.printStackTrace(); + } + } + return response.toString(); + } } -- Gitblit v1.7.1