| | |
| | | package com.ruoyi.order.service.impl; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.alibaba.nacos.shaded.com.google.gson.Gson; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | |
| | | import com.ruoyi.system.api.domain.Logistics; |
| | | import com.ruoyi.system.api.domain.dto.LogisticsDTO; |
| | | import com.ruoyi.system.api.domain.vo.Express100VO; |
| | | import net.sf.json.JSONObject; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.http.HttpEntity; |
| | | import org.springframework.http.HttpHeaders; |
| | |
| | | |
| | | import javax.annotation.Resource; |
| | | 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.ArrayList; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | |
| | | ILogisticsService { |
| | | |
| | | private String key="BltjQodT7186"; |
| | | |
| | | private String kye1="GMtjjhxp9pdEpfz37M"; |
| | | private String customer="56DE8E9E3D58CE73C60755C8B7483043"; |
| | | |
| | | private static final String AUTONUMBER_AUTO_URL = "http://www.kuaidi100.com/autonumber/auto?num=NUM&key=KEY"; |
| | |
| | | |
| | | @Override |
| | | public Boolean isLogisticsOne(LogisticsDTO logisticsDTO) { |
| | | List<KuaiDiCode> m=findKuaiDiCode(logisticsDTO.getPostid()); |
| | | Boolean b=false; |
| | | if (m.size()>0){ |
| | | for (KuaiDiCode k:m){ |
| | | if (k.getComCode().equals(logisticsDTO.getCompany())){ |
| | | b=true; |
| | | } |
| | | |
| | | |
| | | |
| | | 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; |
| | | } |
| | | |
| | | } |
| | | |
| | | return b; |
| | | } |
| | | |
| | | public List<KuaiDiCode> findKuaiDiCode(String orderId) { |
| | | String url = AUTONUMBER_AUTO_URL.replace("NUM", orderId).replace("KEY", key); |
| | | // 发送快递参数处理 |
| | | MultiValueMap<String, Object> sendBody = new LinkedMultiValueMap<>(); |
| | | sendBody.add("num", orderId); |
| | | sendBody.add("key", key); |
| | | //设置请求头参数 |
| | | HttpHeaders headers = new HttpHeaders(); |
| | | headers.add("Content-type", "application/x-www-form-urlencoded"); |
| | | HttpEntity<MultiValueMap<String, Object>> formEntity = new HttpEntity<>(sendBody, headers); |
| | | ResponseEntity<String> result = restTemplate.postForEntity(url, formEntity, String.class); |
| | | List<KuaiDiCode> kuaiDiCode = new ArrayList<>(); |
| | | if (result.getBody() != null && result.getBody().length() > 0) { |
| | | ArrayList body = JSON.parseObject(result.getBody(), ArrayList.class); |
| | | body.forEach(i -> kuaiDiCode.add(JSON.parseObject(JSON.toJSONString(i), KuaiDiCode.class))); |
| | | 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 kuaiDiCode; |
| | | return response.toString(); |
| | | } |
| | | |
| | | } |