This commit is contained in:
parent
d394d8d8f2
commit
e2ef445462
|
|
@ -38,14 +38,14 @@ export type OrderStatus = {
|
||||||
|
|
||||||
// goods
|
// goods
|
||||||
export function getGoods() {
|
export function getGoods() {
|
||||||
return get<ApiResponse<GoodsItem[]>>('/api/order/goods')
|
return get<ApiResponse<GoodsItem[]>>('/api/order/goods', undefined, { tokenType: 'permanent' })
|
||||||
}
|
}
|
||||||
|
|
||||||
// order
|
// order
|
||||||
export function order(payload: OrderPayload) {
|
export function order(payload: OrderPayload) {
|
||||||
return post<ApiResponse<OrderResult>>('/api/order', payload)
|
return post<ApiResponse<OrderResult>>('/api/order', payload, { tokenType: 'permanent' })
|
||||||
}
|
}
|
||||||
|
|
||||||
export function checkOrder(orderId: string) {
|
export function checkOrder(orderId: string) {
|
||||||
return get<ApiResponse<OrderStatus>>('/api/order', { order_id: orderId })
|
return get<ApiResponse<OrderStatus>>('/api/order', { order_id: orderId }, { tokenType: 'permanent' })
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,13 +17,13 @@ export type PackageInfo = {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getConfig() {
|
export function getConfig() {
|
||||||
return get<ApiResponse<UserConfig>>('/api/user/config')
|
return get<ApiResponse<UserConfig>>('/api/user/config', undefined, { tokenType: 'permanent' })
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getService() {
|
export function getService(tokenType: 'permanent' | 'temporary') {
|
||||||
return get<ApiResponse<ServiceConfig>>('/api/weixin/service')
|
return get<ApiResponse<ServiceConfig>>('/api/weixin/service', undefined, { tokenType })
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getPackage() {
|
export function getPackage() {
|
||||||
return get<ApiResponse<PackageInfo>>('/api/package')
|
return get<ApiResponse<PackageInfo>>('/api/package', undefined, { tokenType: 'temporary' })
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -224,7 +224,7 @@ function PayPage() {
|
||||||
|
|
||||||
async function initServiceUrl() {
|
async function initServiceUrl() {
|
||||||
try {
|
try {
|
||||||
const { data } = await getService()
|
const { data } = await getService('permanent')
|
||||||
const nextServiceUrl = data['kf.address']
|
const nextServiceUrl = data['kf.address']
|
||||||
|
|
||||||
if (isMounted && typeof nextServiceUrl === 'string') {
|
if (isMounted && typeof nextServiceUrl === 'string') {
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ function Twins({ installUrl }: TwinsProps) {
|
||||||
|
|
||||||
async function initTwinsConfig() {
|
async function initTwinsConfig() {
|
||||||
try {
|
try {
|
||||||
const { data: service } = await getService()
|
const { data: service } = await getService('temporary')
|
||||||
const nextServiceUrl = service['kf.address']
|
const nextServiceUrl = service['kf.address']
|
||||||
|
|
||||||
if (isMounted && typeof nextServiceUrl === 'string') {
|
if (isMounted && typeof nextServiceUrl === 'string') {
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ type RequestParams = Record<string, RequestValue>
|
||||||
|
|
||||||
type RequestOptions = Omit<RequestInit, 'body' | 'method'> & {
|
type RequestOptions = Omit<RequestInit, 'body' | 'method'> & {
|
||||||
body?: BodyInit | Record<string, unknown> | null
|
body?: BodyInit | Record<string, unknown> | null
|
||||||
|
tokenType?: 'permanent' | 'temporary'
|
||||||
}
|
}
|
||||||
|
|
||||||
type ApiResponseLike = {
|
type ApiResponseLike = {
|
||||||
|
|
@ -155,7 +156,7 @@ function toHeaderValue(value: RequestPrimitive) {
|
||||||
return value === undefined || value === null ? '' : String(value)
|
return value === undefined || value === null ? '' : String(value)
|
||||||
}
|
}
|
||||||
|
|
||||||
function setCommonHeaders(headers: Headers) {
|
function setCommonHeaders(headers: Headers, tokenType: RequestOptions['tokenType']) {
|
||||||
const params = getSearchParams()
|
const params = getSearchParams()
|
||||||
const sysInfo = mergeDefinedSysInfo(getBrowserInfo(), getClientSysInfo())
|
const sysInfo = mergeDefinedSysInfo(getBrowserInfo(), getClientSysInfo())
|
||||||
|
|
||||||
|
|
@ -167,9 +168,9 @@ function setCommonHeaders(headers: Headers) {
|
||||||
headers.set('x-channel', toHeaderValue(sysInfo.channel))
|
headers.set('x-channel', toHeaderValue(sysInfo.channel))
|
||||||
headers.set('x-click-id', toHeaderValue(params.get('bd_vid') ?? sysInfo.bd_vid ?? ''))
|
headers.set('x-click-id', toHeaderValue(params.get('bd_vid') ?? sysInfo.bd_vid ?? ''))
|
||||||
headers.set('x-app-id', toHeaderValue(__APP_ID__))
|
headers.set('x-app-id', toHeaderValue(__APP_ID__))
|
||||||
const token =
|
const tokenStorageKey = tokenType === 'temporary' ? TEMP_TOKEN_STORAGE_KEY : TOKEN_STORAGE_KEY
|
||||||
window.sessionStorage.getItem(TOKEN_STORAGE_KEY) || window.sessionStorage.getItem(TEMP_TOKEN_STORAGE_KEY)
|
const token = window.sessionStorage.getItem(tokenStorageKey)
|
||||||
if(token){
|
if (token) {
|
||||||
headers.set('x-token', token)
|
headers.set('x-token', token)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -273,9 +274,9 @@ function getBusinessErrorMessage(message: unknown) {
|
||||||
}
|
}
|
||||||
|
|
||||||
async function request<T>(url: string, method: string, options: RequestOptions = {}) {
|
async function request<T>(url: string, method: string, options: RequestOptions = {}) {
|
||||||
const { body, headers, ...restOptions } = options
|
const { body, headers, tokenType, ...restOptions } = options
|
||||||
const requestHeaders = new Headers(headers)
|
const requestHeaders = new Headers(headers)
|
||||||
setCommonHeaders(requestHeaders)
|
setCommonHeaders(requestHeaders, tokenType)
|
||||||
let requestBody: BodyInit | null | undefined
|
let requestBody: BodyInit | null | undefined
|
||||||
|
|
||||||
if (isPlainObject(body)) {
|
if (isPlainObject(body)) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue