Sfoglia il codice sorgente

京东拉单,发货打单回传发货信息

liurui 1 anno fa
parent
commit
175f25e666

+ 7 - 1
watero-rst-service/pom.xml

@@ -23,11 +23,17 @@
             <version>1.0.0</version>
         </dependency>
 
+<!--        <dependency>-->
+<!--            <groupId>com.jd</groupId>-->
+<!--            <artifactId>open-api-sdk</artifactId>-->
+<!--            <version>2.0</version>-->
+<!--        </dependency>-->
         <dependency>
             <groupId>com.jd</groupId>
             <artifactId>open-api-sdk</artifactId>
-            <version>2.0</version>
+            <version>2.0-2023</version>
         </dependency>
+
     </dependencies>
 
     <build>

+ 27 - 0
watero-rst-service/src/main/java/com/iamberry/rst/service/cm/SalesOrderServiceImpl.java

@@ -23,6 +23,7 @@ import com.iamberry.rst.faces.order.OrderBatchService;
 import com.iamberry.rst.faces.order.OrderSyncLogService;
 import com.iamberry.rst.faces.order.OrderWarehouseService;
 import com.iamberry.rst.faces.product.ProductService;
+import com.iamberry.rst.faces.sys.SysConfigService;
 import com.iamberry.rst.service.cm.mapper.SalesOrderMapper;
 import com.iamberry.rst.service.dm.mapper.SupplierProductMapper;
 import com.iamberry.rst.service.fm.mapper.ComplaintDetectInfoMapper;
@@ -32,9 +33,15 @@ import com.iamberry.rst.service.order.mapper.DeliveryStrategyMapper;
 import com.iamberry.rst.service.order.mapper.ProvincesLogisticsMapper;
 import com.iamberry.rst.service.product.mapper.ProductMapper;
 import com.iamberry.rst.service.sys.mapper.SysConfigMapper;
+import com.iamberry.rst.util.JingdongConfig;
 import com.iamberry.rst.util.PageUtil;
 import com.iamberry.rst.util.TaobaoConfig;
 import com.iamberry.wechat.tools.DateTimeUtil;
+import com.jd.open.api.sdk.DefaultJdClient;
+import com.jd.open.api.sdk.JdClient;
+import com.jd.open.api.sdk.JdException;
+import com.jd.open.api.sdk.request.order.PopOrderShipmentRequest;
+import com.jd.open.api.sdk.response.order.PopOrderShipmentResponse;
 import com.taobao.api.ApiException;
 import com.taobao.api.DefaultTaobaoClient;
 import com.taobao.api.TaobaoClient;
@@ -100,6 +107,9 @@ public class SalesOrderServiceImpl implements SalesOrderService {
     @Autowired
     private OrderSyncLogService orderSyncLogService;
 
+    @Autowired
+    private SysConfigService sysConfigService;
+
     /**
      * 缓存订单项的前缀
      */
@@ -2251,6 +2261,23 @@ public class SalesOrderServiceImpl implements SalesOrderService {
                     throw new RuntimeException(e);
                 }
             }
+            //京东订单发货
+            if (salesOrder.getSalesBatchId().startsWith("JT")) {
+                SysConfig sysConfigAll = sysConfigService.getSysConfigAll(27);
+                JdClient client = new DefaultJdClient(JingdongConfig.JINGDONG_API_URL, sysConfigAll.getConfigParameter(), JingdongConfig.jd_appkey, JingdongConfig.jd_secret);
+                PopOrderShipmentRequest req = new PopOrderShipmentRequest();
+                req.setOrderId(Long.parseLong(salesOrder.getSalesOrderId()));
+                req.setLogiCoprId(salesOrder.getSalesPostFirm());
+                req.setLogiNo(o.getSalesPostNum());
+                try {
+                    PopOrderShipmentResponse rsp = client.execute(req);
+                    logger.info("京东订单发货回录:code:{}, msg:{}", rsp.getCode(), rsp.getMsg());
+                } catch (JdException e) {
+                    throw new RuntimeException(e);
+                } catch (Exception e) {
+                    throw new RuntimeException(e);
+                }
+            }
             // 添加订单追踪信息
             OrderTracking orderTracking = new OrderTracking();
             orderTracking.setAdminId(currAdmin);

