Commit cc99bb22 by yixinjj

WS改设备号登录

1 parent b3809c29
Showing 1 changed file with 15 additions and 13 deletions
......@@ -16,12 +16,12 @@ export class Ws {
this.wsAddress = `${config.PROTOCAL}://${config.SERVER}:${config.SOCKET_PORT}`
this.loginAddress = `${config.PROTOCAL}://${config.SERVER}:${config.HTTP_PORT}/login`
}
async connect() {
async connect() {
const { code, data, ...o } = await this.login()
if (code == 200) {
this.deviceId = data.device_id
if (code == 200) {
this.deviceId = data.id
this.token = data.token
this.ws = io(this.wsAddress, {
this.ws = io(this.wsAddress, {
auth: { token: this.token, deviceId: this.deviceId },
transports: ['websocket'],
timeout: 5000
......@@ -32,18 +32,20 @@ export class Ws {
}
}
async login() {
const userInfo = uni.$storage.get('userInfo')
;(userInfo.name = '胡悦'), (userInfo.phone = '18754575574')
if (!userInfo) return uni.$logger.local.error('未获取到系统登录信息')
const { name: user, phone: mobile, merchantName } = userInfo
uni.$logger.local.info(`========WS,用户登录 ${JSON.stringify({ user, mobile, merchantName })}========`)
const sysInfo = uni.getSystemInfoSync()
// const userInfo = uni.$storage.get('userInfo')
// ;(userInfo.name = '胡悦'), (userInfo.phone = '18754575574')
if (!sysInfo?.deviceId) return uni.$logger.local.error('未获取到系统设备信息')
// sysInfo.deviceId='sn123456'
// const { name: user, phone: mobile, merchantName } = userInfo
uni.$logger.local.info(`========WS,用户登录 ${JSON.stringify({deviceId:sysInfo.deviceId})}========`)
return new Promise((resolve, reject) => {
uni.request({
url: this.loginAddress,
data: { user, mobile },
data: { sn: sysInfo.deviceId },
method: 'POST',
dataType: 'json',
success(response) {
dataType: 'json',
success(response) {
resolve(response.data)
},
fail(err) {
......@@ -56,7 +58,7 @@ export class Ws {
this.ws.on(WsTyps.Connected, () => {
uni.$logger.local.info('========WebSocket 连接成功========')
})
this.ws.on(
this.ws.on(
WsTyps.MessageTypes.Private,
function (data) {
uni.$logger.local.info(`WebSocket 收到消息 -> ${JSON.stringify(data)}`)
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!