提交 058e1ae0 编写于 作者: zhaofengliang920817's avatar zhaofengliang920817

iOS|添加苹果内购示例页面

上级 c317a117
......@@ -358,7 +358,7 @@
"navigationBarTitleText": "Touch Events"
}
},
// #ifndef WEB
// #ifndef WEB
{
"path": "pages/component/nested-scroll-header/nested-scroll-header",
"group": "0,1,8,0",
......@@ -366,8 +366,8 @@
"navigationBarTitleText": "nested-scroll-header"
}
},
// #endif
// #ifndef WEB
// #endif
// #ifndef WEB
{
"path": "pages/component/nested-scroll-body/nested-scroll-body",
"group": "0,1,8,1",
......@@ -375,7 +375,7 @@
"navigationBarTitleText": "nested-scroll-body"
}
},
// #endif
// #endif
{
"path": "pages/component/swiper/swiper-list-view",
"style": {
......@@ -383,7 +383,7 @@
"enablePullDownRefresh": false
}
},
// #ifdef WEB
// #ifdef WEB
{
"path": "pages/component/movable-view/movable-view",
"group": "0,1,4,1",
......@@ -391,8 +391,8 @@
"navigationBarTitleText": "movable-view | 可拖动视图容器"
}
},
// #endif
// #ifdef WEB
// #endif
// #ifdef WEB
{
"path": "pages/component/label/label",
"group": "0,3,5",
......@@ -400,8 +400,8 @@
"navigationBarTitleText": "label"
}
},
// #endif
// #ifdef WEB
// #endif
// #ifdef WEB
{
"path": "pages/component/picker/picker",
"group": "0,3,6",
......@@ -409,8 +409,8 @@
"navigationBarTitleText": "picker | 底部弹出滚动选择器"
}
},
// #endif
// #ifdef WEB
// #endif
// #ifdef WEB
{
"path": "pages/component/map/map",
"group": "0,6",
......@@ -418,8 +418,8 @@
"navigationBarTitleText": "map | 地图"
}
},
// #endif
// #ifdef WEB
// #endif
// #ifdef WEB
{
"path": "pages/component/cover-view/cover-view",
"group": "0,1,5,0",
......@@ -427,8 +427,8 @@
"navigationBarTitleText": "cover-view"
}
},
// #endif
// #ifdef WEB
// #endif
// #ifdef WEB
{
"path": "pages/component/editor/editor",
"group": "0,3,4",
......@@ -436,8 +436,8 @@
"navigationBarTitleText": "editor | 富文本编辑器"
}
},
// #endif
// #ifdef WEB
// #endif
// #ifdef WEB
{
"path": "pages/API/open-location/open-location",
"group": "1,8,1",
......@@ -445,8 +445,8 @@
"navigationBarTitleText": "openLocation | 使用地图查看位置"
}
},
// #endif
// #ifdef WEB
// #endif
// #ifdef WEB
{
"path": "pages/API/choose-location/choose-location",
"group": "1,8,2",
......@@ -454,7 +454,7 @@
"navigationBarTitleText": "chooseLocation | 使用地图选择位置"
}
},
// #endif
// #endif
{
"path": "pages/component/list-view/issue-2199",
"style": {
......@@ -490,7 +490,7 @@
"navigationBarTitleText": "getApp | 获取当前应用实例"
}
},
// #ifdef APP-ANDROID
// #ifdef APP-ANDROID
{
"path": "pages/API/exit/exit",
"group": "1,1,5",
......@@ -498,8 +498,8 @@
"navigationBarTitleText": "exit | 退出应用"
}
},
// #endif
// #ifdef APP-ANDROID
// #endif
// #ifdef APP-ANDROID
{
"path": "pages/API/install-apk/install-apk",
"group": "1,6,6",
......@@ -508,7 +508,7 @@
"enablePullDownRefresh": false
}
},
// #endif
// #endif
{
"path": "pages/API/get-current-pages/get-current-pages",
"group": "1,0,1",
......@@ -592,7 +592,7 @@
"navigationBarTitleText": "storage | key-value本地数据存储"
}
},
// #ifndef WEB
// #ifndef WEB
{
"path": "pages/API/get-file-system-manager/get-file-system-manager",
"group": "1,10,0",
......@@ -600,8 +600,8 @@
"navigationBarTitleText": "getFileSystemManager | 获取文件管理器"
}
},
// #endif
// #ifndef WEB
// #endif
// #ifndef WEB
{
"path": "pages/API/env/env",
"group": "1,1,0",
......@@ -609,7 +609,7 @@
"navigationBarTitleText": "env | 环境变量"
}
},
// #endif
// #endif
{
"path": "pages/API/show-action-sheet/show-action-sheet",
"group": "1,4,1",
......@@ -746,7 +746,7 @@
"navigationBarTitleText": "getAppBaseInfo | 获取APP基础信息"
}
},
// #ifndef WEB
// #ifndef WEB
{
"path": "pages/API/get-system-setting/get-system-setting",
"group": "1,6,5",
......@@ -754,8 +754,8 @@
"navigationBarTitleText": "getSystemSetting | 获取系统设置"
}
},
// #endif
// #ifndef WEB
// #endif
// #ifndef WEB
{
"path": "pages/API/element-takesnapshot/element-takesnapshot",
"group": "1,30",
......@@ -764,8 +764,8 @@
"enablePullDownRefresh": false
}
},
// #endif
// #ifndef WEB
// #endif
// #ifndef WEB
{
"path": "pages/API/get-app-authorize-setting/get-app-authorize-setting",
"group": "1,6,4",
......@@ -773,7 +773,7 @@
"navigationBarTitleText": "getAppAuthorizeSetting | 获取APP授权设置"
}
},
// #endif
// #endif
{
"path": "pages/API/preview-image/preview-image",
"group": "1,7,1",
......@@ -795,7 +795,7 @@
"navigationBarTitleText": "getImageInfo | 获取图片信息"
}
},
// #ifndef WEB
// #ifndef WEB
{
"path": "pages/API/compress-image/compress-image",
"group": "1,7,4",
......@@ -803,7 +803,7 @@
"navigationBarTitleText": "compressImage | 压缩图片"
}
},
// #endif
// #endif
{
"path": "pages/API/choose-video/choose-video",
"group": "1,7,5",
......@@ -811,7 +811,7 @@
"navigationBarTitleText": "chooseVideo | 拍摄视频或从相册中选择视频"
}
},
// #ifndef WEB
// #ifndef WEB
{
"path": "pages/API/save-image-to-photos-album/save-image-to-photos-album",
"group": "1,7,2",
......@@ -819,8 +819,8 @@
"navigationBarTitleText": "saveImageToPhotosAlbum | 保存图片到相册"
}
},
// #endif
// #ifndef WEB
// #endif
// #ifndef WEB
{
"path": "pages/API/save-video-to-photos-album/save-video-to-photos-album",
"group": "1,7,6",
......@@ -828,7 +828,7 @@
"navigationBarTitleText": "saveVideoToPhotosAlbum | 保存视频到相册"
}
},
// #endif
// #endif
{
"path": "pages/API/get-video-info/get-video-info",
"group": "1,7,7",
......@@ -836,7 +836,7 @@
"navigationBarTitleText": "getVideoInfo | 获取视频信息"
}
},
// #ifndef WEB
// #ifndef WEB
{
"path": "pages/API/compress-video/compress-video",
"group": "1,7,8",
......@@ -844,7 +844,7 @@
"navigationBarTitleText": "compressVideo | 压缩视频"
}
},
// #endif
// #endif
{
"path": "pages/API/get-network-type/get-network-type",
"group": "1,5,3",
......@@ -894,7 +894,7 @@
"navigationBarTitleText": "getWindowInfo | 获取窗口信息"
}
},
// #ifndef WEB
// #ifndef WEB
{
"path": "pages/API/element-draw/element-draw",
"group": "1,30",
......@@ -903,8 +903,8 @@
"enablePullDownRefresh": false
}
},
// #endif
// #ifndef WEB
// #endif
// #ifndef WEB
{
"path": "pages/API/facial-recognition-meta-info/facial-recognition-meta-info",
"group": "1,11,1",
......@@ -913,8 +913,8 @@
"enablePullDownRefresh": false
}
},
// #endif
// #ifndef WEB
// #endif
// #ifndef WEB
{
"path": "pages/API/get-univerify-manager/get-univerify-manager",
"group": "1,11,0",
......@@ -923,7 +923,7 @@
"enablePullDownRefresh": false
}
},
// #endif
// #endif
{
"path": "pages/API/rpx2px/rpx2px",
"group": "1,4,6",
......@@ -932,7 +932,7 @@
"enablePullDownRefresh": false
}
},
// #ifdef APP-ANDROID
// #ifdef APP-ANDROID
{
"path": "pages/API/create-request-permission-listener/create-request-permission-listener",
"group": "1,6,16",
......@@ -941,8 +941,8 @@
"enablePullDownRefresh": false
}
},
// #endif
// #ifndef WEB
// #endif
// #ifndef WEB
{
"path": "pages/API/request-payment/request-payment",
"group": "1,14,0",
......@@ -951,8 +951,8 @@
"enablePullDownRefresh": false
}
},
// #endif
// #ifndef WEB
// #endif
// #ifndef WEB
{
"path": "pages/API/create-rewarded-video-ad/create-rewarded-video-ad",
"group": "1,12,0",
......@@ -961,7 +961,7 @@
"enablePullDownRefresh": false
}
},
// #endif
// #endif
{
"path": "pages/API/request-payment/request-payment/request-payment-uni-pay",
"group": "1,14",
......@@ -970,6 +970,16 @@
"enablePullDownRefresh": false
}
},
// #ifndef WEB
{
"path": "pages/API/virtual-payment/virtual-payment",
"group": "1,14",
"style": {
"navigationBarTitleText": "virtualPayment | 苹果内购",
"enablePullDownRefresh": false
}
},
// #endif
{
"path": "pages/API/request-payment/request-payment/order-detail",
"style": {
......@@ -977,7 +987,7 @@
"enablePullDownRefresh": false
}
},
// #ifdef WEB
// #ifdef WEB
{
"path": "pages/API/make-phone-call/make-phone-call",
"group": "1,6,9",
......@@ -985,8 +995,8 @@
"navigationBarTitleText": "makePhoneCall | 打电话"
}
},
// #endif
// #ifdef WEB
// #endif
// #ifdef WEB
{
"path": "pages/API/create-inner-audio-context/create-inner-audio-context",
"group": "1,7,9",
......@@ -994,24 +1004,24 @@
"navigationBarTitleText": "createInnerAudioContext | 音频"
}
},
// #endif
// #ifdef WEB
// #endif
// #ifdef WEB
{
"path": "pages/API/create-inner-audio-context/inner-audio-format",
"style": {
"navigationBarTitleText": "inner-audio-format"
}
},
// #endif
// #ifdef WEB
// #endif
// #ifdef WEB
{
"path": "pages/API/create-inner-audio-context/inner-audio-path",
"style": {
"navigationBarTitleText": "inner-audio-path"
}
},
// #endif
// #ifdef WEB
// #endif
// #ifdef WEB
{
"path": "pages/API/clipboard/clipboard",
"group": "1,6,10",
......@@ -1019,8 +1029,8 @@
"navigationBarTitleText": "clipboard | 剪切板"
}
},
// #endif
// #ifdef WEB
// #endif
// #ifdef WEB
{
"path": "pages/API/compass/compass",
"group": "1,6,11",
......@@ -1028,8 +1038,8 @@
"navigationBarTitleText": "compass | 罗盘"
}
},
// #endif
// #ifndef WEB
// #endif
// #ifndef WEB
{
"path": "pages/API/theme-change/theme-change",
"group": "1,4,7",
......@@ -1038,7 +1048,7 @@
"enablePullDownRefresh": false
}
},
// #endif
// #endif
{
"path": "pages/API/get-element-by-id/get-element-by-id",
"group": "1,3,0",
......@@ -1066,7 +1076,7 @@
"navigationBarTitleText": "UniResizeObserver"
}
},
// #ifndef WEB
// #ifndef WEB
{
"path": "pages/API/get-provider/get-provider",
"group": "1,1,6",
......@@ -1074,8 +1084,8 @@
"navigationBarTitleText": "getProvider | 获取服务提供商"
}
},
// #endif
// #ifndef WEB
// #endif
// #ifndef WEB
{
"path": "pages/API/push/push",
"group": "1,6,7",
......@@ -1083,7 +1093,7 @@
"navigationBarTitleText": "push | 推送"
}
},
// #endif
// #endif
{
"path": "pages/tabBar/CSS",
"style": {
......@@ -2650,4 +2660,4 @@
]
}
]
}
\ No newline at end of file
}
<template>
<!-- #ifdef APP -->
<scroll-view style="flex: 1;">
<!-- #endif -->
<page-head title="苹果内购支付"></page-head>
<view style="padding-left: 20px; padding-right: 20px;">
<text>
requestVirtualPayment api 适用于消耗性类型、非消耗性类型、自动续期订阅类型、非自动续期订阅类型产品的购买。\n\n
1. 消耗性类型:该类型的产品可以设置购买数量,默认是1,最大值是10; \n
2. 非消耗性类型、自动续期订阅类型、非自动续期订阅类型: 这些型的产品购买数量设置无效,数量只能是1。
</text>
<button style="margin-top: 20px;" type="primary" v-for="(item,index) in productList" :key="index"
@click="requestVirtualPayment(item)">{{item.name}}</button>
<text>
\nrestoreCompletedTransactions api 适用于非消耗性类型、自动续期订阅类型、非自动续期订阅类型产品的购买。\n\n
1. 非消耗性类型: 返回每个已购买的非消耗性类型产品的购买记录;\n
2. 自动续期订阅类型: 返回每个已购买的自动续期订阅类型产品的最新购买记录;\n
3. 非自动续期订阅类型: 返回每个已购买的非自动续期订阅类型产品的最新购买记录。\n
Note: 不能用来恢复消耗性类型的购买记录。
</text>
<button style="margin-top: 20px;" type="primary" @click="restoreCompletedTransactions">恢复购买订单列表</button>
<text>
\ngetUnfinishedTransactions api 适用于获取未完成的各种类型产品的购买记录(用来防止丢单)。\n\n
1. 比如用户点击购买已经付款成功,但因网络、手机没电关机等特殊情况,Apple IAP 没有返回客户端对应的购买凭证,从而导致无法finish该交易导致的丢单,可以在需要的地方调用该api获得此类未finished的记录; \n
2. 针对消耗性类型产品交易,只能通过该api获取未finished的交易,防止丢单;\n
3. 对于其他类型产品未finished交易, 不仅可以通过该api获取,也可以通过restoreCompletedTransactions api(也可以获取已经finished的交易)获取;
</text>
<button style="margin-top: 20px; margin-bottom: 50px;" type="primary" @click="getUnfinishedTransactions">获取未结束的订单列表</button>
</view>
<!-- #ifdef APP -->
</scroll-view>
<!-- #endif -->
</template>
<script>
export type PayItem = { id : string, name : string, quantity ?: number }
export default {
data() {
return {
productList: [] as PayItem[]
}
},
onLoad: function () {
this.productList.push({
name: '消耗性产品:个人赞助1元',
id: "io.dcloud.uniappx.consumable.sponsor1",
quantity: 5
} as PayItem);
this.productList.push({
name: '消耗性产品:金牌赞助50元',
id: "io.dcloud.uniappx.consumable.sponsor50",
quantity: 1
} as PayItem);
this.productList.push({
name: '非消耗性产品: 赞助特效1元',
id: "io.dcloud.uniappx.nonconsumable.skin"
} as PayItem);
this.productList.push({
name: '自动续期订阅产品:每月定期赞助1元',
id: "io.dcloud.uniappx.autorenewable.monthly"
} as PayItem);
this.productList.push({
name: '非自动续期订阅产品:月赞助1元',
id: "io.dcloud.uniappx.nonrenewable.week"
} as PayItem);
},
methods: {
requestVirtualPayment(e : PayItem) {
uni.showLoading({
title: "",
mask: true
});
uni.requestVirtualPayment({
apple: {
productId: e.id,
appAccountToken: "orderId+accountId",
quantity: e.quantity ?? 1
},
success: (res) => {
uni.hideLoading()
console.log("购买成功:该productId= " + res.apple?.payment.productId)
//TODO: 开发者server验证逻辑
//经过开发者server验证成功后请结束该交易
uni.finishedTransaction({
transaction: res.apple,
success: (r) => {
console.log("关单成功, 该productId= " + res.apple?.payment.productId)
},
fail: (e) => {
console.log("关单失败, 该productId= " + res.apple?.payment.productId)
}
})
uni.showToast({
title: "购买成功:" + res.apple?.payment.productId,
icon: 'error'
})
},
fail: (e) => {
uni.hideLoading()
console.log("购买失败:errSubject= " + e.errSubject + ", errCode= " + e.errCode + ", errMsg= " + e.errMsg)
uni.showToast({
title: "购买失败:errCode=" + e.errCode,
icon: 'error'
})
}
})
},
restoreCompletedTransactions() {
uni.showLoading({
title: "",
mask: true
});
uni.restoreCompletedTransactions({
success: (res) => {
uni.hideLoading()
console.log("restore成功的交易个数:" + res.transactions.length)
res.transactions.forEach(transaction => {
//TODO: 开发者server验证逻辑
console.log("restore成功的交易productId= " + transaction.payment.productId)
})
uni.showToast({
title: "restore成功的交易个数:" + res.transactions.length,
icon: 'error'
})
},
fail: (e) => {
uni.hideLoading()
console.log("restore失败:errSubject= " + e.errSubject + ", errCode= " + e.errCode + ", errMsg= " + e.errMsg)
uni.showToast({
title: "restore失败:errCode=" + e.errCode,
icon: 'error'
})
}
})
},
getUnfinishedTransactions() {
uni.showLoading({
title: "",
mask: true
});
uni.getUnfinishedTransactions({
success: (res) => {
hideLoading()
console.log("获取未结束的订单列表个数:" + res.transactions.length)
res.transactions.forEach(transaction => {
//TODO: 开发者server验证逻辑
//经过开发者server验证成功后请结束该交易
uni.finishedTransaction({
transaction: transaction,
success: (r) => {
console.log("关单成功, 该productId= " + transaction.payment.productId)
},
fail: (e) => {
console.log("关单失败, 该productId= " + transaction.payment.productId)
}
})
})
uni.showToast({
title: "获取未结束的订单列表个数:" + res.transactions.length,
icon: 'error'
})
},
fail: (e) => {
uni.hideLoading()
console.log("获取未结束的订单列表失败:errSubject= " + e.errSubject + ", errCode= " + e.errCode + ", errMsg= " + e.errMsg)
uni.showToast({
title: "获取未结束的订单列表失败:errCode= " + e.errCode,
icon: 'error'
})
}
})
}
}
}
</script>
<style>
</style>
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册