| | |
| | | |
| | | |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import cn.hutool.http.HttpRequest; |
| | | import cn.hutool.http.HttpResponse; |
| | | import cn.hutool.http.HttpUtil; |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.sinata.push.config.QYTConfig; |
| | | import com.sinata.push.util.RedisUtil; |
| | | import com.sinata.push.util.SinataUtil; |
| | | import com.sinata.push.util.SpringUtil; |
| | |
| | | import io.netty.channel.ChannelFuture; |
| | | import io.netty.channel.ChannelHandlerContext; |
| | | import io.netty.handler.codec.http.websocketx.TextWebSocketFrame; |
| | | import org.springframework.http.MediaType; |
| | | |
| | | import java.util.HashMap; |
| | | import java.util.Hashtable; |
| | | import java.util.Map; |
| | | import java.util.Timer; |
| | | import java.util.TimerTask; |
| | | |
| | |
| | | public static Hashtable<String, Hashtable<ChannelHandlerContext, String>> map = new Hashtable<String, Hashtable<ChannelHandlerContext, String>>(); |
| | | |
| | | private RedisUtil redisUtil = SpringUtil.getObject(RedisUtil.class); |
| | | |
| | | private QYTConfig qytConfig = SpringUtil.getObject(QYTConfig.class); |
| | | |
| | | public static Hashtable<String, String> table; |
| | | |
| | |
| | | |
| | | |
| | | } |
| | | // 乘客上传位置,转发到用户端服务做订单校验和司机推送 |
| | | if (method.equals(Method.passengerLocation)) { |
| | | forwardPassengerLocation(ctx, jsonCon); |
| | | } |
| | | } catch (Exception e) { |
| | | if (isdebug) { |
| | | NettyWebSocketController.sendMsgToClient(ctx, "__error__" + msg.toString()); |
| | |
| | | } |
| | | |
| | | /** |
| | | * 转发乘客实时定位到用户服务,由用户服务校验订单后推送给司机端 |
| | | */ |
| | | private void forwardPassengerLocation(ChannelHandlerContext ctx, JSONObject jsonCon) { |
| | | Integer userId = jsonCon.getInteger("userId"); |
| | | Integer orderId = jsonCon.getInteger("orderId"); |
| | | Integer orderType = jsonCon.getInteger("orderType"); |
| | | Double lon = jsonCon.getDouble("lon"); |
| | | Double lat = jsonCon.getDouble("lat"); |
| | | String timestamp = jsonCon.getString("timestamp"); |
| | | // 基础参数不合法时直接返回错误,不再调用后端业务接口 |
| | | if (userId == null || orderId == null || orderType == null || lon == null || lat == null || lon == 0 || lat == 0) { |
| | | sendMsgToClient(ctx, "__error__" + jsonCon.toJSONString()); |
| | | return; |
| | | } |
| | | Map<String, Object> params = new HashMap<>(); |
| | | params.put("userId", String.valueOf(userId)); |
| | | params.put("orderId", String.valueOf(orderId)); |
| | | params.put("orderType", String.valueOf(orderType)); |
| | | params.put("lon", String.valueOf(lon)); |
| | | params.put("lat", String.valueOf(lat)); |
| | | params.put("timestamp", timestamp); |
| | | HttpRequest post = HttpUtil.createPost(qytConfig.getChuxingUrl() + "/user/base/passenger/location/push"); |
| | | post.contentType(MediaType.APPLICATION_FORM_URLENCODED_VALUE); |
| | | post.form(params); |
| | | HttpResponse execute = post.execute(); |
| | | if (200 != execute.getStatus()) { |
| | | System.err.println("调用user-server推送乘客定位出错"); |
| | | return; |
| | | } |
| | | JSONObject jsonObject = JSON.parseObject(execute.body(), JSONObject.class); |
| | | if (jsonObject.getIntValue("code") != 200) { |
| | | System.err.println("调用user-server推送乘客定位出错:" + jsonObject.getString("msg")); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 向客户端发送消息 |
| | | * |
| | | * @param ctx |