完成Salon小程序合规整改
This commit is contained in:
@@ -1,36 +0,0 @@
|
||||
const DEVICE_ID_KEY = 'jayucloud-salon_device_id'
|
||||
|
||||
function createDeviceId() {
|
||||
const randomText = Math.random().toString(36).slice(2, 10)
|
||||
return `manager-mini-device-${Date.now()}-${randomText}`
|
||||
}
|
||||
|
||||
function assertStorageApi() {
|
||||
if (typeof wx === 'undefined' || typeof wx.getStorageSync !== 'function' || typeof wx.setStorageSync !== 'function') {
|
||||
throw new Error('wx storage API is required to build request signature device id')
|
||||
}
|
||||
}
|
||||
|
||||
function readDeviceId() {
|
||||
assertStorageApi()
|
||||
return wx.getStorageSync(DEVICE_ID_KEY) || ''
|
||||
}
|
||||
|
||||
function writeDeviceId(value) {
|
||||
assertStorageApi()
|
||||
wx.setStorageSync(DEVICE_ID_KEY, value)
|
||||
}
|
||||
|
||||
function getDeviceId() {
|
||||
const current = readDeviceId()
|
||||
if (current) {
|
||||
return current
|
||||
}
|
||||
const next = createDeviceId()
|
||||
writeDeviceId(next)
|
||||
return next
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
getDeviceId
|
||||
}
|
||||
@@ -1,9 +1,7 @@
|
||||
const { ADMIN_API_BASE_URL, REQUEST_TIMEOUT, ENABLE_REQUEST_SIGNING } = require('./config')
|
||||
const auth = require('./auth')
|
||||
const { getDeviceId } = require('./device')
|
||||
const { sha256Hex, hmacSha256Hex, buildCanonicalParams, buildJsonPayload, randomNonce } = require('./crypto')
|
||||
|
||||
const DEVICE_ID_HEADER = 'X-Device-Id'
|
||||
const HEADER_TIMESTAMP = 'X-Timestamp'
|
||||
const HEADER_NONCE = 'X-Nonce'
|
||||
const HEADER_SIGNATURE = 'X-Signature'
|
||||
@@ -123,9 +121,7 @@ function isAuthFreePath(url) {
|
||||
}
|
||||
|
||||
function buildSignatureHeaders(options) {
|
||||
const headers = {
|
||||
[DEVICE_ID_HEADER]: getDeviceId()
|
||||
}
|
||||
const headers = {}
|
||||
const method = String(options.method || 'GET').toUpperCase()
|
||||
const accessToken = auth.getAccessToken()
|
||||
if (accessToken && !isAuthFreePath(options.url)) {
|
||||
|
||||
Reference in New Issue
Block a user