Pu Zhibing
4 天以前 3163a383bb58507ac7b0bb56ac20dc26aa1a8e5a
DriverQYTTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/util/PushUtil.java
@@ -1,5 +1,8 @@
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;
@@ -13,12 +16,8 @@
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;
@@ -58,10 +57,12 @@
    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
@@ -80,20 +81,24 @@
        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"));
        }
        }
    }
@@ -115,20 +120,22 @@
        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"));
            }
        }
    }
@@ -341,26 +348,30 @@
        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"));
            }
        }
    }
@@ -379,19 +390,22 @@
        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"));
            }
        }
    }
@@ -418,19 +432,22 @@
        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"));
            }
        }
    }
@@ -455,21 +472,24 @@
        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"));
        }
    }
    }
    /**