+ 9 - 0
watero-rst-service/src/main/java/com/iamberry/rst/util/GenerateKeyUtil.java

@@ -163,6 +163,15 @@ public class GenerateKeyUtil {
     }
 
     /**
+     * 获取批次号 setSalesBatchId -- 京东添加
+     * @return
+     */
+    public String getSalesBatchIdJD(){
+        Integer number = getBatch();
+        return ("J"+ ST_BATCH + SDF_BATCH.format(new Date()) + String.format("%08d", number));
+    }
+
+    /**
      * 获取批次号 setSalesBatchId -- 批量导入
      * @return
      */

+ 2 - 2
watero-rst-service/src/main/java/com/iamberry/rst/util/JdServiceUtil.java

@@ -63,7 +63,7 @@ public class JdServiceUtil {
         PopInvoiceSelfAmountResponse response = null;
         try {
             response = client.execute(rq);
-        } catch (JdException e) {
+        } catch (Exception e) {
             e.printStackTrace();
             billing.setBillResultMsg("京东api调用失败!");
             return billing;
@@ -213,7 +213,7 @@ public class JdServiceUtil {
                 ps.setPushLogResultMsg("发票上传失败!");
                 ps.setPushLogStatus(2);
             }
-        } catch (JdException e) {
+        } catch (Exception e) {
             e.printStackTrace();
         }
         return ps;

+ 57 - 0
watero-rst-service/src/main/java/com/iamberry/rst/util/JingdongConfig.java

@@ -0,0 +1,57 @@
+package com.iamberry.rst.util;
+
+import com.alibaba.dubbo.config.ApplicationConfig;
+import com.alibaba.fastjson.JSONObject;
+import com.iamberry.redis.RedisUtils;
+import com.iamberry.rst.core.sys.SysConfig;
+import com.iamberry.rst.faces.sys.SysConfigService;
+import com.iamberry.wechat.tools.DateTimeUtil;
+import com.iamberry.zk.SpringContextHolder;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.context.support.AbstractApplicationContext;
+
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
+
+public class JingdongConfig {
+
+    //京东授权 关键参数
+    public static final String JINGDONG_API_URL = "https://api.jd.com/routerjson";
+    public static final String JINGDONG_URL = "https://open-oauth.jd.com/oauth2/access_token?app_key=APP_KEY&app_secret=APP_SECRET&grant_type=authorization_code&code=CODE";
+    public static final String jd_appkey = "D4D06F60BFFC308ED4B00D985029C5D1";
+    public static final String jd_secret = "c6cdaef6c2bb453e96b0762fe2a8d40a";
+
+
+    public static SysConfigService sysConfigService;
+
+
+    static {
+           if (sysConfigService == null) {
+               // 获取应用配置
+               AbstractApplicationContext ctx = (AbstractApplicationContext) SpringContextHolder.getApplicationContext();
+               sysConfigService = ctx.getBean(SysConfigService.class);
+           }
+    }
+
+    public static Map<String, Object> getToken() {
+        SysConfig sysConfigAll = sysConfigService.getSysConfigAll(27);
+//        String taobaoSession = RedisUtils.get("JINGDONG_SESSION");
+        // 判断数据
+        if (sysConfigAll == null || StringUtils.isEmpty(sysConfigAll.getConfigParameter()) || StringUtils.isEmpty(sysConfigAll.getConfigRemarks())) {
+            return null;
+        }
+//        JSONObject obj = JSONObject.parseObject(taobaoSession);
+        // 校验时间
+//        Date time = obj.getDate("time");
+        Date time = DateTimeUtil.parse(sysConfigAll.getConfigRemarks());
+        if (time.getTime() <= System.currentTimeMillis()) {
+            return null;
+        }
+        // 组装
+        Map<String, Object> res = new HashMap<>();
+        res.put("token", sysConfigAll.getConfigParameter());
+        res.put("time", time);
+        return res;
+    }
+}

File diff suppressed because it is too large
+ 493 - 0
watero-rst-web/src/main/java/com/iamberry/rst/controllers/mq/JingdongTask.java


+ 10 - 0
watero-rst-web/src/main/java/com/iamberry/rst/controllers/mq/TaobaoConfig.java

@@ -2,6 +2,7 @@ package com.iamberry.rst.controllers.mq;
 
 public class TaobaoConfig {
 
+    //淘宝授权 关键参数
     public static final String TAOBAO_URL = "https://eco.taobao.com/router/rest";
 
     public static final String appkey = "33060815";
@@ -9,4 +10,13 @@ public class TaobaoConfig {
     public static final String secret = "16e44445788f75485fd03e6b333e8484";
 
 
+    //京东授权 关键参数
+    public static final String JINGDONG_API_URL = "https://api.jd.com/routerjson";
+    public static final String JINGDONG_URL = "https://open-oauth.jd.com/oauth2/access_token?app_key=APP_KEY&app_secret=APP_SECRET&grant_type=authorization_code&code=CODE";
+    public static final String jd_appkey = "D4D06F60BFFC308ED4B00D985029C5D1";
+    public static final String jd_secret = "c6cdaef6c2bb453e96b0762fe2a8d40a";
+
+
+
+
 }

+ 167 - 0
watero-rst-web/src/main/java/com/iamberry/rst/controllers/order/AdminJingdongAuthController.java

@@ -0,0 +1,167 @@
+package com.iamberry.rst.controllers.order;
+
+import com.alibaba.fastjson.JSONObject;
+import com.iamberry.app.tool.util.HttpUtility;
+//import com.iamberry.redis.RedisUtils;
+import com.iamberry.rst.controllers.mq.TaobaoConfig;
+import com.iamberry.rst.core.sys.SysConfig;
+import com.iamberry.rst.faces.sys.SysConfigService;
+import com.iamberry.wechat.tools.DateTimeUtil;
+import com.iamberry.wechat.tools.ResponseJson;
+import com.iamberry.wechat.tools.payUtil.StringUtil;
+import com.iamberry.zk.SpringContextHolder;
+import com.jd.open.api.sdk.DefaultJdClient;
+import com.jd.open.api.sdk.internal.util.HttpUtil;
+import com.taobao.api.ApiException;
+import com.taobao.api.DefaultTaobaoClient;
+import com.taobao.api.TaobaoClient;
+import com.taobao.api.request.TopAuthTokenCreateRequest;
+import com.taobao.api.response.TopAuthTokenCreateResponse;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.ResponseBody;
+import org.springframework.web.servlet.ModelAndView;
+
+import javax.servlet.http.HttpServletRequest;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Random;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * @author root
+ */
+@Controller
+@RequestMapping("/jingdong")
+public class AdminJingdongAuthController {
+
+
+    @Autowired
+    private SysConfigService sysConfigService;
+
+    public static final Map<String, String> HREF_CACHE = new ConcurrentHashMap<>(10);
+
+//    @RequestMapping("/tokenPage")
+//    public ModelAndView tokenPage() {
+//        return new ModelAndView("taobao/token").addObject("data", getToken());
+//    }
+
+
+
+
+    public static Map<String, Object> getToken(SysConfig sysConfig) {
+        if (sysConfig == null || StringUtil.isEmpty(sysConfig.getConfigParameter()) || StringUtil.isEmpty(sysConfig.getConfigRemarks())) {
+            return null;
+        }
+
+
+//        String taobaoSession = RedisUtils.get("JINGDONG_SESSION");
+//        // 判断数据
+//        if (taobaoSession == null) {
+//            return null;
+//        }
+//        JSONObject obj = JSONObject.parseObject(taobaoSession);
+        // 校验时间
+//        Date time = obj.getDate("time");
+        Date time = DateTimeUtil.parse(sysConfig.getConfigRemarks());
+        if (time.getTime() <= System.currentTimeMillis()) {
+            return null;
+        }
+        // 组装
+        Map<String, Object> res = new HashMap<>();
+        res.put("token", sysConfig.getConfigParameter());
+        res.put("time", DateTimeUtil.parse(sysConfig.getConfigRemarks()));
+        return res;
+    }
+
+    @ResponseBody
+    @RequestMapping("/check")
+    public ResponseJson checkToken() {
+        SysConfig sysConfig = sysConfigService.getSysConfigAll(27);
+        Map<String, Object> token = getToken(sysConfig);
+        if (token == null) {
+            return ResponseJson.getFAILURE();
+        }
+        Date time = (Date) token.get("time");
+        if (time.getTime() <= System.currentTimeMillis()) {
+            return ResponseJson.getFAILURE();
+        }
+        return ResponseJson.getSUCCESS().addResponseKeyValue("token", token);
+    }
+
+    @ResponseBody
+    @RequestMapping("/invalid")
+    public ResponseJson invalid() {
+//        RedisUtils.del("JINGDONG_SESSION");
+        SysConfig sysConfig = new SysConfig();
+        sysConfig.setConfigId(27);
+        sysConfig.setConfigParameter("");
+        sysConfig.setConfigRemarks("");
+        sysConfigService.updateSysConfig(sysConfig);
+        return ResponseJson.getSUCCESS();
+    }
+
+    @ResponseBody
+    @RequestMapping("/token")
+    public ModelAndView token(
+            @RequestParam("code") String code,
+            @RequestParam("state") String state,
+            HttpServletRequest request) {
+
+        String authUrl = TaobaoConfig.JINGDONG_URL
+                .replaceAll("APP_KEY", TaobaoConfig.jd_appkey)
+                        .replaceAll("APP_SECRET", TaobaoConfig.jd_secret)
+                                .replaceAll("CODE", code);
+        try {
+            Map<String, String> params = new HashMap<>();
+            params.put("app_key", TaobaoConfig.jd_appkey);
+            params.put("app_secret", TaobaoConfig.jd_secret);
+            params.put("grant_type", "authorization_code");
+            params.put("code", code);
+//            String s = HttpUtil.doPost(TaobaoConfig.JINGDONG_URL, params, 6000, 6000);
+            String s = HttpUtility.httpsGet(authUrl);
+            System.out.println("获取到京东结果:" + s);
+            JSONObject result = JSONObject.parseObject(s);
+            System.out.println(result);
+            String accessToken = result.getString("access_token");
+            Integer timeout = result.getInteger("expires_in");//有效期, 单位秒
+            // 缓存数据
+//            Map<String, Object> data = new HashMap<>(2);
+//            data.put("token", accessToken);
+//            data.put("time", DateTimeUtil.addMinute(new Date(), (timeout/60)-30));
+//            RedisUtils.put("JINGDONG_SESSION", JSONObject.toJSONString(data));
+            SysConfig sysConfig = new SysConfig();
+            sysConfig.setConfigId(27);
+            sysConfig.setConfigParameter(accessToken);
+            sysConfig.setConfigRemarks(DateTimeUtil.format(DateTimeUtil.addMinute(new Date(), (timeout/60)-30)));
+            sysConfigService.updateSysConfig(sysConfig);
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        }
+
+        // 跳转地址
+        String url = request.getContextPath() + "/admin/sys/_index";
+        String href = HREF_CACHE.get(state);
+        if (href != null) {
+            url = href;
+            HREF_CACHE.remove(state);
+        }
+        return new ModelAndView("taobao/redirect").addObject("url", url);
+    }
+
+
+    @RequestMapping("/auth")
+    public ModelAndView auth(@RequestParam("url") String href) {
+        // 存储跳转前的URL
+        int state = new Random(1_000_000).nextInt();
+        HREF_CACHE.put(state + "", href);
+        // 跳转  http://liurui.gz2vip.91tunnel.com/watero/jingdong/token
+//        String url = "https://open-oauth.jd.com/oauth2/to_login?response_type=code&client_id=" + TaobaoConfig.jd_appkey + "&redirect_uri=https://rst.iamberry.com/jingdong/token&state=" + state + "&view=web";
+        String url = "https://open-oauth.jd.com/oauth2/to_login?app_key=" + TaobaoConfig.jd_appkey + "&response_type=code&redirect_uri=http://liurui.gz2vip.91tunnel.com/watero/jingdong/token&state=" + state + "&scope=snsapi_base";
+        return new ModelAndView("redirect:" + url);
+    }
+
+}

+ 28 - 5
watero-rst-web/src/main/java/com/iamberry/rst/controllers/order/AdminTaobaoAuthController.java

@@ -4,6 +4,8 @@ import com.alibaba.fastjson.JSONObject;
 import com.alibaba.fastjson.JSONPObject;
 import com.iamberry.redis.RedisUtils;
 import com.iamberry.rst.controllers.mq.TaobaoConfig;
+import com.iamberry.rst.core.sys.SysConfig;
+import com.iamberry.rst.faces.sys.SysConfigService;
 import com.iamberry.wechat.tools.DateTimeUtil;
 import com.iamberry.wechat.tools.ResponseJson;
 import com.taobao.api.ApiException;
@@ -11,6 +13,7 @@ import com.taobao.api.DefaultTaobaoClient;
 import com.taobao.api.TaobaoClient;
 import com.taobao.api.request.TopAuthTokenCreateRequest;
 import com.taobao.api.response.TopAuthTokenCreateResponse;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Controller;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestParam;
@@ -18,10 +21,7 @@ import org.springframework.web.bind.annotation.ResponseBody;
 import org.springframework.web.servlet.ModelAndView;
 
 import javax.servlet.http.HttpServletRequest;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Random;
+import java.util.*;
 import java.util.concurrent.ConcurrentHashMap;
 
 /**
@@ -31,14 +31,36 @@ import java.util.concurrent.ConcurrentHashMap;
 @RequestMapping("/taobao")
 public class AdminTaobaoAuthController {
 
+    @Autowired
+    private SysConfigService sysConfigService;
+
     public static final Map<String, String> HREF_CACHE = new ConcurrentHashMap<>(10);
 
     @RequestMapping("/tokenPage")
     public ModelAndView tokenPage() {
-        return new ModelAndView("taobao/token").addObject("data", getToken());
+        List<Map<String, Object>> reuslt = new ArrayList<>();
+        Map<String, Object> taobaoToken = getToken();
+        if (taobaoToken == null || taobaoToken.size() == 0) {
+            taobaoToken = new HashMap<>();
+        }
+        taobaoToken.put("name", "淘宝认证");
+        taobaoToken.put("type", "1");
+        reuslt.add(taobaoToken);
+
+        SysConfig sysConfig = sysConfigService.getSysConfigAll(27);
+        Map<String, Object> jingdongToken = AdminJingdongAuthController.getToken(sysConfig);
+        if (jingdongToken == null || jingdongToken.size() == 0) {
+            jingdongToken = new HashMap<>();
+        }
+        jingdongToken.put("name", "京东认证");
+        jingdongToken.put("type", "2");
+        reuslt.add(jingdongToken);
+        return new ModelAndView("taobao/token").addObject("result", reuslt);
     }
 
     public static Map<String, Object> getToken() {
+
+        //淘宝授权token
         String taobaoSession = RedisUtils.get("TAOBAO_SESSION");
         // 判断数据
         if (taobaoSession == null) {
@@ -54,6 +76,7 @@ public class AdminTaobaoAuthController {
         Map<String, Object> res = new HashMap<>();
         res.put("token", obj.getString("token"));
         res.put("time", obj.getDate("time"));
+
         return res;
     }
 

+ 43 - 19
watero-rst-web/src/main/webapp/WEB-INF/views/taobao/token.ftl

@@ -12,47 +12,71 @@
     <title>系统管理 - 管理员列表 - Watero-RST 1.0</title>
 </head>
 <body>
-<nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">/</span> 订单管理 <span class="c-gray en">/</span> 淘宝认证 <a class="btn btn-success radius r" href="javascript:location.replace(location.href);" title="刷新" ><i class="Hui-iconfont">&#xe68f;</i></a></nav>
+<nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">/</span> 订单管理 <span class="c-gray en">/</span> 第三方认证 <a class="btn btn-success radius r" href="javascript:location.replace(location.href);" title="刷新" ><i class="Hui-iconfont">&#xe68f;</i></a></nav>
 <div class="page-container">
 
      <table class="table table-border table-bordered table-hover">
         <thead>
             <tr class="text-c">
+                <th width="100">认证机构</th>
                 <th width="100">TOKEN</th>
                 <th width="20">过期时间</th>
                 <th width="10">操作</th>
             </tr>
         </thead>
         <tbody>
-        <#if !((data)??)>
-            <tr class="text-c">
-                <td colspan="3">
-                    <span onclick="re_auth()" style="color: red;font-size: 16px">
-                        重新授权
-                        <i class="Hui-iconfont">&#xe61d;</i>
-                    </span>
-                </td>
-            </tr>
-        <#else>
-            <tr class="text-c">
-                <td>${(data.token)!}</td>
-                <td>${(data.time?string("yyyy-MM-dd HH:mm:ss"))!}</td>
-                <td class="td-manage">
-                    <a title="重新授权" href="javascript:re_auth()" class="ml-5" style="text-decoration:none"><i class="Hui-iconfont">&#xe61d;</i></a>
-                </td>
-            </tr>
-        </#if>
+            <#list result as data>
+                <#if !((data.token)??)>
+                    <tr class="text-c">
+                        <td>${(data.name)!}</td>
+                        <td colspan="3">
+                            <#if data.type == "1">
+                                <span onclick="re_auth()" style="color: red;font-size: 16px">
+                                    重新授权
+                                    <i class="Hui-iconfont">&#xe61d;</i>
+                                </span>
+                            <#elseif data.type == "2">
+                                <span onclick="re_jd_auth()" style="color: red;font-size: 16px">
+                                    重新授权
+                                    <i class="Hui-iconfont">&#xe61d;</i>
+                                </span>
+                            </#if>
+                        </td>
+                    </tr>
+                <#else>
+                    <tr class="text-c">
+                        <td>${(data.name)!}</td>
+                        <td>${(data.token)!}</td>
+                        <td>${(data.time?string("yyyy-MM-dd HH:mm:ss"))!}</td>
+                        <td class="td-manage">
+                            <#if data.type == "1">
+                                <a title="重新授权" href="javascript:re_auth()" class="ml-5" style="text-decoration:none"><i class="Hui-iconfont">&#xe61d;</i></a>
+                            <#elseif data.type == "2">
+                                <a title="重新授权" href="javascript:re_jd_auth()" class="ml-5" style="text-decoration:none"><i class="Hui-iconfont">&#xe61d;</i></a>
+                            </#if>
+                        </td>
+                    </tr>
+                </#if>
+            </#list>
         </tbody>
     </table>
 </div>
 </body>
 <script type="text/javascript">
 
+    //淘宝认证
     function re_auth() {
         // 保存当前url
         let href = window.location.href;
         window.location.href = "${path}/taobao/auth?url=" + href;
     }
 
+    //京东认证
+    function re_jd_auth() {
+        // 保存当前url
+        let href = window.location.href;
+        window.location.href = "${path}/jingdong/auth?url=" + href;
+    }
+
 </script>
 </html>