// 常连接函数
forever_realtive:function(){
var that = this;
wx.closeSocket();
var urls = this.siteInfo.siteroot;
urls = urls.replace("/app/index.php", “”);
urls = urls.replace(“https”, “wss”);
console.log(urls)
wx.connectSocket({
url: urls
})
//监听WebSocket错误
wx.onSocketError(function (res) {
socketOpen = false
console.log(‘WebSocket连接打开失败,请检查!’)
})
//监听WebSocket连接打开事件。
wx.onSocketOpen(function (res) {
console.log(‘WebSocket连接打开’)
socketOpen = true
var arr = {};
arr.type = “login”;
arr.client_name = wx.getStorageSync(“access_token”);
arr.room_id = that.siteInfo.acid;
arr.uid = wx.getStorageSync(“access_token”);;
wx.sendSocketMessage({
data: JSON.stringify(arr),
})
})
//监听WebSocket接受到服务器的消息事件
wx.onSocketMessage(function (res) {
console.log(‘返回参数 回调’, res)
var data = JSON.parse(res.data);
switch (data[‘type’]) {
// 服务端ping客户端
case ‘ping’:
var arr = {};
arr.type = “pong”;
wx.sendSocketMessage({
data: JSON.stringify(arr),
})
break;
// 登录 更新用户列表
case ‘login’:
socketOpen = true
break;
case ‘driver’:
// console.log(‘退缩美好消息2driver’)
if (data[‘status’] == 1 && wx.getStorageSync(“usertype”) == 1) {
// console.log(‘driver-----------’)
new SoundRecordingPlay({
src: wx.getStorageSync(“mp3”),
duration: “14”
});
}
socketOpen = true
break;
case ‘say’:
// console.log(‘收到消息driver’, data)
if (data[‘status’] == 1) {
wx.redirectTo({
url: ‘/pages/map/getOrderNotGoing/getOrderNotGoing?order_no=’ + data[‘order_no’],
})
} else if (data[‘status’] == 2) {
//跳转到进行中页面
wx.redirectTo({
url: ‘/pages/map/orderGoing/orderGoing?order_no=’ + data[‘order_no’],
})
} else if (data[‘status’] == 3) {
//跳转到待付款页面
wx.redirectTo({
url: ‘/pages/pay/paidOrder/paidOrder?order_no=’ + data[‘order_no’],
})
} else if (data[‘status’] == 4) {
//跳转到待付款页面
wx.redirectTo({
url: ‘/pages/userOrder/orderDetail/orderDetail?order_no=’ + data[‘order_no’],
})
} else if (data[‘status’] == 5) {
console.log(data[‘deletesay’],‘22222222222222222222222’)
//跳转到待付款页面
setTimeout(()=>{
wx.redirectTo({
url: ‘/pages/map/driverServer/driverServer?deleteOrder=true’,
})
},1500)
}
socketOpen = true
break;
case ‘positioning’:
// console.log(‘收到消息positioning’, data)
var arrx = [];
that.postlist[’’ + data.token + ‘’] = [data.positioning.lat, data.positioning.lng];
// console.log(‘收到消息positioning222’, postlist)
socketOpen = true
break;
}
})
//监听WebSocket关闭
wx.onSocketClose(function (res) {
socketOpen = false
// console.log(’ 已关闭!’)
})
}
手机连接不上长链接,电脑可以