package cn.com.goldenwater.dcproj.service.impl; import cn.com.goldenwater.dcproj.model.ExtWeiXinMessage; import cn.com.goldenwater.dcproj.model.WeiXinMsg; import cn.com.goldenwater.dcproj.service.ExtWeiXinMessageService; import cn.com.goldenwater.dcproj.utils.HttpClientUtils; import cn.com.goldenwater.dcproj.utils.impexcel.ImportExcel; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.TypeReference; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import java.io.IOException; import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; @Service public class RedisDataCenterReceiver { protected static final Logger LOGGER = LoggerFactory.getLogger(RedisDataCenterReceiver.class); @Value("${api.url}") private String apiUrl; @Value("${api.apiKey}") private String apiKey; @Autowired private ExtWeiXinMessageService weiXinMessageService; public void receiveMessage(String message) throws Exception { LOGGER.info("发生信息:" + message); LOGGER.info("apiUrl:" + apiUrl + "/gateway/api/sms/login"); JSONObject jsonObject = JSONObject.parseObject(message); Map params = JSONObject.parseObject(jsonObject.toJSONString(), new TypeReference>() { }); params.put("apiKey", apiKey); String content = HttpClientUtils.simplePostInvoke(apiUrl + "/gateway/api/sms/login", params); LOGGER.info("content:" + content); } @Value("${api.apiKeyUpdate}") private String apiKeyUpdate; public void receiveMessageUpdate(String message) throws Exception { JSONObject jsonObject = JSONObject.parseObject(message); Map params = JSONObject.parseObject(jsonObject.toJSONString(), new TypeReference>() { }); params.put("apiKey", apiKeyUpdate); LOGGER.info("urlupdate-->" + apiUrl + "/gateway/api/sms/updateBase"); String content = HttpClientUtils.simplePostInvoke(apiUrl + "/gateway/api/sms/updateBase", params); LOGGER.info("content:" + content); } public void receiveMessageStart(String message) throws Exception { try { JSONObject jsonObject = JSONObject.parseObject(message); Map params = JSONObject.parseObject(jsonObject.toJSONString(), new TypeReference>() { }); params.put("apiKey", apiKeyUpdate); LOGGER.info("urlupdate-->" + apiUrl + "/gateway/api/gw/sys/start/insert"); String content = HttpClientUtils.simplePostInvoke(apiUrl + "/gateway/api/gw/sys/start/insert", params); LOGGER.info("content:" + content); } catch (Exception e) { LOGGER.error("消息接收启动--调用网关失败:", e); } } public void receiveMessageRun(String message) throws Exception { try { JSONObject jsonObject = JSONObject.parseObject(message); Map params = JSONObject.parseObject(jsonObject.toJSONString(), new TypeReference>() { }); params.put("apiKey", apiKeyUpdate); LOGGER.info("urlupdate-->" + apiUrl + "/gateway/api/gw/sys/run/insert"); String content = HttpClientUtils.simplePostInvoke(apiUrl + "/gateway/api/gw/sys/run/insert", params); LOGGER.info("content:" + content); } catch (Exception e) { LOGGER.error("消息接收运行--调用网关失败:", e); } } public void receiveMessageWeiXin(String message) throws Exception { try { //处理消息入库 LOGGER.info("微信消息通知【订阅发布模式】转换前:" + message.toString()); WeiXinMsg weiXinMsg = JSON.parseObject(JSON.parse(message).toString(), WeiXinMsg.class); ExtWeiXinMessage extWeiXinMessage = new ExtWeiXinMessage(); extWeiXinMessage.setAccount(weiXinMsg.getAccount()); extWeiXinMessage.setWcId(weiXinMsg.getWcId()); extWeiXinMessage.setMessageType(weiXinMsg.getMessageType()); extWeiXinMessage.setFromUser(weiXinMsg.getData().getFromUser()); extWeiXinMessage.setFromGroup(weiXinMsg.getData().getFromGroup()); extWeiXinMessage.setToUser(weiXinMsg.getData().getToUser()); extWeiXinMessage.setMsgId(weiXinMsg.getData().getMsgId()); extWeiXinMessage.setNewMsgId(weiXinMsg.getData().getNewMsgId()); extWeiXinMessage.setTm(new Date(weiXinMsg.getData().getTimestamp() * 1000)); extWeiXinMessage.setContent(weiXinMsg.getData().getContent()); extWeiXinMessage.setSelf(weiXinMsg.getData().getSelf() ? "1" : "0"); weiXinMessageService.insert(extWeiXinMessage); LOGGER.info("微信消息通知【订阅发布模式】转对象后:" + weiXinMsg.toString()); } catch (Exception e) { LOGGER.error("微信消息通知【订阅发布模式】 错误:", e); } } public static void main(String[] args) { 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\\\"}"; Long n = 1697619995 * 1000l; Date date = new Date(n); java.util.Date day = new Date(); System.out.println(day.getTime()); System.out.println(day.getTime()); //WeiXinMsg weiXinMsg = JSON.parseObject(message, WeiXinMsg.class); } }