lidongdong
2022-10-24 bd927f5c9f26d5ae89a272e56a4b3bd655bd148f
springcloud_k8s_panzhihuazhihuishequ/common/src/main/java/com/panzhihua/common/utlis/WxXCXTempSend.java
@@ -155,6 +155,35 @@
        }
        return accessToken;
    }
    /**
     * 发布消息时重新设置access_token 防止过期
     * @param appId
     * @param appSecret
     * @throws Exception
     */
    public void setAppAccessTokenToCache(String appId,String appSecret) throws Exception{
        String accessToken = "0";
        try {
            log.info("获取微信token参数:appid=" + appId + ",appSecret=" + appSecret);
            String accessTokenUrl = ACCESS_TOKEN_URL + "&appid=" + appId + "&secret=" + appSecret;
            String result = HttpClientUtil.httpGet(accessTokenUrl, null, null);
            Map<String, Object> resultMap = JSON.parseObject(result, Map.class);
            if (resultMap.containsKey("access_token")) {
                accessToken = resultMap.get("access_token").toString();
                wxXCXTempSend.stringRedisTemplate.opsForValue().set("access_token:access_token:" + appId, accessToken, EXPIRE_TIME,TimeUnit.HOURS);
            }
        } catch (IOException ioe) {
            log.error("小程序http请求异常");
            ioe.printStackTrace();
        }
    }
    public String getAccessTokenNoValid(String appId) throws Exception {
        String accessToken = "";
        accessToken=wxXCXTempSend.stringRedisTemplate.boundValueOps("access_token:access_token:"+appId).get();
        return accessToken;
    }
    public String getWsAccessToken() throws Exception {
        String accessToken = "0";
        try {