New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

node-red-contrib-gps

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-red-contrib-gps - npm Package Compare versions

Comparing version 1.0.4 to 1.0.5

155

lib/GpsApi.js

@@ -1,103 +0,126 @@

const axios = require('axios')
const CryptoJS = require('crypto-js')
const GpsApiCode = require('./GpsApiCode')
const axios = require("axios");
const CryptoJS = require("crypto-js");
const GpsApiCode = require("./GpsApiCode");
// 提前一分钟更新
const EXPIRE_TIME = (60 * 1000)
const EXPIRE_TIME = 60 * 1000;
const baseUrl = { 'gpsoo': 'http://api.gpsoo.net/1',
'gmiot': 'http://litapi.gmiot.net/1' }
const baseUrl = {
gpsoo: "http://api.gpsoo.net/1",
gmiot: "https://litin.gmiot.net/1",
};
class GpsApi {
constructor (node, config) {
this.node = node
this.config = config
constructor(node, config) {
this.node = node;
this.config = config;
}
getToken () {
const { set: setCache, get: getCache } = this.node.context().global
const { phone, password, platform } = this.config
const cache_key = `gps-${phone}-${platform}`
getToken() {
const { set: setCache, get: getCache } = this.node.context().global;
const { phone, password, platform } = this.config;
const cache_key = `gps-${phone}-${platform}`;
return new Promise(async (resolve, reject) => {
try {
const cache = getCache(cache_key)
if (cache && cache.time && ((cache.time - new Date().valueOf()) > EXPIRE_TIME)) {
resolve(cache.token)
return
const cache = getCache(cache_key);
if (
cache &&
cache.time &&
cache.time - new Date().valueOf() > EXPIRE_TIME
) {
resolve(cache.token);
return;
}
const time = parseInt(new Date().getTime() / 1000, 10)
const md5Pass = CryptoJS.MD5(password).toString()
const signature = CryptoJS.MD5(md5Pass + time).toString()
const { data } = await axios.get(`${baseUrl[platform]}/auth/access_token?account=${phone}&time=${time}&signature=${signature}`, {
headers: {
'Content-type': 'Content-type: text/html; charset=utf-8'
}
}).catch(err => {
throw new Error(`[GPS api Token]${err}`)
})
const time = parseInt(new Date().getTime() / 1000, 10);
const md5Pass = CryptoJS.MD5(password).toString();
const signature = CryptoJS.MD5(md5Pass + time).toString();
const { data } = await axios
.get(
`${baseUrl[platform]}/auth/access_token?account=${phone}&time=${time}&signature=${signature}`,
{
headers: {
"Content-type": "Content-type: text/html; charset=utf-8",
},
}
)
.catch((err) => {
throw new Error(`[GPS api Token]${err}`);
});
if (data.ret != 0) {
const msg = GpsApiCode[data.ret] || data.msg
throw new Error(`[GPS api Token]${msg}`)
const msg = GpsApiCode[data.ret] || data.msg;
throw new Error(`[GPS api Token]${msg}`);
}
if (!data.access_token) {
reject(new Error('[GPS api Token]token获取失败'))
reject(new Error("[GPS api Token]token获取失败"));
}
setCache(cache_key, {
token: data.access_token,
time: data.expires_in * 1000 + new Date().getTime()
})
resolve(data.access_token)
} catch (err) { reject(err) }
})
time: data.expires_in * 1000 + new Date().getTime(),
});
resolve(data.access_token);
} catch (err) {
reject(err);
}
});
}
monitor () {
monitor() {
return new Promise(async (resolve, reject) => {
try {
const { phone, platform } = this.config
const access_token = await this.getToken()
const { phone, platform } = this.config;
const access_token = await this.getToken();
const { data } = await axios.get(`${baseUrl[platform]}/account/monitor?target=${phone}&access_token=${access_token}`, {
headers: {
'Content-type': 'Content-type: text/html; charset=utf-8'
}
}).catch(err => {
throw new Error(`【监控】monitor ${err}`)
})
const { data } = await axios
.get(
`${baseUrl[platform]}/account/monitor?target=${phone}&access_token=${access_token}`,
{
headers: {
"Content-type": "Content-type: text/html; charset=utf-8",
},
}
)
.catch((err) => {
throw new Error(`【监控】monitor ${err}`);
});
if (data.ret != 0) {
const msg = GpsApiCode[data.ret] || data.msg
throw new Error(`【监控】monitor${msg}`)
const msg = GpsApiCode[data.ret] || data.msg;
throw new Error(`【监控】monitor${msg}`);
}
resolve(data.data)
resolve(data.data);
} catch (error) {
reject(error)
reject(error);
}
})
});
}
address (longitude, latitude) {
address(longitude, latitude) {
return new Promise(async (resolve, reject) => {
try {
const { platform } = this.config
const access_token = await this.getToken()
const { platform } = this.config;
const access_token = await this.getToken();
const { data } = await axios.get(`${baseUrl[platform]}/tool/address?lng=${longitude}&lat=${latitude}&access_token=${access_token}`, {
headers: {
'Content-type': 'Content-type: text/html; charset=utf-8'
}
}).catch(err => {
throw new Error(`[【逆地理位置解析】]${err}`)
})
const { data } = await axios
.get(
`${baseUrl[platform]}/tool/address?lng=${longitude}&lat=${latitude}&access_token=${access_token}`,
{
headers: {
"Content-type": "Content-type: text/html; charset=utf-8",
},
}
)
.catch((err) => {
throw new Error(`[【逆地理位置解析】]${err}`);
});
if (data.ret != 0) {
const msg = GpsApiCode[data.ret] || data.msg
throw new Error(`[【逆地理位置解析】]${msg}`)
const msg = GpsApiCode[data.ret] || data.msg;
throw new Error(`[【逆地理位置解析】]${msg}`);
}
resolve(data)
resolve(data);
} catch (error) {
reject(error)
reject(error);
}
})
});
}
}
module.exports = GpsApi
module.exports = GpsApi;
{
"name": "node-red-contrib-gps",
"version": "1.0.4",
"version": "1.0.5",
"description": "汽车在线和万物在线 ,可以获取设备的gps位置和逆地理位置解析",

@@ -28,3 +28,3 @@ "main": "index.js",

"dependencies": {
"axios": "^0.18.0",
"axios": ">=0.21.2",
"crypto-js": "^3.1.9-1"

@@ -31,0 +31,0 @@ },

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc