- input 提交后 键盘不收起
input输入框每次输入完成之后 点击了发送按钮,然后键盘就会被收起 设置聚焦后 又会拉起键盘,有没有办法保持键盘一直不被收起,一直处于拉起状态,这个太坑了,用户体验感极差,每次一闪一闪的,这个问题倒是给个解决方案啊,你想想 要是微信每次聊天了每次键盘都要收起一下有多难受
2018-08-13 - websocket 接收不到数据
微信发送给服务端是数据能正常接收到,但是服务端发送给微信端的接收不到,服务端和网页的websocket交互正常,但是和微信这就不行了 微信代码如下 [代码]var[代码] [代码]urls = require([代码][代码]'../constant.js'[代码][代码]).urls;[代码][代码]var[代码] [代码]Stomp = require([代码][代码]'../lib/stomp.js'[代码][代码]).Stomp;[代码] [代码]function[代码] [代码]request(url, data, success) {[代码][代码] [代码][代码]wx.getStorage({[代码][代码] [代码][代码]key: [代码][代码]'net_sessionid'[代码][代码],[代码][代码] [代码][代码]success: [代码][代码]function[代码] [代码](sessionIdRes) {[代码][代码] [代码][代码]console.log([代码][代码]'sessionID:'[代码] [代码]+ sessionIdRes.data);[代码][代码] [代码][代码]wx.request({[代码][代码] [代码][代码]url: url,[代码][代码] [代码][代码]data: data,[代码][代码] [代码][代码]method: [代码][代码]'POST'[代码][代码],[代码][代码] [代码][代码]dataType: [代码][代码]'json'[代码][代码],[代码][代码] [代码][代码]header: {[代码][代码] [代码][代码]'content-type'[代码][代码]: [代码][代码]'application/x-www-form-urlencoded'[代码][代码], [代码][代码]// 默认值[代码][代码] [代码][代码]'Cookie'[代码][代码]: [代码][代码]'JSESSIONID='[代码] [代码]+ sessionIdRes.data[代码][代码] [代码][代码]},[代码][代码] [代码][代码]success: [代码][代码]function[代码] [代码](res) {[代码][代码] [代码][代码]success(res);[代码][代码] [代码][代码]}[代码][代码] [代码][代码]})[代码][代码] [代码][代码]}[代码][代码] [代码][代码]})[代码][代码]}[代码] [代码]function[代码] [代码]sendSocketMessage(msg) {[代码][代码] [代码][代码]console.log([代码][代码]'send msg:'[代码][代码])[代码][代码] [代码][代码]console.log(msg);[代码][代码] [代码][代码]wx.sendSocketMessage({[代码][代码] [代码][代码]data: msg,[代码][代码] [代码][代码]success: [代码][代码]function[代码] [代码](res) {[代码][代码] [代码][代码]console.log([代码][代码]'消息发送成功'[代码][代码]);[代码][代码] [代码][代码]wx.setStorage({[代码][代码] [代码][代码]key: [代码][代码]"msg_"[代码][代码],[代码][代码] [代码][代码]data: msg[代码][代码] [代码][代码]})[代码][代码] [代码][代码]}[代码][代码] [代码][代码]})[代码][代码]}[代码] [代码]function[代码] [代码]onSocketOpen() {[代码] [代码]}[代码][代码]var[代码] [代码]ws = {[代码][代码] [代码][代码]send: sendSocketMessage,[代码][代码] [代码][代码]onopen: [代码][代码]null[代码][代码],[代码][代码] [代码][代码]onmessage: [代码][代码]null[代码][代码]}[代码][代码]var[代码] [代码]stompClient = Stomp.over(ws);[代码] [代码]function[代码] [代码]testSocet() {[代码][代码] [代码][代码]wx.connectSocket({[代码][代码] [代码][代码]url: [代码][代码]'wss://192.168.1.85:8443/websocket'[代码][代码],[代码][代码] [代码][代码]//url: 'ws://127.0.0.1:8080/websocket/websocket',[代码][代码] [代码][代码]});[代码][代码] [代码][代码]wx.onSocketMessage([代码][代码]function[代码] [代码](res) {[代码][代码] [代码][代码]console.log([代码][代码]'收到服务器内容:'[代码][代码]);[代码][代码] [代码][代码]console.log([代码][代码]'收到服务器内容:'[代码] [代码]+ res.data)[代码][代码] [代码][代码]});[代码][代码] [代码] [代码] [代码][代码]wx.onSocketClose([代码][代码]function[代码] [代码](res) {[代码][代码] [代码][代码]console.log([代码][代码]'WebSocket 已关闭!'[代码][代码])[代码][代码] [代码][代码]})[代码][代码] [代码] [代码] [代码][代码]wx.onSocketOpen([代码][代码]function[代码] [代码](res) {[代码][代码] [代码][代码]console.log([代码][代码]'WebSocket连接已打开!'[代码][代码])[代码][代码] [代码][代码]stompClient.send([代码][代码]"/app/req"[代码][代码], {}, [代码][代码]"ssss"[代码][代码]);[代码][代码] [代码][代码]})[代码][代码] [代码][代码]Stomp.setInterval = [代码][代码]function[代码] [代码](interval, f) {[代码][代码] [代码][代码]return[代码] [代码]setInterval(f, interval);[代码][代码] [代码][代码]};[代码][代码] [代码][代码]Stomp.clearInterval = [代码][代码]function[代码] [代码](id) {[代码][代码] [代码][代码]return[代码] [代码]clearInterval(id);[代码][代码] [代码][代码]};[代码] [代码] [代码][代码]wx.onSocketError([代码][代码]function[代码] [代码](res) {[代码][代码] [代码][代码]console.log([代码][代码]'WebSocket连接打开失败,请检查!'[代码][代码])[代码][代码] [代码][代码]})[代码][代码]}[代码] [代码]// stompClient.connect({}[代码][代码]// // ,[代码][代码]// // function connectCallback(frame) {[代码][代码]// // console.log('已连接');[代码][代码]// // stompClient.subscribe('/topic/resp', function (response) {[代码][代码]// // console.log("返回内容:" + response.body);[代码][代码]// // });[代码][代码]// // },[代码][代码]// // function errorCallBack(error) {[代码][代码]// // console.log('连接失败【' + error + '】');[代码][代码]// // }[代码][代码]// );[代码] [代码]function[代码] [代码]init() {[代码][代码] [代码][代码]//getSession();[代码][代码] [代码][代码]testSocet();[代码][代码]}[代码] [代码]function[代码] [代码]getSession() {[代码][代码] [代码][代码]wx.request({[代码][代码] [代码][代码]url: urls.getSession,[代码][代码] [代码][代码]method: [代码][代码]'POST'[代码][代码],[代码][代码] [代码][代码]dataType: [代码][代码]'json'[代码][代码],[代码][代码] [代码][代码]header: {[代码][代码] [代码][代码]'content-type'[代码][代码]: [代码][代码]'application/x-www-form-urlencoded'[代码][代码], [代码][代码]// 默认值[代码][代码] [代码][代码]},[代码][代码] [代码][代码]success: [代码][代码]function[代码] [代码](res) {[代码][代码] [代码][代码]wx.setStorage({[代码][代码] [代码][代码]key: [代码][代码]"net_sessionid"[代码][代码],[代码][代码] [代码][代码]data: res.data.data[代码][代码] [代码][代码]})[代码][代码] [代码][代码]}[代码][代码] [代码][代码]})[代码][代码]}[代码] [代码]module.exports = {[代码][代码] [代码][代码]request: request,[代码][代码] [代码][代码]init: init[代码][代码]}[代码]结果 [图片] 服务端代码 [代码]package[代码] [代码]com.hykj.zonechat.controller;[代码][代码]import[代码] [代码]org.slf4j.Logger;[代码][代码]import[代码] [代码]org.slf4j.LoggerFactory;[代码][代码]import[代码] [代码]org.springframework.beans.factory.annotation.Autowired;[代码][代码]import[代码] [代码]org.springframework.messaging.handler.annotation.MessageMapping;[代码][代码]import[代码] [代码]org.springframework.messaging.simp.SimpMessagingTemplate;[代码][代码]import[代码] [代码]org.springframework.messaging.simp.annotation.SendToUser;[代码][代码]import[代码] [代码]org.springframework.stereotype.Controller;[代码][代码]@Controller[代码][代码]public[代码] [代码]class[代码] [代码]SocketController {[代码][代码] [代码][代码]private[代码] [代码]final[代码] [代码]Logger log = LoggerFactory.getLogger([代码][代码]this[代码][代码].getClass());[代码][代码] [代码][代码]@Autowired[代码][代码] [代码][代码]private[代码] [代码]SimpMessagingTemplate simpMessagingTemplate;[代码][代码] [代码][代码]@MessageMapping[代码][代码]([代码][代码]"/req"[代码][代码])[代码][代码] [代码][代码]public[代码] [代码]void[代码] [代码]sendPublicMessage(String msg) {[代码][代码] [代码][代码]log.info([代码][代码]"收到消息:"[代码][代码]+msg);[代码][代码] [代码][代码]simpMessagingTemplate.convertAndSend([代码][代码]"/topic/resp"[代码][代码], [代码][代码]"qwerty"[代码][代码]);[代码][代码] [代码][代码]}[代码][代码]}[代码] [代码]package[代码] [代码]com.hykj.zonechat.sys;[代码][代码]import[代码] [代码]org.springframework.context.annotation.Configuration;[代码][代码]import[代码] [代码]org.springframework.messaging.simp.config.MessageBrokerRegistry;[代码][代码]import[代码] [代码]org.springframework.web.socket.config.annotation.*;[代码][代码]@Configuration[代码][代码]@EnableWebSocketMessageBroker[代码][代码]public[代码] [代码]class[代码] [代码]WebSocketConfig [代码][代码]implements[代码] [代码]WebSocketMessageBrokerConfigurer {[代码][代码] [代码][代码]@Override[代码][代码] [代码][代码]public[代码] [代码]void[代码] [代码]registerStompEndpoints(StompEndpointRegistry registry) {[代码][代码] [代码][代码]registry.addEndpoint([代码][代码]"/websocket"[代码][代码]).setAllowedOrigins([代码][代码]"*"[代码][代码]);[代码][代码] [代码][代码]}[代码][代码] [代码][代码]@Override[代码][代码] [代码][代码]public[代码] [代码]void[代码] [代码]configureMessageBroker(MessageBrokerRegistry config) {[代码][代码] [代码][代码]config.enableSimpleBroker( [代码][代码]"/topic/"[代码][代码]);[代码][代码] [代码][代码]config.setApplicationDestinationPrefixes([代码][代码]"/app"[代码][代码]);[代码][代码] [代码][代码]}[代码][代码] [代码][代码]@Override[代码][代码] [代码][代码]public[代码] [代码]void[代码] [代码]configureWebSocketTransport(WebSocketTransportRegistration registration) {[代码][代码] [代码][代码]registration.setMessageSizeLimit([代码][代码]128[代码] [代码]* [代码][代码]1024[代码][代码]);[代码][代码] [代码][代码]}[代码][代码]}[代码]结果 [图片] 网页代码 [代码][代码][代码]<[代码][代码]html[代码] [代码]lang[代码][代码]=[代码][代码]"zh-CN"[代码] [代码]xmlns:th[代码][代码]=[代码][代码]"http://www.thymeleaf.org"[代码][代码]>[代码][代码]<[代码][代码]head[代码][代码]>[代码][代码] [代码][代码]<[代码][代码]meta[代码] [代码]charset[代码][代码]=[代码][代码]"UTF-8"[代码][代码]>[代码][代码] [代码][代码]<[代码][代码]script[代码] [代码]src[代码][代码]=[代码][代码]"https://cdn.bootcss.com/stomp.js/2.3.3/stomp.min.js"[代码][代码]>[代码]script[代码][代码]>[代码][代码][代码][代码] [代码][代码]<[代码][代码]script[代码] [代码]src[代码][代码]=[代码][代码]"https://cdn.bootcss.com/sockjs-client/1.1.4/sockjs.js"[代码][代码]>[代码]script[代码][代码]>[代码][代码][代码][代码][代码][代码] [代码][代码]<[代码][代码]title[代码][代码]>socketTest[代码]title[代码][代码]>[代码][代码][代码][代码][代码][代码][代码][代码]head[代码][代码]>[代码][代码][代码][代码][代码][代码][代码]<[代码][代码]body[代码][代码]>[代码][代码][代码][代码][代码][代码]<[代码][代码]button[代码] [代码]onclick[代码][代码]=[代码][代码]"send('aaaaaaaaaa')"[代码][代码]>Send[代码]button[代码][代码]>[代码][代码][代码][代码][代码][代码][代码]<[代码][代码]table[代码] [代码]id[代码][代码]=[代码][代码]'state-info'[代码][代码]>[代码]table[代码][代码]>[代码][代码][代码][代码][代码][代码][代码][代码]body[代码][代码]>[代码][代码][代码][代码][代码][代码][代码]<[代码][代码]script[代码] [代码]type[代码][代码]=[代码][代码]"text/javascript"[代码][代码]>[代码][代码][代码][代码][代码][代码] [代码][代码]var socket = new WebSocket("wss://127.0.0.1:8443/websocket");[代码][代码][代码][代码][代码][代码] [代码][代码]var stompClient = Stomp.over(socket);[代码][代码][代码][代码][代码][代码] [代码][代码]stompClient.connect({},[代码][代码][代码][代码][代码][代码] [代码][代码]function connectCallback(frame) {[代码][代码][代码][代码][代码][代码] [代码][代码]// 连接成功时(服务器响应 CONNECTED 帧)的回调方法[代码][代码][代码][代码][代码][代码] [代码][代码]document.getElementById("state-info").innerHTML = "连接成功";[代码][代码][代码][代码][代码][代码] [代码][代码]console.log('已连接【' + frame + '】');[代码][代码][代码][代码][代码][代码] [代码][代码]stompClient.subscribe('/topic/resp', function (response) {[代码][代码][代码][代码][代码][代码] [代码][代码]alert(response.body)[代码][代码][代码][代码][代码][代码] [代码][代码]});[代码][代码][代码][代码][代码][代码] [代码][代码]},[代码][代码][代码][代码][代码][代码] [代码][代码]function errorCallBack(error) {[代码][代码][代码][代码][代码][代码] [代码][代码]// 连接失败时(服务器响应 ERROR 帧)的回调方法[代码][代码][代码][代码][代码][代码] [代码][代码]document.getElementById("state-info").innerHTML = "连接失败";[代码][代码][代码][代码][代码][代码] [代码][代码]console.log('连接失败【' + error + '】');[代码][代码][代码][代码][代码][代码] [代码][代码]}[代码][代码][代码][代码][代码][代码] [代码][代码]);[代码][代码][代码][代码][代码][代码] [代码][代码]function send(txt) {[代码][代码][代码][代码][代码][代码] [代码][代码]stompClient.send("/app/req", {}, txt);[代码][代码][代码][代码][代码][代码] [代码][代码]}[代码][代码][代码][代码][代码][代码][代码]script[代码][代码]>[代码][代码][代码][代码][代码][代码][代码][代码]html[代码][代码]>[代码][代码][代码][代码]结果 [图片] 这个问题,弄了好久都没搞定,后台用的是springboot 2.0.1.RELEASE 版本 是希望借助websocket 和stomp协议进行交互,但是在微信和服务端进行websocket交互时出现问题了,就是微信发给后台的数据,后台能够接收到,但是后台发送给微信小程序的数据,微信端却接收不到,期间用网页进行测试,发现网页能够接收到数据,然后又用最基础的servlet建立一个简单的websocket进行测试,发现微信端还是收不到数据, 希望各位前辈能给予解惑,谢谢,联系方式qq 1324618209
2018-04-18