xuhy
2025-10-30 acea31500b7dd03918227527e43a9250fa8e2014
服务号消息推送
6个文件已修改
49 ■■■■■ 已修改文件
ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TRegionController.java 11 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-admin/src/main/resources/application-prod.yml 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-admin/src/main/resources/application-test.yml 6 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-framework/src/main/java/com/ruoyi/framework/config/SecurityConfig.java 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-system/src/main/java/com/ruoyi/system/utils/util/TemplateMessageSendUtil.java 7 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-system/src/main/java/com/ruoyi/system/utils/wx/tools/WxAppletTools.java 21 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TRegionController.java
@@ -5,6 +5,7 @@
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;
@@ -29,10 +30,12 @@
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;
    }
@@ -47,5 +50,11 @@
    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();
//    }
}
ruoyi-admin/src/main/resources/application-prod.yml
@@ -200,6 +200,8 @@
    allowExt: .jpg|.png|.gif|.jpeg|.doc|.docx|.apk|.MP4|.mp4|.pdf|.PDF
wx:
  conf:
    officeAppId: wx0e2c1d653f666dfc
    officeSecretId: d96adfb5e67179d668148a614a136643
    appId: wxa17e8d1331e50934
    secretId: 79c234527fd3b6553679d52be5e29b19
    appLiveResultTemplateId: 1wheNdyQ88Cz9Z7L1EXxR2L0u4X4LaeXoZVtZwHCagk
ruoyi-admin/src/main/resources/application-test.yml
@@ -195,6 +195,8 @@
#    prefix: http://localhost:${server.port}${server.servlet.context-path}
wx:
  conf:
    officeAppId: wx0e2c1d653f666dfc
    officeSecretId: d96adfb5e67179d668148a614a136643
    appId: wxa17e8d1331e50934
    secretId: 79c234527fd3b6553679d52be5e29b19
    appLiveResultTemplateId: 1wheNdyQ88Cz9Z7L1EXxR2L0u4X4LaeXoZVtZwHCagk
@@ -206,8 +208,8 @@
  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:
ruoyi-framework/src/main/java/com/ruoyi/framework/config/SecurityConfig.java
@@ -124,7 +124,7 @@
                        "/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()
ruoyi-system/src/main/java/com/ruoyi/system/utils/util/TemplateMessageSendUtil.java
@@ -27,7 +27,8 @@
@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
@@ -88,9 +89,9 @@
    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("模板消息发送提醒通知:------------------------");
ruoyi-system/src/main/java/com/ruoyi/system/utils/wx/tools/WxAppletTools.java
@@ -22,6 +22,7 @@
@Slf4j
public class WxAppletTools {
    private final static String ACCESSTOKEN_CACHE_KEY = "accessToken";
    private final static String ACCESS_TOKEN_OFFICE_CACHE_KEY = "accessTokenOffice";
    /**
     * 请求参数
     * 属性    类型    默认值    必填    说明
@@ -161,4 +162,24 @@
        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();
    }
}