苹果内购+订单结算页面条件编译
This commit is contained in:
8
App.vue
8
App.vue
@@ -1,8 +1,7 @@
|
|||||||
<script>
|
<script>
|
||||||
import {
|
import {
|
||||||
music,
|
iap
|
||||||
bgm
|
} from "@/utils/myIapCheck.js";
|
||||||
} from "@/utils/music.js";
|
|
||||||
import store from "@/store/index.js";
|
import store from "@/store/index.js";
|
||||||
import socket from "@/config/socket";
|
import socket from "@/config/socket";
|
||||||
// #ifdef H5
|
// #ifdef H5
|
||||||
@@ -59,7 +58,8 @@
|
|||||||
if (store.state.userInfo.token) {
|
if (store.state.userInfo.token) {
|
||||||
socket.init();
|
socket.init();
|
||||||
}
|
}
|
||||||
// APPUpdate();
|
// 检测是否有未关闭苹果内购订单
|
||||||
|
iap.getChannels()
|
||||||
// #endif
|
// #endif
|
||||||
},
|
},
|
||||||
onShow: function(e) {
|
onShow: function(e) {
|
||||||
|
|||||||
@@ -1078,16 +1078,11 @@ export default {
|
|||||||
} else if (payItem.paymentMethod == 3) {
|
} else if (payItem.paymentMethod == 3) {
|
||||||
// 苹果充值
|
// 苹果充值
|
||||||
console.log("苹果二次支付");
|
console.log("苹果二次支付");
|
||||||
if (this.isAndorid) {
|
|
||||||
uni.showModal({
|
uni.showModal({
|
||||||
title: "提示",
|
content:'apple内购订单不支持继续支付,请重新发起支付申请并完成支付',
|
||||||
showCancel: false,
|
confirmText:'好的',
|
||||||
content:
|
showCancel:false
|
||||||
"很抱歉,当前订单属于苹果系统内购订单,安卓系统无法完成支付操作,您可切换到苹果系统进行支付,也可以取消该订单,并重新下单",
|
})
|
||||||
});
|
|
||||||
} else {
|
|
||||||
this.iphonepay(payItem);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
@@ -897,7 +897,7 @@ export default {
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
console.log(res, "内容获取成功");
|
// console.log(res, "内容获取成功");
|
||||||
that.pagination.total = res.data.total;
|
that.pagination.total = res.data.total;
|
||||||
if (res.data.total == 0) {
|
if (res.data.total == 0) {
|
||||||
this.isLoadingHide = true;
|
this.isLoadingHide = true;
|
||||||
@@ -948,7 +948,6 @@ export default {
|
|||||||
);
|
);
|
||||||
} else if (payItem.paymentMethod == 1) {
|
} else if (payItem.paymentMethod == 1) {
|
||||||
console.log("微信支付");
|
console.log("微信支付");
|
||||||
// console.log(this.isAndorid)
|
|
||||||
if (this.isAndorid == false) {
|
if (this.isAndorid == false) {
|
||||||
uni.showModal({
|
uni.showModal({
|
||||||
title: "提示",
|
title: "提示",
|
||||||
@@ -986,19 +985,24 @@ export default {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} else if (payItem.paymentMethod == 3) {
|
} else if (payItem.paymentMethod == 3 && this.ordersListTab == 0 ) {
|
||||||
// 苹果充值
|
// 苹果充值
|
||||||
console.log("苹果二次支付");
|
console.log("苹果二次支付");
|
||||||
if (this.isAndorid) {
|
|
||||||
uni.showModal({
|
uni.showModal({
|
||||||
title: "提示",
|
content:'apple内购订单不支持继续支付,请重新发起支付申请并完成支付',
|
||||||
showCancel: false,
|
confirmText:'好的',
|
||||||
content:
|
showCancel:false
|
||||||
"很抱歉,当前订单属于苹果系统内购订单,安卓系统无法完成支付操作,您可切换到苹果系统进行支付,也可以取消该订单,并重新下单",
|
})
|
||||||
});
|
// if (this.isAndorid) {
|
||||||
} else {
|
// uni.showModal({
|
||||||
this.iphonepay(payItem);
|
// title: "提示",
|
||||||
}
|
// showCancel: false,
|
||||||
|
// content:
|
||||||
|
// "很抱歉,当前订单属于苹果系统内购订单,安卓系统无法完成支付操作,您可切换到苹果系统进行支付,也可以取消该订单,并重新下单",
|
||||||
|
// });
|
||||||
|
// } else {
|
||||||
|
// this.iphonepay(payItem);
|
||||||
|
// }
|
||||||
}else if (payItem.paymentMethod == 4){
|
}else if (payItem.paymentMethod == 4){
|
||||||
console.log('天医币二次支付')
|
console.log('天医币二次支付')
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -360,6 +360,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.jianjie {
|
.jianjie {
|
||||||
|
overflow: hidden!important;
|
||||||
margin-top: 10rpx;
|
margin-top: 10rpx;
|
||||||
font-size: 24rpx;
|
font-size: 24rpx;
|
||||||
@include bov();
|
@include bov();
|
||||||
|
|||||||
@@ -885,7 +885,7 @@
|
|||||||
if (res.code == 0) {
|
if (res.code == 0) {
|
||||||
if (res.chapterList.length > 0) {
|
if (res.chapterList.length > 0) {
|
||||||
this.courseList = res.chapterList
|
this.courseList = res.chapterList
|
||||||
console.log('status++++++++++++++', this.courseList)
|
// console.log('status++++++++++++++', this.courseList)
|
||||||
} else {
|
} else {
|
||||||
this.courseList = []
|
this.courseList = []
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -212,7 +212,7 @@
|
|||||||
</view>
|
</view>
|
||||||
<view class="order_top common_radius_box color_shandow goods_box pay_box">
|
<view class="order_top common_radius_box color_shandow goods_box pay_box">
|
||||||
<view class="title">支付方式</view>
|
<view class="title">支付方式</view>
|
||||||
|
<template v-if="isAndorid">
|
||||||
<view
|
<view
|
||||||
class="curriulum_title_box goods_item pay_item"
|
class="curriulum_title_box goods_item pay_item"
|
||||||
v-for="(v, i) in payList"
|
v-for="(v, i) in payList"
|
||||||
@@ -260,7 +260,58 @@
|
|||||||
</template>
|
</template>
|
||||||
</view>
|
</view>
|
||||||
</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
|
<view
|
||||||
class="goods_detail_list_title bg_box_shandow color_shandow bg_color"
|
class="goods_detail_list_title bg_box_shandow color_shandow bg_color"
|
||||||
>
|
>
|
||||||
@@ -525,6 +576,14 @@ export default {
|
|||||||
value: "2",
|
value: "2",
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
payListIOS: [
|
||||||
|
{
|
||||||
|
text: "天医币",
|
||||||
|
imgUrl: require("@/static/icon/pay_3.png"),
|
||||||
|
type: 4,
|
||||||
|
value: "2",
|
||||||
|
},
|
||||||
|
],
|
||||||
priceBreakdownList: [],
|
priceBreakdownList: [],
|
||||||
orderInfoList: [
|
orderInfoList: [
|
||||||
{
|
{
|
||||||
@@ -628,6 +687,9 @@ export default {
|
|||||||
color: "#fff",
|
color: "#fff",
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
haveCourse: false, // 结算队列是否有课程类型的商品
|
||||||
|
isAndorid:null, //操作系统
|
||||||
|
beizhuShow:false, // 是否显示天医币说明?
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
async onLoad(options) {
|
async onLoad(options) {
|
||||||
@@ -641,6 +703,10 @@ export default {
|
|||||||
// this.isShowAddress = true;
|
// this.isShowAddress = true;
|
||||||
// }
|
// }
|
||||||
this.goodsDataList = this.options.goods;
|
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") {
|
if (this.options.sourceType == "curriculum") {
|
||||||
this.goToInfo = {
|
this.goToInfo = {
|
||||||
url: "/pages/curriculum/order/index/index",
|
url: "/pages/curriculum/order/index/index",
|
||||||
@@ -683,13 +749,32 @@ export default {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
// this.selectPayIndex = 0;
|
// this.selectPayIndex = 0;
|
||||||
|
|
||||||
console.log("this.addressData at line 416:", this.addressData);
|
console.log("this.addressData at line 416:", this.addressData);
|
||||||
|
// #ifdef APP-PLUS
|
||||||
|
this.getOS()
|
||||||
|
// #endif
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
...mapState(["userInfo"]),
|
...mapState(["userInfo"]),
|
||||||
},
|
},
|
||||||
methods: {
|
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) {
|
handleChangejf(val) {
|
||||||
console.log("val at line 653:", val);
|
console.log("val at line 653:", val);
|
||||||
var value = val;
|
var value = val;
|
||||||
@@ -1197,8 +1282,10 @@ export default {
|
|||||||
|
|
||||||
radioChange(index) {
|
radioChange(index) {
|
||||||
this.selectPayIndex = index;
|
this.selectPayIndex = index;
|
||||||
|
this.selectPayIndex == 2 ? this.beizhuShow = true : this.beizhuShow = false
|
||||||
this.payType = this.payList[this.selectPayIndex].type;
|
this.payType = this.payList[this.selectPayIndex].type;
|
||||||
console.log("this.selectPayIndex at line 315:", this.selectPayIndex);
|
console.log("this.selectPayIndex at line 315:", this.selectPayIndex);
|
||||||
|
|
||||||
this.$forceUpdate();
|
this.$forceUpdate();
|
||||||
},
|
},
|
||||||
handleValChange(e) {
|
handleValChange(e) {
|
||||||
|
|||||||
@@ -103,6 +103,7 @@
|
|||||||
export default {
|
export default {
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
|
checking : false,
|
||||||
playData: {},
|
playData: {},
|
||||||
options: {},
|
options: {},
|
||||||
xieyi: {
|
xieyi: {
|
||||||
@@ -180,15 +181,45 @@
|
|||||||
//方法
|
//方法
|
||||||
methods: {
|
methods: {
|
||||||
...mapMutations(["setUserInfo"]),
|
...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) {
|
finishTransaction(trans) {
|
||||||
this.iapChannel.finishTransaction(
|
this.iapChannel.finishTransaction(
|
||||||
trans,
|
trans,
|
||||||
(success) => {
|
(success) => {
|
||||||
console.log("关闭订单成功");
|
console.log("关闭订单成功");
|
||||||
this.setUserInfo({
|
|
||||||
restoreFlag: false
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
(fail) => {
|
(fail) => {
|
||||||
console.log("关闭订单失败");
|
console.log("关闭订单失败");
|
||||||
@@ -196,13 +227,6 @@
|
|||||||
);
|
);
|
||||||
},
|
},
|
||||||
async showXieyi() {
|
async showXieyi() {
|
||||||
|
|
||||||
// this.$http.get(`sys/agreement/list?key=pay`).then((res) => {
|
|
||||||
// this.xieyi = res.page.list[0];
|
|
||||||
// this.xieyiShow = true;
|
|
||||||
// });
|
|
||||||
|
|
||||||
|
|
||||||
var data = await this.$commonJS.getAgreement(106);
|
var data = await this.$commonJS.getAgreement(106);
|
||||||
if (data.content) {
|
if (data.content) {
|
||||||
data.content = data.content.replace(
|
data.content = data.content.replace(
|
||||||
@@ -231,17 +255,41 @@
|
|||||||
}
|
}
|
||||||
// console.log(this.radioValue)
|
// console.log(this.radioValue)
|
||||||
},
|
},
|
||||||
iphonepay() {
|
async iphonepay() {
|
||||||
const that = this;
|
const that = this;
|
||||||
// 如果ios已经绑定支付信息,就直接支付,如果没有绑定,就需要先绑定
|
// 如果ios已经绑定支付信息,就直接支付,如果没有绑定,就需要先绑定
|
||||||
console.log("检测支付环境...");
|
uni.showLoading({
|
||||||
plus.payment.getChannels((channels) => {
|
title:'检测支付环境'
|
||||||
|
})
|
||||||
|
// console.log("检测支付环境...");
|
||||||
|
plus.payment.getChannels(async (channels) => {
|
||||||
console.log(channels, "channels");
|
console.log(channels, "channels");
|
||||||
for (var i in channels) {
|
for (var i in channels) {
|
||||||
// 判断是否苹果支付1
|
|
||||||
if (channels[i].id === "appleiap") {
|
if (channels[i].id === "appleiap") {
|
||||||
that.iapChannel = channels[i];
|
that.iapChannel = channels[i];
|
||||||
|
// 先检测有没有未完成的订单
|
||||||
|
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();
|
that.requestOrder();
|
||||||
|
clearInterval(timer)
|
||||||
|
console.log('timer清除了吗',timer);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
},1000)
|
||||||
|
// console.log('that.checking',that.checking)
|
||||||
|
/// 限制调用
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -255,9 +303,13 @@
|
|||||||
console.log(that.stepsCj.priceTypeId, 88888888);
|
console.log(that.stepsCj.priceTypeId, 88888888);
|
||||||
// ['xxxxx'] 是平台申请拿到的内购商品的id
|
// ['xxxxx'] 是平台申请拿到的内购商品的id
|
||||||
let IAPOrders = [];
|
let IAPOrders = [];
|
||||||
IAPOrders.push(that.stepsCj.priceTypeId + "");
|
IAPOrders.push("p"+that.stepsCj.priceTypeId);
|
||||||
console.log(IAPOrders, "IAPOrders");
|
console.log(IAPOrders, "IAPOrders");
|
||||||
// 新建订单
|
// 新建订单
|
||||||
|
uni.showLoading({
|
||||||
|
title: "正在创建订单",
|
||||||
|
mask: true,
|
||||||
|
});
|
||||||
that.iapChannel.requestOrder(
|
that.iapChannel.requestOrder(
|
||||||
IAPOrders,
|
IAPOrders,
|
||||||
function(event) {
|
function(event) {
|
||||||
@@ -280,16 +332,10 @@
|
|||||||
},
|
},
|
||||||
topay(id) {
|
topay(id) {
|
||||||
const that = this;
|
const that = this;
|
||||||
uni.hideLoading();
|
uni.showLoading({
|
||||||
// if(this.chargeOrderSn != '' || this.chargeOrderSn != undefined){ // 判断是不是二次支付的订单
|
title: "正在支付",
|
||||||
// that.orderSn = this.chargeOrderSn
|
mask: true,
|
||||||
// console.log(that.orderSn,'二次支付的订单号')
|
|
||||||
// }
|
|
||||||
// var restoreFlag = true; // 调用支付接口时标记 restoreFlag = true , 实际应用请将标记存储在 storage 中
|
|
||||||
this.setUserInfo({
|
|
||||||
restoreFlag: true
|
|
||||||
});
|
});
|
||||||
console.log(this.userInfo, "更新后的用户信息");
|
|
||||||
plus.payment.request(
|
plus.payment.request(
|
||||||
that.iapChannel, {
|
that.iapChannel, {
|
||||||
productid: id,
|
productid: id,
|
||||||
@@ -297,38 +343,51 @@
|
|||||||
manualFinishTransaction: true, // 3.5.1+ 支持,设置此参数后需要开发者主动关闭订单,参见下面的关闭订单方法 finishTransaction()
|
manualFinishTransaction: true, // 3.5.1+ 支持,设置此参数后需要开发者主动关闭订单,参见下面的关闭订单方法 finishTransaction()
|
||||||
},
|
},
|
||||||
function(result) {
|
function(result) {
|
||||||
// restoreFlag = false; // 支付成功清除标记 restoreFlag = false
|
// that.checking = false
|
||||||
that.transaction = result;
|
that.transaction = result;
|
||||||
// 支付成功,result 为 IAP商品交易信息对象 IAPTransaction 需将返回的支付凭证传给后端进行二次认证
|
// 支付成功,result 为 IAP商品交易信息对象 IAPTransaction 需将返回的支付凭证传给后端进行二次认证
|
||||||
that.iapCheck(result);
|
that.iapCheck(result);
|
||||||
},
|
},
|
||||||
function(e) {
|
function(e) {
|
||||||
|
// that.checking = false
|
||||||
console.log("错误回调", e);
|
console.log("错误回调", e);
|
||||||
if (e.errCode == 2) {
|
if (e.code == 2) {
|
||||||
|
uni.showToast({
|
||||||
|
title:'取消支付,内购订单即将关闭',
|
||||||
|
icon:'none'
|
||||||
|
})
|
||||||
|
|
||||||
// 用户未绑定支付方式,app内支付流程结束,系统弹出框引导用户绑定支付方式,此过程将跳转到系统应用 AppStore 进行绑定支付方式,绑定成功同步支付成功,用户成功付款
|
// 用户未绑定支付方式,app内支付流程结束,系统弹出框引导用户绑定支付方式,此过程将跳转到系统应用 AppStore 进行绑定支付方式,绑定成功同步支付成功,用户成功付款
|
||||||
plus.runtime.openURL("https://apps.apple.com/account/billing");
|
// plus.runtime.openURL("https://apps.apple.com/account/billing");
|
||||||
} else {
|
} else {
|
||||||
// restoreFlag = false; // 支付失败清楚标记
|
uni.showToast({
|
||||||
that.finishTransaction(result);
|
title:'支付失败,内购订单即将关闭',
|
||||||
//console.log('订单关闭后的用户信息', that.userInfo);
|
icon:'none'
|
||||||
console.log(e);
|
})
|
||||||
//console.log(e.message)
|
console.log('其他支付错误',e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// that.finishTransaction(result);
|
||||||
|
that.restoreComplateRequest()
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
iapCheck(result) {
|
iapCheck(result) {
|
||||||
let that = this;
|
let that = this;
|
||||||
console.log("进入后台验证");
|
console.log("进入后台验证");
|
||||||
|
uni.showLoading({
|
||||||
|
title:'正在验证订单结果'
|
||||||
|
})
|
||||||
let data = {
|
let data = {
|
||||||
transactionId: result.transactionIdentifier, // 支付交易id
|
transactionId: result.transactionIdentifier, // 支付交易id
|
||||||
customerOid: that.userInfo.id,
|
customerOid: that.userInfo.id,
|
||||||
productId: result.payment.productid, // 产品id
|
productId: result.payment.productid.slice(1), // 产品id
|
||||||
orderId: result.payment.username, // 系统订单号
|
orderId: result.payment.username, // 系统订单号
|
||||||
receiptData: result.transactionReceipt, // 苹果返回收据
|
receiptData: result.transactionReceipt, // 苹果返回收据
|
||||||
|
// isSandBox:true
|
||||||
// body: that.stepsCj.priceTypeId // 充值类型id
|
// body: that.stepsCj.priceTypeId // 充值类型id
|
||||||
};
|
};
|
||||||
console.log(data, "data");
|
console.log("提交给后台的数据",data);
|
||||||
$http
|
$http
|
||||||
.request({
|
.request({
|
||||||
url: "/Ipa/veri",
|
url: "/Ipa/veri",
|
||||||
@@ -342,19 +401,24 @@
|
|||||||
.then((res) => {
|
.then((res) => {
|
||||||
console.log(JSON.stringify(res));
|
console.log(JSON.stringify(res));
|
||||||
if (res.code == 0) {
|
if (res.code == 0) {
|
||||||
//uni.hideLoading()
|
uni.hideLoading()
|
||||||
that.userInfo.restoreFlag == true ?
|
// that.userInfo.restoreFlag == true ?
|
||||||
that.setUserInfo({
|
// that.setUserInfo({
|
||||||
restoreFlag: false
|
// restoreFlag: false
|
||||||
}) :
|
// }) :
|
||||||
"";
|
// "";
|
||||||
console.log(that.userInfo.restoreFlag);
|
uni.showToast({
|
||||||
|
title:'充值成功!',
|
||||||
|
icon:'success'
|
||||||
|
})
|
||||||
console.log("充值订单已处理,请留意账户金额变动....");
|
console.log("充值订单已处理,请留意账户金额变动....");
|
||||||
// 服务器验证票据有效后在客户端关闭订单 (iapChannel.finishTransaction)
|
// 服务器验证票据有效后在客户端关闭订单 (iapChannel.finishTransaction)
|
||||||
that.finishTransaction(result);
|
that.finishTransaction(result);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch((e) => {
|
.catch((e) => {
|
||||||
|
uni.hideLoading()
|
||||||
|
console.log('后台验证失败=>',e);
|
||||||
uni.showModal({
|
uni.showModal({
|
||||||
title: "提示",
|
title: "提示",
|
||||||
showCancel: false,
|
showCancel: false,
|
||||||
@@ -449,6 +513,10 @@
|
|||||||
},
|
},
|
||||||
//ios充值
|
//ios充值
|
||||||
iosPay() {
|
iosPay() {
|
||||||
|
// 苹果内购实现思路:
|
||||||
|
// 1.先确认支付通道是否包含苹果内购
|
||||||
|
// 2.检查一下是否存在上次未处理完的订单(主要是支付成功没有走回调的订单),异常订单直接关闭掉,成功没有走回调的提交给后台进行验证
|
||||||
|
// 3.请求并创建新的订单
|
||||||
this.iphonepay();
|
this.iphonepay();
|
||||||
},
|
},
|
||||||
// 充值
|
// 充值
|
||||||
|
|||||||
@@ -386,7 +386,7 @@
|
|||||||
this.$http
|
this.$http
|
||||||
.post('medical/home/getCourseMedicalTree')
|
.post('medical/home/getCourseMedicalTree')
|
||||||
.then(res => {
|
.then(res => {
|
||||||
console.log(res)
|
// console.log(res)
|
||||||
if (res.code == 0) {
|
if (res.code == 0) {
|
||||||
if (res.labels.length > 0) {
|
if (res.labels.length > 0) {
|
||||||
this.curseTagList = res.labels
|
this.curseTagList = res.labels
|
||||||
|
|||||||
@@ -249,7 +249,7 @@
|
|||||||
yszcText: {},
|
yszcText: {},
|
||||||
quShow: false,
|
quShow: false,
|
||||||
quCodeList: [], // 国家区域码
|
quCodeList: [], // 国家区域码
|
||||||
quCode: 86,
|
quCode: '86',
|
||||||
submitClickNum:0, // 登陆按钮点击次数
|
submitClickNum:0, // 登陆按钮点击次数
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
@@ -507,6 +507,7 @@
|
|||||||
}
|
}
|
||||||
if (this.quCode == null || this.quCode == 86) {
|
if (this.quCode == null || this.quCode == 86) {
|
||||||
if (!this.$base.phoneRegular.test(this.phone)) {
|
if (!this.$base.phoneRegular.test(this.phone)) {
|
||||||
|
this.submitClickNum += 1
|
||||||
uni.showToast({
|
uni.showToast({
|
||||||
title: '手机格式不正确',
|
title: '手机格式不正确',
|
||||||
icon: 'none'
|
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