接口环境设置

This commit is contained in:
仲么了
2023-03-16 15:26:25 +08:00
parent 7e9cfadb23
commit c5ed54924b
20 changed files with 6480 additions and 37 deletions

30
common/api/user.js Normal file
View File

@@ -0,0 +1,30 @@
import request from '../js/request'
export function apiGetYms (params) {
return request({
url: '/shiningCloud/user/authCode',
data: {
phone: params.phone,
devCode: uni.getStorageSync('cidAES'),
type: 0
},
method: 'POST'
})
}
/**
*
* @param {*} type 0:ysm 1:pwd
* @returns
*/
export function apiLogin (params) {
return request({
url: '/shiningCloud/user/login',
data: {
phone: params.phone,
devCode: uni.getStorageSync('cidAES'),
key: params.key.trim(),
type: params.type
},
method: 'POST'
})
}

36
common/js/aes.js Normal file
View File

@@ -0,0 +1,36 @@
import CryptoJS from './crypto.js'
// const key = CryptoJS.enc.Utf8.parse('1234123412ABCDEF') // 十六位十六进制数作为密钥
// const iv = CryptoJS.enc.Utf8.parse('ABCDEF1234123412') // 十六位十六进制数作为密钥偏移量
// 解密方法
function Decrypt (word, key) {
let ckey = CryptoJS.enc.Utf8.parse(key) // 十六位十六进制数作为密钥
// let encryptedHexStr = CryptoJS.enc.Hex.parse(word)
// let srcs = CryptoJS.enc.Base64.stringify(encryptedHexStr)
let decrypt = CryptoJS.AES.decrypt(word, ckey, {
mode: CryptoJS.mode.ECB,
padding: CryptoJS.pad.Pkcs7
})
let decryptedStr = decrypt.toString(CryptoJS.enc.Utf8)
console.log('decryptedStr', decryptedStr.toString())
return decryptedStr.toString()
}
// 加密方法
function Encrypt (word, key) {
let ckey = CryptoJS.enc.Utf8.parse(key)
// let srcs = CryptoJS.enc.Utf8.parse(word)
let encrypted = CryptoJS.AES.encrypt(word, ckey, {
mode: CryptoJS.mode.ECB,
padding: CryptoJS.pad.Pkcs7
})
return encrypted.toString()
}
export default {
Decrypt,
Encrypt
}

View File

@@ -1,32 +1,22 @@
const debug = false // true 是连地服务端本地false 是连接线上
const debug = true // true 是连地服务端本地false 是连接线上
const development = {
DOMAIN: 'http://192.168.1.60:8094',
MQTT_OPTIONS: {
clientId: '',
connectTimeout: 15000,
username: 'admin',
password: 'admin',
}
domain: 'http://pqmcc.com:8040',
devCode: "2aaecd0b124df819eda75e639a1f91fd",
key: "f81804778c89c779"
}
const production = {
DOMAIN: 'http://192.168.1.60:8094',
MQTT_OPTIONS: {
clientId: '',
connectTimeout: 15000,
username: 'admin',
password: 'admin',
}
domain: 'http://192.168.1.60:8094',
}
const config = debug ? development : production
// #ifdef H5
if (process.env.NODE_ENV === 'development') {
config.DOMAIN = '/api'
config.domain = '/api'
} else {
config.DOMAIN = window.location.origin
config.domain = window.location.origin
}
// #endif

5988
common/js/crypto.js Normal file

File diff suppressed because it is too large Load Diff

24
common/js/des.js Normal file
View File

@@ -0,0 +1,24 @@
import CryptoJS from '../js/crypto.js'
// DES加密
export const encryptDes = (message, key) => {
const keyHex = CryptoJS.enc.Utf8.parse(key);
const encrypted = CryptoJS.DES.encrypt(message, keyHex, {
mode: CryptoJS.mode.ECB,
padding: CryptoJS.pad.Pkcs7
});
return encrypted.toString();
}
// DES解密
export const decryptDes = (ciphertext, key) => {
const keyHex = CryptoJS.enc.Utf8.parse(key);
// direct decrypt ciphertext
const decrypted = CryptoJS.DES.decrypt({
ciphertext: CryptoJS.enc.Base64.parse(ciphertext)
}, keyHex, {
mode: CryptoJS.mode.ECB,
padding: CryptoJS.pad.Pkcs7
});
return decrypted.toString(CryptoJS.enc.Utf8);
}

View File

@@ -30,16 +30,12 @@ export default (options = {}) => {
},
method: options.method || 'GET',
success: async (res) => {
console.warn(res);
if (options.url.indexOf('/org/login/valid') > -1) {
uni.setStorageSync('Cookie', res.header['Set-Cookie']);
}
if (arr.indexOf(options.url) > -1) {
arr.splice(arr.indexOf(options.url), 1)
}
if (res.data.isOk === false) {
reject(res.data)
if (res.data.resultCode !== 10000) {
errHandler(res.data)
reject(res.data)
} else {
reslove(res.data)
}
@@ -66,7 +62,7 @@ export default (options = {}) => {
* @param {Number} code 错误码
*/
function errHandler (res) {
switch (res.code) {
switch (res.resultCode) {
case '401':
// #ifdef MP
uni.removeStorageSync('Cookie');

View File

@@ -196,6 +196,10 @@ const loadConfig = (call, need_fresh = false) => {
})
}
export default {
validatePhoneNumber,
toast,