admin
2024-06-30 b6fdf185c7e8fb1f06da0e609e39aecaef6b66f5
src/main/java/com/taoke/autopay/controller/WebApiController.java
@@ -48,6 +48,9 @@
    @ResponseBody
    @RequestMapping(value = "submitKey")
    public String submitKey(String key) {
        if(1>0){
            return JsonUtil.loadFalseResult(0, "接口已关闭");
        }
        if (StringUtil.isNullOrEmpty(key)) {
            return JsonUtil.loadFalseResult(0, "请上传key");
        }
@@ -74,6 +77,20 @@
        }
    }
    private void addKey(String key, Long wxUid) throws KeyOrderException, WxOrderCountException {
        KeyOrder order = keyOrderService.addKeyOrder(key, wxUid, TimeUtil.getGernalTime(System.currentTimeMillis(), "yyyyMMdd"));
        Long uid = keyOrderService.getCanDistributeUid();
        if (uid != null) {
            KeyOrder orderUpdate = new KeyOrder();
            orderUpdate.setId(order.getId());
            orderUpdate.setDistributeClientUid(uid);
            orderUpdate.setDistributeTime(new Date());
            keyOrderService.update(orderUpdate);
        }
    }
    @ResponseBody
    @RequestMapping(value = "submitKeyV2")
    public String submitKeyV2(String key, HttpSession session) {
@@ -87,7 +104,10 @@
        }
        if (user == null) {
            wxLogger.info("微信没有授权");
            // 先保存KEY
//            SESSION_KEY_TEMP_ALIPAY_KEY
            session.setAttribute(Constant.SESSION_KEY_TEMP_ALIPAY_KEY, key);
            wxLogger.info("微信没有授权:" + session.getId());
            String redictLink = systemConfigService.getValueCache(SystemConfigKeyEnum.WX_REDIRECT_LINK);
            if (StringUtil.isNullOrEmpty(redictLink)) {
                return JsonUtil.loadFalseResult("无法获取到授权链接");
@@ -97,29 +117,23 @@
            root.put("link", redictLink);
            return JsonUtil.loadTrueResult(Constant.RESULT_CODE_NEED_LOGIN, root);
        }
        wxLogger.info("微信有授权:" + session.getId());
        try {
            KeyOrder order = keyOrderService.addKeyOrder(key, user.getId(), TimeUtil.getGernalTime(System.currentTimeMillis(), "yyyyMMdd"));
            Long uid = keyOrderService.getCanDistributeUid();
            if (uid != null) {
                KeyOrder orderUpdate = new KeyOrder();
                orderUpdate.setId(order.getId());
                orderUpdate.setDistributeClientUid(uid);
                orderUpdate.setDistributeTime(new Date());
                keyOrderService.update(orderUpdate);
            }
            addKey(key, user.getId());
            return JsonUtil.loadTrueResult("");
        } catch (KeyOrderException e) {
            e.printStackTrace();
            return JsonUtil.loadFalseResult(e.getMessage());
        } catch (WxOrderCountException e) {
            return JsonUtil.loadFalseResult("今日超过最大提交次数");
            return JsonUtil.loadFalseResult(e.getMessage());
        }
    }
    @RequestMapping(value = "wxLogin")
    public void wxLogin(String code, String state, HttpServletResponse response, HttpSession session) throws IOException {
        // 根据code获取openid
        wxLogger.info("微信授权回调:{} code-{}", session.getId(), code);
        String failLink = systemConfigService.getValueCache(SystemConfigKeyEnum.WX_LOGIN_FAIL_LINK);
        try {
            WXAppInfoDto wxApp = systemConfigService.getWxAppInfoCache();
@@ -128,6 +142,12 @@
            if (tokenInfo != null && !StringUtil.isNullOrEmpty(tokenInfo.getOpenid())) {
                WxUserInfo user = wxUserService.login(tokenInfo.getOpenid());
                session.setAttribute(Constant.SESSION_KEY_USER, user);
                wxLogger.info("微信保存用户信息:{} id-{}", session.getId(), user.getId());
                String alipayKey = (String) session.getAttribute(Constant.SESSION_KEY_TEMP_ALIPAY_KEY);
                wxLogger.info("从session读取到key:{}", alipayKey);
                if (alipayKey != null) {
                    addKey(alipayKey, user.getId());
                }
                response.sendRedirect(successLink);
                return;
            }