socket.js
3.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
var util = require('util.js')
var timer;
function initSocket(){
connect();
}
function connect(){
const socketTask= wx.connectSocket({
url: 'wss://zywm.colorcun.com/wss',
success: function (res) {
console.log(res,'xxxxxxx');
},
fail: function (fail) {
console.log(fail,'xxxxxx');
initSocket();
}
});
// 打开连接
wx.onSocketOpen(function () {
console.log('xxxxxxxxxxxx','已经打开')
})
wx.onSocketError(function (res) {
console.log('WebSocket连接打开失败,请检查!')
wx.onSocketOpen(function () {
console.log('xxxxxxxxxxxx','已经打开')
})
})
wx.onSocketClose(function(res){
console.log('WebSocket连接断开,请检查!')
connect();
})
return socketTask;
}
function resiverMessage() {
console.log('cccccc',timer)
//接收推送
var that=this;
wx.onSocketMessage(function (data) {
try{
if(JSON.parse(data.data)){
console.log('dddddddddd')
console.log(data.data)
if(JSON.parse(data.data)['a']=='deleteAuthUser'){
if(util.cache('openid')==JSON.parse(data.data)['d']['oi']){
wx.showToast({
title:'您已被商家移除',
icon:'none',
duration:2000,
success:function () {
console.log('xxxxx测试')
timer=setInterval(function(){
if(timer){
clearInterval(timer)
}
wx.clearStorageSync();
wx.reLaunch({
url:'/pages/me/s_index',
})
},2000)
// wx.clearStorageSync();
// wx.reLaunch({
// url:'/pages/me/s_index',
// })
}
})
}
}
if(JSON.parse(data.data)['a']=='transfer'){
if(util.cache('openid')==JSON.parse(data.data)['d']['oi']){
if(util.cache('sellerid')==JSON.parse(data.data)['d']['os']){
wx.showToast({
title:'您已被商家移除',
icon:'none',
duration:2000,
success:function () {
timer=setInterval(function(){
if(timer){
clearInterval(timer)
}
wx.clearStorageSync();
wx.reLaunch({
url:'/pages/me/s_index',
})
},2000)
// wx.clearStorageSync();
// wx.reLaunch({
// url:'/pages/me/s_index',
// })
}
})
}
// var pages=getCurrentPages();
}
}
}
}catch(e){
console.log(e);
}
})
}
module.exports = {
initSocket,
resiverMessage
}