fix: 修复抖音支付双端UTS编译兼容
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"id": "tb-douyin-pay",
|
||||
"displayName": "TB 抖音支付",
|
||||
"version": "0.2.0",
|
||||
"version": "0.2.1",
|
||||
"description": "独立实现的抖音支付官方 SDK UTS 桥接",
|
||||
"engines": { "HBuilderX": ">=4.36.0" },
|
||||
"uni_modules": {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { PayOptions, PayCallback, PayResult } from './interface.uts'
|
||||
import { PayInfo, PayOptions, PayCallback, PayResult } from './interface.uts'
|
||||
|
||||
let appId = ''
|
||||
let busy = false
|
||||
@@ -24,12 +24,25 @@ export function invoke(options: PayOptions, callback: PayCallback,
|
||||
return
|
||||
}
|
||||
let valid = false
|
||||
let payload: string = ''
|
||||
try {
|
||||
const info = options.payInfo
|
||||
const values = [info.appid, info.partnerid, info.prepayid, info.package, info.noncestr, info.timestamp, info.sign]
|
||||
valid = appId.length > 0 && info.appid == appId && info.package == 'Sign=DYPay'
|
||||
values.forEach((value: string) => { if (value.trim().length == 0) valid = false })
|
||||
if (!/^[0-9]{1,10}$/.test(info.timestamp) || info.noncestr.length > 32) valid = false
|
||||
// Swift infers an optional from the generated PayInfo! property unless
|
||||
// the local type is explicit. Check before narrowing on both platforms.
|
||||
const candidate: PayInfo | null = options.payInfo
|
||||
if (candidate != null) {
|
||||
const info: PayInfo = candidate as PayInfo
|
||||
const values = new Array<string>(info.appid ?? '', info.partnerid ?? '', info.prepayid ?? '',
|
||||
info.package ?? '', info.noncestr ?? '', info.timestamp ?? '', info.sign ?? '')
|
||||
valid = appId.length > 0 && values[0] == appId && values[3] == 'Sign=DYPay'
|
||||
values.forEach((value: string) => { if (value.trim().length == 0) valid = false })
|
||||
if (!/^[0-9]{1,10}$/.test(values[5]) || values[4].length > 32) valid = false
|
||||
// UTS JSON.stringify returns string | null. Serialize before taking the
|
||||
// payment lock, and never pass a nullable value to a native String API.
|
||||
if (valid) {
|
||||
payload = JSON.stringify(info) ?? ''
|
||||
if (payload.length == 0) valid = false
|
||||
}
|
||||
}
|
||||
} catch (e) { valid = false }
|
||||
if (!valid) {
|
||||
const result: PayResult = { resultCode: '-1', errorMsg: '支付参数不完整或 AppID 不匹配,请重新下单', needsQuery: false }
|
||||
@@ -61,7 +74,7 @@ export function invoke(options: PayOptions, callback: PayCallback,
|
||||
callback(result)
|
||||
}
|
||||
try {
|
||||
nativePay(JSON.stringify(options.payInfo), options.showLoading ?? true, complete)
|
||||
nativePay(payload, options.showLoading ?? true, complete)
|
||||
} catch (e) {
|
||||
complete('{"resultCode":"2","errorMsg":"无法调用支付 SDK,请查询订单后重试"}')
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user