Files
property-resident-side/property-uniapp-project/uni_modules/unionpay-full/utssdk/app-android/index.uts
2026-06-04 17:55:18 +08:00

91 lines
2.8 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { startPayOptions } from '../../interface.uts'
// UMS SDK 核心类包名
const UMS_PKG = 'com.chinaums.pppay.unify'
/**
* 检查是否安装云闪付App
* 【注】UMS SDK 未提供安装检测接口,默认返回 true
*/
export function checkWalletInstalled(): boolean {
return true
}
/**
* 发起支付(云闪付)
* 调用 UMS SDK 的 UnifyPayPlugin 进行支付
*/
export function startPay(options: startPayOptions): void {
try {
const activity = UTSAndroid.getUniActivity()
if (activity == null) {
options.callback({ code: -1, msg: '获取当前 Activity 失败' })
return
}
// 动态导入 UMS SDK 类
const UnifyPayPlugin = plus.android.importClass(UMS_PKG + '.UnifyPayPlugin')
const UnifyPayListener = plus.android.importClass(UMS_PKG + '.UnifyPayListener')
// payData后端返回的 appPayRequest 对应的 JSON 字符串
// 如果后端返回的 tn 字段已经是 JSON 格式,直接传入即可
const payData = options.tn
// 创建支付结果监听器
const listener = new UnifyPayListener({
onResult: (resultCode: string, resultInfo: string) => {
console.log('UMS 支付结果:', resultCode, resultInfo)
let code = -1
let msg = resultInfo || '支付失败'
if (resultCode === '0000' || resultCode === '0') {
code = 0
msg = '支付成功'
} else if (resultCode === '-2' || resultCode === '2000' || resultCode === '2001') {
code = -2
msg = '支付已取消'
} else if (resultCode === '1') {
code = 1
msg = '支付处理中'
}
options.callback({
code: code,
msg: msg,
data: { resultCode: resultCode, resultInfo: resultInfo }
})
}
})
// 根据支付渠道调用不同方法
const channel = options.channel || 'unionpay'
if (channel === 'unionpay') {
// 云闪付
UnifyPayPlugin.cloudPay(activity, 'uppayfull', payData, listener)
} else if (channel === 'alipay') {
// 支付宝间联支付
// 如果 aliSafePay 方法不存在,请尝试改用 pay 方法:
// UnifyPayPlugin.pay(activity, 'ALIPAY', payData, listener)
UnifyPayPlugin.aliSafePay(activity, 'uppayfull', payData, listener)
} else if (channel === 'weixin') {
// 微信支付需申请微信SDK后才能使用
// UnifyPayPlugin.pay(activity, 'WEIXIN', payData, listener)
options.callback({ code: -1, msg: '微信支付暂不支持请先申请微信SDK' })
} else {
options.callback({ code: -1, msg: '未知支付渠道: ' + channel })
}
} catch (e) {
console.error('UMS 支付调用异常:', e)
options.callback({ code: -1, msg: '支付调用异常: ' + (e.message || String(e)) })
}
}
/**
* 获取直通银行 App 列表
* 【注】UMS SDK 暂未实现此功能
*/
export function getDirectApps(callback: Function): void {
callback({ code: 0, msg: 'UMS SDK 暂不支持此功能', data: [] })
}