定时任务添加推送原

This commit is contained in:
yangjun 2023-12-01 21:05:33 +08:00
parent 140a1c7f06
commit 2d2a46e85d
3 changed files with 66 additions and 19 deletions

View File

@ -3,8 +3,7 @@
<mapper namespace="org.jeecg.modules.kc.KcBdgxbcopy.mapper.KcBdgxbcopyMapper"> <mapper namespace="org.jeecg.modules.kc.KcBdgxbcopy.mapper.KcBdgxbcopyMapper">
<insert id="saveStudentKqtx"> <insert id="saveStudentKqtx">
INSERT INTO kc_messagelistcopy ( id, touser, template_id, tourl, firstdata, remarkdata, keyword1, keyword2, keyword3, scheduleddatetime ) SELECT INSERT INTO kc_messagelistcopy ( touser, template_id, tourl, firstdata, remarkdata, keyword1, keyword2, keyword3, scheduleddatetime ) SELECT
0,-- id:
bd.openid,-- touser:oak6lwA02iVyBKrVSok4uUpzeBmY bd.openid,-- touser:oak6lwA02iVyBKrVSok4uUpzeBmY
'KtWw0lwQ8FOgJdKgrmya0eoafGkMfMN8ECdZs8oSJys',-- template_id: 'KtWw0lwQ8FOgJdKgrmya0eoafGkMfMN8ECdZs8oSJys',-- template_id:
'https://zxkccxwebvpnnenueducn/index',-- tourl: 'https://zxkccxwebvpnnenueducn/index',-- tourl:
@ -40,7 +39,7 @@
kc_xuekeduiyingbiao xk, kc_xuekeduiyingbiao xk,
kc_ketangbiao kt, kc_ketangbiao kt,
kc_kechengtixingdingyue kd, kc_kechengtixingdingyue kd,
kc_bdgxbcopy bd (select * from choice.bdgxbcopy) bd
WHERE WHERE
xk.rwbh = kt.rwbh xk.rwbh = kt.rwbh
AND xk.xh = kd.userid AND xk.xh = kd.userid
@ -50,8 +49,7 @@
</insert> </insert>
<insert id="saveTeacherKqtx"> <insert id="saveTeacherKqtx">
INSERT INTO kc_messagelistcopy ( id, touser, template_id, tourl, firstdata, remarkdata,.keyword1, keyword2, keyword3, scheduleddatetime ) SELECT INSERT INTO kc_messagelistcopy ( touser, template_id, tourl, firstdata, remarkdata,keyword1, keyword2, keyword3, scheduleddatetime ) SELECT
0,
bd.openid, bd.openid,
'KtWw0lwQ8FOgJdKgrmya0eoafGkMfMN8ECdZs8oSJys', 'KtWw0lwQ8FOgJdKgrmya0eoafGkMfMN8ECdZs8oSJys',
'https://zxkccx.webvpn.nenu.edu.cn/index', 'https://zxkccx.webvpn.nenu.edu.cn/index',
@ -86,7 +84,7 @@
FROM FROM
kc_kechengtixingdingyue kd, kc_kechengtixingdingyue kd,
kc_ketangbiao kt, kc_ketangbiao kt,
kc_bdgxbcopy bd (select * from choice.bdgxbcopy) bd
WHERE WHERE
kd.userid = kt.jgh kd.userid = kt.jgh
AND kd.userid = bd.userid AND kd.userid = bd.userid
@ -95,8 +93,7 @@
</insert> </insert>
<insert id="saveStudentMrtx"> <insert id="saveStudentMrtx">
INSERT INTO kc_messagelistcopy ( id, touser, template_id, tourl, firstdata, remarkdata, keyword1, keyword2, keyword3, scheduleddatetime ) SELECT INSERT INTO kc_messagelistcopy ( touser, template_id, tourl, firstdata, remarkdata, keyword1, keyword2, keyword3, scheduleddatetime ) SELECT
0,-- id:
bd.openid,-- touser:oak6lwA02iVyBKrVSok4uUpzeBmY bd.openid,-- touser:oak6lwA02iVyBKrVSok4uUpzeBmY
'KtWw0lwQ8FOgJdKgrmya0eoafGkMfMN8ECdZs8oSJys',-- template_id:KtWw0lwQ8FOgJdKgrmya0eoafGkMfMN8ECdZs8oSJys 'KtWw0lwQ8FOgJdKgrmya0eoafGkMfMN8ECdZs8oSJys',-- template_id:KtWw0lwQ8FOgJdKgrmya0eoafGkMfMN8ECdZs8oSJys
'https://zxkccx.webvpn.nenu.edu.cn/index',-- tourl:https://zxkccx.webvpn.nenu.edu.cn/index 'https://zxkccx.webvpn.nenu.edu.cn/index',-- tourl:https://zxkccx.webvpn.nenu.edu.cn/index
@ -130,7 +127,7 @@
kc_kechengtixingdingyue kd, kc_kechengtixingdingyue kd,
kc_xuekeduiyingbiao xk, kc_xuekeduiyingbiao xk,
kc_ketangbiao kt, kc_ketangbiao kt,
kc_bdgxbcopy bd (select * from choice.bdgxbcopy) bd
WHERE WHERE
kd.userid = xk.xh kd.userid = xk.xh
AND xk.rwbh = kt.rwbh AND xk.rwbh = kt.rwbh
@ -144,8 +141,7 @@
</insert> </insert>
<insert id="saveTeacherMrtx"> <insert id="saveTeacherMrtx">
INSERT INTO kc_messagelistcopy ( id, touser, template_id, tourl, firstdata, remarkdata, keyword1, keyword2, keyword3, scheduleddatetime ) SELECT INSERT INTO kc_messagelistcopy ( touser, template_id, tourl, firstdata, remarkdata, keyword1, keyword2, keyword3, scheduleddatetime ) SELECT
0,-- id:
bd.openid,-- touser:oak6lwAa1epMAgwQziF2K9yBkiLE bd.openid,-- touser:oak6lwAa1epMAgwQziF2K9yBkiLE
'KtWw0lwQ8FOgJdKgrmya0eoafGkMfMN8ECdZs8oSJys',-- template_id:KtWw0lwQ8FOgJdKgrmya0eoafGkMfMN8ECdZs8oSJys 'KtWw0lwQ8FOgJdKgrmya0eoafGkMfMN8ECdZs8oSJys',-- template_id:KtWw0lwQ8FOgJdKgrmya0eoafGkMfMN8ECdZs8oSJys
'https://zxkccx.webvpn.nenu.edu.cn/index',-- tourl:https://zxkccx.webvpn.nenu.edu.cn/index 'https://zxkccx.webvpn.nenu.edu.cn/index',-- tourl:https://zxkccx.webvpn.nenu.edu.cn/index
@ -178,7 +174,7 @@
FROM FROM
kc_kechengtixingdingyue kd, kc_kechengtixingdingyue kd,
kc_ketangbiao kt, kc_ketangbiao kt,
kc_bdgxbcopy bd (select * from choice.bdgxbcopy) bd
WHERE WHERE
kd.userid = kt.jgh kd.userid = kt.jgh
AND kd.userid = bd.userid AND kd.userid = bd.userid

