83e6e7b7c5111686018756ff7feef9da47ff8536.svn-base 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. package cn.com.goldenwater.dcproj.service.impl;
  2. import cn.com.goldenwater.dcproj.model.ExtWeiXinMessage;
  3. import cn.com.goldenwater.dcproj.model.WeiXinMsg;
  4. import cn.com.goldenwater.dcproj.service.ExtWeiXinMessageService;
  5. import cn.com.goldenwater.dcproj.utils.HttpClientUtils;
  6. import cn.com.goldenwater.dcproj.utils.impexcel.ImportExcel;
  7. import com.alibaba.fastjson.JSON;
  8. import com.alibaba.fastjson.JSONObject;
  9. import com.alibaba.fastjson.TypeReference;
  10. import org.slf4j.Logger;
  11. import org.slf4j.LoggerFactory;
  12. import org.springframework.beans.factory.annotation.Autowired;
  13. import org.springframework.beans.factory.annotation.Value;
  14. import org.springframework.stereotype.Service;
  15. import java.io.IOException;
  16. import java.util.Date;
  17. import java.util.HashMap;
  18. import java.util.List;
  19. import java.util.Map;
  20. @Service
  21. public class RedisDataCenterReceiver {
  22. protected static final Logger LOGGER = LoggerFactory.getLogger(RedisDataCenterReceiver.class);
  23. @Value("${api.url}")
  24. private String apiUrl;
  25. @Value("${api.apiKey}")
  26. private String apiKey;
  27. @Autowired
  28. private ExtWeiXinMessageService weiXinMessageService;
  29. public void receiveMessage(String message) throws Exception {
  30. LOGGER.info("发生信息:" + message);
  31. LOGGER.info("apiUrl:" + apiUrl + "/gateway/api/sms/login");
  32. JSONObject jsonObject = JSONObject.parseObject(message);
  33. Map<String, String> params = JSONObject.parseObject(jsonObject.toJSONString(), new TypeReference<Map<String, String>>() {
  34. });
  35. params.put("apiKey", apiKey);
  36. String content = HttpClientUtils.simplePostInvoke(apiUrl + "/gateway/api/sms/login", params);
  37. LOGGER.info("content:" + content);
  38. }
  39. @Value("${api.apiKeyUpdate}")
  40. private String apiKeyUpdate;
  41. public void receiveMessageUpdate(String message) throws Exception {
  42. JSONObject jsonObject = JSONObject.parseObject(message);
  43. Map<String, String> params = JSONObject.parseObject(jsonObject.toJSONString(), new TypeReference<Map<String, String>>() {
  44. });
  45. params.put("apiKey", apiKeyUpdate);
  46. LOGGER.info("urlupdate-->" + apiUrl + "/gateway/api/sms/updateBase");
  47. String content = HttpClientUtils.simplePostInvoke(apiUrl + "/gateway/api/sms/updateBase", params);
  48. LOGGER.info("content:" + content);
  49. }
  50. public void receiveMessageStart(String message) throws Exception {
  51. try {
  52. JSONObject jsonObject = JSONObject.parseObject(message);
  53. Map<String, String> params = JSONObject.parseObject(jsonObject.toJSONString(), new TypeReference<Map<String, String>>() {
  54. });
  55. params.put("apiKey", apiKeyUpdate);
  56. LOGGER.info("urlupdate-->" + apiUrl + "/gateway/api/gw/sys/start/insert");
  57. String content = HttpClientUtils.simplePostInvoke(apiUrl + "/gateway/api/gw/sys/start/insert", params);
  58. LOGGER.info("content:" + content);
  59. } catch (Exception e) {
  60. LOGGER.error("消息接收启动--调用网关失败:", e);
  61. }
  62. }
  63. public void receiveMessageRun(String message) throws Exception {
  64. try {
  65. JSONObject jsonObject = JSONObject.parseObject(message);
  66. Map<String, String> params = JSONObject.parseObject(jsonObject.toJSONString(), new TypeReference<Map<String, String>>() {
  67. });
  68. params.put("apiKey", apiKeyUpdate);
  69. LOGGER.info("urlupdate-->" + apiUrl + "/gateway/api/gw/sys/run/insert");
  70. String content = HttpClientUtils.simplePostInvoke(apiUrl + "/gateway/api/gw/sys/run/insert", params);
  71. LOGGER.info("content:" + content);
  72. } catch (Exception e) {
  73. LOGGER.error("消息接收运行--调用网关失败:", e);
  74. }
  75. }
  76. public void receiveMessageWeiXin(String message) throws Exception {
  77. try {
  78. //处理消息入库
  79. LOGGER.info("微信消息通知【订阅发布模式】转换前:" + message.toString());
  80. WeiXinMsg weiXinMsg = JSON.parseObject(JSON.parse(message).toString(), WeiXinMsg.class);
  81. ExtWeiXinMessage extWeiXinMessage = new ExtWeiXinMessage();
  82. extWeiXinMessage.setAccount(weiXinMsg.getAccount());
  83. extWeiXinMessage.setWcId(weiXinMsg.getWcId());
  84. extWeiXinMessage.setMessageType(weiXinMsg.getMessageType());
  85. extWeiXinMessage.setFromUser(weiXinMsg.getData().getFromUser());
  86. extWeiXinMessage.setFromGroup(weiXinMsg.getData().getFromGroup());
  87. extWeiXinMessage.setToUser(weiXinMsg.getData().getToUser());
  88. extWeiXinMessage.setMsgId(weiXinMsg.getData().getMsgId());
  89. extWeiXinMessage.setNewMsgId(weiXinMsg.getData().getNewMsgId());
  90. extWeiXinMessage.setTm(new Date(weiXinMsg.getData().getTimestamp() * 1000));
  91. extWeiXinMessage.setContent(weiXinMsg.getData().getContent());
  92. extWeiXinMessage.setSelf(weiXinMsg.getData().getSelf() ? "1" : "0");
  93. weiXinMessageService.insert(extWeiXinMessage);
  94. LOGGER.info("微信消息通知【订阅发布模式】转对象后:" + weiXinMsg.toString());
  95. } catch (Exception e) {
  96. LOGGER.error("微信消息通知【订阅发布模式】 错误:", e);
  97. }
  98. }
  99. public static void main(String[] args) {
  100. String message = "{\\\"account\\\":\\\"13401079738\\\",\\\"data\\\":{\\\"content\\\":\\\"程苏苏\\\",\\\"fromUser\\\":\\\"wxid_1666566671714\\\",\\\"msgId\\\":1190406649,\\\"newMsgId\\\":6298776597559993915,\\\"self\\\":true,\\\"timestamp\\\":1697611416,\\\"toUser\\\":\\\"filehelper\\\",\\\"wId\\\":\\\"2d9d83e0-40c5-41cb-b646-13ec4ee09575\\\"},\\\"messageType\\\":\\\"60001\\\",\\\"wcId\\\":\\\"wxid_1666566671714\\\"}";
  101. Long n = 1697619995 * 1000l;
  102. Date date = new Date(n);
  103. java.util.Date day = new Date();
  104. System.out.println(day.getTime());
  105. System.out.println(day.getTime());
  106. //WeiXinMsg weiXinMsg = JSON.parseObject(message, WeiXinMsg.class);
  107. }
  108. }