ReminderService.java 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. package com.bosshand.virgo.api.service;
  2. import com.alibaba.fastjson.JSONObject;
  3. import com.bosshand.virgo.api.dao.ReminderDao;
  4. import com.bosshand.virgo.api.model.Reminder;
  5. import com.bosshand.virgo.core.utils.StringUtil;
  6. import com.bosshand.virgo.core.utils.WeChatUtil;
  7. import org.apache.commons.codec.digest.DigestUtils;
  8. import org.slf4j.Logger;
  9. import org.slf4j.LoggerFactory;
  10. import org.springframework.beans.factory.annotation.Autowired;
  11. import org.springframework.stereotype.Service;
  12. import java.util.List;
  13. @Service
  14. public class ReminderService {
  15. static Logger log = LoggerFactory.getLogger(ReminderService.class);
  16. @Autowired
  17. ReminderDao reminderDao;
  18. public int getTotalCount(Reminder reminder) {
  19. return reminderDao.getTotalCount(reminder);
  20. }
  21. public List<Reminder> getLimit(Reminder reminder, int currPage, int pageSize) {
  22. int currIndex = (currPage - 1) * pageSize;
  23. return reminderDao.getLimit(reminder, currIndex, pageSize);
  24. }
  25. public Reminder get(long id) {
  26. return reminderDao.get(id);
  27. }
  28. public Reminder insert(Reminder reminder) {
  29. reminderDao.insert(reminder);
  30. return reminder;
  31. }
  32. public Reminder update(Reminder reminder) {
  33. reminderDao.update(reminder);
  34. return reminder;
  35. }
  36. public List<Reminder> getList(Reminder reminder) {
  37. return reminderDao.getList(reminder);
  38. }
  39. public int delete(long id) {
  40. return reminderDao.delete(id);
  41. }
  42. public String getToken() {
  43. JSONObject js = new JSONObject();
  44. String userId = "system";
  45. long timestamp = System.currentTimeMillis() + 30000;
  46. String yei = "50abd47112ebe8c5a73f4694c96a49ce";
  47. String sign = DigestUtils.md5Hex(userId + timestamp + yei);
  48. js.put("userId", userId);
  49. js.put("timestamp", timestamp);
  50. js.put("sign", sign);
  51. String s = WeChatUtil.httpPost("https://www.waywish.com/im/user/token/get", js, null);
  52. if (StringUtil.notBlank(s)) {
  53. String token = JSONObject.parseObject(s).getJSONObject("data").getString("token");
  54. return token;
  55. }
  56. return null;
  57. }
  58. public void send(String token, String userId, String data, String type) {
  59. long m = System.currentTimeMillis();
  60. JSONObject js = new JSONObject();
  61. js.put("conversationId", userId);
  62. js.put("conversationType", "private");
  63. js.put("from", "system");
  64. js.put("to", userId);
  65. js.put("type", "text");
  66. js.put("isRead", 0);
  67. js.put("isRevoke", 0);
  68. js.put("isDeleted", 0);
  69. js.put("status", "unSend");
  70. js.put("time", m);
  71. js.put("extra", data);
  72. JSONObject jo = new JSONObject();
  73. jo.put("nickname", "系统通知");
  74. jo.put("avatarUrl", "https://file-node.oss-cn-shanghai.aliyuncs.com/youji/3156449b8a1a4874981b2a76d5947721");
  75. js.put("fromUserInfo", jo);
  76. JSONObject j = new JSONObject();
  77. j.put("text", type);
  78. js.put("body", j);
  79. String s = WeChatUtil.httpPost("https://www.waywish.com/im/message/save", js, token);
  80. log.info("在" + m + "时间点给userId:" + userId + "发送消息成功.");
  81. }
  82. }