|
@ -152,12 +152,29 @@ public class PushMsgTask {
|
|
try {
|
|
try {
|
|
// 如果queue为空,则当前线程会堵塞,直到有新数据加入
|
|
// 如果queue为空,则当前线程会堵塞,直到有新数据加入
|
|
JSONObject json = queue.take();
|
|
JSONObject json = queue.take();
|
|
String accessToken = json.getString("access_token");
|
|
|
|
Integer type = json.getInt("type");
|
|
|
|
String name = json.getString("name");
|
|
|
|
String openid = json.getString("openid");
|
|
|
|
// 发送消息到微信端
|
|
|
|
sendWeixinMessage(accessToken, type, openid, name, json);
|
|
|
|
|
|
|
|
|
|
boolean wx = json.has("wx") ? json.getBoolean("wx") : false;
|
|
|
|
if (wx) {
|
|
|
|
String accessToken = json.getString("access_token");
|
|
|
|
Integer type = json.getInt("type");
|
|
|
|
String name = json.getString("name");
|
|
|
|
String openid = json.getString("openid");
|
|
|
|
// 发送消息到微信端
|
|
|
|
sendWeixinMessage(accessToken, type, openid, name, json);
|
|
|
|
}else{
|
|
|
|
// 推送平台消息
|
|
|
|
String receiver = json.has("receiver") ? json.getString("receiver") : "";
|
|
|
|
String type = json.has("type") ? json.getString("type") : "";
|
|
|
|
String title = json.has("title") ? json.getString("title") : "";
|
|
|
|
String msg = json.has("msg") ? json.getString("msg") : "";
|
|
|
|
String data = json.has("data") ? json.getString("data") : "";
|
|
|
|
boolean res = httpUtil.pushMessage(receiver, type, title, msg, data);
|
|
|
|
if (res) {
|
|
|
|
logger.info("消息推送成功!");
|
|
|
|
} else {
|
|
|
|
logger.error("消息推送失败!");
|
|
|
|
}
|
|
|
|
}
|
|
} catch (Exception ex) {
|
|
} catch (Exception ex) {
|
|
ex.printStackTrace();
|
|
ex.printStackTrace();
|
|
}
|
|
}
|
|
@ -276,10 +293,24 @@ public class PushMsgTask {
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
@Deprecated
|
|
|
|
|
|
/**
|
|
|
|
* 添加一条推送消息
|
|
|
|
*
|
|
|
|
* @param receiver 接收人
|
|
|
|
* @param type 消息类型
|
|
|
|
* @param title 消息标题
|
|
|
|
* @param msg 消息内容
|
|
|
|
* @param data 消息数据
|
|
|
|
*/
|
|
public void put(String receiver, String type, String title, String msg, String data) {
|
|
public void put(String receiver, String type, String title, String msg, String data) {
|
|
try {
|
|
try {
|
|
|
|
|
|
|
|
JSONObject json = new JSONObject();
|
|
|
|
json.put("receiver", receiver);
|
|
|
|
json.put("type", type);
|
|
|
|
json.put("title", title);
|
|
|
|
json.put("msg", msg);
|
|
|
|
json.put("data", data);
|
|
|
|
queue.put(json);
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
logger.error("添加到消息队列失败!", e);
|
|
logger.error("添加到消息队列失败!", e);
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|