app 内购+充值bug
This commit is contained in:
@@ -685,7 +685,6 @@
|
||||
// this.getJtData()
|
||||
},
|
||||
getJtData(cid) {
|
||||
|
||||
this.$http
|
||||
// .post('book/label/list',{
|
||||
.post('book/labelAndMarket/getShopProductListByLabelId', {
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<public-module></public-module>
|
||||
<z-nav-bar title="充值"></z-nav-bar>
|
||||
<view class="cha_jine">
|
||||
<view class="cj_title">充值金额</view>
|
||||
<view class="cj_title">充值金额1</view>
|
||||
<view class="cj_xiang">
|
||||
<view v-for="(item, index) in cjList" @click="chosPric(item)"
|
||||
:class="stepsCj.priceTypeId == item.priceTypeId?'Tab_cj cj_price':'cj_price'">
|
||||
@@ -87,11 +87,13 @@
|
||||
// IapTransactionState
|
||||
// } from "@/utils/iap.js"
|
||||
import {
|
||||
mapState,mapMutations
|
||||
mapState,
|
||||
mapMutations
|
||||
} from 'vuex';
|
||||
import {
|
||||
setPay,
|
||||
setPayAssign,setWXPay
|
||||
setPayAssign,
|
||||
setWXPay
|
||||
} from '@/config/utils';
|
||||
// const IAPOrders = [ // 根据这些ids获取到苹果app内商品信息,这些ids就是你上面设置的产品id
|
||||
// 'add69'
|
||||
@@ -99,12 +101,12 @@
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
playData:{},
|
||||
playData: {},
|
||||
xieyi: {
|
||||
title: '',
|
||||
content: ''
|
||||
},
|
||||
chargeOrderSn:'', // 通过query传过来的orderSN(二次支付情况)
|
||||
chargeOrderSn: '', // 通过query传过来的orderSN(二次支付情况)
|
||||
xieyiShow: false,
|
||||
stepsCj: {},
|
||||
cjList: [],
|
||||
@@ -135,7 +137,7 @@
|
||||
}
|
||||
],
|
||||
iosPaylist: [{
|
||||
title: 'apple pay支付',
|
||||
title: 'IAP支付',
|
||||
id: 3,
|
||||
img: '../../static/icon/pay_2.png'
|
||||
}],
|
||||
@@ -156,7 +158,7 @@
|
||||
// 隐藏原生的tabbar
|
||||
// this.iphonepay()
|
||||
uni.hideTabBar();
|
||||
this.getDevName()
|
||||
this.getDevName()
|
||||
// setTimeout(()=>{
|
||||
// uni.navigateTo({
|
||||
// url:'/pages/user/persCount'
|
||||
@@ -166,20 +168,52 @@
|
||||
computed: {
|
||||
...mapState(['userInfo']),
|
||||
},
|
||||
components:{
|
||||
musicPlay
|
||||
components: {
|
||||
musicPlay
|
||||
},
|
||||
//方法
|
||||
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) => {
|
||||
console.log('关闭订单成功');
|
||||
this.setUserInfo({restoreFlag:false});
|
||||
}, (fail) => {
|
||||
console.log('关闭订单失败');
|
||||
});
|
||||
console.log('关闭订单成功');
|
||||
this.setUserInfo({
|
||||
restoreFlag: false
|
||||
});
|
||||
}, (fail) => {
|
||||
console.log('关闭订单失败');
|
||||
});
|
||||
},
|
||||
showXieyi() {
|
||||
this.$http
|
||||
@@ -201,17 +235,37 @@
|
||||
}
|
||||
// console.log(this.radioValue)
|
||||
},
|
||||
iphonepay() {
|
||||
async iphonepay() {
|
||||
const that = this
|
||||
// 如果ios已经绑定支付信息,就直接支付,如果没有绑定,就需要先绑定
|
||||
console.log('检测支付环境...')
|
||||
plus.payment.getChannels((channels) => {
|
||||
console.log(channels, 'channels')
|
||||
uni.showLoading({
|
||||
title: '检测支付环境'
|
||||
})
|
||||
plus.payment.getChannels(async (channels) => {
|
||||
// console.log(channels, 'channels')
|
||||
for (var i in channels) {
|
||||
// 判断是否苹果支付1
|
||||
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)
|
||||
}
|
||||
}
|
||||
})
|
||||
@@ -226,16 +280,20 @@
|
||||
console.log(that.stepsCj.priceTypeId, 88888888)
|
||||
// ['xxxxx'] 是平台申请拿到的内购商品的id
|
||||
let IAPOrders = []
|
||||
IAPOrders.push(that.stepsCj.priceTypeId+'')
|
||||
IAPOrders.push(that.stepsCj.priceTypeId+'');
|
||||
console.log(IAPOrders, 'IAPOrders')
|
||||
// 新建订单
|
||||
// 新建订单
|
||||
uni.showLoading({
|
||||
title: "正在创建订单",
|
||||
mask: true,
|
||||
});
|
||||
that.iapChannel.requestOrder(IAPOrders, function(event) {
|
||||
// uni.hideLoading()
|
||||
console.log(event, 'event')
|
||||
for (var index in event) {
|
||||
var OrderItem = event[index]
|
||||
// console.log(OrderItem, 'OrderItem')
|
||||
console.log(OrderItem.productid,'OrderItem.productid')
|
||||
console.log(OrderItem.productid, 'OrderItem.productid')
|
||||
that.topay(OrderItem.productid)
|
||||
}
|
||||
}, function(erroemsg) {
|
||||
@@ -245,21 +303,21 @@
|
||||
})
|
||||
})
|
||||
},
|
||||
topay(id) {
|
||||
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});
|
||||
console.log(this.userInfo,'更新后的用户信息')
|
||||
uni.showLoading({
|
||||
title: "正在支付",
|
||||
mask: true,
|
||||
});
|
||||
// this.setUserInfo({
|
||||
// restoreFlag: true
|
||||
// });
|
||||
// console.log(this.userInfo, '更新后的用户信息')
|
||||
plus.payment.request(that.iapChannel, {
|
||||
productid: id,
|
||||
username: that.orderSn, // 用户标识/订单标识
|
||||
manualFinishTransaction: true // 3.5.1+ 支持,设置此参数后需要开发者主动关闭订单,参见下面的关闭订单方法 finishTransaction()
|
||||
|
||||
|
||||
}, function(result) {
|
||||
// restoreFlag = false; // 支付成功清除标记 restoreFlag = false
|
||||
that.transaction = result
|
||||
@@ -267,30 +325,35 @@
|
||||
that.iapCheck(result)
|
||||
}, function(e) {
|
||||
console.log('错误回调', e)
|
||||
if(e.errCode == 2){
|
||||
// 用户未绑定支付方式,app内支付流程结束,系统弹出框引导用户绑定支付方式,此过程将跳转到系统应用 AppStore 进行绑定支付方式,绑定成功同步支付成功,用户成功付款
|
||||
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)
|
||||
if (e.code == 2) {
|
||||
uni.showToast({
|
||||
title:'取消支付,内购订单即将关闭',
|
||||
icon:'none'
|
||||
})
|
||||
}else {
|
||||
uni.showToast({
|
||||
title:'支付失败,内购订单即将关闭',
|
||||
icon:'none'
|
||||
})
|
||||
console.log('其他支付错误',e);
|
||||
}
|
||||
});
|
||||
});
|
||||
},
|
||||
iapCheck(result) {
|
||||
let that = this
|
||||
console.log('进入后台验证')
|
||||
uni.showLoading({
|
||||
title:'正在验证订单结果'
|
||||
})
|
||||
let data = {
|
||||
transactionId: result.transactionIdentifier, // 支付交易id
|
||||
customerOid: that.userInfo.id,
|
||||
customerOid: that.userInfo.id,
|
||||
productId: result.payment.productid, // 产品id
|
||||
orderId: result.payment.username, // 系统订单号
|
||||
receiptData: result.transactionReceipt ,// 苹果返回收据
|
||||
// body: that.stepsCj.priceTypeId // 充值类型id
|
||||
receiptData: result.transactionReceipt, // 苹果返回收据
|
||||
// body: that.stepsCj.priceTypeId // 充值类型id
|
||||
}
|
||||
console.log(data,'data')
|
||||
console.log("提交给后台的数据",data);
|
||||
$http.request({
|
||||
url: "/Ipa/veri",
|
||||
method: "POST", // POST、GET、PUT、DELETE,具体说明查看官方文档
|
||||
@@ -300,25 +363,28 @@
|
||||
},
|
||||
}).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)
|
||||
console.log('充值订单已处理,请留意账户金额变动....')
|
||||
// 服务器验证票据有效后在客户端关闭订单 (iapChannel.finishTransaction)
|
||||
that.finishTransaction(result);
|
||||
if (res.code == 0) {
|
||||
uni.hideLoading()
|
||||
uni.showToast({
|
||||
title:'充值成功!',
|
||||
icon:'success'
|
||||
})
|
||||
console.log("充值订单已处理,请留意账户金额变动....");
|
||||
that.finishTransaction(result);
|
||||
}
|
||||
}).catch(e => {
|
||||
}).catch(e => {
|
||||
uni.hideLoading()
|
||||
console.log('后台验证失败=>',e);
|
||||
uni.showModal({
|
||||
title: '提示',
|
||||
showCancel:false,
|
||||
content: '支付验证失败,请稍后重启app,如不能解决您的问题,可联系官方客服',
|
||||
success: function (res) {
|
||||
title: "提示",
|
||||
showCancel: false,
|
||||
content: "支付验证失败,请稍后重启app,如不能解决您的问题,可联系官方客服",
|
||||
success: function(res) {
|
||||
if (res.confirm) {
|
||||
console.log('用户点击确定');
|
||||
console.log("用户点击确定");
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
});
|
||||
})
|
||||
},
|
||||
getDevName() {
|
||||
@@ -335,15 +401,15 @@
|
||||
// 获取充值金额
|
||||
getData() {
|
||||
// console.log(this.isAndroid)
|
||||
if(this.isAndroid){
|
||||
if (this.isAndroid) {
|
||||
this.getAndorList()
|
||||
}else{
|
||||
} else {
|
||||
this.getAppleList()
|
||||
}
|
||||
|
||||
|
||||
},
|
||||
// 安卓充值列表
|
||||
getAndorList(){
|
||||
getAndorList() {
|
||||
this.$http
|
||||
.post('book/bookbuyconfig/getVipOrPoint', {
|
||||
type: 'point',
|
||||
@@ -355,7 +421,7 @@
|
||||
});
|
||||
},
|
||||
// 苹果充值列表
|
||||
getAppleList(){
|
||||
getAppleList() {
|
||||
this.$http
|
||||
.post('book/bookbuyconfig/getVipOrPoint', {
|
||||
type: 'point',
|
||||
@@ -382,11 +448,11 @@
|
||||
this.iphonepay()
|
||||
},
|
||||
// 充值
|
||||
goToPay(){
|
||||
goToPay() {
|
||||
this.kaiChar()
|
||||
},
|
||||
// 正常充值
|
||||
kaiChar() { // 常规充值
|
||||
kaiChar() { // 常规充值
|
||||
if (this.radioValue == '1') {
|
||||
uni.showLoading({
|
||||
title: '支付中,请勿离开',
|
||||
@@ -402,7 +468,9 @@
|
||||
realMoney: that.stepsCj.money * 1, //实收金额
|
||||
orderStatus: 0, //订单状态
|
||||
orderType: "point", //订单类型
|
||||
productId: that.stepsCj.priceTypeId // 充值的类型id
|
||||
// appName: "",
|
||||
come: 0,
|
||||
productId: that.stepsCj.priceTypeId // 充值的类型id
|
||||
}
|
||||
$http.request({
|
||||
url: "book/buyOrder/rechargeSave",
|
||||
@@ -412,8 +480,8 @@
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
}).then(res => {
|
||||
that.orderSn = res.orderSn
|
||||
uni.hideLoading()
|
||||
that.orderSn = res.orderSn
|
||||
// uni.hideLoading()
|
||||
if (res.code == 0) {
|
||||
if (that.payType == 2) {
|
||||
setPay({
|
||||
@@ -425,15 +493,17 @@
|
||||
body: that.stepsCj.priceTypeId,
|
||||
}, res => {
|
||||
if (res.success) {
|
||||
uni.hideLoading();
|
||||
uni.showToast({
|
||||
title: "支付成功"
|
||||
});
|
||||
setTimeout(()=>{
|
||||
setTimeout(() => {
|
||||
uni.navigateTo({
|
||||
url:'/pages/user/persCount'
|
||||
url: '/pages/user/persCount'
|
||||
})
|
||||
},2000)
|
||||
} else {
|
||||
}, 2000)
|
||||
} else {
|
||||
uni.hideLoading();
|
||||
uni.showToast({
|
||||
title: "支付失败",
|
||||
icon: "none",
|
||||
@@ -444,51 +514,58 @@
|
||||
} else if (that.payType == 1) {
|
||||
// 微信支付
|
||||
that.orderSn = res.orderSn
|
||||
let data1={
|
||||
orderSn:that.orderSn,
|
||||
let data1 = {
|
||||
orderSn: that.orderSn,
|
||||
buyOrderId: that.stepsCj.priceTypeId,
|
||||
totalAmount: that.stepsCj.money
|
||||
}
|
||||
console.log(data1,'data1')
|
||||
console.log(data1, 'data1')
|
||||
// console.log(this.userInfo.channelList,'channelList')
|
||||
// this.userInfo.channelList.map(item => {
|
||||
// if(item.id == "wxpay"){
|
||||
// console.log('支持微信支付')
|
||||
setWXPay(data1,res => {
|
||||
if (res.success) {
|
||||
uni.showToast({
|
||||
title: "支付成功"
|
||||
});
|
||||
setTimeout(()=>{
|
||||
uni.navigateTo({
|
||||
url:'/pages/user/persCount'
|
||||
})
|
||||
},2000)
|
||||
} else {
|
||||
console.log(res)
|
||||
if(res.data.errMsg.indexOf('User canceled') != -1){
|
||||
uni.showToast({
|
||||
title: "用户取消支付",
|
||||
icon: "none",
|
||||
image: '../../static/icon/ic_close.png'
|
||||
});
|
||||
}else{
|
||||
uni.showToast({
|
||||
title: "支付失败",
|
||||
icon: "none",
|
||||
image: '../../static/icon/ic_close.png'
|
||||
});
|
||||
}
|
||||
}
|
||||
})
|
||||
// console.log('支持微信支付')
|
||||
setWXPay(data1, res => {
|
||||
if (res.success) {
|
||||
uni.hideLoading();
|
||||
uni.showToast({
|
||||
title: "支付成功"
|
||||
});
|
||||
setTimeout(() => {
|
||||
uni.navigateTo({
|
||||
url: '/pages/user/persCount'
|
||||
})
|
||||
}, 2000)
|
||||
} else {
|
||||
console.log(res)
|
||||
uni.hideLoading();
|
||||
if (res.data.errMsg.indexOf('User canceled') != -1) {
|
||||
uni.showToast({
|
||||
title: "用户取消支付",
|
||||
icon: "none",
|
||||
image: '../../static/icon/ic_close.png'
|
||||
});
|
||||
} else {
|
||||
uni.showToast({
|
||||
title: "支付失败",
|
||||
icon: "none",
|
||||
image: '../../static/icon/ic_close.png'
|
||||
});
|
||||
}
|
||||
}
|
||||
})
|
||||
// }
|
||||
// })
|
||||
|
||||
|
||||
} else if (that.payType == 3) {
|
||||
console.log('苹果支付', )
|
||||
that.iosPay()
|
||||
that.iosPay()
|
||||
}
|
||||
}
|
||||
}).catch(e => {
|
||||
uni.showToast({
|
||||
title: "系统下单失败",
|
||||
icon: "none",
|
||||
});
|
||||
})
|
||||
|
||||
} else {
|
||||
@@ -500,7 +577,7 @@
|
||||
}
|
||||
|
||||
|
||||
},
|
||||
},
|
||||
// 跳转
|
||||
onPageJump(url) {
|
||||
uni.navigateTo({
|
||||
@@ -753,4 +830,4 @@
|
||||
border-radius: 50rpx;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
</style>
|
||||
@@ -247,7 +247,7 @@
|
||||
yszcText: {},
|
||||
quShow: false,
|
||||
quCodeList: [], // 国家区域码
|
||||
quCode: 86,
|
||||
quCode: "86",
|
||||
|
||||
};
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user