浏览代码

优化小程序码生成逻辑

wangyuanbo 2 年之前
父节点
当前提交
9d075a6669
共有 1 个文件被更改,包括 31 次插入7 次删除
  1. 31 7
      imcs-bt-be/imcs-authority-server/src/main/java/com/github/zuihou/api/AndroidApi.java

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

@@ -25,6 +25,7 @@ import com.github.zuihou.business.spe.service.SpeService;
 import com.github.zuihou.business.util.CommonUtil;
 import com.github.zuihou.business.wxpay.CipherDto;
 import com.github.zuihou.cfg.WxPayCfg;
+import com.github.zuihou.common.util.StringUtil;
 import com.github.zuihou.context.BaseContextHandler;
 import com.github.zuihou.database.mybatis.conditions.Wraps;
 import com.github.zuihou.database.mybatis.conditions.query.LbqWrapper;
@@ -148,24 +149,47 @@ public class AndroidApi {
 
 //        小程序码
         Object accessToken = redisTemplate.opsForValue().get("access_token");
+        if (null != accessToken) {
+            System.out.println("从redis里获取小程序token==" + accessToken.toString());
+            token = accessToken.toString();
 
-        if (accessToken == null) {
-
-            token = goodsService.getToken(accessTokenUrl, appId, secret);
-            redisTemplate.opsForValue().set("access_token", token, 7000, TimeUnit.SECONDS);
         } else {
-            token = (String) accessToken;
-        }
+            System.out.println("从redis里获取小程序token失败,准备从接口获取");
+            token = goodsService.getToken(accessTokenUrl, appId, secret);
+            if (StringUtil.isNotEmpty(token)) {
+                System.out.println("通过接口获取小程序token==" + token);
+                redisTemplate.opsForValue().set("access_token", token, 7000, TimeUnit.SECONDS);
+            } else {
+                return R.fail("生成小程序码失败");
+            }
 
 
+        }
+//
+//
+//        if (accessToken == null && accessToken.equals("")) {
+//
+//            token = goodsService.getToken(accessTokenUrl, appId, secret);
+//            if (StringUtil.isNotEmpty(token)) {
+//                redisTemplate.opsForValue().set("access_token", token, 7000, TimeUnit.SECONDS);
+//            } else {
+//                return R.fail("生成小程序码失败");
+//            }
+//
+//        } else {
+//            token = (String) accessToken;
+//        }
+
+        System.out.println("开始生成" + System.currentTimeMillis());
         String qrCode = goodsService.getQrCode(response, token, preOrder.getId());
+        System.out.println("开始生成1" + System.currentTimeMillis());
 
         HashMap<String, Object> resultMap = new HashMap<>();
         resultMap.put("orderId", preOrder.getId());
 //        resultMap.put("productCfg", productConfig);
+
         resultMap.put("qrCode", qrCode);
         System.out.println("安卓端下单返回orderId=" + preOrder.getId());
-
         return R.success(resultMap);
     }