doum
2025-09-11 7298d5354963a88643a543b51b90192dc9fc934c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package com.doumee.api;
 
import com.alibaba.fastjson.JSONObject;
import com.doumee.biz.system.SystemDictDataBiz;
import com.doumee.core.haikang.model.HKConstants;
import com.doumee.core.haikang.model.param.BaseResponse;
import com.doumee.core.haikang.service.HKService;
import com.doumee.service.business.third.model.ApiResponse;
import com.doumee.core.utils.Constants;
import com.doumee.core.utils.HttpsUtil;
import com.doumee.core.wx.WXConstant;
import com.doumee.dao.system.model.SystemDictData;
import com.doumee.service.system.SystemDictDataService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.mgt.DefaultSecurityManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
 
import java.util.Date;
import java.util.Objects;
 
/**
 * @author 江蹄蹄
 * @date 2023/11/30 15:33
 */
@Api(tags = "微信token定时器接口")
@RestController
@RequestMapping("/timer/wxtoken")
public class WxTokenTimerController extends BaseController {
    @Autowired
    private SystemDictDataBiz systemDictDataBiz;
 
    @Autowired
    private SystemDictDataService systemDictDataService;
    /**
     * 是否开发者
     */
    @Value("${debug_model}")
    private Boolean timing;
//    @ApiOperation("开启定时更新微信公众号accesstoken")
//    @PostMapping("/updateWxAccessToken")
//    public ApiResponse updateWxAccessToken() {
//       DefaultSecurityManager securityManager = new DefaultSecurityManager();
//        SecurityUtils.setSecurityManager(securityManager);
//        String token =null;
//        BaseResponse<String> result = HKService.wxAccessToken(systemDictDataBiz.queryByCode(Constants.HK_PARAM,Constants.HK_WXTOKEN_CONFIGID).getCode(),systemDictDataBiz.queryByCode(Constants.HK_PARAM,Constants.HK_WXTOKEN_TAGID).getCode());
//        if(StringUtils.equals(result.getCode(), HKConstants.RESPONSE_SUCCEE) ){
//            token= result.getData();
//            SystemDictData systemDictData =  systemDictDataBiz.queryByCode(Constants.WX_PLATFORM,Constants.WX_PLATFORM_ACCESS_TOKEN);
//            if(!Objects.isNull(systemDictData)){
//                systemDictData.setCode(token);
//                systemDictData.setUpdateTime(new Date());
//                systemDictDataService.updateById(systemDictData);
//            }
//        }else{
//            return ApiResponse.success("开启定时更新微信公众号accesstoken失败");
//        }
//        return ApiResponse.success("开启定时更新微信公众号accesstoken成功");
//    }
    @ApiOperation("开启定时更新微信公众号accesstoken")
    @PostMapping("/updateWxAccessTokenOrigin")
    public ApiResponse updateWxAccessTokenOrigin() {
       DefaultSecurityManager securityManager = new DefaultSecurityManager();
        SecurityUtils.setSecurityManager(securityManager);
 
        String appId = systemDictDataBiz.queryByCode(Constants.WX_PLATFORM,Constants.WX_PLATFORM_APPID).getCode();
        String appSecret = systemDictDataBiz.queryByCode(Constants.WX_PLATFORM,Constants.WX_PLATFORM_SECRET).getCode();
        //生成微信token
        String url = WXConstant.GET_ACCESS_TOKEN_URL.replace("APPID",appId).replace("APPSECRET",appSecret);
        String response = HttpsUtil.get(url,false);
        JSONObject json = JSONObject.parseObject(response);
        System.out.println(json);
        SystemDictData systemDictData =  systemDictDataBiz.queryByCode(Constants.WX_PLATFORM,Constants.WX_PLATFORM_ACCESS_TOKEN);
        if(!Objects.isNull(systemDictData)){
            systemDictData.setCode(json.getString("access_token"));
            systemDictData.setUpdateTime(new Date());
            systemDictDataService.updateById(systemDictData);
        }
        return ApiResponse.success("开启定时更新微信公众号accesstoken成功");
    }
 
 
 
}