feat:支付方式
This commit is contained in:
1 parent
99e4f28b3e
commit
6fc521b8bd
4 files changed
+14
-259
No files matched your search
+7
-50
@@ -7,7 +7,6 @@ interface JsonpOptions {
|
||||
timeout?: number
|
||||
callbackName?: string
|
||||
callbackParam?: string
|
||||
debug?: boolean
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -18,17 +17,11 @@ interface JsonpOptions {
|
||||
*/
|
||||
export function jsonp(url: string, options: JsonpOptions = {}): Promise<any> {
|
||||
const {
|
||||
timeout = 15000,
|
||||
timeout = 10000,
|
||||
callbackName = `jsonp_callback_${Date.now()}_${Math.random().toString(36).substr(2)}`,
|
||||
callbackParam = "callback",
|
||||
debug = false
|
||||
} = options
|
||||
|
||||
if (debug) {
|
||||
console.log('[JSONP] 发起请求:', url)
|
||||
console.log('[JSONP] 回调函数名:', callbackName)
|
||||
}
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
// 创建 script 标签
|
||||
const script = document.createElement("script")
|
||||
@@ -36,11 +29,7 @@ export function jsonp(url: string, options: JsonpOptions = {}): Promise<any> {
|
||||
// 设置超时
|
||||
const timer = setTimeout(() => {
|
||||
cleanup()
|
||||
const error = new Error(`JSONP request timeout after ${timeout}ms`)
|
||||
if (debug) {
|
||||
console.error('[JSONP] 请求超时:', error)
|
||||
}
|
||||
reject(error)
|
||||
reject(new Error("JSONP request timeout"))
|
||||
}, timeout)
|
||||
|
||||
// 清理函数
|
||||
@@ -56,34 +45,22 @@ export function jsonp(url: string, options: JsonpOptions = {}): Promise<any> {
|
||||
|
||||
// 设置全局回调函数
|
||||
;(window as any)[callbackName] = (data: any) => {
|
||||
if (debug) {
|
||||
console.log('[JSONP] 收到响应:', data)
|
||||
}
|
||||
cleanup()
|
||||
resolve(data)
|
||||
}
|
||||
|
||||
// 处理错误
|
||||
script.onerror = (event) => {
|
||||
script.onerror = () => {
|
||||
cleanup()
|
||||
const error = new Error("JSONP request failed to load script")
|
||||
if (debug) {
|
||||
console.error('[JSONP] 脚本加载失败:', event)
|
||||
}
|
||||
reject(error)
|
||||
reject(new Error("JSONP request failed"))
|
||||
}
|
||||
|
||||
// 构建请求 URL
|
||||
const separator = url.includes("?") ? "&" : "?"
|
||||
const requestUrl = `${url}${separator}${callbackParam}=${callbackName}`
|
||||
|
||||
if (debug) {
|
||||
console.log('[JSONP] 完整请求URL:', requestUrl)
|
||||
}
|
||||
|
||||
// 发起请求
|
||||
script.src = requestUrl
|
||||
script.async = true
|
||||
document.head.appendChild(script)
|
||||
})
|
||||
}
|
||||
@@ -93,11 +70,9 @@ export function jsonp(url: string, options: JsonpOptions = {}): Promise<any> {
|
||||
*/
|
||||
export class TencentMapAPI {
|
||||
private apiKey: string
|
||||
private debug: boolean
|
||||
|
||||
constructor(apiKey: string, debug: boolean = false) {
|
||||
constructor(apiKey: string) {
|
||||
this.apiKey = apiKey
|
||||
this.debug = debug
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -109,17 +84,8 @@ export class TencentMapAPI {
|
||||
async reverseGeocode(lat: number, lng: number): Promise<any> {
|
||||
const url = `https://apis.map.qq.com/ws/geocoder/v1/?location=${lat},${lng}&key=${this.apiKey}&get_poi=1&output=jsonp`
|
||||
|
||||
if (this.debug) {
|
||||
console.log('[TencentMapAPI] 逆地址解析请求:', { lat, lng })
|
||||
}
|
||||
|
||||
try {
|
||||
const data = await jsonp(url, { debug: this.debug })
|
||||
|
||||
if (this.debug) {
|
||||
console.log('[TencentMapAPI] 逆地址解析响应:', data)
|
||||
}
|
||||
|
||||
const data = await jsonp(url)
|
||||
return data
|
||||
} catch (error) {
|
||||
console.error("逆地址解析失败:", error)
|
||||
@@ -138,17 +104,8 @@ export class TencentMapAPI {
|
||||
keyword,
|
||||
)}&page_size=10&page_index=1&key=${this.apiKey}&output=jsonp`
|
||||
|
||||
if (this.debug) {
|
||||
console.log('[TencentMapAPI] 地址搜索请求:', { keyword, boundary })
|
||||
}
|
||||
|
||||
try {
|
||||
const data = await jsonp(url, { debug: this.debug })
|
||||
|
||||
if (this.debug) {
|
||||
console.log('[TencentMapAPI] 地址搜索响应:', data)
|
||||
}
|
||||
|
||||
const data = await jsonp(url)
|
||||
return data
|
||||
} catch (error) {
|
||||
console.error("地址搜索失败:", error)
|
||||
|
||||
Reference in new issue
Block a user