|
|
|
|
@ -1,10 +1,20 @@
|
|
|
|
|
/*
|
|
|
|
|
* @Author: zxf 1532322479@qq.com
|
|
|
|
|
* @Date: 2025-06-21 12:18:44
|
|
|
|
|
* @LastEditors: zxf 1532322479@qq.com
|
|
|
|
|
* @LastEditTime: 2026-05-20 14:48:26
|
|
|
|
|
* @FilePath: \crmebTwo\crmeb\crmeb-admin\src\main\java\com\zbkj\admin\controller\WeChatAdminController.java
|
|
|
|
|
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
|
|
|
|
|
*/
|
|
|
|
|
package com.zbkj.admin.controller;
|
|
|
|
|
|
|
|
|
|
import com.zbkj.common.response.CommonResult;
|
|
|
|
|
import com.zbkj.common.response.WeChatJsSdkConfigResponse;
|
|
|
|
|
import com.zbkj.service.service.WechatFansService;
|
|
|
|
|
import com.zbkj.service.service.WechatNewService;
|
|
|
|
|
import io.swagger.annotations.Api;
|
|
|
|
|
import io.swagger.annotations.ApiImplicitParam;
|
|
|
|
|
import io.swagger.annotations.ApiImplicitParams;
|
|
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
@ -14,6 +24,8 @@ import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
|
|
import org.springframework.web.bind.annotation.RequestParam;
|
|
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
|
|
|
|
import javax.annotation.security.PermitAll;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 微信 -- 开放平台 admin
|
|
|
|
|
* +----------------------------------------------------------------------
|
|
|
|
|
@ -35,6 +47,9 @@ public class WeChatAdminController {
|
|
|
|
|
@Autowired
|
|
|
|
|
private WechatNewService wechatNewService;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private WechatFansService wechatFansService;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取微信公众号js配置
|
|
|
|
|
*/
|
|
|
|
|
@ -45,4 +60,40 @@ public class WeChatAdminController {
|
|
|
|
|
public CommonResult<WeChatJsSdkConfigResponse> configJs(@RequestParam(value = "url") String url) {
|
|
|
|
|
return CommonResult.success(wechatNewService.getJsSdkConfig(url));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 发送一次性订阅消息
|
|
|
|
|
* 通过unionId获取公众号openId,然后发送订阅消息
|
|
|
|
|
*/
|
|
|
|
|
@ApiOperation(value = "发送一次性订阅消息")
|
|
|
|
|
@RequestMapping(value = "/subscribe/message/send", method = RequestMethod.POST)
|
|
|
|
|
@PermitAll
|
|
|
|
|
@ApiImplicitParams({
|
|
|
|
|
@ApiImplicitParam(name = "unionId", value = "用户unionId", dataType = "String", required = true),
|
|
|
|
|
@ApiImplicitParam(name = "templateId", value = "订阅消息模板ID", dataType = "String", required = true),
|
|
|
|
|
@ApiImplicitParam(name = "scene", value = "订阅场景值", dataType = "String", required = true),
|
|
|
|
|
@ApiImplicitParam(name = "title", value = "消息标题(15字以内)", dataType = "String", required = true),
|
|
|
|
|
@ApiImplicitParam(name = "content", value = "消息内容(200字以内)", dataType = "String", required = true),
|
|
|
|
|
@ApiImplicitParam(name = "url", value = "跳转链接(需ICP备案)", dataType = "String")
|
|
|
|
|
})
|
|
|
|
|
public CommonResult<Boolean> sendSubscribeMessage(@RequestParam(value = "unionId") String unionId,
|
|
|
|
|
@RequestParam(value = "templateId") String templateId,
|
|
|
|
|
@RequestParam(value = "scene") String scene,
|
|
|
|
|
@RequestParam(value = "title") String title,
|
|
|
|
|
@RequestParam(value = "content") String content,
|
|
|
|
|
@RequestParam(value = "url", required = false) String url){
|
|
|
|
|
// 通过unionId获取公众号openId
|
|
|
|
|
String openId = wechatFansService.getOpenIdByUnionId(unionId);
|
|
|
|
|
if (openId == null) {
|
|
|
|
|
return CommonResult.failed("未找到该用户的公众号openId");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 发送订阅消息
|
|
|
|
|
boolean success = wechatFansService.sendSubscribeMessage(openId, templateId, scene, title, content, url);
|
|
|
|
|
if (success) {
|
|
|
|
|
return CommonResult.success(true, "发送成功");
|
|
|
|
|
} else {
|
|
|
|
|
return CommonResult.failed("发送失败");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|