| | |
| | | import com.ruoyi.common.core.domain.R; |
| | | import com.ruoyi.system.model.TRegion; |
| | | import com.ruoyi.system.service.TRegionService; |
| | | import com.ruoyi.system.utils.util.TemplateMessageSendUtil; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | |
| | | public class TRegionController { |
| | | |
| | | private final TRegionService regionService; |
| | | private final TemplateMessageSendUtil templateMessageSendUtil; |
| | | |
| | | @Autowired |
| | | public TRegionController(TRegionService regionService) { |
| | | public TRegionController(TRegionService regionService, TemplateMessageSendUtil templateMessageSendUtil) { |
| | | this.regionService = regionService; |
| | | this.templateMessageSendUtil = templateMessageSendUtil; |
| | | } |
| | | |
| | | |
| | |
| | | public R<List<TRegion>> getProvince() { |
| | | return R.ok(regionService.list(Wrappers.lambdaQuery(TRegion.class).eq(TRegion::getParentId,0))); |
| | | } |
| | | // @ApiOperation(value = "发送测试") |
| | | // @PostMapping(value = "/sendTest") |
| | | // public R<String> sendTest() { |
| | | // templateMessageSendUtil.wxOfficeTemplateAppLiveRequest("oZhAN2OiGSQVC_dciGXAtCX_mAfY","医药直播","2025-10-30 00:00:00"); |
| | | // return R.ok(); |
| | | // } |
| | | } |
| | | |
| | |
| | | allowExt: .jpg|.png|.gif|.jpeg|.doc|.docx|.apk|.MP4|.mp4|.pdf|.PDF |
| | | wx: |
| | | conf: |
| | | officeAppId: wx0e2c1d653f666dfc |
| | | officeSecretId: d96adfb5e67179d668148a614a136643 |
| | | appId: wxa17e8d1331e50934 |
| | | secretId: 79c234527fd3b6553679d52be5e29b19 |
| | | appLiveResultTemplateId: 1wheNdyQ88Cz9Z7L1EXxR2L0u4X4LaeXoZVtZwHCagk |
| | |
| | | # prefix: http://localhost:${server.port}${server.servlet.context-path} |
| | | wx: |
| | | conf: |
| | | officeAppId: wx0e2c1d653f666dfc |
| | | officeSecretId: d96adfb5e67179d668148a614a136643 |
| | | appId: wxa17e8d1331e50934 |
| | | secretId: 79c234527fd3b6553679d52be5e29b19 |
| | | appLiveResultTemplateId: 1wheNdyQ88Cz9Z7L1EXxR2L0u4X4LaeXoZVtZwHCagk |
| | |
| | | subAppId: 1 |
| | | appId: OP00000003 |
| | | serialNo: 00dfba8194c41b84cf |
| | | priKeyStr: C:\Users\Admin\Desktop\test\OP00000003_private_key.pem |
| | | lklNotifyCerStr: F:\demo\demo\src\lkl-apigw-v2.cer |
| | | priKeyStr: D:\app\cert\lakala\OP00000003_private_key.pem |
| | | lklNotifyCerStr: D:\app\cert\lakala\lkl-apigw-v2.cer |
| | | sm4Key: LHo55AjrT4aDhAIBZhb5KQ== |
| | | serverUrl: https://test.wsmsd.cn/ |
| | | payment: |
| | |
| | | "/t-sys-product-introduction/list","/t-sys-product-introduction/getDetailById","/t-sys-config/getDetailById", |
| | | "/t-sys-educational-info/list","/t-sys-educational-info/getDetailById","/t-sys-educational-info/pageList", |
| | | "/t-sys-live/list","/t-sys-live/getDetailById","/t-sys-live/pageList", |
| | | "/open/**","/cos/get/**","/openIdByJsCode","/t-sys-order/**","/openIdByCode" |
| | | "/open/**","/cos/get/**","/openIdByJsCode","/t-sys-order/**","/openIdByCode","/tRegion/sendTest" |
| | | ).permitAll() |
| | | // 静态资源,可匿名访问 |
| | | .antMatchers(HttpMethod.GET, "/", "/*.html", "/**/*.html", "/**/*.css", "/**/*.js", "/profile/**").permitAll() |
| | |
| | | @Slf4j |
| | | @Component |
| | | public class TemplateMessageSendUtil implements Serializable { |
| | | private final static String ACCESS_TOKEN_CACHE_KEY = "accessToken:"; |
| | | private final static String ACCESS_TOKEN_CACHE_KEY = "accessToken"; |
| | | private final static String ACCESS_TOKEN_OFFICE_CACHE_KEY = "accessTokenOffice"; |
| | | @Autowired |
| | | private RedisCache redisCache; |
| | | @Autowired |
| | |
| | | public String wxOfficeTemplateAppLiveRequest(String openId,String liveTitle,String startTime) { |
| | | WxAppletTools appletTools = new WxAppletTools(wxRestTemplate, weixinProperties, redisService); |
| | | // 1,获取access_token |
| | | String accessToken = redisCache.getCacheObject(ACCESS_TOKEN_CACHE_KEY); |
| | | String accessToken = redisCache.getCacheObject(ACCESS_TOKEN_OFFICE_CACHE_KEY); |
| | | if (!StringUtils.hasLength(accessToken)) { |
| | | accessToken = appletTools.getAccessToken(); |
| | | accessToken = appletTools.getAccessTokenOffice(); |
| | | } |
| | | try { |
| | | log.info("模板消息发送提醒通知:------------------------"); |
| | |
| | | @Slf4j |
| | | public class WxAppletTools { |
| | | private final static String ACCESSTOKEN_CACHE_KEY = "accessToken"; |
| | | private final static String ACCESS_TOKEN_OFFICE_CACHE_KEY = "accessTokenOffice"; |
| | | /** |
| | | * 请求参数 |
| | | * 属性 类型 默认值 必填 说明 |
| | |
| | | return accessTokenRespBody.getAccessToken(); |
| | | } |
| | | |
| | | /** |
| | | * @return |
| | | */ |
| | | public String getAccessTokenOffice() { |
| | | String accessToken = redisService.getCacheObject(ACCESS_TOKEN_OFFICE_CACHE_KEY); |
| | | if (StringUtils.hasLength(accessToken)) { |
| | | return accessToken; |
| | | } |
| | | String requestUrl = MessageFormat.format(ACCESS_TOKEN_URL, wxConfig.getOfficeAppId(), wxConfig.getOfficeSecretId()); |
| | | String respBody = wxRestTemplate.getForEntity(requestUrl, String.class).getBody(); |
| | | AccessTokenRespBody accessTokenRespBody = WxJsonUtils.parseObject(respBody, AccessTokenRespBody.class); |
| | | // 判断有误异常 |
| | | if (StringUtils.hasLength(accessTokenRespBody.getErrorMsg())) { |
| | | // 抛出错误 |
| | | throw new WxException(accessTokenRespBody.getErrorCode() + ":" + accessTokenRespBody.getErrorMsg()); |
| | | } |
| | | redisService.setCacheObject(ACCESS_TOKEN_OFFICE_CACHE_KEY, accessTokenRespBody.getAccessToken(), 7200L, TimeUnit.SECONDS); |
| | | return accessTokenRespBody.getAccessToken(); |
| | | } |
| | | |
| | | } |