| | |
| | | package com.stylefeng.guns.modular.system.util; |
| | | |
| | | import cn.hutool.http.HttpRequest; |
| | | import cn.hutool.http.HttpResponse; |
| | | import cn.hutool.http.HttpUtil; |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.stylefeng.guns.core.util.ToolUtil; |
| | |
| | | import com.stylefeng.guns.modular.taxi.service.IOrderTaxiService; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.data.redis.core.RedisTemplate; |
| | | import org.springframework.http.HttpEntity; |
| | | import org.springframework.http.HttpHeaders; |
| | | import org.springframework.http.MediaType; |
| | | import org.springframework.stereotype.Component; |
| | | import org.springframework.util.LinkedMultiValueMap; |
| | | import org.springframework.util.MultiValueMap; |
| | | import org.springframework.web.client.RestTemplate; |
| | | |
| | | import java.math.BigDecimal; |
| | |
| | | |
| | | private Map<String, Timer> taskMap = new HashMap<>();//存储定时推送的定时器 |
| | | |
| | | private final String socket_uri = "http://172.21.35.142:6000"; |
| | | |
| | | |
| | | /** |
| | | * 推送订单状态 |
| | | * |
| | | * @param type 1=用户,2=司机 |
| | | * @param uid 对象id |
| | | * @param orderId 订单id |
| | |
| | | jsonObject.put("data", map); |
| | | |
| | | //调用推送 |
| | | HttpHeaders headers = new HttpHeaders(); |
| | | // 以表单的方式提交 |
| | | headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED); |
| | | HttpRequest post = HttpUtil.createPost(socket_uri + "/netty/sendMsgToClient"); |
| | | post.header("Content-Type", MediaType.APPLICATION_FORM_URLENCODED_VALUE); |
| | | //将请求头部和参数合成一个请求 |
| | | MultiValueMap<String, Object> params = new LinkedMultiValueMap<>(); |
| | | params.add("msg", jsonObject.toJSONString()); |
| | | params.add("id", String.valueOf(uid)); |
| | | params.add("type", String.valueOf(type)); |
| | | HttpEntity<MultiValueMap<String, Object>> requestEntity = new HttpEntity<>(params, headers); |
| | | String s = internalRestTemplate.postForObject("http://zuul-gateway/netty/sendMsgToClient",requestEntity , String.class); |
| | | JSONObject jsonObject1 = JSON.parseObject(s, JSONObject.class); |
| | | Map<String, Object> params = new HashMap<>(); |
| | | params.put("msg", jsonObject.toJSONString()); |
| | | params.put("id", uid); |
| | | params.put("type", type); |
| | | post.form(params); |
| | | HttpResponse execute = post.execute(); |
| | | if (200 != execute.getStatus()) { |
| | | System.err.println("推送异常"); |
| | | } else { |
| | | JSONObject jsonObject1 = JSON.parseObject(execute.body(), JSONObject.class); |
| | | if(jsonObject1.getIntValue("code") != 200){ |
| | | System.err.println(jsonObject1.getString("msg")); |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | |
| | |
| | | jsonObject.put("data", map); |
| | | |
| | | //调用推送 |
| | | HttpHeaders headers = new HttpHeaders(); |
| | | // 以表单的方式提交 |
| | | headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED); |
| | | HttpRequest post = HttpUtil.createPost(socket_uri + "/netty/sendMsgToClient"); |
| | | post.header("Content-Type", MediaType.APPLICATION_FORM_URLENCODED_VALUE); |
| | | //将请求头部和参数合成一个请求 |
| | | MultiValueMap<String, Object> params = new LinkedMultiValueMap<>(); |
| | | params.add("msg", jsonObject.toJSONString()); |
| | | params.add("id", String.valueOf(uid)); |
| | | params.add("type", type.toString()); |
| | | HttpEntity<MultiValueMap<String, Object>> requestEntity = new HttpEntity<>(params, headers); |
| | | String s = internalRestTemplate.postForObject("http://zuul-gateway/netty/sendMsgToClient",requestEntity , String.class); |
| | | System.out.println("result:"+s); |
| | | JSONObject jsonObject1 = JSON.parseObject(s, JSONObject.class); |
| | | Map<String, Object> params = new HashMap<>(); |
| | | params.put("msg", jsonObject.toJSONString()); |
| | | params.put("id", uid); |
| | | params.put("type", type); |
| | | post.form(params); |
| | | HttpResponse execute = post.execute(); |
| | | if (200 != execute.getStatus()) { |
| | | System.err.println("推送异常"); |
| | | } else { |
| | | JSONObject jsonObject1 = JSON.parseObject(execute.body(), JSONObject.class); |
| | | if(jsonObject1.getIntValue("code") != 200){ |
| | | System.err.println(jsonObject1.getString("msg")); |
| | | } |
| | | } |
| | | } |
| | | |
| | |
| | | |
| | | msg.put("data", map); |
| | | |
| | | //调用推送 |
| | | HttpHeaders headers = new HttpHeaders(); |
| | | // 以表单的方式提交 |
| | | headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED); |
| | | //将请求头部和参数合成一个请求 |
| | | String value1 = (String) redisTemplate.opsForValue().get(orderId + "_" + orderType); |
| | | if(ToolUtil.isEmpty(value1)){ |
| | | this.removeTask(orderId, orderType); |
| | | return; |
| | | } |
| | | JSONObject jsonObject = JSON.parseObject(value1); |
| | | MultiValueMap<String, Object> params = new LinkedMultiValueMap<>(); |
| | | params.add("msg", msg.toJSONString()); |
| | | params.add("id", jsonObject.getString("id")); |
| | | params.add("type", jsonObject.getString("type")); |
| | | HttpEntity<MultiValueMap<String, Object>> requestEntity = new HttpEntity<>(params, headers); |
| | | String s = internalRestTemplate.postForObject("http://zuul-gateway/netty/sendMsgToClient",requestEntity , String.class); |
| | | JSONObject jsonObject1 = JSON.parseObject(s, JSONObject.class); |
| | | |
| | | //调用推送 |
| | | HttpRequest post = HttpUtil.createPost(socket_uri + "/netty/sendMsgToClient"); |
| | | post.header("Content-Type", MediaType.APPLICATION_FORM_URLENCODED_VALUE); |
| | | //将请求头部和参数合成一个请求 |
| | | Map<String, Object> params = new HashMap<>(); |
| | | params.put("msg", msg.toJSONString()); |
| | | params.put("id", jsonObject.getIntValue("id")); |
| | | params.put("type", jsonObject.getIntValue("type")); |
| | | post.form(params); |
| | | HttpResponse execute = post.execute(); |
| | | if (200 != execute.getStatus()) { |
| | | System.err.println("推送异常"); |
| | | } else { |
| | | JSONObject jsonObject1 = JSON.parseObject(execute.body(), JSONObject.class); |
| | | if(jsonObject1.getIntValue("code") != 200){ |
| | | System.err.println(jsonObject1.getString("msg")); |
| | | } |
| | | } |
| | | } |
| | | |
| | |
| | | msg.put("data", new Object()); |
| | | |
| | | //调用推送 |
| | | HttpHeaders headers = new HttpHeaders(); |
| | | // 以表单的方式提交 |
| | | headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED); |
| | | HttpRequest post = HttpUtil.createPost(socket_uri + "/netty/sendMsgToClient"); |
| | | post.header("Content-Type", MediaType.APPLICATION_FORM_URLENCODED_VALUE); |
| | | //将请求头部和参数合成一个请求 |
| | | MultiValueMap<String, Object> params = new LinkedMultiValueMap<>(); |
| | | params.add("msg", msg.toJSONString()); |
| | | params.add("id", id.toString()); |
| | | params.add("type", type.toString()); |
| | | HttpEntity<MultiValueMap<String, Object>> requestEntity = new HttpEntity<>(params, headers); |
| | | String s = internalRestTemplate.postForObject("http://zuul-gateway/netty/sendMsgToClient",requestEntity , String.class); |
| | | JSONObject jsonObject1 = JSON.parseObject(s, JSONObject.class); |
| | | Map<String, Object> params = new HashMap<>(); |
| | | params.put("msg", msg.toJSONString()); |
| | | params.put("id", id); |
| | | params.put("type", type); |
| | | post.form(params); |
| | | HttpResponse execute = post.execute(); |
| | | if (200 != execute.getStatus()) { |
| | | System.err.println("推送异常"); |
| | | } else { |
| | | JSONObject jsonObject1 = JSON.parseObject(execute.body(), JSONObject.class); |
| | | if(jsonObject1.getIntValue("code") != 200){ |
| | | System.err.println(jsonObject1.getString("msg")); |
| | | } |
| | | } |
| | | } |
| | | |
| | |
| | | jsonObject.put("data", map); |
| | | |
| | | //调用推送 |
| | | HttpHeaders headers = new HttpHeaders(); |
| | | // 以表单的方式提交 |
| | | headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED); |
| | | HttpRequest post = HttpUtil.createPost(socket_uri + "/netty/sendMsgToClient"); |
| | | post.header("Content-Type", MediaType.APPLICATION_FORM_URLENCODED_VALUE); |
| | | //将请求头部和参数合成一个请求 |
| | | MultiValueMap<String, Object> params = new LinkedMultiValueMap<>(); |
| | | params.add("msg", jsonObject.toJSONString()); |
| | | params.add("id", String.valueOf(uid)); |
| | | params.add("type", String.valueOf(type)); |
| | | HttpEntity<MultiValueMap<String, Object>> requestEntity = new HttpEntity<>(params, headers); |
| | | String s = internalRestTemplate.postForObject("http://zuul-gateway/netty/sendMsgToClient",requestEntity , String.class); |
| | | JSONObject jsonObject1 = JSON.parseObject(s, JSONObject.class); |
| | | Map<String, Object> params = new HashMap<>(); |
| | | params.put("msg", jsonObject.toJSONString()); |
| | | params.put("id", uid); |
| | | params.put("type", type); |
| | | post.form(params); |
| | | HttpResponse execute = post.execute(); |
| | | if (200 != execute.getStatus()) { |
| | | System.err.println("推送异常"); |
| | | } else { |
| | | JSONObject jsonObject1 = JSON.parseObject(execute.body(), JSONObject.class); |
| | | if(jsonObject1.getIntValue("code") != 200){ |
| | | System.err.println(jsonObject1.getString("msg")); |
| | | } |
| | | } |
| | | } |
| | | |
| | |
| | | jsonObject.put("data", map); |
| | | |
| | | //调用推送 |
| | | HttpHeaders headers = new HttpHeaders(); |
| | | // 以表单的方式提交 |
| | | headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED); |
| | | HttpRequest post = HttpUtil.createPost(socket_uri + "/netty/sendMsgToClient"); |
| | | post.header("Content-Type", MediaType.APPLICATION_FORM_URLENCODED_VALUE); |
| | | //将请求头部和参数合成一个请求 |
| | | MultiValueMap<String, Object> params = new LinkedMultiValueMap<>(); |
| | | params.add("msg", jsonObject.toJSONString()); |
| | | params.add("id", String.valueOf(uid)); |
| | | params.add("type", String.valueOf(type)); |
| | | HttpEntity<MultiValueMap<String, Object>> requestEntity = new HttpEntity<>(params, headers); |
| | | String s = internalRestTemplate.postForObject("http://zuul-gateway/netty/sendMsgToClient",requestEntity , String.class); |
| | | JSONObject jsonObject1 = JSON.parseObject(s, JSONObject.class); |
| | | Map<String, Object> params = new HashMap<>(); |
| | | params.put("msg", jsonObject.toJSONString()); |
| | | params.put("id", uid); |
| | | params.put("type", type); |
| | | post.form(params); |
| | | HttpResponse execute = post.execute(); |
| | | if (200 != execute.getStatus()) { |
| | | System.err.println("推送异常"); |
| | | } else { |
| | | JSONObject jsonObject1 = JSON.parseObject(execute.body(), JSONObject.class); |
| | | if(jsonObject1.getIntValue("code") != 200){ |
| | | System.err.println(jsonObject1.getString("msg")); |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |