更新记录

1.0.0(2026-06-03)

1.插件的第一次发布,鸿蒙没有做真机测测试


平台兼容性

uni-app(4.36)

Vue2 Vue3 Chrome Safari app-vue app-nvue Android iOS 鸿蒙
√ √ × × √ √ 5.0 12 12
微信小程序 支付宝小程序 抖音小程序 百度小程序 快手小程序 京东小程序 鸿蒙元服务 QQ小程序 飞书小程序 小红书小程序 快应用-华为 快应用-联盟
× × × × × × × × × - × ×

uni-app x(4.36)

Chrome Safari Android Android插件版本 iOS iOS插件版本 鸿蒙 鸿蒙插件版本 微信小程序
× × 5.0 1.0.0 12 1.0.0 12 1.0.0 ×

其他

多语言 暗黑模式 宽屏模式 蒸汽模式
× × × √

tt-unionpay

【Android + iOS + Harmony】银联云闪付支付插件,基于银联支付控件 TN 模式,三平台统一接口。

注意:本插件仅支持 TN 模式(银联原生支付控件),不支持 Direct 直连模式。

目录


快速开始

安装

将 tt-unionpay 目录放入项目的 uni_modules/ 下。

使用

import * as unionpay from "@/uni_modules/tt-unionpay"

const up = unionpay.getTTUnionPaySDK()

// 1. 初始化
up.register({
    env: "00",                        // "00": 生产环境  "01": 测试环境
    urlScheme: "your-app-scheme",     // iOS / Harmony 的 URL Scheme
    success: () => {
        console.log("初始化成功")
    },
    fail: (err) => {
        console.error("初始化失败:", err.errMsg)
    }
})

// 2. 检查是否安装云闪付
if (up.isInstall()) {
    // 3. 发起支付(TN 模式)
    up.pay({
        mode: "tn",
        tn: "20260511000000001",      // 服务端返回的交易流水号
        success: (res) => {
            if (res.code === "success") {
                console.log("支付成功", res.rawData)
            } else if (res.code === "cancel") {
                console.log("用户取消")
            }
        },
        fail: (err) => {
            console.error("支付失败:", err.errCode, err.errMsg)
        },
        complete: (res) => {
            console.log("支付流程结束")
        }
    })
} else {
    console.log("未安装云闪付 App")
}

API 参考

getTTUnionPaySDK()

获取 SDK 实例,单例模式。

const up = unionpay.getTTUnionPaySDK()

isInstall()

检查是否安装了云闪付 App。

up.isInstall(): boolean

register(options)

初始化支付配置,建议在 App 启动后尽早调用。

up.register(options: TTUnionPayRegisterOptions): void
参数 类型 必填 说明
env "00" | "01" ✅ 生产 / 测试环境
urlScheme string ✅ iOS / Harmony URL Scheme(如 "uppaytest")
appScheme string? - Android 回调 Scheme(备用)
success callback - 初始化成功
fail callback - 初始化失败
complete callback - 始终回调

pay(options)

发起 TN 模式支付。

up.pay(options: TTUnionPayPayOptions): void
参数 类型 必填 说明
mode "tn" ✅ 固定为 "tn"
tn string ✅ 交易流水号(服务端获取)
success callback - 支付成功回调
fail callback - 支付失败回调
complete callback - 始终回调

平台集成

Android

Manifest 配置

在项目 AndroidManifest.xml 中添加:

<uses-permission android:name="android.permission.INTERNET" />

<application android:usesCleartextTraffic="true">
    <activity
        android:name="com.unionpay.uppay.PayActivity"
        android:exported="false"
        android:launchMode="singleTask"
        android:screenOrientation="portrait" />
</application>

回调处理

在 MainActivity 中转发 onActivityResult:

import { handleActivityResult } from "@/uni_modules/tt-unionpay"

override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
    super.onActivityResult(requestCode, resultCode, data)
    handleActivityResult(requestCode, resultCode, data)
}

iOS

Info.plist 配置

<key>CFBundleURLTypes</key>
<array>
    <dict>
        <key>CFBundleURLSchemes</key>
        <array>
            <string>YourAppScheme</string>
        </array>
    </dict>
</array>

<key>LSApplicationQueriesSchemes</key>
<array>
    <string>uppaywallet</string>
    <string>uppayx</string>
    <string>uppay</string>
</array>

<key>NSAppTransportSecurity</key>
<dict>
    <key>NSAllowsArbitraryLoads</key>
    <true/>
</dict>

回调处理

插件内置 UnionPayHookProxy,自动拦截支付回调 URL,无需额外代码。

Harmony

回调处理

在 EntryAbility 的 onNewWant 中转发:

import { handleWant } from "@/uni_modules/tt-unionpay"

export default class EntryAbility extends UIAbility {
    onNewWant(want: Want, launchParam: AbilityConstant.LaunchParam): void {
        handleWant(want)
    }
}

类型定义

TTUnionPayPaySuccess

支付成功回调参数:

字段 类型 说明
code "success" | "cancel" | "fail" | "unknown" 支付结果码
rawData string 原始返回数据(JSON / 键值对)
message string \| null 附加消息
sign string \| null 签名数据(鸿蒙验签用)

TTUnionPayPayFail

支付失败回调参数(IUniError):

字段 类型 说明
errCode number 错误码
errMsg string 错误描述
rawError any? 原始错误

平台差异

特性 Android iOS Harmony
TN 模式 ✅ ✅ ✅
回调方式 onActivityResult OpenURL (HookProxy) onNewWant

错误码

错误码 说明
201 参数非法(urlScheme 为空)
202 不支持的支付模式(仅支持 "tn")
204 tn 不能为空
999 其他错误(获取上下文失败、重复调用等)

安全建议

  1. 服务端下单:TN 由服务端向银联下单后返回,客户端不持有商户密钥
  2. 异步通知确认:支付成功回调仅表示客户端收到结果,最终状态建议通过服务端 notifyUrl 确认
  3. 订单幂等:使用唯一订单号,防止重复支付
  4. 生产环境验证:切换 env: "00" 前完成测试环境验证

隐私、权限声明

1. 本插件需要申请的系统权限列表:

INTERNET

2. 本插件采集的数据、发送的服务器地址、以及数据用途说明:

支付信息(金额、订单号等)

3. 本插件是否包含广告,如包含需详细说明广告表达方式、展示频率:

无

暂无用户评论。