提交 0f96983c 编写于 作者: zhaofengliang920817's avatar zhaofengliang920817

调整 virtualPayment 示例,规避 Apple Store 审核 失败的问题。

上级 6ba98427
......@@ -3,7 +3,7 @@
<view class="uni-list">
<radio-group @change="applePriceChange">
<view class="uni-list-cell" v-for="(item, index) in productList" :key="index">
<radio :value="item['product_id']" :checked="product_id == item['product_id']"/>
<radio :value="item['product_id']" :checked="product_id == item['product_id']" />
<view class="price" @click="applePriceClick(item)">{{item['title']}} {{item['goods_price']}}元</view>
</view>
</radio-group>
......@@ -13,7 +13,9 @@
</view>
<!-- 统一支付组件 -->
<uni-pay ref="payRef" :debug="true" :adpid="adpid" return-url="/pages/API/request-payment/request-payment/order-detail" @mounted="onMounted" @success="onSuccess" @fail="onFail" @cancel="onCancel"></uni-pay>
<uni-pay ref="payRef" :debug="true" :adpid="adpid"
return-url="/pages/API/request-payment/request-payment/order-detail" @mounted="onMounted" @success="onSuccess"
@fail="onFail" @cancel="onCancel"></uni-pay>
</view>
</template>
......@@ -27,64 +29,68 @@
loading: false, // 支付按钮是否在loading中
disabled: true, // 支付按钮是否禁用
product_id: "", // 用户选择的商品id
product_id: "" // 用户选择的商品id
}
},
onLoad: function () {
},
onShow() {
},
onUnload() { },
computed: {
// 出售的苹果虚拟商品列表
productList: [
productList() {
return [
{
"description": "为DCloud提供的免费软件进行赞助",
"goods_price": 1, // 单价(元)
"buy_quantity": 1, // 数量(消耗性类型: 数量默认是1,最大值是10)
"product_id": "uniappx.consumable.sponsor_1",
"product_id": this.isDebug() ? "uniappx.consumable.sponsor_1" : "uniappx.consumable.sponsor1",
"title": "消耗性产品:赞助"
},
{
"description": "为DCloud提供的免费软件进行赞助",
"goods_price": 5, // 单价(元)
"buy_quantity": 1, // 数量(消耗性类型: 数量默认是1,最大值是10)
"product_id": "uniappx.consumable.sponsor_50",
"product_id": this.isDebug() ? "uniappx.consumable.sponsor_50" : "uniappx.consumable.sponsor50",
"title": "消耗性产品:赞助"
},
{
"description": "为DCloud提供的免费软件进行赞助",
"goods_price": 1, // 单价(元)
"buy_quantity": 1, // 数量(非消耗性: 数量只能是1,且一个该类型产品一个appleId只能购买一次)
"product_id": "uniappx.nonconsumable.sponsorskin_1",
"product_id": this.isDebug() ? "uniappx.nonconsumable.sponsorskin_1" : "uniappx.nonconsumable.sponsorskin1",
"title": "非消耗性产品: 赞助"
},
{
"description": "为DCloud提供的免费软件进行赞助",
"goods_price": 1, // 单价(元)
"buy_quantity": 1, // 数量(自动续期订阅产品: 数量只能是1)
"product_id": "uniappx.autorenewable.monthly_1",
"title": "自动续期订阅产品:每月定期赞助", // 注意自动续期订阅产品在沙盒模式下,实际周期会缩短到几分钟续期一次(即现实世界几分钟 = 沙盒世界1个月)
},
// {
// "description": "为DCloud提供的免费软件进行赞助",
// "goods_price": 1, // 单价(元)
// "buy_quantity": 1, // 数量(自动续期订阅产品: 数量只能是1)
// "product_id": this.isDebug() ? "uniappx.autorenewable.monthly_1" : "uniappx.autorenewable.monthly1",
// "title": "自动续期订阅产品:每月定期赞助", // 注意自动续期订阅产品在沙盒模式下,实际周期会缩短到几分钟续期一次(即现实世界几分钟 = 沙盒世界1个月)
// },
{
"description": "为DCloud提供的免费软件进行赞助",
"goods_price": 1, // 单价(元)
"buy_quantity": 1, // 数量(非自动续期订阅产品: 数量只能是1)
"product_id": "uniappx.nonrenewable.monthly_1",
"product_id": this.isDebug() ? "uniappx.nonrenewable.monthly_1" : "uniappx.nonrenewable.monthly1",
"title": "非自动续期订阅产品:月赞助",
},
{
"description": "为DCloud提供的免费软件进行赞助",
"goods_price": 1, // 单价(元)
"buy_quantity": 1, // 数量
"product_id": "uniappx.nonrenewable.none",
"title": "测试不存在的产品"
}
] as Array<UTSJSONObject>,
// {
// "description": "为DCloud提供的免费软件进行赞助",
// "goods_price": 1, // 单价(元)
// "buy_quantity": 1, // 数量
// "product_id": "uniappx.nonrenewable.none",
// "title": "测试不存在的产品"
// }
] as Array<UTSJSONObject>
}
},
onLoad: function() {
},
onShow() {
},
onUnload() {},
methods: {
// 支付组件加载完毕后执行
onMounted(insideData: any){
onMounted(insideData : any) {
this.init();
},
// 初始化
......@@ -99,10 +105,10 @@
* 发起支付
* 在调用此api前,你应该先创建自己的业务系统订单,并获得订单号 order_no,把order_no当参数传给此api,而示例中为了简化跟支付插件无关的代码,这里直接已时间戳生成了order_no
*/
createOrder(){
this.order_no = `test`+Date.now();
createOrder() {
this.order_no = `test` + Date.now();
this.out_trade_no = this.order_no;
let productInfo: UTSJSONObject = this.productList.find((item: UTSJSONObject) : boolean => {
let productInfo : UTSJSONObject = this.productList.find((item : UTSJSONObject) : boolean => {
return item['product_id'] == this.product_id;
});
let buy_quantity = productInfo.getNumber('buy_quantity') || 1;
......@@ -126,7 +132,7 @@
});
},
// 监听事件 - 支付成功
onSuccess(res){
onSuccess(res) {
console.log('success: ', res);
if (res.user_order_success) {
// 代表用户已付款,且你自己写的回调成功并正确执行了
......@@ -137,7 +143,7 @@
}
},
onFail(err){
onFail(err) {
uni.showModal({
content: `${err.errSubject} : ${err.errCode} : ${err.errMsg}`,
showCancel: false,
......@@ -145,7 +151,7 @@
});
},
onCancel(err){
onCancel(err) {
uni.showToast({
title: "用户取消了支付",
icon: 'none'
......@@ -156,8 +162,28 @@
applePriceChange(e) {
this.product_id = e.detail.value;
},
applePriceClick(item: any){
applePriceClick(item : any) {
this.product_id = item['product_id'] as string;
},
getPackageName() : string {
const res = uni.getAppBaseInfo();
let packageName : string = ""
// #ifdef APP-ANDROID
packageName = res.packageName
// #endif
// #ifdef APP-IOS
packageName = res.bundleId
// #endif
return packageName
},
isDebug() : boolean {
if (this.getPackageName() == 'io.dcloud.uniappx') {
return true
}
return false
}
}
}
......
......@@ -70,15 +70,20 @@
id: this.isDebug() ? "uniappx.nonconsumable.sponsorskin_1" : "uniappx.nonconsumable.sponsorskin1"
} as PayItem);
// this.productList.push({
// name: '自动续期订阅产品:每月定期赞助1元',
// id: this.isDebug() ? "uniappx.autorenewable.monthly_1" : "uniappx.autorenewable.monthly1"
// } as PayItem);
this.productList.push({
name: '非自动续期订阅产品:月赞助1元',
id: this.isDebug() ? "uniappx.nonrenewable.monthly_1" : "uniappx.nonrenewable.monthly1"
} as PayItem);
this.productList.push({
name: '测试不存在的产品',
id: "uniappx.nonrenewable.none"
} as PayItem);
// this.productList.push({
// name: '测试不存在的产品',
// id: "uniappx.nonrenewable.none"
// } as PayItem);
},
getPackageName() : string {
const res = uni.getAppBaseInfo();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册