|
@@ -1,7 +1,13 @@
|
|
|
package com.bosshand.virgo.api.service;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
import com.bosshand.virgo.api.dao.ReminderDao;
|
|
|
import com.bosshand.virgo.api.model.Reminder;
|
|
|
+import com.bosshand.virgo.core.utils.StringUtil;
|
|
|
+import com.bosshand.virgo.core.utils.WeChatUtil;
|
|
|
+import org.apache.commons.codec.digest.DigestUtils;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
@@ -10,6 +16,8 @@ import java.util.List;
|
|
|
@Service
|
|
|
public class ReminderService {
|
|
|
|
|
|
+ static Logger log = LoggerFactory.getLogger(ReminderService.class);
|
|
|
+
|
|
|
@Autowired
|
|
|
ReminderDao reminderDao;
|
|
|
|
|
@@ -44,4 +52,48 @@ public class ReminderService {
|
|
|
return reminderDao.delete(id);
|
|
|
}
|
|
|
|
|
|
+ private String getToken() {
|
|
|
+ JSONObject js = new JSONObject();
|
|
|
+ String userId = "system";
|
|
|
+ long timestamp = System.currentTimeMillis() + 30000;
|
|
|
+ String yei = "50abd47112ebe8c5a73f4694c96a49ce";
|
|
|
+ String sign = DigestUtils.md5Hex(userId + timestamp + yei);
|
|
|
+
|
|
|
+ js.put("userId", userId);
|
|
|
+ js.put("timestamp", timestamp);
|
|
|
+ js.put("sign", sign);
|
|
|
+ String s = WeChatUtil.httpPost("https://www.waywish.com/im/user/token/get", js, null);
|
|
|
+ if (StringUtil.notBlank(s)) {
|
|
|
+ String token = JSONObject.parseObject(s).getJSONObject("data").getString("token");
|
|
|
+ return token;
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void send(String userId, String data, String type) {
|
|
|
+ long m = System.currentTimeMillis();
|
|
|
+ JSONObject js = new JSONObject();
|
|
|
+ js.put("conversationId", userId);
|
|
|
+ js.put("conversationType", "private");
|
|
|
+ js.put("from", "system");
|
|
|
+ js.put("to", userId);
|
|
|
+ js.put("type", "text");
|
|
|
+ js.put("isRead", 0);
|
|
|
+ js.put("isRevoke", 0);
|
|
|
+ js.put("isDeleted", 0);
|
|
|
+ js.put("status", "unSend");
|
|
|
+ js.put("time", m);
|
|
|
+ js.put("extra", data);
|
|
|
+ JSONObject jo = new JSONObject();
|
|
|
+ jo.put("nickname", "系统通知");
|
|
|
+ jo.put("avatarUrl", "https://file-node.oss-cn-shanghai.aliyuncs.com/youji/3156449b8a1a4874981b2a76d5947721");
|
|
|
+ js.put("fromUserInfo", jo);
|
|
|
+ JSONObject j = new JSONObject();
|
|
|
+ j.put("text", type);
|
|
|
+ js.put("body", j);
|
|
|
+ String s = WeChatUtil.httpPost("https://www.waywish.com/im/message/save", js, getToken());
|
|
|
+ log.info("在" + m + "时间点给userId:" + userId + "发送消息成功.");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
}
|