123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- 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;
- import java.util.List;
- @Service
- public class ReminderService {
- static Logger log = LoggerFactory.getLogger(ReminderService.class);
- @Autowired
- ReminderDao reminderDao;
- public int getTotalCount(Reminder reminder) {
- return reminderDao.getTotalCount(reminder);
- }
- public List<Reminder> getLimit(Reminder reminder, int currPage, int pageSize) {
- int currIndex = (currPage - 1) * pageSize;
- return reminderDao.getLimit(reminder, currIndex, pageSize);
- }
- public Reminder get(long id) {
- return reminderDao.get(id);
- }
- public Reminder insert(Reminder reminder) {
- reminderDao.insert(reminder);
- return reminder;
- }
- public Reminder update(Reminder reminder) {
- reminderDao.update(reminder);
- return reminder;
- }
- public List<Reminder> getList(Reminder reminder) {
- return reminderDao.getList(reminder);
- }
- public int delete(long id) {
- return reminderDao.delete(id);
- }
- public 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 token, 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, token);
- log.info("在" + m + "时间点给userId:" + userId + "发送消息成功.");
- }
- }
|