You need to sign in or sign up before continuing.
提交 c1dff489 编写于 作者: VK1688's avatar VK1688

feat: 调整uni-pay示例

上级 f5dd08a5
<template> <template>
<view class="app"> <view class="app">
<view v-if="errMsg != ''">
<text class="err-msg">注意:{{ errMsg }}</text>
</view>
<view> <view>
<view class="label">支付单号:</view> <view class="label">支付单号:</view>
<view><input class="input" v-model="out_trade_no" placeholder="点击发起支付会自动生成" /></view> <view><input class="input" v-model="out_trade_no" placeholder="点击发起支付会自动生成" /></view>
...@@ -121,11 +124,14 @@ ...@@ -121,11 +124,14 @@
adpid: "1000000001", // uni-ad的广告位id adpid: "1000000001", // uni-ad的广告位id
transaction_id: "", // 查询订单接口的查询条件 transaction_id: "", // 查询订单接口的查询条件
getOrderRes: {} as UTSJSONObject, // 查询订单支付成功后的返回值 getOrderRes: {} as UTSJSONObject, // 查询订单支付成功后的返回值
useUniCloud: true,
errMsg: ""
} }
}, },
onLoad(options) { onLoad(options) {
console.log('onLoad: ', options) console.log('onLoad: ', options);
this.useUniCloud = this.checkUniCloud();
// #ifdef H5 // #ifdef H5
// 微信公众号特殊逻辑开始----------------------------------------------------------- // 微信公众号特殊逻辑开始-----------------------------------------------------------
// 以下代码仅为获取openid,正常你自己项目应该是登录后才能支付,登录后已经拿到openid,无需编写下面的代码 // 以下代码仅为获取openid,正常你自己项目应该是登录后才能支付,登录后已经拿到openid,无需编写下面的代码
...@@ -156,7 +162,7 @@ ...@@ -156,7 +162,7 @@
// 微信公众号特殊逻辑结束----------------------------------------------------------- // 微信公众号特殊逻辑结束-----------------------------------------------------------
// #endif // #endif
}, },
methods: { methods: {
/** /**
* 发起支付(唤起收银台,如果只有一种支付方式,则收银台不会弹出来,会直接使用此支付方式) * 发起支付(唤起收银台,如果只有一种支付方式,则收银台不会弹出来,会直接使用此支付方式)
* 在调用此api前,你应该先创建自己的业务系统订单,并获得订单号 order_no,把order_no当参数传给此api,而示例中为了简化跟支付插件无关的代码,这里直接已时间戳生成了order_no * 在调用此api前,你应该先创建自己的业务系统订单,并获得订单号 order_no,把order_no当参数传给此api,而示例中为了简化跟支付插件无关的代码,这里直接已时间戳生成了order_no
...@@ -407,6 +413,23 @@ ...@@ -407,6 +413,23 @@
} else { } else {
return (totalFee / 100).toFixed(2) return (totalFee / 100).toFixed(2)
} }
},
checkUniCloud() : boolean {
let useUniCloud = false;
if (typeof uniCloud != 'undefined' && typeof uniCloud.config == "object" && uniCloud.config.spaceId != "") {
useUniCloud = true;
}
if (!useUniCloud) {
let errMsg = "本示例依赖 uniCloud,请先关联服务空间,填写正确的支付配置,支付配置文件地址:/uni_modules/uni-config-center/uniCloud/cloudfunctions/common/uni-config-center/uni-pay/config.js";
this.errMsg = errMsg;
uni.showModal({
title: "提示",
content: errMsg,
showCancel: false
})
console.error(errMsg);
}
return useUniCloud;
} }
}, },
computed: { computed: {
...@@ -524,5 +547,10 @@ ...@@ -524,5 +547,10 @@
.text { .text {
font-size: 24rpx; font-size: 24rpx;
} }
}
.err-msg {
color: red;
font-size: 14px;
} }
</style> </style>
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册