打开信道出现如下错误。
{"code":0,"data":{"invalidTunnelIds":[]},"message":"OK"}
java.lang.Exception: 信道服务器响应格式错误,无法解析 JSON 字符串
at com.qcloud.weapp.tunnel.TunnelAPI.request(TunnelAPI.java:112)
at com.qcloud.weapp.tunnel.TunnelAPI.emitPacket(TunnelAPI.java:72)
at com.qcloud.weapp.tunnel.TunnelAPI.emitMessage(TunnelAPI.java:54)
at com.qcloud.weapp.tunnel.TunnelAPI.emitMessage(TunnelAPI.java:43)
at com.qcloud.weapp.tunnel.TunnelRoom.broadcast(TunnelRoom.java:72)
at com.qcloud.ChatTunnelHandler.broadcast(ChatTunnelHandler.java:138)
at com.qcloud.ChatTunnelHandler.onTunnelMessage(ChatTunnelHandler.java:93)
at com.qcloud.weapp.tunnel.TunnelService.handlePost(TunnelService.java:212)
at com.qcloud.weapp.tunnel.TunnelService.handle(TunnelService.java:78)
实现代码:
[@RequestMapping](/user/RequestMapping) public void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { System.err.println(WxAuthenticationUtils.getWxid(request)); // 创建信道服务处理信道相关请求 TunnelService tunnelService = new TunnelService(request, response); try { // 配置是可选的,配置 CheckLogin 为 true 的话,会在隧道建立之前获取用户信息,以便业务将隧道和用户关联起来 TunnelHandleOptions options = new TunnelHandleOptions(); options.setCheckLogin( true ); // 需要实现信道处理器,ChatTunnelHandler 是一个实现的范例 tunnelService.handle( new ChatTunnelHandler(), options); } catch (ConfigurationException e) { e.printStackTrace(); } } |