苹果内购+订单结算页面条件编译
This commit is contained in:
8
App.vue
8
App.vue
@@ -1,8 +1,7 @@
|
||||
<script>
|
||||
import {
|
||||
music,
|
||||
bgm
|
||||
} from "@/utils/music.js";
|
||||
iap
|
||||
} from "@/utils/myIapCheck.js";
|
||||
import store from "@/store/index.js";
|
||||
import socket from "@/config/socket";
|
||||
// #ifdef H5
|
||||
@@ -59,7 +58,8 @@
|
||||
if (store.state.userInfo.token) {
|
||||
socket.init();
|
||||
}
|
||||
// APPUpdate();
|
||||
// 检测是否有未关闭苹果内购订单
|
||||
iap.getChannels()
|
||||
// #endif
|
||||
},
|
||||
onShow: function(e) {
|
||||
|
||||
@@ -1,38 +1,38 @@
|
||||
{
|
||||
"version": "1",
|
||||
"prompt": "template",
|
||||
"title": "服务协议和隐私政策",
|
||||
"message": " 请你务必审慎阅读、充分理解“隐私政策”各条款,包括但不限于:为了更好的向你提供服务,我们需要收集你的设备标识、操作日志等信息用于分析、优化应用性能。<br/> 你可阅读<a href=\"https://wumen.taihumed.com/agreement.html\">《用户协议》</a>和<a href=\"https://wumen.taihumed.com/privacy.html\">《隐私政策》</a>了解详细信息。如果你同意,请点击下面按钮开始接受我们的服务。",
|
||||
"buttonAccept": "同意并接受",
|
||||
"buttonRefuse": "暂不同意",
|
||||
"hrefLoader": "system",
|
||||
"backToExit":"false",
|
||||
"second": {
|
||||
"title": "确认提示",
|
||||
"message": " 进入应用前,你需先同意<a href=\"https://wumen.taihumed.com/agreement.html\">《用户协议》</a>和<a href=\"https://wumen.taihumed.com/privacy.html\">《隐私政策》</a>,否则将退出应用。",
|
||||
"buttonAccept": "同意并继续",
|
||||
"buttonRefuse": "退出应用"
|
||||
},
|
||||
"disagreeMode":{
|
||||
"support": false,
|
||||
"loadNativePlugins": false,
|
||||
"visitorEntry": false,
|
||||
"showAlways": false
|
||||
},
|
||||
"styles": {
|
||||
"backgroundColor": "#FFF",
|
||||
"borderRadius":"5px",
|
||||
"title": {
|
||||
"color": "#333"
|
||||
"version" : "1",
|
||||
"prompt" : "template",
|
||||
"title" : "服务协议和隐私政策",
|
||||
"message" : " 请你务必审慎阅读、充分理解“隐私政策”各条款,包括但不限于:为了更好的向你提供服务,我们需要收集你的设备标识、操作日志等信息用于分析、优化应用性能。<br/> 你可阅读<a href=\"https://wumen.taihumed.com/agreement.html\">《用户协议》</a>和<a href=\"https://wumen.taihumed.com/privacy.html\">《隐私政策》</a>了解详细信息。如果你同意,请点击下面按钮开始接受我们的服务。",
|
||||
"buttonAccept" : "同意并接受",
|
||||
"buttonRefuse" : "暂不同意",
|
||||
"hrefLoader" : "system",
|
||||
"backToExit" : "false",
|
||||
"second" : {
|
||||
"title" : "确认提示",
|
||||
"message" : " 进入应用前,你需先同意<a href=\"https://wumen.taihumed.com/agreement.html\">《用户协议》</a>和<a href=\"https://wumen.taihumed.com/privacy.html\">《隐私政策》</a>,否则将退出应用。",
|
||||
"buttonAccept" : "同意并继续",
|
||||
"buttonRefuse" : "退出应用"
|
||||
},
|
||||
"buttonAccept": {
|
||||
"color": "#333"
|
||||
"disagreeMode" : {
|
||||
"support" : false,
|
||||
"loadNativePlugins" : false,
|
||||
"visitorEntry" : false,
|
||||
"showAlways" : false
|
||||
},
|
||||
"buttonRefuse": {
|
||||
"color": "#333"
|
||||
},
|
||||
"buttonVisitor": {
|
||||
"color": "#55aaff"
|
||||
"styles" : {
|
||||
"backgroundColor" : "#FFF",
|
||||
"borderRadius" : "5px",
|
||||
"title" : {
|
||||
"color" : "#333"
|
||||
},
|
||||
"buttonAccept" : {
|
||||
"color" : "#333"
|
||||
},
|
||||
"buttonRefuse" : {
|
||||
"color" : "#333"
|
||||
},
|
||||
"buttonVisitor" : {
|
||||
"color" : "#55aaff"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1078,16 +1078,11 @@ export default {
|
||||
} else if (payItem.paymentMethod == 3) {
|
||||
// 苹果充值
|
||||
console.log("苹果二次支付");
|
||||
if (this.isAndorid) {
|
||||
uni.showModal({
|
||||
title: "提示",
|
||||
showCancel: false,
|
||||
content:
|
||||
"很抱歉,当前订单属于苹果系统内购订单,安卓系统无法完成支付操作,您可切换到苹果系统进行支付,也可以取消该订单,并重新下单",
|
||||
});
|
||||
} else {
|
||||
this.iphonepay(payItem);
|
||||
}
|
||||
uni.showModal({
|
||||
content:'apple内购订单不支持继续支付,请重新发起支付申请并完成支付',
|
||||
confirmText:'好的',
|
||||
showCancel:false
|
||||
})
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
@@ -897,7 +897,7 @@ export default {
|
||||
},
|
||||
})
|
||||
.then((res) => {
|
||||
console.log(res, "内容获取成功");
|
||||
// console.log(res, "内容获取成功");
|
||||
that.pagination.total = res.data.total;
|
||||
if (res.data.total == 0) {
|
||||
this.isLoadingHide = true;
|
||||
@@ -947,8 +947,7 @@ export default {
|
||||
}
|
||||
);
|
||||
} else if (payItem.paymentMethod == 1) {
|
||||
console.log("微信支付");
|
||||
// console.log(this.isAndorid)
|
||||
console.log("微信支付");
|
||||
if (this.isAndorid == false) {
|
||||
uni.showModal({
|
||||
title: "提示",
|
||||
@@ -986,19 +985,24 @@ export default {
|
||||
}
|
||||
});
|
||||
}
|
||||
} else if (payItem.paymentMethod == 3) {
|
||||
} else if (payItem.paymentMethod == 3 && this.ordersListTab == 0 ) {
|
||||
// 苹果充值
|
||||
console.log("苹果二次支付");
|
||||
if (this.isAndorid) {
|
||||
uni.showModal({
|
||||
title: "提示",
|
||||
showCancel: false,
|
||||
content:
|
||||
"很抱歉,当前订单属于苹果系统内购订单,安卓系统无法完成支付操作,您可切换到苹果系统进行支付,也可以取消该订单,并重新下单",
|
||||
});
|
||||
} else {
|
||||
this.iphonepay(payItem);
|
||||
}
|
||||
uni.showModal({
|
||||
content:'apple内购订单不支持继续支付,请重新发起支付申请并完成支付',
|
||||
confirmText:'好的',
|
||||
showCancel:false
|
||||
})
|
||||
// if (this.isAndorid) {
|
||||
// uni.showModal({
|
||||
// title: "提示",
|
||||
// showCancel: false,
|
||||
// content:
|
||||
// "很抱歉,当前订单属于苹果系统内购订单,安卓系统无法完成支付操作,您可切换到苹果系统进行支付,也可以取消该订单,并重新下单",
|
||||
// });
|
||||
// } else {
|
||||
// this.iphonepay(payItem);
|
||||
// }
|
||||
}else if (payItem.paymentMethod == 4){
|
||||
console.log('天医币二次支付')
|
||||
}
|
||||
|
||||
@@ -360,6 +360,7 @@
|
||||
}
|
||||
|
||||
.jianjie {
|
||||
overflow: hidden!important;
|
||||
margin-top: 10rpx;
|
||||
font-size: 24rpx;
|
||||
@include bov();
|
||||
|
||||
@@ -885,7 +885,7 @@
|
||||
if (res.code == 0) {
|
||||
if (res.chapterList.length > 0) {
|
||||
this.courseList = res.chapterList
|
||||
console.log('status++++++++++++++', this.courseList)
|
||||
// console.log('status++++++++++++++', this.courseList)
|
||||
} else {
|
||||
this.courseList = []
|
||||
}
|
||||
|
||||
@@ -212,7 +212,7 @@
|
||||
</view>
|
||||
<view class="order_top common_radius_box color_shandow goods_box pay_box">
|
||||
<view class="title">支付方式</view>
|
||||
|
||||
<template v-if="isAndorid">
|
||||
<view
|
||||
class="curriulum_title_box goods_item pay_item"
|
||||
v-for="(v, i) in payList"
|
||||
@@ -260,7 +260,58 @@
|
||||
</template>
|
||||
</view>
|
||||
</view>
|
||||
<template v-if="selectPayIndex == 2">
|
||||
</template>
|
||||
<!-- ios 支付列表 -->
|
||||
<template v-else>
|
||||
<view
|
||||
class="curriulum_title_box goods_item pay_item"
|
||||
v-for="(v, i) in payListIOS"
|
||||
>
|
||||
<view :class="isDefaultCurrency && i != 2 ? 'bgGrey top' : 'top'">
|
||||
<view class="left">
|
||||
<image
|
||||
class="pay_item_img"
|
||||
:src="v.imgUrl"
|
||||
mode="aspectFil"
|
||||
:style="v.style"
|
||||
>
|
||||
</image>
|
||||
<template v-if="v.type == 4">
|
||||
<text> {{ v.text }}</text>
|
||||
<text
|
||||
style="color: #258feb; font-weight: 600; margin-left: 10rpx"
|
||||
>
|
||||
(余额:{{
|
||||
initData && initData.user ? initData.user.peanutCoin : 0
|
||||
}})</text
|
||||
>
|
||||
</template>
|
||||
|
||||
<text v-else> {{ v.text }}</text>
|
||||
</view>
|
||||
<template v-if="isDefaultCurrency">
|
||||
<radio
|
||||
v-if="i == 2"
|
||||
:value="v.value"
|
||||
color="#258feb"
|
||||
:checked="selectPayIndex == i ? true : false"
|
||||
@click="radioChange(i)"
|
||||
size="10"
|
||||
/>
|
||||
</template>
|
||||
<template v-else>
|
||||
<radio
|
||||
:value="v.value"
|
||||
color="#258feb"
|
||||
:checked="selectPayIndex == i ? true : false"
|
||||
@click="radioChange(i)"
|
||||
size="10"
|
||||
/>
|
||||
</template>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
<template v-if="beizhuShow">
|
||||
<view
|
||||
class="goods_detail_list_title bg_box_shandow color_shandow bg_color"
|
||||
>
|
||||
@@ -525,6 +576,14 @@ export default {
|
||||
value: "2",
|
||||
},
|
||||
],
|
||||
payListIOS: [
|
||||
{
|
||||
text: "天医币",
|
||||
imgUrl: require("@/static/icon/pay_3.png"),
|
||||
type: 4,
|
||||
value: "2",
|
||||
},
|
||||
],
|
||||
priceBreakdownList: [],
|
||||
orderInfoList: [
|
||||
{
|
||||
@@ -628,10 +687,13 @@ export default {
|
||||
color: "#fff",
|
||||
},
|
||||
],
|
||||
haveCourse: false, // 结算队列是否有课程类型的商品
|
||||
isAndorid:null, //操作系统
|
||||
beizhuShow:false, // 是否显示天医币说明?
|
||||
};
|
||||
},
|
||||
async onLoad(options) {
|
||||
console.log("调用了onLoad方法");
|
||||
console.log("调用了onLoad方法");
|
||||
var that = this;
|
||||
console.log("options at line 387:", options);
|
||||
this.options = JSON.parse(options.data);
|
||||
@@ -641,6 +703,10 @@ export default {
|
||||
// this.isShowAddress = true;
|
||||
// }
|
||||
this.goodsDataList = this.options.goods;
|
||||
var list = [...this.options.goods]
|
||||
list = list.map(e => e.goodsType)
|
||||
this.haveCourse = list.some(ele => ele === '05')
|
||||
console.log('list--------->',list, this.haveCourse);
|
||||
if (this.options.sourceType == "curriculum") {
|
||||
this.goToInfo = {
|
||||
url: "/pages/curriculum/order/index/index",
|
||||
@@ -683,13 +749,32 @@ export default {
|
||||
}
|
||||
});
|
||||
// this.selectPayIndex = 0;
|
||||
|
||||
console.log("this.addressData at line 416:", this.addressData);
|
||||
// #ifdef APP-PLUS
|
||||
this.getOS()
|
||||
// #endif
|
||||
},
|
||||
computed: {
|
||||
...mapState(["userInfo"]),
|
||||
},
|
||||
methods: {
|
||||
// 获得操作系统
|
||||
getOS() {
|
||||
let oprateOs = ''
|
||||
oprateOs = uni.getSystemInfoSync().platform
|
||||
// console.log(oprateOs)
|
||||
if (oprateOs == 'android') {
|
||||
this.isAndorid = true
|
||||
} else {
|
||||
this.isAndorid = false
|
||||
if(this.haveCourse && !this.isAndorid){
|
||||
console.log('苹果系统,并且有商品类型为05');
|
||||
this.selectPayIndex = 0;
|
||||
this.payType = this.payListIOS[0].type;
|
||||
this.beizhuShow = true
|
||||
}
|
||||
}
|
||||
},
|
||||
handleChangejf(val) {
|
||||
console.log("val at line 653:", val);
|
||||
var value = val;
|
||||
@@ -1197,8 +1282,10 @@ export default {
|
||||
|
||||
radioChange(index) {
|
||||
this.selectPayIndex = index;
|
||||
this.selectPayIndex == 2 ? this.beizhuShow = true : this.beizhuShow = false
|
||||
this.payType = this.payList[this.selectPayIndex].type;
|
||||
console.log("this.selectPayIndex at line 315:", this.selectPayIndex);
|
||||
|
||||
this.$forceUpdate();
|
||||
},
|
||||
handleValChange(e) {
|
||||
|
||||
@@ -103,6 +103,7 @@
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
checking : false,
|
||||
playData: {},
|
||||
options: {},
|
||||
xieyi: {
|
||||
@@ -180,29 +181,52 @@
|
||||
//方法
|
||||
methods: {
|
||||
...mapMutations(["setUserInfo"]),
|
||||
// 查询未关闭iap订单
|
||||
async restoreComplateRequest() {
|
||||
let that = this
|
||||
console.log('检测未完成订单')
|
||||
// if (!that.checking) {
|
||||
// that.checking = true
|
||||
// console.log(this.iapChannel, 'this.iapChannel')
|
||||
await this.iapChannel.restoreComplateRequest({
|
||||
manualFinishTransaction: true
|
||||
}, function(results) {
|
||||
// console.log(that.checking)
|
||||
// results 格式为数组存放恢复的IAP商品交易信息对象 IAPTransaction,通用需将返回的支付凭证传给后端进行二次认证
|
||||
that.ComplateRequestArr = results
|
||||
console.log('未完成订单数组共有:=》',that.ComplateRequestArr.length )
|
||||
if (results && results.length > 0) {
|
||||
results.map((item, index) => {
|
||||
// "0"为正在支付;"1"为支付成功;"2"为支付失败;"3"为支付已恢复。
|
||||
if (item.transactionState == '1') {
|
||||
// 已经支付,但是没有走逻辑的内购订单 就发给后台做验证
|
||||
that.iapCheck('未完成订单的验证',item, index)
|
||||
// that.finishTransaction(item)
|
||||
} else if(item.transactionState != '1' || item.transactionState != '0') {
|
||||
// 不是正在支付订单,也不是已经支付订单就关闭掉
|
||||
// 其他状态的内购订单
|
||||
that.finishTransaction(item)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
});
|
||||
// }
|
||||
|
||||
},
|
||||
// 关闭交易订单
|
||||
finishTransaction(trans) {
|
||||
this.iapChannel.finishTransaction(
|
||||
trans,
|
||||
(success) => {
|
||||
console.log("关闭订单成功");
|
||||
this.setUserInfo({
|
||||
restoreFlag: false
|
||||
});
|
||||
console.log("关闭订单成功");
|
||||
},
|
||||
(fail) => {
|
||||
console.log("关闭订单失败");
|
||||
}
|
||||
);
|
||||
},
|
||||
async showXieyi() {
|
||||
|
||||
// this.$http.get(`sys/agreement/list?key=pay`).then((res) => {
|
||||
// this.xieyi = res.page.list[0];
|
||||
// this.xieyiShow = true;
|
||||
// });
|
||||
|
||||
|
||||
async showXieyi() {
|
||||
var data = await this.$commonJS.getAgreement(106);
|
||||
if (data.content) {
|
||||
data.content = data.content.replace(
|
||||
@@ -231,17 +255,41 @@
|
||||
}
|
||||
// console.log(this.radioValue)
|
||||
},
|
||||
iphonepay() {
|
||||
async iphonepay() {
|
||||
const that = this;
|
||||
// 如果ios已经绑定支付信息,就直接支付,如果没有绑定,就需要先绑定
|
||||
console.log("检测支付环境...");
|
||||
plus.payment.getChannels((channels) => {
|
||||
uni.showLoading({
|
||||
title:'检测支付环境'
|
||||
})
|
||||
// console.log("检测支付环境...");
|
||||
plus.payment.getChannels(async (channels) => {
|
||||
console.log(channels, "channels");
|
||||
for (var i in channels) {
|
||||
// 判断是否苹果支付1
|
||||
for (var i in channels) {
|
||||
if (channels[i].id === "appleiap") {
|
||||
that.iapChannel = channels[i];
|
||||
that.requestOrder();
|
||||
// 先检测有没有未完成的订单
|
||||
uni.showLoading({
|
||||
title:'检测历史订单'
|
||||
})
|
||||
await that.restoreComplateRequest()
|
||||
var timer = setInterval(()=>{
|
||||
console.log('检测历史订单数量');
|
||||
that.iapChannel.restoreComplateRequest({
|
||||
manualFinishTransaction: true
|
||||
}, function(results) {
|
||||
if(results.length > 0){
|
||||
console.log('未处理订单还存在,继续轮询...');
|
||||
}else{
|
||||
console.log('没有历史订单,开始请求新订单..');
|
||||
that.requestOrder();
|
||||
clearInterval(timer)
|
||||
console.log('timer清除了吗',timer);
|
||||
}
|
||||
})
|
||||
},1000)
|
||||
// console.log('that.checking',that.checking)
|
||||
/// 限制调用
|
||||
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -251,13 +299,17 @@
|
||||
title: "获取商品信息",
|
||||
mask: true,
|
||||
});
|
||||
const that = this;
|
||||
const that = this;
|
||||
console.log(that.stepsCj.priceTypeId, 88888888);
|
||||
// ['xxxxx'] 是平台申请拿到的内购商品的id
|
||||
let IAPOrders = [];
|
||||
IAPOrders.push(that.stepsCj.priceTypeId + "");
|
||||
IAPOrders.push("p"+that.stepsCj.priceTypeId);
|
||||
console.log(IAPOrders, "IAPOrders");
|
||||
// 新建订单
|
||||
uni.showLoading({
|
||||
title: "正在创建订单",
|
||||
mask: true,
|
||||
});
|
||||
that.iapChannel.requestOrder(
|
||||
IAPOrders,
|
||||
function(event) {
|
||||
@@ -279,17 +331,11 @@
|
||||
);
|
||||
},
|
||||
topay(id) {
|
||||
const that = this;
|
||||
uni.hideLoading();
|
||||
// if(this.chargeOrderSn != '' || this.chargeOrderSn != undefined){ // 判断是不是二次支付的订单
|
||||
// that.orderSn = this.chargeOrderSn
|
||||
// console.log(that.orderSn,'二次支付的订单号')
|
||||
// }
|
||||
// var restoreFlag = true; // 调用支付接口时标记 restoreFlag = true , 实际应用请将标记存储在 storage 中
|
||||
this.setUserInfo({
|
||||
restoreFlag: true
|
||||
const that = this;
|
||||
uni.showLoading({
|
||||
title: "正在支付",
|
||||
mask: true,
|
||||
});
|
||||
console.log(this.userInfo, "更新后的用户信息");
|
||||
plus.payment.request(
|
||||
that.iapChannel, {
|
||||
productid: id,
|
||||
@@ -297,38 +343,51 @@
|
||||
manualFinishTransaction: true, // 3.5.1+ 支持,设置此参数后需要开发者主动关闭订单,参见下面的关闭订单方法 finishTransaction()
|
||||
},
|
||||
function(result) {
|
||||
// restoreFlag = false; // 支付成功清除标记 restoreFlag = false
|
||||
// that.checking = false
|
||||
that.transaction = result;
|
||||
// 支付成功,result 为 IAP商品交易信息对象 IAPTransaction 需将返回的支付凭证传给后端进行二次认证
|
||||
that.iapCheck(result);
|
||||
},
|
||||
function(e) {
|
||||
// that.checking = false
|
||||
console.log("错误回调", e);
|
||||
if (e.errCode == 2) {
|
||||
if (e.code == 2) {
|
||||
uni.showToast({
|
||||
title:'取消支付,内购订单即将关闭',
|
||||
icon:'none'
|
||||
})
|
||||
|
||||
// 用户未绑定支付方式,app内支付流程结束,系统弹出框引导用户绑定支付方式,此过程将跳转到系统应用 AppStore 进行绑定支付方式,绑定成功同步支付成功,用户成功付款
|
||||
plus.runtime.openURL("https://apps.apple.com/account/billing");
|
||||
// plus.runtime.openURL("https://apps.apple.com/account/billing");
|
||||
} else {
|
||||
// restoreFlag = false; // 支付失败清楚标记
|
||||
that.finishTransaction(result);
|
||||
//console.log('订单关闭后的用户信息', that.userInfo);
|
||||
console.log(e);
|
||||
//console.log(e.message)
|
||||
uni.showToast({
|
||||
title:'支付失败,内购订单即将关闭',
|
||||
icon:'none'
|
||||
})
|
||||
console.log('其他支付错误',e);
|
||||
}
|
||||
|
||||
// that.finishTransaction(result);
|
||||
that.restoreComplateRequest()
|
||||
}
|
||||
);
|
||||
},
|
||||
iapCheck(result) {
|
||||
let that = this;
|
||||
console.log("进入后台验证");
|
||||
uni.showLoading({
|
||||
title:'正在验证订单结果'
|
||||
})
|
||||
let data = {
|
||||
transactionId: result.transactionIdentifier, // 支付交易id
|
||||
customerOid: that.userInfo.id,
|
||||
productId: result.payment.productid, // 产品id
|
||||
productId: result.payment.productid.slice(1), // 产品id
|
||||
orderId: result.payment.username, // 系统订单号
|
||||
receiptData: result.transactionReceipt, // 苹果返回收据
|
||||
// isSandBox:true
|
||||
// body: that.stepsCj.priceTypeId // 充值类型id
|
||||
};
|
||||
console.log(data, "data");
|
||||
console.log("提交给后台的数据",data);
|
||||
$http
|
||||
.request({
|
||||
url: "/Ipa/veri",
|
||||
@@ -342,19 +401,24 @@
|
||||
.then((res) => {
|
||||
console.log(JSON.stringify(res));
|
||||
if (res.code == 0) {
|
||||
//uni.hideLoading()
|
||||
that.userInfo.restoreFlag == true ?
|
||||
that.setUserInfo({
|
||||
restoreFlag: false
|
||||
}) :
|
||||
"";
|
||||
console.log(that.userInfo.restoreFlag);
|
||||
uni.hideLoading()
|
||||
// that.userInfo.restoreFlag == true ?
|
||||
// that.setUserInfo({
|
||||
// restoreFlag: false
|
||||
// }) :
|
||||
// "";
|
||||
uni.showToast({
|
||||
title:'充值成功!',
|
||||
icon:'success'
|
||||
})
|
||||
console.log("充值订单已处理,请留意账户金额变动....");
|
||||
// 服务器验证票据有效后在客户端关闭订单 (iapChannel.finishTransaction)
|
||||
that.finishTransaction(result);
|
||||
}
|
||||
})
|
||||
.catch((e) => {
|
||||
uni.hideLoading()
|
||||
console.log('后台验证失败=>',e);
|
||||
uni.showModal({
|
||||
title: "提示",
|
||||
showCancel: false,
|
||||
@@ -448,7 +512,11 @@
|
||||
that.payType = e;
|
||||
},
|
||||
//ios充值
|
||||
iosPay() {
|
||||
iosPay() {
|
||||
// 苹果内购实现思路:
|
||||
// 1.先确认支付通道是否包含苹果内购
|
||||
// 2.检查一下是否存在上次未处理完的订单(主要是支付成功没有走回调的订单),异常订单直接关闭掉,成功没有走回调的提交给后台进行验证
|
||||
// 3.请求并创建新的订单
|
||||
this.iphonepay();
|
||||
},
|
||||
// 充值
|
||||
|
||||
@@ -386,7 +386,7 @@
|
||||
this.$http
|
||||
.post('medical/home/getCourseMedicalTree')
|
||||
.then(res => {
|
||||
console.log(res)
|
||||
// console.log(res)
|
||||
if (res.code == 0) {
|
||||
if (res.labels.length > 0) {
|
||||
this.curseTagList = res.labels
|
||||
|
||||
@@ -249,7 +249,7 @@
|
||||
yszcText: {},
|
||||
quShow: false,
|
||||
quCodeList: [], // 国家区域码
|
||||
quCode: 86,
|
||||
quCode: '86',
|
||||
submitClickNum:0, // 登陆按钮点击次数
|
||||
};
|
||||
},
|
||||
@@ -507,6 +507,7 @@
|
||||
}
|
||||
if (this.quCode == null || this.quCode == 86) {
|
||||
if (!this.$base.phoneRegular.test(this.phone)) {
|
||||
this.submitClickNum += 1
|
||||
uni.showToast({
|
||||
title: '手机格式不正确',
|
||||
icon: 'none'
|
||||
@@ -523,7 +524,7 @@
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (!this.$base.mailRegular.test(this.email)) {
|
||||
if (!this.$base.mailRegular.test(this.email)) {
|
||||
uni.showToast({
|
||||
title: '邮箱格式不正确',
|
||||
icon: 'none'
|
||||
|
||||
Binary file not shown.
117
utils/myIapCheck.js
Normal file
117
utils/myIapCheck.js
Normal file
@@ -0,0 +1,117 @@
|
||||
import store from '@/store/index.js'
|
||||
import $http from '@/config/requestConfig.js';
|
||||
// #ifdef APP-PLUS
|
||||
const iapChannel = null;
|
||||
const checking = false
|
||||
const ComplateRequestArr = []
|
||||
// #endif
|
||||
// #ifdef H5
|
||||
// const bgm = {};
|
||||
// #endif
|
||||
|
||||
|
||||
var iap = {
|
||||
// 检测支付通道
|
||||
getChannels(){
|
||||
const that = this;
|
||||
console.log('检测支付通道')
|
||||
plus.payment.getChannels(async (channels) => {
|
||||
for (var i in channels) {
|
||||
// 判断是否苹果支付1
|
||||
if (channels[i].id === "appleiap") {
|
||||
console.log("存在苹果内购channels",channels, );
|
||||
that.iapChannel = channels[i];
|
||||
// 先检测有没有未完成的订单
|
||||
that.restoreComplateRequest()
|
||||
}else{
|
||||
console.log('安卓客户端');
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
// 检测是否有未关闭订单
|
||||
restoreComplateRequest() {
|
||||
let that = this
|
||||
console.log('检测未完成订单')
|
||||
this.iapChannel.restoreComplateRequest({
|
||||
manualFinishTransaction: true
|
||||
}, function(results) {
|
||||
if (!that.checking) {
|
||||
that.checking = true
|
||||
// results 格式为数组存放恢复的IAP商品交易信息对象 IAPTransaction,通用需将返回的支付凭证传给后端进行二次认证
|
||||
that.ComplateRequestArr = results
|
||||
console.log('未完成订单数组共有:=》',that.ComplateRequestArr.length ,that.ComplateRequestArr)
|
||||
|
||||
if (that.ComplateRequestArr.length > 0) {
|
||||
that.ComplateRequestArr.map((item, index) => {
|
||||
// "0"为正在支付;"1"为支付成功;"2"为支付失败;"3"为支付已恢复。
|
||||
if (item.transactionState == '1') {
|
||||
console.log('待验证订单,即将进入后台验证:=>', item)
|
||||
// return false
|
||||
// 已经支付,但是没有走逻辑的内购订单 就发给后台做验证
|
||||
that.iapCheck(item, index)
|
||||
// that.finishTransaction(item)
|
||||
} else {
|
||||
// 其他状态的内购订单
|
||||
that.finishTransaction(item)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
// 关闭订单
|
||||
finishTransaction(trans) {
|
||||
this.iapChannel.finishTransaction(
|
||||
trans,
|
||||
(success) => {
|
||||
console.log("关闭订单成功");
|
||||
that.checking = false
|
||||
},
|
||||
(fail) => {
|
||||
console.log("关闭订单失败");
|
||||
that.checking = false
|
||||
}
|
||||
);
|
||||
},
|
||||
iapCheck(result) {
|
||||
let that = this;
|
||||
console.log("进入后台验证");
|
||||
let data = {
|
||||
transactionId: result.transactionIdentifier, // 支付交易id
|
||||
customerOid: store.state.userInfo.id,
|
||||
productId: result.payment.productid.slice(1), // 产品id
|
||||
orderId: result.payment.username, // 系统订单号
|
||||
receiptData: result.transactionReceipt, // 苹果返回收据
|
||||
// isSandBox:true
|
||||
// body: that.stepsCj.priceTypeId // 充值类型id
|
||||
};
|
||||
console.log("提交给后台的数据=>", data);
|
||||
// return false
|
||||
$http
|
||||
.request({
|
||||
url: "/Ipa/veri",
|
||||
method: "POST", // POST、GET、PUT、DELETE,具体说明查看官方文档
|
||||
data,
|
||||
header: {
|
||||
//默认 无 说明:请求头
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
})
|
||||
// $http.post('Ipa/veri', data)
|
||||
.then((res) => {
|
||||
// console.log(JSON.stringify(res));
|
||||
if (res.code == 0) {
|
||||
// uni.hideLoading()
|
||||
console.log("充值订单已处理....");
|
||||
// 服务器验证票据有效后在客户端关闭订单 (iapChannel.finishTransaction)
|
||||
that.finishTransaction(result);
|
||||
}
|
||||
})
|
||||
.catch((e) => {
|
||||
console.log('后台验证失败=>',e);
|
||||
});
|
||||
},
|
||||
}
|
||||
module.exports = {iap}
|
||||
|
||||
Reference in New Issue
Block a user