Browse Source

Merge branch 'master' of http://106.14.142.95:3000/wangyuanbo/bt

oyq28 2 years ago
parent
commit
3723f89ae4

+ 44 - 9
imcs-bt-be/imcs-authority-server/src/main/java/com/github/zuihou/api/AndroidApi.java

@@ -25,6 +25,7 @@ import com.github.zuihou.cfg.WxPayCfg;
 import com.github.zuihou.context.BaseContextHandler;
 import com.github.zuihou.database.mybatis.conditions.Wraps;
 import com.github.zuihou.database.mybatis.conditions.query.LbqWrapper;
+import com.github.zuihou.service.WxPayService;
 import com.github.zuihou.utils.WxPayUtil;
 import com.wechat.pay.contrib.apache.httpclient.auth.Verifier;
 import com.wechat.pay.contrib.apache.httpclient.util.AesUtil;
@@ -83,6 +84,8 @@ public class AndroidApi {
     private MiniAppService miniAppService;
     @Autowired
     private ProductionTenantResourceService productionTenantResourceService;
+    @Autowired
+    private WxPayService wxPayService;
 
 
 //    @ApiOperation("获取商品列表")
@@ -97,7 +100,7 @@ public class AndroidApi {
 
     @ApiOperation("获取商品列表")
     @GetMapping({"/goodsList"})
-    public R<List<EquGoodsDto>> goodsList(@RequestParam(name = "equId",required = true) Long equId) {
+    public R<List<EquGoodsDto>> goodsList(@RequestParam(name = "equId", required = true) Long equId) {
         BaseContextHandler.setTenant("0000");
         List<EquGoodsDto> equGoods = productionTenantResourceService.getEquGoods(equId);
         return R.success(equGoods);
@@ -160,7 +163,7 @@ public class AndroidApi {
 
     @ApiOperation("订单状态查询接口")
     @GetMapping({"/getOrder"})
-    public R<Map<Object, Object>> getOrder(@RequestParam(name = "orderId" ,required = true) Long orderId) {
+    public R<Map<Object, Object>> getOrder(@RequestParam(name = "orderId", required = true) Long orderId) {
         BaseContextHandler.setTenant("0000");
         HashMap<Object, Object> resultMap = new HashMap<>();
         Order order = orderService.getById(orderId);
@@ -179,7 +182,7 @@ public class AndroidApi {
 
     @ApiOperation("料筒查询接口")
     @PostMapping({"/getBarrelList"})
-    public R<List<EquBarrel>> getBarrelList(@RequestParam(name="equId",required = true) Long equId) {
+    public R<List<EquBarrel>> getBarrelList(@RequestParam(name = "equId", required = true) Long equId) {
         BaseContextHandler.setTenant("0000");
         HashMap<String, Object> paramMap = new HashMap<>();
         paramMap.put("equId", equId);
@@ -318,24 +321,56 @@ public class AndroidApi {
 
     //修改订单状态接口
     @PostMapping("/updateOrderSta")
-    public R<Boolean> updateOrderSta(@RequestBody Map<String, String> req) {
+    public R<Boolean> updateOrderSta(@RequestBody Map<String, String> req) throws Exception {
         BaseContextHandler.setTenant("0000");
         String orderId = req.get("orderId");
         String orderStatus = req.get("orderStatus");
         String equId = req.get("equId");
         String speId = req.get("speId");
 
-        //只更新一个属性,把名字为rhb的用户年龄更新为18,其他属性不变
+//        安卓端超时后取消订单
+        if (orderStatus == "2") {
+            //调用微信支付api,关闭订单
+            int i = wxPayService.wxCloseOrder(orderId);
+            if (i == 204) {
+//                订单关闭成功,修改本地订单状态
+                UpdateWrapper<Order> updateWrapper = new UpdateWrapper<>();
+                updateWrapper.eq("id", orderId).set("order_status", orderStatus);
+                boolean update = orderService.update(updateWrapper);
+                return R.success(update);
+            } else {
+                return R.fail("订单关闭失败,建议等待5秒,然后调用被扫订单结果查询API,查询当前订单的不同状态,决定下一步的操作");
+            }
+        }
+        //        生产异常,发起退款
+        if (orderStatus == "4") {
+            //调用微信支付api,发起退款
+            int i = wxPayService.wxCloseOrder(orderId);
+            if (i == 204) {
+//                订单关闭成功,修改本地订单状态
+                UpdateWrapper<Order> updateWrapper = new UpdateWrapper<>();
+                updateWrapper.eq("id", orderId).set("order_status", orderStatus);
+                boolean update = orderService.update(updateWrapper);
+                return R.success(update);
+            } else {
+                return R.fail("订单关闭失败,建议等待5秒,然后调用被扫订单结果查询API,查询当前订单的不同状态,决定下一步的操作");
+            }
+        }
 
 
-        UpdateWrapper<Order> updateWrapper = new UpdateWrapper<>();
-        updateWrapper.eq("id", orderId).set("order_status", orderStatus);
-        boolean update = orderService.update(updateWrapper);
         if (orderStatus == "5") {
+            UpdateWrapper<Order> updateWrapper = new UpdateWrapper<>();
+            updateWrapper.eq("id", orderId).set("order_status", orderStatus);
+            boolean update = orderService.update(updateWrapper);
 //            生产完成,扣减物料,更新料筒和商品状态
-
             barrelService.updateBarrel(speId, equId);
+            return R.success(update);
         }
+
+        UpdateWrapper<Order> updateWrapper = new UpdateWrapper<>();
+        updateWrapper.eq("id", orderId).set("order_status", orderStatus);
+        boolean update = orderService.update(updateWrapper);
+
         return R.success(update);
     }
 

+ 77 - 20
imcs-bt-be/imcs-authority-server/src/main/java/com/github/zuihou/service/WxPayService.java

@@ -1,14 +1,10 @@
 package com.github.zuihou.service;
 
-import cn.hutool.core.convert.Convert;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.github.zuihou.business.wxpay.UnifiedorderDto;
 import com.github.zuihou.cfg.WxPayCfg;
-import com.github.zuihou.jwt.model.Token;
-import com.github.zuihou.jwt.utils.JwtUtil;
 import com.github.zuihou.utils.WxPayUtil;
-import io.jsonwebtoken.Claims;
 import org.apache.http.client.methods.CloseableHttpResponse;
 import org.apache.http.client.methods.HttpPost;
 import org.apache.http.entity.StringEntity;
@@ -18,7 +14,6 @@ import org.springframework.stereotype.Service;
 
 import java.io.IOException;
 import java.nio.charset.Charset;
-import java.util.HashMap;
 
 /**
  * @author User
@@ -43,7 +38,7 @@ public class WxPayService {
         try {
             int statusCode = response.getStatusLine().getStatusCode();
             if (statusCode == 200) {
-                System.out.println("微信统一下单返回结果success,body=" );
+                System.out.println("微信统一下单返回结果success,body=");
 //                System.out.println("微信统一下单返回结果success,body=" + EntityUtils.toString(response.getEntity()));
                 String s = EntityUtils.toString(response.getEntity());
                 JSONObject jsonObject = JSONObject.parseObject(s);
@@ -64,30 +59,92 @@ public class WxPayService {
         return "";
     }
 
+    /**
+     * 调用关闭订单接口
+     * @param out_trade_no
+     * @return
+     * @throws Exception
+     */
+    public int wxCloseOrder(String out_trade_no) throws Exception {
+        int statusCode = 0;
+        String url = "https://api.mch.weixin.qq.com/v3/pay/transactions/out-trade-no/" + out_trade_no + "/close";
+        String mchId = wxPayCfg.getMchId();
 
-    public static void test() {
+        JSONObject payObj = new JSONObject();
+        payObj.put("mchid", mchId);
+        String body = payObj.toJSONString();
 
 
+        HttpPost httpPost = new HttpPost(url);
+        StringEntity entity = new StringEntity(body, Charset.forName("UTF-8"));
+        entity.setContentType("application/json");
+        httpPost.setEntity(entity);
+        httpPost.addHeader("Accept", "application/json");
+        httpPost.addHeader("Content-type", "application/json; charset=utf-8");
+        CloseableHttpResponse response = WxPayUtil.getClint(wxPayCfg.getMchId(), wxPayCfg.getCertNo(), wxPayCfg.getPrivateKeyPath(), wxPayCfg.getApiV3Key()).execute(httpPost);
+
+        try {
+            //响应码
+            statusCode = response.getStatusLine().getStatusCode();
+            System.out.println("关闭订单响应码:{},无响应体" + statusCode);
+
+        } finally {
+            response.close();
+        }
+
+        return statusCode;
+
+//        202用户支付中,需要输入密码	等待5秒,然后调用被扫订单结果查询API,查询当前订单的不同状态,决定下一步的操作
+//
+//
+//        202  用户支付中,需要输入密码   204 正常  400 已关闭
     }
 
-    public static void main(String[] args) {
-        HashMap<String, String> tokenMap = new HashMap<>();
 
-        tokenMap.put("a", "aaa");
-        tokenMap.put("b", "bbb");
-        Token jwt = JwtUtil.createJWT(tokenMap, 25920000L);
-        String token = jwt.getToken();
-        System.out.println("生成的测试token=" + token);
+    /**
+     * 调用关闭订单接口
+     * @param out_trade_no
+     * @return
+     * @throws Exception
+     */
+    public int wxCloseOrder(String out_trade_no) throws Exception {
+        int statusCode = 0;
+        String url = "https://api.mch.weixin.qq.com/v3/pay/transactions/out-trade-no/" + out_trade_no + "/close";
+        String mchId = wxPayCfg.getMchId();
+
+        JSONObject payObj = new JSONObject();
+        payObj.put("mchid", mchId);
+        String body = payObj.toJSONString();
+
 
+        HttpPost httpPost = new HttpPost(url);
+        StringEntity entity = new StringEntity(body, Charset.forName("UTF-8"));
+        entity.setContentType("application/json");
+        httpPost.setEntity(entity);
+        httpPost.addHeader("Accept", "application/json");
+        httpPost.addHeader("Content-type", "application/json; charset=utf-8");
+        CloseableHttpResponse response = WxPayUtil.getClint(wxPayCfg.getMchId(), wxPayCfg.getCertNo(), wxPayCfg.getPrivateKeyPath(), wxPayCfg.getApiV3Key()).execute(httpPost);
 
-        Claims claims = JwtUtil.parseJWT(token);
+        try {
+            //响应码
+            statusCode = response.getStatusLine().getStatusCode();
+            System.out.println("关闭订单响应码:{},无响应体" + statusCode);
 
-        String a = Convert.toStr(claims.get("a"));
-        String b = Convert.toStr(claims.get("b"));
-        Long expire = Convert.toLong(claims.getExpiration());
-        System.out.println("解析的a=" + a);
-        System.out.println("token有效期=" + expire);
+        } finally {
+            response.close();
+        }
+
+        return statusCode;
+
+//        202用户支付中,需要输入密码	等待5秒,然后调用被扫订单结果查询API,查询当前订单的不同状态,决定下一步的操作
+//
+//
+//        202  用户支付中,需要输入密码   204 正常  400 已关闭
     }
 
 
+
+
+
+
 }