- 想做个前端后端联动的,怎么都调不通,求解答
前端微信代码如下: wxml [代码]<[代码][代码]button[代码] [代码]type[代码][代码]=[代码][代码]'default'[代码] [代码]bindtap[代码][代码]=[代码][代码]'createConn'[代码][代码]>创建连接</[代码][代码]button[代码][代码]>[代码][代码]<[代码][代码]view[代码] [代码]style[代码][代码]=[代码][代码]'display:flex;flex-direction:row;margin:10px'[代码][代码]>[代码][代码]<[代码][代码]input[代码] [代码]type[代码][代码]=[代码][代码]'txet'[代码] [代码]name[代码][代码]=[代码][代码]'msg'[代码] [代码]bindblur[代码][代码]=[代码][代码]'getMsg'[代码] [代码]style[代码][代码]=[代码][代码]'width:200px;border:1px solid #cccccc'[代码][代码]></[代码][代码]input[代码][代码]>[代码][代码]<[代码][代码]button[代码] [代码]type[代码][代码]=[代码][代码]'primary'[代码] [代码]size[代码][代码]=[代码][代码]'mini'[代码] [代码]bindtap[代码][代码]=[代码][代码]'send'[代码][代码]>发送消息</[代码][代码]button[代码][代码]>[代码][代码]</[代码][代码]view[代码][代码]>[代码][代码]<[代码][代码]view[代码] [代码]style[代码][代码]=[代码][代码]'height:200px;'[代码][代码]>[代码][代码]<[代码][代码]view[代码] [代码]style[代码][代码]=[代码][代码]'font-weight:bold'[代码][代码]>客户端发送的消息:</[代码][代码]view[代码][代码]>[代码][代码]<[代码][代码]block[代码] [代码]wx:for[代码][代码]=[代码][代码]'{{sendMsg}}'[代码] [代码]wx:for-item[代码][代码]=[代码][代码]'item1'[代码][代码]>[代码][代码]<[代码][代码]view[代码] [代码]style[代码][代码]=[代码][代码]'color:green'[代码][代码]>{{item1}}</[代码][代码]view[代码][代码]>[代码][代码]</[代码][代码]block[代码][代码]>[代码][代码]</[代码][代码]view[代码][代码]>[代码][代码]<[代码][代码]view[代码] [代码]style[代码][代码]=[代码][代码]'height:200px'[代码][代码]>[代码][代码]<[代码][代码]view[代码] [代码]style[代码][代码]=[代码][代码]'font-weight:bold'[代码][代码]>服务器返回消息</[代码][代码]view[代码][代码]>[代码][代码]<[代码][代码]block[代码] [代码]wx:for[代码][代码]=[代码][代码]'{{restData}}'[代码] [代码]wx:for-item[代码][代码]=[代码][代码]'item2'[代码][代码]>[代码][代码]<[代码][代码]view[代码] [代码]style[代码][代码]=[代码][代码]'color:red'[代码][代码]>{{item2}}</[代码][代码]view[代码][代码]>[代码][代码]</[代码][代码]block[代码][代码]>[代码][代码]</[代码][代码]view[代码][代码]>[代码][代码]<[代码][代码]view[代码] [代码]style[代码][代码]=[代码][代码]'margin:10px'[代码][代码]>{{content}}</[代码][代码]view[代码][代码]>[代码][代码]<[代码][代码]button[代码] [代码]type[代码][代码]=[代码][代码]'default'[代码] [代码]bindtap[代码][代码]=[代码][代码]'closeConn'[代码][代码]>关闭连接</[代码][代码]button[代码][代码]>[代码]js [代码]Page({[代码][代码] [代码][代码]data: {[代码][代码] [代码][代码]},[代码][代码] [代码][代码]createConn:[代码][代码]function[代码][代码](){[代码][代码] [代码][代码]var[代码] [代码]page=[代码][代码]this[代码][代码];[代码][代码] [代码][代码]wx.connectSocket({[代码][代码] [代码][代码]url: [代码][代码]'192.168.31.233:7788'[代码][代码],[代码][代码] [代码][代码]data:{[代码][代码] [代码][代码]x:[代码][代码]''[代码][代码],[代码][代码] [代码][代码]y:[代码][代码]''[代码][代码] [代码][代码]},[代码][代码] [代码][代码]header:{[代码][代码] [代码][代码]'content-type'[代码][代码]:[代码][代码]'Application/json'[代码][代码] [代码][代码]},[代码][代码] [代码][代码]method:[代码][代码]'GET'[代码][代码] [代码][代码]});[代码][代码] [代码][代码]wx.onSocketOpen([代码][代码]function[代码][代码](res){[代码][代码] [代码][代码]console.log(res);[代码][代码] [代码][代码]page.setData({socketOpen:[代码][代码]true[代码][代码]});[代码][代码] [代码][代码]console.log([代码][代码]'WebSocket连接已打开!'[代码][代码])[代码][代码] [代码][代码]});[代码][代码] [代码][代码]wx.onSocketError([代码][代码]function[代码][代码](res){[代码][代码] [代码][代码]console.log([代码][代码]'WebSocket连接打开失败,请检查!'[代码][代码])[代码][代码] [代码][代码]})[代码][代码] [代码][代码]},[代码][代码] [代码][代码]send:[代码][代码]function[代码][代码](e){[代码][代码] [代码][代码]if[代码][代码]([代码][代码]this[代码][代码].data.socketOpen){[代码][代码] [代码][代码]console.log([代码][代码]this[代码][代码].data.socketOpen);[代码][代码] [代码][代码]wx.sendSocketMessage({[代码][代码] [代码][代码]data: [代码][代码]this[代码][代码].data.msg[代码][代码] [代码][代码]});[代码][代码] [代码][代码]var[代码] [代码]sendMsg=[代码][代码]this[代码][代码].data.sendMsg;[代码][代码] [代码][代码]sendMsg.push([代码][代码]this[代码][代码].data.msg);[代码][代码] [代码][代码]this[代码][代码].setData({sendMsg:sendMsg});[代码][代码] [代码][代码]var[代码] [代码]page=[代码][代码]this[代码][代码];[代码][代码] [代码][代码]wx.onSocketMessage([代码][代码]function[代码][代码](res){[代码][代码] [代码][代码]var[代码] [代码]resData=page.data.resData;[代码][代码] [代码][代码]resData.push(res.data);[代码][代码] [代码][代码]page.setData({resData:resData});[代码][代码] [代码][代码]console.log(resData);[代码][代码] [代码][代码]console.log([代码][代码]'收到服务器内容:'[代码][代码]+res.data)[代码][代码] [代码][代码]})[代码][代码] [代码][代码]}[代码][代码]else[代码][代码]{[代码][代码] [代码][代码]console.log([代码][代码]'WebSocket连接打开失败,请检查!'[代码][代码]);[代码][代码] [代码][代码]}[代码][代码] [代码][代码]},[代码][代码] [代码][代码]closeConn:[代码][代码]function[代码][代码](e){[代码][代码] [代码][代码]wx.closeSocketClose([代码][代码]function[代码][代码](res){[代码][代码] [代码][代码]console.log([代码][代码]'WebSocket已关闭!'[代码][代码])[代码][代码] [代码][代码]});[代码][代码] [代码][代码]},[代码][代码] [代码][代码]getMsg:[代码][代码]function[代码][代码](e){[代码][代码] [代码][代码]var[代码] [代码]page=[代码][代码]this[代码][代码];[代码][代码] [代码][代码]page.setData({msg:e.detail.value});[代码][代码] [代码][代码]}[代码][代码]})[代码]显示界面如下 [图片] 报错如下: [图片] 用JAVA代码互操作可以实现相互通信: [图片] java服务器代码如下: [代码]import[代码] [代码]java.io.*;[代码][代码]import[代码] [代码]java.net.*;[代码][代码]public[代码] [代码]class[代码] [代码]Example06[代码][代码]{[代码][代码] [代码][代码]public[代码] [代码]static[代码] [代码]void[代码] [代码]main(String[] args)[代码][代码]throws[代码] [代码]Exception[代码][代码] [代码][代码]{[代码][代码] [代码][代码]new[代码] [代码]TCPServer().listen();[代码][代码] [代码][代码]}[代码][代码]}[代码][代码]class[代码] [代码]TCPServer[代码][代码]{[代码][代码] [代码][代码]private[代码] [代码]static[代码] [代码]final[代码] [代码]int[代码] [代码]PORT=[代码][代码]7788[代码][代码];[代码][代码]//定义一个静态常量作为端口号[代码][代码] [代码][代码]public[代码] [代码]void[代码] [代码]listen()[代码][代码]throws[代码] [代码]Exception[代码][代码] [代码][代码]{[代码][代码] [代码][代码]//创建ServerSocket对象,监听指定的端口[代码][代码] [代码][代码]ServerSocket serverSocket=[代码][代码]new[代码] [代码]ServerSocket(PORT);[代码][代码] [代码][代码]//使用while循环不停的接收客户端发送的请求[代码][代码] [代码][代码]while[代码][代码]([代码][代码]true[代码][代码])[代码][代码] [代码][代码]{[代码][代码] [代码][代码]//调用ServerSocket的accept()方法与客户端建立连接[代码][代码] [代码][代码]final[代码] [代码]Socket client=serverSocket.accept();[代码][代码] [代码][代码]//下面的代码用来开启一个新的线程[代码][代码] [代码][代码]new[代码] [代码]Thread()[代码][代码] [代码][代码]{[代码][代码] [代码][代码]public[代码] [代码]void[代码] [代码]run()[代码][代码] [代码][代码]{[代码][代码] [代码][代码]OutputStream os;[代码][代码]//定义一个输出流对象[代码][代码] [代码][代码]try[代码][代码] [代码][代码]{[代码][代码] [代码][代码]os=client.getOutputStream();[代码][代码]//获取客户端的输出流[代码][代码] [代码][代码]System.out.println([代码][代码]"开始与客户端交互数据"[代码][代码]);[代码][代码] [代码][代码]os.write(([代码][代码]"传智播客欢迎你!"[代码][代码]).getBytes());[代码][代码] [代码][代码]Thread.sleep([代码][代码]5000[代码][代码]);[代码][代码]//使线程休眠5000毫秒[代码][代码] [代码][代码]System.out.println([代码][代码]"结束与客户端的交互数据"[代码][代码]);[代码][代码] [代码][代码]os.close();[代码][代码]//关闭输出流[代码][代码] [代码][代码]client.close();[代码][代码]//关闭Socket对象[代码][代码] [代码][代码]}[代码][代码] [代码][代码]catch[代码] [代码](Exception e)[代码][代码] [代码][代码]{[代码][代码] [代码][代码]e.printStackTrace();[代码][代码] [代码][代码]}[代码][代码] [代码][代码]}[代码][代码] [代码][代码]}.start();[代码][代码] [代码][代码]}[代码][代码] [代码][代码]}[代码][代码]}[代码]java客户端代码如下: [代码]import[代码] [代码]java.io.*;[代码][代码]import[代码] [代码]java.net.*;[代码][代码]public[代码] [代码]class[代码] [代码]Example05[代码][代码]{[代码][代码] [代码][代码]public[代码] [代码]static[代码] [代码]void[代码] [代码]main(String[] args)[代码][代码]throws[代码] [代码]Exception[代码][代码] [代码][代码]{[代码][代码] [代码][代码]new[代码] [代码]TCPClient().connect();[代码][代码]//创建TCPClient对象,并调用connect()方法[代码][代码] [代码][代码]}[代码][代码]}[代码][代码]//TCP客户端[代码][代码]class[代码] [代码]TCPClient[代码][代码]{[代码][代码] [代码][代码]private[代码] [代码]static[代码] [代码]final[代码] [代码]int[代码] [代码]PORT=[代码][代码]7788[代码][代码];[代码][代码]//服务端的端口号[代码][代码] [代码][代码]public[代码] [代码]void[代码] [代码]connect()[代码][代码]throws[代码] [代码]Exception[代码][代码] [代码][代码]{[代码][代码] [代码][代码]//创建一个Socket并连接到给出地址和端口号的计算机[代码][代码] [代码][代码]Socket client=[代码][代码]new[代码] [代码]Socket([代码][代码]"192.168.31.233"[代码][代码],PORT);[代码][代码] [代码][代码]InputStream is=client.getInputStream(); [代码][代码]//得到接收数据的流[代码][代码] [代码][代码]byte[代码][代码][] buf=[代码][代码]new[代码] [代码]byte[代码][代码][[代码][代码]1024[代码][代码]];[代码][代码]//定义1024个字节数组的缓冲区[代码][代码] [代码][代码]int[代码] [代码]len=is.read(buf);[代码][代码]//将数据读到缓冲区[代码][代码] [代码][代码]System.out.println([代码][代码]new[代码] [代码]String(buf,[代码][代码]0[代码][代码],len));[代码][代码]//将缓冲区的数据输出[代码][代码] [代码][代码]OutputStream os=client.getOutputStream();[代码][代码] [代码][代码]os.write(([代码][代码]"客户端发送消息给服务器"[代码][代码]).getBytes());[代码][代码] [代码][代码]os.close();[代码][代码] [代码][代码]is.close();[代码][代码] [代码][代码]client.close();[代码][代码]//关闭Socket对象,释放资源[代码][代码] [代码][代码]}[代码][代码]}[代码]请问各位,为什么java之间可以正常通信,微信无法连接上呢?
2018-11-01 - 开发工具里面的域名信息不更新
根据教程去后台开发设置里面设置了服务器域名信息,怎么在开发工具里面刷新了无数遍还是更新不出来域名信息呢?请教官方及各位
2018-10-31 - CSS排版调试预览不一致问题
最近刚开始学习小程序,照书写了一段,但是开发工具预览和发布预览效果不一致,求教各位怎么调整CSS,源代码,开发工具预览效果和发布预览效果(在华为mate10pro上)。实机测试,“账号”,“密码”字体排版变成了竖直显示,应该怎么修改样式?[代码]<!--pages/login/login.wxml-->[代码][代码]<[代码][代码]view[代码] [代码]class[代码][代码]=[代码][代码]'content'[代码][代码]>[代码][代码] [代码][代码]<[代码][代码]view[代码] [代码]class[代码][代码]=[代码][代码]'account'[代码][代码]>[代码][代码] [代码][代码]<[代码][代码]view[代码] [代码]class[代码][代码]=[代码][代码]'title'[代码][代码]>账号</[代码][代码]view[代码][代码]>[代码][代码] [代码][代码]<[代码][代码]view[代码] [代码]class[代码][代码]=[代码][代码]'num'[代码][代码]><[代码][代码]input[代码] [代码]bindinput[代码][代码]=[代码][代码]'accountInput'[代码] [代码]placeholder[代码][代码]=[代码][代码]'用户名/邮箱/手机号'[代码] [代码]placeholder-style[代码][代码]=[代码][代码]'color:#999999'[代码][代码]></[代码][代码]input[代码][代码]></[代码][代码]view[代码][代码]>[代码][代码] [代码][代码]</[代码][代码]view[代码][代码]>[代码][代码] [代码][代码]<[代码][代码]view[代码] [代码]class[代码][代码]=[代码][代码]'hr'[代码][代码]></[代码][代码]view[代码][代码]>[代码][代码] [代码][代码]<[代码][代码]view[代码] [代码]class[代码][代码]=[代码][代码]'account'[代码][代码]>[代码][代码] [代码][代码]<[代码][代码]view[代码] [代码]class[代码][代码]=[代码][代码]'title'[代码][代码]>密码</[代码][代码]view[代码][代码]>[代码][代码] [代码][代码]<[代码][代码]view[代码] [代码]class[代码][代码]=[代码][代码]'num'[代码][代码]><[代码][代码]input[代码] [代码]bindblur[代码][代码]=[代码][代码]'pwdBlur'[代码] [代码]placeholder[代码][代码]=[代码][代码]'请输入密码'[代码] [代码]password[代码][代码]=[代码][代码]'true'[代码] [代码]placeholder-style[代码][代码]=[代码][代码]'color:#999999'[代码][代码]></[代码][代码]input[代码][代码]></[代码][代码]view[代码][代码]>[代码][代码] [代码][代码]<[代码][代码]view[代码] [代码]class[代码][代码]=[代码][代码]'see'[代码][代码]>[代码][代码] [代码][代码]<[代码][代码]image[代码] [代码]src[代码][代码]=[代码][代码]'/images/see.jpg'[代码] [代码]style[代码][代码]=[代码][代码]'width:42px;height:30px'[代码][代码]></[代码][代码]image[代码][代码]>[代码][代码] [代码][代码]</[代码][代码]view[代码][代码]>[代码][代码] [代码][代码]</[代码][代码]view[代码][代码]>[代码][代码] [代码][代码]<[代码][代码]view[代码] [代码]class[代码][代码]=[代码][代码]'hr'[代码][代码]></[代码][代码]view[代码][代码]>[代码][代码] [代码][代码]<[代码][代码]button[代码] [代码]class[代码][代码]=[代码][代码]'btn'[代码] [代码]disabled[代码][代码]=[代码][代码]'{{disabled}}'[代码] [代码]type[代码][代码]=[代码][代码]'{{btnstate}}'[代码] [代码]bindtap[代码][代码]=[代码][代码]'login'[代码][代码]>登录</[代码][代码]button[代码][代码]>[代码][代码] [代码][代码]<[代码][代码]view[代码] [代码]class[代码][代码]=[代码][代码]'operate'[代码][代码]>[代码][代码] [代码][代码]<[代码][代码]view[代码][代码]><[代码][代码]n‘a’vigator[代码] [代码]url[代码][代码]=[代码][代码]'../mobile/mobile'[代码][代码]>手机快速注册</[代码][代码]n‘a’vigator[代码][代码]></[代码][代码]view[代码][代码]>[代码][代码] [代码][代码]<[代码][代码]view[代码][代码]><[代码][代码]n‘a’vigator[代码] [代码]url[代码][代码]=[代码][代码]'../company/company'[代码][代码]>企业用户注册</[代码][代码]n‘a’vigator[代码][代码]></[代码][代码]view[代码][代码]>[代码][代码] [代码][代码]<[代码][代码]view[代码][代码]>找回密码</[代码][代码]view[代码][代码]>[代码][代码] [代码][代码]</[代码][代码]view[代码][代码]>[代码][代码] [代码][代码]<[代码][代码]view[代码] [代码]class[代码][代码]=[代码][代码]'login'[代码][代码]>[代码][代码] [代码][代码]<[代码][代码]view[代码][代码]><[代码][代码]image[代码] [代码]src[代码][代码]=[代码][代码]'/images/wxlogin.png'[代码] [代码]style[代码][代码]=[代码][代码]'width:70px;height:98px'[代码][代码]></[代码][代码]image[代码][代码]></[代码][代码]view[代码][代码]>[代码][代码] [代码][代码]<[代码][代码]view[代码][代码]><[代码][代码]image[代码] [代码]src[代码][代码]=[代码][代码]'/images/qqlogin.png'[代码] [代码]style[代码][代码]=[代码][代码]'width:70px;height:98px'[代码][代码]></[代码][代码]image[代码][代码]></[代码][代码]view[代码][代码]>[代码][代码] [代码][代码]</[代码][代码]view[代码][代码]>[代码][代码]</[代码][代码]view[代码][代码]>[代码] [代码]/* pages/login/login.wxss */[代码][代码].content{[代码][代码] [代码][代码]margin-top[代码][代码]:[代码][代码]40px[代码][代码];[代码][代码]}[代码][代码].account{[代码][代码] [代码][代码]display[代码][代码]: flex;[代码][代码] [代码][代码]flex-[代码][代码]direction[代码][代码]: row;[代码][代码] [代码][代码]padding-left[代码][代码]: [代码][代码]20px[代码][代码];[代码][代码] [代码][代码]padding-top[代码][代码]:[代码][代码]20px[代码][代码];[代码][代码] [代码][代码]padding-bottom[代码][代码]: [代码][代码]10px[代码][代码];[代码][代码] [代码][代码]width[代码][代码]: [代码][代码]90%[代码][代码];[代码][代码]}[代码][代码].title{[代码][代码] [代码][代码]margin-right[代码][代码]: [代码][代码]30px[代码][代码];[代码][代码] [代码][代码]font-weight[代码][代码]:[代码][代码]bold[代码][代码];[代码][代码]}[代码][代码].hr{[代码][代码] [代码][代码]border[代码][代码]:[代码][代码]1px[代码] [代码]solid[代码] [代码]#cccccc[代码][代码];[代码][代码] [代码][代码]opacity: [代码][代码]0.2[代码][代码];[代码][代码] [代码][代码]width[代码][代码]: [代码][代码]90%[代码][代码];[代码][代码] [代码][代码]margin[代码][代码]: [代码][代码]0[代码] [代码]auto[代码][代码];[代码][代码]}[代码][代码].see{[代码][代码] [代码][代码]position[代码][代码]: [代码][代码]absolute[代码][代码];[代码][代码] [代码][代码]right[代码][代码]: [代码][代码]20px[代码][代码];[代码][代码]}[代码][代码].btn{[代码][代码] [代码][代码]width[代码][代码]: [代码][代码]90%[代码][代码];[代码][代码] [代码][代码]margin-top[代码][代码]:[代码][代码]40px[代码][代码];[代码][代码] [代码][代码]color[代码][代码]: [代码][代码]#999999[代码][代码];[代码][代码]}[代码][代码].operate{[代码][代码] [代码][代码]display[代码][代码]: flex;[代码][代码] [代码][代码]flex-[代码][代码]direction[代码][代码]: row;[代码][代码]}[代码][代码].operate view{[代码][代码] [代码][代码]margin[代码][代码]: [代码][代码]0[代码] [代码]auto[代码][代码];[代码][代码] [代码][代码]margin-top[代码][代码]: [代码][代码]40px[代码][代码];[代码][代码] [代码][代码]font-size[代码][代码]: [代码][代码]14px[代码][代码];[代码][代码] [代码][代码]color[代码][代码]: [代码][代码]#333333[代码][代码];[代码][代码]}[代码][代码].login{[代码][代码] [代码][代码]display[代码][代码]: flex;[代码][代码] [代码][代码]flex-[代码][代码]direction[代码][代码]: row;[代码][代码] [代码][代码]margin-top[代码][代码]: [代码][代码]140px[代码][代码];[代码][代码]}[代码][代码].login view{[代码][代码] [代码][代码]margin[代码][代码]:[代码][代码]0[代码] [代码]auto[代码][代码];[代码][代码]}[代码][图片] [图片]
2018-10-30