View File

@ -31,7 +31,7 @@ public class SyncWechartTsxx extends BaseSync {
private static final String appId = "wx59920eb69d611d7f"; private static final String appId = "wx59920eb69d611d7f";
// appIdSecret // appIdSecret
private static final String appIdSecret = "60b429xxxxxxxxxxxxxxx"; private static final String appIdSecret = "bf0c19af0e956f447ede4dd902ea63b7";
/** /**
* 若参数变量名修改 QuartzJobController中也需对应修改 * 若参数变量名修改 QuartzJobController中也需对应修改
*/ */

View File

@ -29,16 +29,13 @@ public class WxgzhController {
private static final Logger log = LoggerFactory.getLogger(WxgzhController.class); private static final Logger log = LoggerFactory.getLogger(WxgzhController.class);
// appId // appId
// private static final String appId = "wx59920eb69d611d7f";//东师 private static final String appId = "wx59920eb69d611d7f";//东师
private static final String appId = "wxafdbb51ba3aa614d";//测试
// appIdSecret // appIdSecret
// private static final String appIdSecret = "";//东师 private static final String appIdSecret = "bf0c19af0e956f447ede4dd902ea63b7";//东师
private static final String appIdSecret = "bdf346ae8b986e9fa5d33b2e4495b27e";//测试
// 公众号的模板id(也有相应的接口可以查询到) // 公众号的模板id(也有相应的接口可以查询到)
// private static final String templateId = "KtWw0lwQ8FOgJdKgrmya0eoafGkMfMN8ECdZs8oSJys";//东师 private static final String templateId = "KtWw0lwQ8FOgJdKgrmya0eoafGkMfMN8ECdZs8oSJys";//东师
private static final String templateId = "cFD7lyjpppIZUB9ipuGjkjZr9ED-BhJZ7bw3ILaFgbg";//测试
// 微信申请的域名(提前准备) // 微信申请的域名(提前准备)
private static final String domain = "https://zxkccx.webvpn.nenu.edu.cn/wxpay"; private static final String domain = "https://zxkccx.webvpn.nenu.edu.cn/wxpay";
@ -182,4 +179,58 @@ public class WxgzhController {
return Result.OK("推送成功!"); return Result.OK("推送成功!");
} }
public static void main(String[] args) {
String urlToken = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid="+ appId +"&secret=" + appIdSecret;
System.out.println("urlToken "+ urlToken);
String res = HttpUtil.get(urlToken);
JSONObject jsonObjectToken = JSONObject.parseObject(res);
System.out.println("jsonObjectToken{}"+ jsonObjectToken);
String accessToken = jsonObjectToken.getString("access_token");
System.out.println("accessToken{}"+ accessToken);
// 模板参数
Map<String, WeChatTemplateMsg> sendMag = new HashMap<String, WeChatTemplateMsg>();
String openId = "oak6lwKGlGQQwt83nuynZnP4HUR4";//曹老师账号
// 微信的基础accessToken
// String accessToken = getAccessToken();
String url = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" + accessToken;
/**
* 其他模板可以从模板库中自己添加
* 模板ID
* KtWw0lwQ8FOgJdKgrmya0eoafGkMfMN8ECdZs8oSJys
* 开发者调用模板消息接口时需提供模板ID
* 标题 上课提醒
* 行业 教育 - 院校
* 详细内容
* {{first.DATA}}
* 课程{{keyword1.DATA}}
* 时间{{keyword2.DATA}}
* 地点{{keyword3.DATA}}
* {{remark.DATA}}
*/
sendMag.put("first", new WeChatTemplateMsg("有课程即将开始"));
sendMag.put("keyword1", new WeChatTemplateMsg("线性代数"));
sendMag.put("keyword2", new WeChatTemplateMsg("[1,2节] 08:30-10:00"));
sendMag.put("keyword3", new WeChatTemplateMsg("上课地点N304"));
sendMag.put("remark", new WeChatTemplateMsg("请开发者为用户提供定制提醒的选项,以免打扰。"));
RestTemplate restTemplate = new RestTemplate();
//拼接base参数
Map<String, Object> sendBody = new HashMap<>();
sendBody.put("touser", openId); // openId
sendBody.put("url", domainTo); // 点击模板信息跳转地址
sendBody.put("topcolor", "#FF0000"); // 顶色
sendBody.put("data", sendMag); // 模板参数
sendBody.put("template_id", templateId); // 模板Id
ResponseEntity<String> forEntity = restTemplate.postForEntity(url, sendBody, String.class);
log.info("结果是: {}",forEntity.getBody());
JSONObject jsonObject2 = JSONObject.parseObject(forEntity.getBody());
// 0
String messageCode = jsonObject2.getString("errcode");
// 2431260672639467520
String msgId = jsonObject2.getString("msgid");
System.out.println("messageCode : " + messageCode + ", msgId: " +msgId);
}
} }