app 内购+充值bug
This commit is contained in:
8
App.vue
8
App.vue
@@ -3,6 +3,9 @@
|
|||||||
music,
|
music,
|
||||||
bgm
|
bgm
|
||||||
} from '@/utils/music.js'
|
} from '@/utils/music.js'
|
||||||
|
import {
|
||||||
|
iap
|
||||||
|
} from "@/utils/myIapCheck.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
|
||||||
@@ -27,7 +30,10 @@
|
|||||||
onLaunch: function(e) {
|
onLaunch: function(e) {
|
||||||
// 检测自动更新
|
// 检测自动更新
|
||||||
// #ifdef APP-PLUS
|
// #ifdef APP-PLUS
|
||||||
updata()
|
updata();
|
||||||
|
// 检测是否有未关闭苹果内购订单
|
||||||
|
iap.getChannels();
|
||||||
|
console.log('引入了?');
|
||||||
// #endif
|
// #endif
|
||||||
|
|
||||||
uni.getSystemInfo({
|
uni.getSystemInfo({
|
||||||
|
|||||||
@@ -12,8 +12,8 @@
|
|||||||
"src" : "图片路径"
|
"src" : "图片路径"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"versionName" : "1.2.48",
|
"versionName" : "1.2.49",
|
||||||
"versionCode" : 1248,
|
"versionCode" : 1249,
|
||||||
"app-plus" : {
|
"app-plus" : {
|
||||||
"compatible" : {
|
"compatible" : {
|
||||||
"ignoreVersion" : true
|
"ignoreVersion" : true
|
||||||
|
|||||||
@@ -685,7 +685,6 @@
|
|||||||
// this.getJtData()
|
// this.getJtData()
|
||||||
},
|
},
|
||||||
getJtData(cid) {
|
getJtData(cid) {
|
||||||
|
|
||||||
this.$http
|
this.$http
|
||||||
// .post('book/label/list',{
|
// .post('book/label/list',{
|
||||||
.post('book/labelAndMarket/getShopProductListByLabelId', {
|
.post('book/labelAndMarket/getShopProductListByLabelId', {
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
<public-module></public-module>
|
<public-module></public-module>
|
||||||
<z-nav-bar title="充值"></z-nav-bar>
|
<z-nav-bar title="充值"></z-nav-bar>
|
||||||
<view class="cha_jine">
|
<view class="cha_jine">
|
||||||
<view class="cj_title">充值金额</view>
|
<view class="cj_title">充值金额1</view>
|
||||||
<view class="cj_xiang">
|
<view class="cj_xiang">
|
||||||
<view v-for="(item, index) in cjList" @click="chosPric(item)"
|
<view v-for="(item, index) in cjList" @click="chosPric(item)"
|
||||||
:class="stepsCj.priceTypeId == item.priceTypeId?'Tab_cj cj_price':'cj_price'">
|
:class="stepsCj.priceTypeId == item.priceTypeId?'Tab_cj cj_price':'cj_price'">
|
||||||
@@ -87,11 +87,13 @@
|
|||||||
// IapTransactionState
|
// IapTransactionState
|
||||||
// } from "@/utils/iap.js"
|
// } from "@/utils/iap.js"
|
||||||
import {
|
import {
|
||||||
mapState,mapMutations
|
mapState,
|
||||||
|
mapMutations
|
||||||
} from 'vuex';
|
} from 'vuex';
|
||||||
import {
|
import {
|
||||||
setPay,
|
setPay,
|
||||||
setPayAssign,setWXPay
|
setPayAssign,
|
||||||
|
setWXPay
|
||||||
} from '@/config/utils';
|
} from '@/config/utils';
|
||||||
// const IAPOrders = [ // 根据这些ids获取到苹果app内商品信息,这些ids就是你上面设置的产品id
|
// const IAPOrders = [ // 根据这些ids获取到苹果app内商品信息,这些ids就是你上面设置的产品id
|
||||||
// 'add69'
|
// 'add69'
|
||||||
@@ -99,12 +101,12 @@
|
|||||||
export default {
|
export default {
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
playData:{},
|
playData: {},
|
||||||
xieyi: {
|
xieyi: {
|
||||||
title: '',
|
title: '',
|
||||||
content: ''
|
content: ''
|
||||||
},
|
},
|
||||||
chargeOrderSn:'', // 通过query传过来的orderSN(二次支付情况)
|
chargeOrderSn: '', // 通过query传过来的orderSN(二次支付情况)
|
||||||
xieyiShow: false,
|
xieyiShow: false,
|
||||||
stepsCj: {},
|
stepsCj: {},
|
||||||
cjList: [],
|
cjList: [],
|
||||||
@@ -135,7 +137,7 @@
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
iosPaylist: [{
|
iosPaylist: [{
|
||||||
title: 'apple pay支付',
|
title: 'IAP支付',
|
||||||
id: 3,
|
id: 3,
|
||||||
img: '../../static/icon/pay_2.png'
|
img: '../../static/icon/pay_2.png'
|
||||||
}],
|
}],
|
||||||
@@ -166,20 +168,52 @@
|
|||||||
computed: {
|
computed: {
|
||||||
...mapState(['userInfo']),
|
...mapState(['userInfo']),
|
||||||
},
|
},
|
||||||
components:{
|
components: {
|
||||||
musicPlay
|
musicPlay
|
||||||
},
|
},
|
||||||
//方法
|
//方法
|
||||||
methods: {
|
methods: {
|
||||||
...mapMutations(['setUserInfo']),
|
...mapMutations(['setUserInfo']),
|
||||||
|
// 查询未关闭iap订单
|
||||||
|
async restoreComplateRequest() {
|
||||||
|
let that = this
|
||||||
|
console.log('检测未完成订单')
|
||||||
|
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(trans, (success) => {
|
this.iapChannel.finishTransaction(trans, (success) => {
|
||||||
console.log('关闭订单成功');
|
console.log('关闭订单成功');
|
||||||
this.setUserInfo({restoreFlag:false});
|
this.setUserInfo({
|
||||||
}, (fail) => {
|
restoreFlag: false
|
||||||
console.log('关闭订单失败');
|
});
|
||||||
});
|
}, (fail) => {
|
||||||
|
console.log('关闭订单失败');
|
||||||
|
});
|
||||||
},
|
},
|
||||||
showXieyi() {
|
showXieyi() {
|
||||||
this.$http
|
this.$http
|
||||||
@@ -201,17 +235,37 @@
|
|||||||
}
|
}
|
||||||
// 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(channels, 'channels')
|
})
|
||||||
|
plus.payment.getChannels(async (channels) => {
|
||||||
|
// console.log(channels, 'channels')
|
||||||
for (var i in channels) {
|
for (var i in channels) {
|
||||||
// 判断是否苹果支付1
|
// 判断是否苹果支付1
|
||||||
if (channels[i].id === 'appleiap') {
|
if (channels[i].id === 'appleiap') {
|
||||||
that.iapChannel = channels[i]
|
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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -226,16 +280,20 @@
|
|||||||
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(that.stepsCj.priceTypeId+'');
|
||||||
console.log(IAPOrders, 'IAPOrders')
|
console.log(IAPOrders, 'IAPOrders')
|
||||||
// 新建订单
|
// 新建订单
|
||||||
|
uni.showLoading({
|
||||||
|
title: "正在创建订单",
|
||||||
|
mask: true,
|
||||||
|
});
|
||||||
that.iapChannel.requestOrder(IAPOrders, function(event) {
|
that.iapChannel.requestOrder(IAPOrders, function(event) {
|
||||||
// uni.hideLoading()
|
// uni.hideLoading()
|
||||||
console.log(event, 'event')
|
console.log(event, 'event')
|
||||||
for (var index in event) {
|
for (var index in event) {
|
||||||
var OrderItem = event[index]
|
var OrderItem = event[index]
|
||||||
// console.log(OrderItem, 'OrderItem')
|
// console.log(OrderItem, 'OrderItem')
|
||||||
console.log(OrderItem.productid,'OrderItem.productid')
|
console.log(OrderItem.productid, 'OrderItem.productid')
|
||||||
that.topay(OrderItem.productid)
|
that.topay(OrderItem.productid)
|
||||||
}
|
}
|
||||||
}, function(erroemsg) {
|
}, function(erroemsg) {
|
||||||
@@ -247,14 +305,14 @@
|
|||||||
},
|
},
|
||||||
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,'二次支付的订单号')
|
});
|
||||||
// }
|
// this.setUserInfo({
|
||||||
// var restoreFlag = true; // 调用支付接口时标记 restoreFlag = true , 实际应用请将标记存储在 storage 中
|
// restoreFlag: true
|
||||||
this.setUserInfo({restoreFlag:true});
|
// });
|
||||||
console.log(this.userInfo,'更新后的用户信息')
|
// console.log(this.userInfo, '更新后的用户信息')
|
||||||
plus.payment.request(that.iapChannel, {
|
plus.payment.request(that.iapChannel, {
|
||||||
productid: id,
|
productid: id,
|
||||||
username: that.orderSn, // 用户标识/订单标识
|
username: that.orderSn, // 用户标识/订单标识
|
||||||
@@ -267,30 +325,35 @@
|
|||||||
that.iapCheck(result)
|
that.iapCheck(result)
|
||||||
}, function(e) {
|
}, function(e) {
|
||||||
console.log('错误回调', e)
|
console.log('错误回调', e)
|
||||||
if(e.errCode == 2){
|
if (e.code == 2) {
|
||||||
// 用户未绑定支付方式,app内支付流程结束,系统弹出框引导用户绑定支付方式,此过程将跳转到系统应用 AppStore 进行绑定支付方式,绑定成功同步支付成功,用户成功付款
|
uni.showToast({
|
||||||
plus.runtime.openURL("https://apps.apple.com/account/billing");
|
title:'取消支付,内购订单即将关闭',
|
||||||
}else{
|
icon:'none'
|
||||||
// restoreFlag = false; // 支付失败清楚标记
|
})
|
||||||
that.finishTransaction(result);
|
}else {
|
||||||
//console.log('订单关闭后的用户信息', that.userInfo);
|
uni.showToast({
|
||||||
console.log(e)
|
title:'支付失败,内购订单即将关闭',
|
||||||
//console.log(e.message)
|
icon:'none'
|
||||||
|
})
|
||||||
|
console.log('其他支付错误',e);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
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, // 产品id
|
||||||
orderId: result.payment.username, // 系统订单号
|
orderId: result.payment.username, // 系统订单号
|
||||||
receiptData: result.transactionReceipt ,// 苹果返回收据
|
receiptData: result.transactionReceipt, // 苹果返回收据
|
||||||
// body: that.stepsCj.priceTypeId // 充值类型id
|
// body: that.stepsCj.priceTypeId // 充值类型id
|
||||||
}
|
}
|
||||||
console.log(data,'data')
|
console.log("提交给后台的数据",data);
|
||||||
$http.request({
|
$http.request({
|
||||||
url: "/Ipa/veri",
|
url: "/Ipa/veri",
|
||||||
method: "POST", // POST、GET、PUT、DELETE,具体说明查看官方文档
|
method: "POST", // POST、GET、PUT、DELETE,具体说明查看官方文档
|
||||||
@@ -300,24 +363,27 @@
|
|||||||
},
|
},
|
||||||
}).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.setUserInfo({restoreFlag:false}) : ''
|
uni.showToast({
|
||||||
console.log(that.userInfo.restoreFlag)
|
title:'充值成功!',
|
||||||
console.log('充值订单已处理,请留意账户金额变动....')
|
icon:'success'
|
||||||
// 服务器验证票据有效后在客户端关闭订单 (iapChannel.finishTransaction)
|
})
|
||||||
that.finishTransaction(result);
|
console.log("充值订单已处理,请留意账户金额变动....");
|
||||||
|
that.finishTransaction(result);
|
||||||
}
|
}
|
||||||
}).catch(e => {
|
}).catch(e => {
|
||||||
|
uni.hideLoading()
|
||||||
|
console.log('后台验证失败=>',e);
|
||||||
uni.showModal({
|
uni.showModal({
|
||||||
title: '提示',
|
title: "提示",
|
||||||
showCancel:false,
|
showCancel: false,
|
||||||
content: '支付验证失败,请稍后重启app,如不能解决您的问题,可联系官方客服',
|
content: "支付验证失败,请稍后重启app,如不能解决您的问题,可联系官方客服",
|
||||||
success: function (res) {
|
success: function(res) {
|
||||||
if (res.confirm) {
|
if (res.confirm) {
|
||||||
console.log('用户点击确定');
|
console.log("用户点击确定");
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
@@ -335,15 +401,15 @@
|
|||||||
// 获取充值金额
|
// 获取充值金额
|
||||||
getData() {
|
getData() {
|
||||||
// console.log(this.isAndroid)
|
// console.log(this.isAndroid)
|
||||||
if(this.isAndroid){
|
if (this.isAndroid) {
|
||||||
this.getAndorList()
|
this.getAndorList()
|
||||||
}else{
|
} else {
|
||||||
this.getAppleList()
|
this.getAppleList()
|
||||||
}
|
}
|
||||||
|
|
||||||
},
|
},
|
||||||
// 安卓充值列表
|
// 安卓充值列表
|
||||||
getAndorList(){
|
getAndorList() {
|
||||||
this.$http
|
this.$http
|
||||||
.post('book/bookbuyconfig/getVipOrPoint', {
|
.post('book/bookbuyconfig/getVipOrPoint', {
|
||||||
type: 'point',
|
type: 'point',
|
||||||
@@ -355,7 +421,7 @@
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
// 苹果充值列表
|
// 苹果充值列表
|
||||||
getAppleList(){
|
getAppleList() {
|
||||||
this.$http
|
this.$http
|
||||||
.post('book/bookbuyconfig/getVipOrPoint', {
|
.post('book/bookbuyconfig/getVipOrPoint', {
|
||||||
type: 'point',
|
type: 'point',
|
||||||
@@ -382,11 +448,11 @@
|
|||||||
this.iphonepay()
|
this.iphonepay()
|
||||||
},
|
},
|
||||||
// 充值
|
// 充值
|
||||||
goToPay(){
|
goToPay() {
|
||||||
this.kaiChar()
|
this.kaiChar()
|
||||||
},
|
},
|
||||||
// 正常充值
|
// 正常充值
|
||||||
kaiChar() { // 常规充值
|
kaiChar() { // 常规充值
|
||||||
if (this.radioValue == '1') {
|
if (this.radioValue == '1') {
|
||||||
uni.showLoading({
|
uni.showLoading({
|
||||||
title: '支付中,请勿离开',
|
title: '支付中,请勿离开',
|
||||||
@@ -402,7 +468,9 @@
|
|||||||
realMoney: that.stepsCj.money * 1, //实收金额
|
realMoney: that.stepsCj.money * 1, //实收金额
|
||||||
orderStatus: 0, //订单状态
|
orderStatus: 0, //订单状态
|
||||||
orderType: "point", //订单类型
|
orderType: "point", //订单类型
|
||||||
productId: that.stepsCj.priceTypeId // 充值的类型id
|
// appName: "",
|
||||||
|
come: 0,
|
||||||
|
productId: that.stepsCj.priceTypeId // 充值的类型id
|
||||||
}
|
}
|
||||||
$http.request({
|
$http.request({
|
||||||
url: "book/buyOrder/rechargeSave",
|
url: "book/buyOrder/rechargeSave",
|
||||||
@@ -413,7 +481,7 @@
|
|||||||
},
|
},
|
||||||
}).then(res => {
|
}).then(res => {
|
||||||
that.orderSn = res.orderSn
|
that.orderSn = res.orderSn
|
||||||
uni.hideLoading()
|
// uni.hideLoading()
|
||||||
if (res.code == 0) {
|
if (res.code == 0) {
|
||||||
if (that.payType == 2) {
|
if (that.payType == 2) {
|
||||||
setPay({
|
setPay({
|
||||||
@@ -425,15 +493,17 @@
|
|||||||
body: that.stepsCj.priceTypeId,
|
body: that.stepsCj.priceTypeId,
|
||||||
}, res => {
|
}, res => {
|
||||||
if (res.success) {
|
if (res.success) {
|
||||||
|
uni.hideLoading();
|
||||||
uni.showToast({
|
uni.showToast({
|
||||||
title: "支付成功"
|
title: "支付成功"
|
||||||
});
|
});
|
||||||
setTimeout(()=>{
|
setTimeout(() => {
|
||||||
uni.navigateTo({
|
uni.navigateTo({
|
||||||
url:'/pages/user/persCount'
|
url: '/pages/user/persCount'
|
||||||
})
|
})
|
||||||
},2000)
|
}, 2000)
|
||||||
} else {
|
} else {
|
||||||
|
uni.hideLoading();
|
||||||
uni.showToast({
|
uni.showToast({
|
||||||
title: "支付失败",
|
title: "支付失败",
|
||||||
icon: "none",
|
icon: "none",
|
||||||
@@ -444,43 +514,45 @@
|
|||||||
} else if (that.payType == 1) {
|
} else if (that.payType == 1) {
|
||||||
// 微信支付
|
// 微信支付
|
||||||
that.orderSn = res.orderSn
|
that.orderSn = res.orderSn
|
||||||
let data1={
|
let data1 = {
|
||||||
orderSn:that.orderSn,
|
orderSn: that.orderSn,
|
||||||
buyOrderId: that.stepsCj.priceTypeId,
|
buyOrderId: that.stepsCj.priceTypeId,
|
||||||
totalAmount: that.stepsCj.money
|
totalAmount: that.stepsCj.money
|
||||||
}
|
}
|
||||||
console.log(data1,'data1')
|
console.log(data1, 'data1')
|
||||||
// console.log(this.userInfo.channelList,'channelList')
|
// console.log(this.userInfo.channelList,'channelList')
|
||||||
// this.userInfo.channelList.map(item => {
|
// this.userInfo.channelList.map(item => {
|
||||||
// if(item.id == "wxpay"){
|
// if(item.id == "wxpay"){
|
||||||
// console.log('支持微信支付')
|
// console.log('支持微信支付')
|
||||||
setWXPay(data1,res => {
|
setWXPay(data1, res => {
|
||||||
if (res.success) {
|
if (res.success) {
|
||||||
uni.showToast({
|
uni.hideLoading();
|
||||||
title: "支付成功"
|
uni.showToast({
|
||||||
});
|
title: "支付成功"
|
||||||
setTimeout(()=>{
|
});
|
||||||
uni.navigateTo({
|
setTimeout(() => {
|
||||||
url:'/pages/user/persCount'
|
uni.navigateTo({
|
||||||
})
|
url: '/pages/user/persCount'
|
||||||
},2000)
|
})
|
||||||
} else {
|
}, 2000)
|
||||||
console.log(res)
|
} else {
|
||||||
if(res.data.errMsg.indexOf('User canceled') != -1){
|
console.log(res)
|
||||||
uni.showToast({
|
uni.hideLoading();
|
||||||
title: "用户取消支付",
|
if (res.data.errMsg.indexOf('User canceled') != -1) {
|
||||||
icon: "none",
|
uni.showToast({
|
||||||
image: '../../static/icon/ic_close.png'
|
title: "用户取消支付",
|
||||||
});
|
icon: "none",
|
||||||
}else{
|
image: '../../static/icon/ic_close.png'
|
||||||
uni.showToast({
|
});
|
||||||
title: "支付失败",
|
} else {
|
||||||
icon: "none",
|
uni.showToast({
|
||||||
image: '../../static/icon/ic_close.png'
|
title: "支付失败",
|
||||||
});
|
icon: "none",
|
||||||
}
|
image: '../../static/icon/ic_close.png'
|
||||||
}
|
});
|
||||||
})
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
// }
|
// }
|
||||||
// })
|
// })
|
||||||
|
|
||||||
@@ -489,6 +561,11 @@
|
|||||||
that.iosPay()
|
that.iosPay()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}).catch(e => {
|
||||||
|
uni.showToast({
|
||||||
|
title: "系统下单失败",
|
||||||
|
icon: "none",
|
||||||
|
});
|
||||||
})
|
})
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -247,7 +247,7 @@
|
|||||||
yszcText: {},
|
yszcText: {},
|
||||||
quShow: false,
|
quShow: false,
|
||||||
quCodeList: [], // 国家区域码
|
quCodeList: [], // 国家区域码
|
||||||
quCode: 86,
|
quCode: "86",
|
||||||
|
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|||||||
Binary file not shown.
118
utils/myIapCheck.js
Normal file
118
utils/myIapCheck.js
Normal file
@@ -0,0 +1,118 @@
|
|||||||
|
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, // 产品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);
|
||||||
|
// that.finishTransaction(result);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
}
|
||||||
|
module.exports = {iap}
|
||||||
|
|
||||||
Reference in New Issue
Block a user