简体中文
请求支付
名称 | 类型 | 必填 | 默认值 | 描述 | ||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options | RequestPaymentOptions | 是 | - | |||||||||||||||||||||||||||||||
|
名称 | 类型 | 必备 | 默认值 | 描述 |
---|---|---|---|---|
data | any | null | 否 | - |
名称 | 类型 | 必备 | 默认值 | 描述 |
---|---|---|---|---|
errCode | 700710 | 700711 | 700712 | 700713 | 700714 | 700715 | 700716 | 是 | - | 错误码 - 700710 正在处理中,支付结果未知(有可能已经支付成功),请查询商家订单列表中订单的支付状态 - 700711 订单支付失败。 - 700712 重复请求。 - 700713 用户中途取消。 - 700714 网络连接出错。 - 700715 支付结果未知(有可能已经支付成功),请查询商家订单列表中订单的支付状态。 - 700716 其它支付错误。 |
errSubject | string | 是 | - | 统一错误主题(模块)名称 |
data | any | null | 否 | - | 错误信息中包含的数据 |
cause | Error | null | 否 | - | 源错误信息,可以包含多个错误,详见SourceError |
errMsg | string | 是 | - | - |
app_id=2015052600090779&biz_content=%7B%22timeout_express%22%3A%2230m%22%2C%22seller_id%22%3A%22%22%2C%22product_code%
22%3A%22QUICK_MSECURITY_PAY%22%2C%22total_amount%22%3A%220.02%22%2C%22subject%22%3A%221%22%2C%22body%22%3A%22%E6%88%
91%E6%98%AF%E6%B5%8B%E8%AF%95%E6%95%B0%E6%8D%AE%22
%2C%22out_trade_no%22%3A%22314VYGIAGG7ZOYY%22%7D&charset=utf-8&method=alipay.trade.app.pay&sign_type=R
SA2×tamp=2016-08-15%2012%3A12%3A15&version=1.0&sign=MsbylYkCzlfYLy9PeRwUUIg9nZPeN9SfXPNavUCroGKR5Kqvx0nEnd3eRmKxJuthNUx4ERCXe552
EV9PfwexqW%2B1wbKOdYtDIb4%2B7PL3Pc94RZL0zKaWcaY3tSL89%2FuAVUsQuFqEJd
hIukuKygrXucvejOUgTCfoUdwTi7z%2BZzQ%3D<br>
[更多详情参考支付宝官方文档]
{
"appid":"wxd569c7238830733b",
"noncestr":"6N47VnR42bqIm4xq",
"package":"Sign=WXPay",
"partnerid":"1230636401",
"prepayid":"wx26174750316675ac54b89c224eb3250000",
"timestamp":1711446470,
"sign":"EE987459B9CFF6462462147130110D31"
}
[更多详情参考微信官方文档]
Android | iOS | web |
---|---|---|
4.02 | x | x |
支付宝错误码 | 错误信息 |
---|---|
-9000 | 订单支付成功 |
-8000 | 正在处理中,支付结果未知(有可能已经支付成功),请查询商家订单列表中订单的支付状态 |
-4000 | 订单支付失败 |
-5000 | 重复请求 |
-6001 | 用户中途取消 |
-6002 | 网络连接出错 |
-6004 | 支付结果未知(有可能已经支付成功),请查询商家订单列表中订单的支付状态 |
其它 | 其它支付错误 |
注意:
import WXAPIFactory from 'com.tencent.mm.opensdk.openapi.WXAPIFactory';
let api = WXAPIFactory.createWXAPI(UTSAndroid.getTopPageActivity(), '');
api!.isWXAppInstalled()
{
"app": {
"distribute": {
"modules": {
"uni-payment": {
"alipay": {},//支付宝支付
"wxpay": {}//微信支付
}
}
}
}
}
[更多详情参考模块配置]
<template>
<page-head title="发起支付"></page-head>
<template v-if="providerList.length > 0">
<button style="margin-top: 20px;" type="primary" v-for="(item,index) in providerList" :key="index"
@click="requestPayment(item)">{{item.name}}支付</button>
</template>
</template>
<script>
export type PayItem = { id : string, name : string }
export default {
data() {
return {
btnText: "支付宝支付",
btnType: "primary",
orderInfo: "",
errorCode: 0,
errorMsg: "",
complete: false,
providerList: [] as PayItem[]
}
},
onLoad: function () {
uni.getProvider({
service: "payment",
success: (e) => {
console.log("payment success:" + JSON.stringify(e));
let array = e.provider as string[]
array.forEach((value : string) => {
switch (value) {
case 'alipay':
this.providerList.push({
name: '支付宝',
id: "alipay",
} as PayItem);
break;
case 'wxpay':
this.providerList.push({
name: '微信',
id: "wxpay",
} as PayItem);
break;
default:
break;
}
})
},
fail: (e) => {
console.log("获取支付通道失败:", e);
}
});
},
methods: {
requestPayment(e : PayItem) {
const provider = e.id
if (provider == "alipay") {
this.payAli()
} else if (provider == "wxpay") {
this.payWX()
}
},
payAli() {
uni.showLoading({
title: "请求中..."
})
uni.request({
url: 'https://demo.dcloud.net.cn/payment/alipay/?total=0.01',
method: 'GET',
timeout: 6000,
success: (res) => {
this.orderInfo = JSON.stringify(res.data);
console.log("====" + this.orderInfo)
uni.hideLoading()
uni.requestPayment({
provider: "alipay",
orderInfo: res.data as string,
fail: (res) => {
console.log(JSON.stringify(res))
this.errorCode = res.errCode
uni.showToast({
icon: 'error',
title: 'errorCode:' + this.errorCode
});
},
success: (res) => {
console.log(JSON.stringify(res))
uni.showToast({
icon: 'success',
title: '支付成功'
});
}
})
},
fail: (e) => {
console.log(e)
uni.hideLoading()
},
});
},
payWX() {
uni.showLoading({
title: "请求中..."
})
let url = 'https://demo.dcloud.net.cn/payment/wxpayv3.__UNI__uniappx/?total=1'
const res = uni.getAppBaseInfo();
if (res.packageName == 'io.dcloud.hellouniappx') {//hello uniappx
url = 'https://demo.dcloud.net.cn/payment/wxpayv3.__UNI__HelloUniAppX/?total=1'
}
uni.request({
url: url,
method: 'GET',
timeout: 6000,
header: {
"Content-Type": "application/json"
} as UTSJSONObject,
success: (res) => {
console.log(res.data)
uni.hideLoading()
uni.requestPayment({
provider: "wxpay",
orderInfo: JSON.stringify(res.data),
fail: (res) => {
console.log(JSON.stringify(res))
this.errorCode = res.errCode
uni.showToast({
duration: 5000,
icon: 'error',
title: 'errorCode:' + this.errorCode,
});
},
success: (res) => {
console.log(JSON.stringify(res))
uni.showToast({
duration: 5000,
icon: 'success',
title: '支付成功'
});
}
})
},
fail: (res) => {
uni.hideLoading()
console.log(res)
},
});
},
//自动化测试使用
jest_pay() {
uni.requestPayment({
provider: "alipay",
orderInfo: this.orderInfo,
fail: (res : RequestPaymentFail) => {
this.errorCode = res.errCode
this.complete = true
},
success: (res : RequestPaymentSuccess) => {
console.log(JSON.stringify(res))
this.complete = true
}
} as RequestPaymentOptions)
}
}
}
</script>
<style>
</style>
名称 | 类型 | 必备 | 默认值 | 描述 |
---|---|---|---|---|
errMsg | string | 是 | - | 错误信息 |