server/admin/src/main/java/com/doumee/timer/WeixinTokenJobBiz.java
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,36 @@ package com.doumee.timer; import com.doumee.biz.system.SystemDictDataBiz; import com.doumee.biz.zbom.ZbomIAMService; import com.doumee.service.business.MemberService; import com.doumee.service.system.SystemDictService; import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import java.lang.reflect.Method; /** * @author å ¬ä¼å·:ç¥äºä¸ç¬ * @since 2023-07-26 11:44 */ @Component("weixinTokenJob") public class WeixinTokenJobBiz implements JobService { private static final Logger log = LoggerFactory.getLogger(WeixinTokenJobBiz.class); @Autowired SystemDictDataBiz systemDictService; @Override public void run(String params,String module) { Method method = null; try { systemDictService.updWxMiniToken(); log.info("\n ======== 宿¶ä»»å¡å·²æ§è¡ï¼weixinTokenJob.========"+module); } catch (Exception e) { e.printStackTrace(); } } } server/service/src/main/java/com/doumee/biz/system/SystemDictDataBiz.java
@@ -37,4 +37,5 @@ String getPreFixPath(String resourceCode, String targetCode); void updWxMiniToken(); } server/service/src/main/java/com/doumee/biz/system/impl/SystemDictDataBizImpl.java
@@ -7,6 +7,7 @@ import com.doumee.core.exception.BusinessException; import com.doumee.core.model.LoginUserInfo; import com.doumee.core.utils.Constants; import com.doumee.core.utils.HttpsUtil; import com.doumee.dao.business.vo.UnitCodeVo; import com.doumee.dao.system.model.SystemDict; import com.doumee.dao.system.model.SystemDictData; @@ -182,6 +183,36 @@ String targetPath = list.stream().filter(s -> s.getLabel().equals(targetCode)).findFirst().map(s -> s.getCode()).orElse(""); return resourcePath+targetPath; } @Override public void updWxMiniToken() { updWxMiniTokenDo(Constants.WX_APPID_CUSTOMER,Constants.WX_SECRET_CUSTOMER,Constants.WX_TOKEN_CUSTOMER); updWxMiniTokenDo(Constants.WX_APPID_PERSONNEL,Constants.WX_SECRET_PERSONNEL,Constants.WX_TOKEN_PERSONNEL); } public void updWxMiniTokenDo(String appID,String appKey,String token) { String appId = queryByCode(Constants.WX_MINI_CONFIG,appID).getCode(); String appSecret = queryByCode(Constants.WX_MINI_CONFIG,appKey).getCode(); //çæå¾®ä¿¡token String url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid="+appId+"&secret="+appSecret; String response = HttpsUtil.sendGet(url); JSONObject json = JSONObject.parseObject(response); SystemDictData systemDictData = queryByCode(Constants.WX_MINI_CONFIG,token); systemDictData.setCode(json.getString("access_token")); systemDictData.setUpdateTime(new Date()); updateByIdNew(systemDictData); appId = queryByCode(Constants.WX_MINI_CONFIG,Constants.WX_APPID_PERSONNEL).getCode(); appSecret = queryByCode(Constants.WX_MINI_CONFIG,Constants.WX_APPID_PERSONNEL).getCode(); //çæå¾®ä¿¡token url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid="+appId+"&secret="+appSecret; response = HttpsUtil.sendGet(url); json = JSONObject.parseObject(response); systemDictData = queryByCode(Constants.WX_MINI_CONFIG,Constants.WX_TOKEN_PERSONNEL); systemDictData.setCode(json.getString("access_token")); systemDictData.setUpdateTime(new Date()); updateByIdNew(systemDictData); } } server/service/src/main/java/com/doumee/core/utils/Constants.java
@@ -722,48 +722,7 @@ } /** * åégetè¯·æ± * @param url 请æ±URL * @param param 请æ±åæ° key:value urlæºå¸¦åæ° æè æ åå¯ä¸å¡« * @return */ public static String doGet(String url, Map<String, String> param) { // å建Httpclient对象 CloseableHttpClient httpclient = HttpClients.createDefault(); String resultString = ""; CloseableHttpResponse response = null; try { // å建uri URIBuilder builder = new URIBuilder(url); if (param != null) { for (String key : param.keySet()) { builder.addParameter(key, param.get(key)); } } URI uri = builder.build(); // å建http GETè¯·æ± HttpGet httpGet = new HttpGet(uri); // æ§è¡è¯·æ± response = httpclient.execute(httpGet); // 夿è¿åç¶ææ¯å¦ä¸º200 if (response.getStatusLine().getStatusCode() == 200) { resultString = EntityUtils.toString(response.getEntity(), "UTF-8"); } } catch (Exception e) { e.printStackTrace(); } finally { try { if (response != null) { response.close(); } httpclient.close(); } catch (IOException e) { e.printStackTrace(); } } return resultString; } server/service/src/main/java/com/doumee/service/business/MemberService.java
@@ -136,9 +136,4 @@ */ void logOff(Long memberId); /** * æ´æ°å®¢æ·ç«¯å°ç¨åºToken */ void updWxMiniToken(); } server/service/src/main/java/com/doumee/service/business/UsersService.java
@@ -115,10 +115,6 @@ void editUserInfo(EditUsersRequest editUsersRequest); /** * æ´æ°å工端å°ç¨åºToken */ void updWxMiniToken(); String getContentShareImg(Users loginUserInfo, ContentShareImgDto param); } server/service/src/main/java/com/doumee/service/business/impl/MemberServiceImpl.java
@@ -17,10 +17,7 @@ import com.doumee.core.model.PageData; import com.doumee.core.model.PageWrap; import com.doumee.core.oss.FileModel; import com.doumee.core.utils.CodeVerifyUtils; import com.doumee.core.utils.Constants; import com.doumee.core.utils.DateUtil; import com.doumee.core.utils.Utils; import com.doumee.core.utils.*; import com.doumee.core.wx.WxMiniConfig; import com.doumee.dao.business.CustomerUserMapper; import com.doumee.dao.business.MemberMapper; @@ -40,6 +37,7 @@ import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.hikvision.artemis.sdk.util.HttpUtils; import me.chanjar.weixin.common.error.WxErrorException; import okhttp3.OkHttpClient; import okhttp3.Request; @@ -57,6 +55,7 @@ import java.io.ByteArrayInputStream; import java.io.InputStream; import java.util.*; import java.util.Date; import java.util.concurrent.TimeUnit; /** @@ -532,20 +531,5 @@ @Override public void updWxMiniToken(){ DefaultWebSecurityManager manager = new DefaultWebSecurityManager(); ThreadContext.bind(manager); String appId = systemDictDataBiz.queryByCode(Constants.WX_MINI_CONFIG,Constants.WX_APPID_CUSTOMER).getCode(); String appSecret = systemDictDataBiz.queryByCode(Constants.WX_MINI_CONFIG,Constants.WX_SECRET_CUSTOMER).getCode(); //çæå¾®ä¿¡token String url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid="+appId+"&secret="+appSecret; String response = Constants.doGet(url,null); JSONObject json = JSONObject.parseObject(response); SystemDictData systemDictData = systemDictDataBiz.queryByCode(Constants.WX_MINI_CONFIG,Constants.WX_TOKEN_CUSTOMER); systemDictData.setCode(json.getString("access_token")); systemDictData.setUpdateTime(new Date()); systemDictDataBiz.updateByIdNew(systemDictData); } } server/service/src/main/java/com/doumee/service/business/impl/UsersServiceImpl.java
@@ -744,21 +744,7 @@ @Override public void updWxMiniToken(){ DefaultWebSecurityManager manager = new DefaultWebSecurityManager(); ThreadContext.bind(manager); String appId = systemDictDataBiz.queryByCode(Constants.WX_MINI_CONFIG,Constants.WX_APPID_PERSONNEL).getCode(); String appSecret = systemDictDataBiz.queryByCode(Constants.WX_MINI_CONFIG,Constants.WX_SECRET_PERSONNEL).getCode(); //çæå¾®ä¿¡token String url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid="+appId+"&secret="+appSecret; String response = Constants.doGet(url,null); JSONObject json = JSONObject.parseObject(response); SystemDictData systemDictData = systemDictDataBiz.queryByCode(Constants.WX_MINI_CONFIG,Constants.WX_TOKEN_PERSONNEL); systemDictData.setCode(json.getString("access_token")); systemDictData.setUpdateTime(new Date()); systemDictDataBiz.updateByIdNew(systemDictData); } } server/service/src/main/java/com/doumee/service/system/SystemDictService.java
@@ -84,4 +84,5 @@ * @date 2023/03/21 14:49 */ long count(SystemDict systemDict); } server/service/src/main/java/com/doumee/service/system/impl/SystemDictServiceImpl.java
@@ -1,5 +1,9 @@ package com.doumee.service.system.impl; import com.alibaba.fastjson.JSONObject; import com.doumee.core.utils.Constants; import com.doumee.core.utils.HttpsUtil; import com.doumee.dao.system.model.SystemDictData; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; import com.doumee.core.model.PageData; @@ -16,6 +20,7 @@ import org.springframework.transaction.annotation.Transactional; import org.springframework.util.CollectionUtils; import java.util.Date; import java.util.List; /** @@ -94,4 +99,5 @@ Wrapper<SystemDict> wrapper = new QueryWrapper<>(systemDict); return systemDictMapper.selectCount(wrapper); } } server/web/src/main/java/com/doumee/api/web/CustomerApi.java
@@ -66,6 +66,8 @@ @Autowired private CustomerUserService customerUserService; @Autowired private SystemDictDataBiz systemDictDataBiz; @ApiOperation(value = "客æ·ç«¯å°ç¨åºç»é", notes = "客æ·ç«¯å°ç¨åº") @GetMapping("/wxLoginCustomer") @@ -247,13 +249,11 @@ @ApiImplicitParam(paramType = "header", dataType = "String", name = "token", value = "ç¨æ·tokenå¼", required = true) }) public ApiResponse testToken () { memberService.updWxMiniToken(); systemDictDataBiz.updWxMiniToken(); return ApiResponse.success("æ´æ°æå"); } @Autowired private SystemDictDataBiz systemDictDataBiz; @LoginRequired @ApiOperation(value = "è·åå享å°ç¨åºäºç»´ç ï¼å¾çæµï¼imgæ ç¾srcæå®ï¼", notes = "客æ·ç«¯å°ç¨åº")