作者 赵云辉

ios支付修改完成安卓支付注释掉了

... ... @@ -2,8 +2,8 @@
"name" : "问野",
"appid" : "__UNI__6108A26",
"description" : "问野",
"versionName" : "1.6",
"versionCode" : 109,
"versionName" : "1.4",
"versionCode" : 112,
"transformPx" : false,
/* 5+App特有相关 */
"app-plus" : {
... ... @@ -97,14 +97,6 @@
}
},
"payment" : {
"weixin" : {
"__platform__" : [ "ios", "android" ],
"appid" : "wx71e7bfe66057f7fb",
"UniversalLinks" : "https://yuebang.brofirst.cn/ulink/"
},
"alipay" : {
"__platform__" : [ "ios", "android" ]
},
"appleiap" : {}
},
"geolocation" : {
... ...
... ... @@ -42,33 +42,38 @@
number: '', //问野币数量
pay_type: 'wechat'
},
iosPay: {
order_id: '',
data: ''
},
showPay: false, //展示支付弹框
price: 0,
list: [{
num: 10,
price: 1,
id: 'S3FKBIR',
},
{
num: 60,
price: 6,
id: 'K93MD8T',
},
{
num: 120,
price: 12,
id: 'TR5CNJF',
},
{
num: 250,
price: 25,
id: 'AIDHZK4',
},
{
num: 500,
price: 50,
id: '87FC0DH',
}
list: [
// {
// num: 10,
// price: 1,
// id: 'PTMH2SF',
// },
// {
// num: 60,
// price: 6,
// id: 'K93MD8T',
// },
// {
// num: 120,
// price: 12,
// id: 'TR5CNJF',
// },
// {
// num: 250,
// price: 25,
// id: 'AIDHZK4',
// },
// {
// num: 500,
// price: 50,
// id: '87FC0DH',
// }
]
}
},
... ... @@ -76,39 +81,57 @@
payType
},
onLoad() {
this.getMoneyGoods()
uni.getProvider({
service: 'payment',
success: function(res) {
console.log('获取通道', res.provider)
}
});
let that = this
console.log('查看支付通道')
plus.payment.getChannels((channels) => {
console.log('判断是否是苹果支付',channels)
console.log('判断是否是苹果支付', channels)
for (var i in channels) {
// 判断是否苹果支付
if (channels[i].id === 'appleiap') {
that.iapChannel = channels[i]
that.requestOrder()
} else {
// that.payment()
that.requestOrder()
console.log('判断是否是苹果支付赋值', that.iapChannel)
// that.requestOrder()
}
}
})
},
methods: {
// {
// num: 120,
// price: 12,
// id: 'TR5CNJF',
// },
getMoneyGoods () {
return new Promise((reslove) => {
this.$request('/wallet/getMoneyGoods', {type:'ios'}).then((res) => {
console.log('充值选项列表', res)
this.list = res.data
this.list.forEach((item)=>{
item.num = item.number
item.price = item.number /10
})
reslove(res)
})
})
},
//修改支付类型
changePayType(e) {
console.log('修改支付类型', e)
console.log('修改支付类型', e)
this.param.pay_type = e
},
//显示支付类型选择弹框
showPayType(index) {
this.price = this.list[index].price
this.param.number = this.list[index].num
this.id = this.list[index].id
this.id = this.list[index].apple_goods_id
this.param.pay_type = 'wechat'
this.showPay = true
},
... ... @@ -134,23 +157,24 @@
},
pay() {
const that = this
uni.showLoading({
title: '检测支付环境...',
mask: true
})
plus.payment.getChannels((channels) => {
console.log('判断是否是苹果支付',channels)
for (var i in channels) {
// 判断是否苹果支付
if (channels[i].id === 'appleiap') {
that.iapChannel = channels[i]
that.requestOrder()
} else {
// that.payment()
that.requestOrder()
}
}
})
// uni.showLoading({
// title: '检测支付环境...',
// mask: true
// })
// plus.payment.getChannels((channels) => {
// console.log('判断是否是苹果支付1',channels)
// for (var i in channels) {
// // 判断是否苹果支付
// if (channels[i].id === 'appleiap') {
// that.iapChannel = channels[i]
// console.log('判断是否是苹果支付2',that.iapChannel)
that.requestOrder()
// } else {
// that.payment()
// // that.requestOrder()
// }
// }
// })
},
async payment() {
console.log('安卓')
... ... @@ -177,11 +201,11 @@
requestOrder() {
const that = this
// ['xxxxx'] 是平台申请拿到的内购商品的id
console.log('苹果支付')
that.iapChannel.requestOrder([this.id],
console.log('苹果支付', that.iapChannel)
that.iapChannel.requestOrder([that.id],
function(event) {
uni.hideLoading()
console.log('苹果支付',event)
// uni.hideLoading()
console.log('苹果支付1', event)
for (var index in event) {
var OrderItem = event[index]
console.log(OrderItem)
... ... @@ -189,27 +213,38 @@
}
},
function(erroemsg) {
uni.hideLoading()
// uni.hideLoading()
console.log('获取支付通道失败', erroemsg)
uni.showToast({
title: "获取支付通道失败:" + errormsg.message,
title: "获取支付通道失败:" + erroemsg.message,
icon: 'none'
})
})
console.log('苹果支付', that.iapChannel)
},
topay(id) {
async topay(id) {
const that = this
that.param.pay_type = 'ios'
var orderInfo = await this.getOrderInfo();
uni.showLoading({
title: '充值中请勿离开',
mask: true
})
console.log(id)
uni.requestPayment({
provider: 'appleiap',
orderInfo: {
productid: id
},
success: (res => {
console.log(1)
console.log(res)
uni.hideLoading()
var orderInfo = this.getOrderInfo();
this.rechargeIosPay(res.transactionReceipt);
// 支付成功查询订单
// plus.payment.request(that.iapChannel, statement, function(res){
// console.log(res)
// })
}),
fail: (e) => {
uni.hideLoading()
... ... @@ -217,14 +252,35 @@
content: "支付失败",
showCancel: false
})
},
complete: () => {
console.log("payment结束")
this.loading = false;
}
})
},
getOrderInfo() {
return new Promise((reslove) => {
this.$request('/wallet/recharge', this.param).then((res) => {
console.log('充值问野币', res)
this.iosPay.order_id = res.data.order_id
reslove(res)
})
})
},
rechargeIosPay(data) {
this.iosPay.data = data
return new Promise((reslove) => {
this.$request('/wallet/rechargeIosPay', this.iosPay).then((res) => {
console.log('充值问野币ios支付', res)
uni.navigateBack({
delta: 1
})
setTimeout(() => {
uni.showToast({
title: '充值成功'
})
}, 500)
reslove(res)
})
})
... ...