|
@@ -98,86 +98,4 @@ public class WxApiController {
|
|
|
public ResultVo<DoctorInfo> getDoctorInfo(@RequestParam("doctorCode") String doctorCode) {
|
|
|
return service.getDoctorInfo(doctorCode);
|
|
|
}
|
|
|
-
|
|
|
- @GetMapping("/pushMsgToAllUser")
|
|
|
- public void pushMsgToAllUser() {
|
|
|
-
|
|
|
- // http://127.0.0.1:8805/wxserver/wxApi/pushMsgToAllUser
|
|
|
-
|
|
|
- int taskOrder = 0;
|
|
|
-
|
|
|
- String token = PropertiesUtil.getProperty("access_token");
|
|
|
- String getUserListUrl = "https://api.weixin.qq.com/cgi-bin/user/get?access_token=" + token;
|
|
|
-
|
|
|
- RestTemplate template = new RestTemplate();
|
|
|
- JSONObject userList = template.getForObject(getUserListUrl, JSONObject.class);
|
|
|
- assert userList != null;
|
|
|
- JSONArray openIds = userList.getJSONObject("data").getJSONArray("openid");
|
|
|
- new Business(openIds, taskOrder).start();
|
|
|
-
|
|
|
- while (userList.containsKey("next_openid") && StringUtil.notBlank(userList.getString("next_openid"))) {
|
|
|
- getUserListUrl = "https://api.weixin.qq.com/cgi-bin/user/get?access_token=" + token + "&next_openid=" +
|
|
|
- userList.getString("next_openid");
|
|
|
- userList = template.getForObject(getUserListUrl, JSONObject.class);
|
|
|
- assert userList != null;
|
|
|
- if (userList.getInteger("count") > 0) {
|
|
|
- taskOrder += 1;
|
|
|
- openIds = userList.getJSONObject("data").getJSONArray("openid");
|
|
|
- new Business(openIds, taskOrder).start();
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- static class Business extends Thread {
|
|
|
- private final JSONArray openIds;
|
|
|
- private final int order;
|
|
|
- JSONObject content;
|
|
|
-
|
|
|
- public Business(JSONArray openIds, int order) {
|
|
|
- this.openIds = openIds;
|
|
|
- String msgContent = "{\"touser\":\"\",\"data\":" +
|
|
|
- "{\"keyword2\":{\"color\":\"#173177\",\"value\":\"长沙市医保局\"}," +
|
|
|
- "\"keyword1\":{\"color\":\"#173177\",\"value\":\"湖南省医保局、长沙市医保局联合指导普惠型补充医疗保险缴费仅剩30天,还未缴费的市民请抓紧办理!\"}," +
|
|
|
- "\"remark\":{\"color\":\"#FF0000\",\"value\":\"【政府指导,普惠全民】超50万长沙市民已办理!订单金额:139元/年,每天不到4毛钱,最高保障300万。" +
|
|
|
- "不限年龄、性别,老幼同价,带病可保可赔,支持医保个账支付。订单状态:即将截止!\"}," +
|
|
|
- "\"first\":{\"color\":\"#FF0000\",\"value\":\"你好,你有新的待办事项未办理,请2小时内点击办理!\"}}," +
|
|
|
- "\"template_id\":\"qW3HNhNfFFbBVQ9TtIuAr7Z70UB1jDwK8LtjNkU9uDQ\"," +
|
|
|
- "\"url\":\"https://hmb.yinbangbroker.com/changsha22/h5/product/index?shareFrom=0001110&shareCode=a5d776450f9dd8d8249221f02580c4b4&template=0f83ca02360b498711e8930cacdf2a3c\"}";
|
|
|
- this.content = JSONObject.parseObject(msgContent);
|
|
|
- this.order = order;
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void run() {
|
|
|
- RestTemplate template = new RestTemplate();
|
|
|
- int pushSuccessCount = 0;
|
|
|
- for (int i = 0; i < openIds.size(); i++) {
|
|
|
- content.replace("touser", openIds.getString(i));
|
|
|
- String sendMsgUrl = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" + PropertiesUtil.getProperty("access_token");
|
|
|
- JSONObject res = template.postForObject(sendMsgUrl, content, JSONObject.class);
|
|
|
- if (null != res) {
|
|
|
- Integer code = res.getInteger("errcode");
|
|
|
- if (null != code && code == 0) {
|
|
|
- pushSuccessCount += 1;
|
|
|
- } else {
|
|
|
- try {
|
|
|
- TimeUnit.MILLISECONDS.sleep(300);
|
|
|
- sendMsgUrl = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" + PropertiesUtil.getProperty("access_token");
|
|
|
- res = template.postForObject(sendMsgUrl, content, JSONObject.class);
|
|
|
- if (null != res) {
|
|
|
- code = res.getInteger("errcode");
|
|
|
- if (null != code && code == 0) {
|
|
|
- pushSuccessCount += 1;
|
|
|
- }
|
|
|
- }
|
|
|
- } catch (InterruptedException e) {
|
|
|
- throw new RuntimeException(e);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- log.info("【线程{},序号{}】推送消息结果:{}", order, pushSuccessCount, res);
|
|
|
- }
|
|
|
- log.info("【线程{}】推送完成,用户列表共 {} 位,推送成功 {} 条。", order, openIds.size(), pushSuccessCount);
|
|
|
- }
|
|
|
- }
|
|
|
}
|