更换苹果支付模式
This commit is contained in:
12
pages.json
12
pages.json
@@ -546,14 +546,6 @@
|
|||||||
"navigationBarTitleText" : "工单提交页面",
|
"navigationBarTitleText" : "工单提交页面",
|
||||||
"enablePullDownRefresh": true
|
"enablePullDownRefresh": true
|
||||||
}
|
}
|
||||||
},
|
|
||||||
{
|
|
||||||
"path" : "pages/stsViode/index/index",
|
|
||||||
"style" :
|
|
||||||
{
|
|
||||||
"navigationBarTitleText" : "STS加密视频播放页面",
|
|
||||||
"enablePullDownRefresh": true
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"globalStyle": {
|
"globalStyle": {
|
||||||
@@ -607,8 +599,8 @@
|
|||||||
"current": 0, //当前激活的模式(list 的索引项)
|
"current": 0, //当前激活的模式(list 的索引项)
|
||||||
"list": [
|
"list": [
|
||||||
{
|
{
|
||||||
"name": "sts测试", //模式名称
|
"name": "", //模式名称
|
||||||
"path": "pages/stsViode/index/index", //启动页面,必选
|
"path": "", //启动页面,必选
|
||||||
"query": "" //启动参数,在页面的onLoad函数里面得到
|
"query": "" //启动参数,在页面的onLoad函数里面得到
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -188,7 +188,7 @@
|
|||||||
// if (!that.checking) {
|
// if (!that.checking) {
|
||||||
// that.checking = true
|
// that.checking = true
|
||||||
// console.log(this.iapChannel, 'this.iapChannel')
|
// console.log(this.iapChannel, 'this.iapChannel')
|
||||||
await this.iapChannel.restoreComplateRequest({
|
await this.iapChannel.restoreCompletedTransactions({
|
||||||
manualFinishTransaction: true
|
manualFinishTransaction: true
|
||||||
}, function(results) {
|
}, function(results) {
|
||||||
// console.log(that.checking)
|
// console.log(that.checking)
|
||||||
@@ -255,44 +255,69 @@
|
|||||||
}
|
}
|
||||||
// console.log(this.radioValue)
|
// console.log(this.radioValue)
|
||||||
},
|
},
|
||||||
async iphonepay() {
|
requestPayment(orderInfo) {
|
||||||
const that = this;
|
let that = this
|
||||||
// 如果ios已经绑定支付信息,就直接支付,如果没有绑定,就需要先绑定
|
return new Promise((resolve, reject) => {
|
||||||
uni.showLoading({
|
uni.requestPayment({
|
||||||
title:'检测支付环境'
|
provider: 'appleiap',
|
||||||
|
orderInfo: orderInfo,
|
||||||
|
success: (res) => {
|
||||||
|
that.iapCheck(res);
|
||||||
|
resolve(res);
|
||||||
|
},
|
||||||
|
fail: (err) => {
|
||||||
|
uni.hideLoading()
|
||||||
|
// console.log('其他支付错误', err);
|
||||||
|
that.restoreComplateRequest()
|
||||||
|
if (err.code == 2) {
|
||||||
|
uni.showToast({
|
||||||
|
title: '取消支付,内购订单即将关闭',
|
||||||
|
icon: 'none'
|
||||||
})
|
})
|
||||||
// console.log("检测支付环境...");
|
} else {
|
||||||
plus.payment.getChannels(async (channels) => {
|
uni.showToast({
|
||||||
console.log(channels, "channels");
|
title: '支付失败,内购订单即将关闭',
|
||||||
for (var i in channels) {
|
icon: 'none'
|
||||||
if (channels[i].id === "appleiap") {
|
|
||||||
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();
|
|
||||||
clearInterval(timer)
|
|
||||||
console.log('timer清除了吗',timer);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
},1000)
|
|
||||||
// console.log('that.checking',that.checking)
|
|
||||||
/// 限制调用
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
reject(err);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
})
|
||||||
|
},
|
||||||
|
getProvider() {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
uni.getProvider({
|
||||||
|
service: 'payment',
|
||||||
|
success: (res) => {
|
||||||
|
const iapChannel = res.providers.find((channel) => {
|
||||||
|
return (channel.id === 'appleiap')
|
||||||
|
})
|
||||||
|
resolve(iapChannel);
|
||||||
|
// 如果 iapChannel 为 null,说明当前包没有包含iap支付模块。注意:HBuilder基座不包含 iap 通道
|
||||||
|
}
|
||||||
|
});
|
||||||
|
})
|
||||||
|
},
|
||||||
|
async iphonepay() {
|
||||||
|
const that = this;
|
||||||
|
uni.showLoading({
|
||||||
|
title:"检测支付环境"
|
||||||
|
})
|
||||||
|
console.log("检测支付环境...");
|
||||||
|
this.iapChannel = await this.getProvider()
|
||||||
|
console.log('that.iapChannel',this.iapChannel);
|
||||||
|
if(this.iapChannel){
|
||||||
|
this.requestOrder();
|
||||||
|
}else{
|
||||||
|
uni.hideLoading()
|
||||||
|
uni.showToast({
|
||||||
|
title:'不支持内购支付',
|
||||||
|
icon:'none'
|
||||||
|
})
|
||||||
|
console.log("获取iap支付通道失败:" + e.message, that.iapChannel);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
requestOrder() {
|
requestOrder() {
|
||||||
uni.showLoading({
|
uni.showLoading({
|
||||||
@@ -303,14 +328,14 @@
|
|||||||
console.log(that.stepsCj.priceTypeId, 88888888);
|
console.log(that.stepsCj.priceTypeId, 88888888);
|
||||||
// ['xxxxx'] 是平台申请拿到的内购商品的id
|
// ['xxxxx'] 是平台申请拿到的内购商品的id
|
||||||
let IAPOrders = [];
|
let IAPOrders = [];
|
||||||
IAPOrders.push("p"+that.stepsCj.priceTypeId);
|
IAPOrders.push('p' + that.stepsCj.priceTypeId);
|
||||||
console.log(IAPOrders, "IAPOrders");
|
// console.log(IAPOrders, "IAPOrders");
|
||||||
// 新建订单
|
// 新建订单
|
||||||
uni.showLoading({
|
uni.showLoading({
|
||||||
title: "正在创建订单",
|
title: "正在创建订单",
|
||||||
mask: true,
|
mask: true,
|
||||||
});
|
});
|
||||||
that.iapChannel.requestOrder(
|
that.iapChannel.requestProduct(
|
||||||
IAPOrders,
|
IAPOrders,
|
||||||
function(event) {
|
function(event) {
|
||||||
// uni.hideLoading()
|
// uni.hideLoading()
|
||||||
@@ -330,47 +355,20 @@
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
topay(id) {
|
async topay(id) {
|
||||||
const that = this;
|
const that = this;
|
||||||
uni.showLoading({
|
uni.showLoading({
|
||||||
title: "正在支付",
|
title: "正在支付",
|
||||||
mask: true,
|
mask: true,
|
||||||
});
|
});
|
||||||
plus.payment.request(
|
let orderInfo = {
|
||||||
that.iapChannel, {
|
|
||||||
productid: id,
|
productid: id,
|
||||||
username: that.orderSn, // 用户标识/订单标识
|
username: that.orderSn, // 用户标识/订单标识
|
||||||
|
quantity:1,
|
||||||
manualFinishTransaction: true, // 3.5.1+ 支持,设置此参数后需要开发者主动关闭订单,参见下面的关闭订单方法 finishTransaction()
|
manualFinishTransaction: true, // 3.5.1+ 支持,设置此参数后需要开发者主动关闭订单,参见下面的关闭订单方法 finishTransaction()
|
||||||
},
|
|
||||||
function(result) {
|
|
||||||
// that.checking = false
|
|
||||||
that.transaction = result;
|
|
||||||
// 支付成功,result 为 IAP商品交易信息对象 IAPTransaction 需将返回的支付凭证传给后端进行二次认证
|
|
||||||
that.iapCheck(result);
|
|
||||||
},
|
|
||||||
function(e) {
|
|
||||||
// that.checking = false
|
|
||||||
console.log("错误回调", e);
|
|
||||||
if (e.code == 2) {
|
|
||||||
uni.showToast({
|
|
||||||
title:'取消支付,内购订单即将关闭',
|
|
||||||
icon:'none'
|
|
||||||
})
|
|
||||||
|
|
||||||
// 用户未绑定支付方式,app内支付流程结束,系统弹出框引导用户绑定支付方式,此过程将跳转到系统应用 AppStore 进行绑定支付方式,绑定成功同步支付成功,用户成功付款
|
|
||||||
// plus.runtime.openURL("https://apps.apple.com/account/billing");
|
|
||||||
} else {
|
|
||||||
uni.showToast({
|
|
||||||
title:'支付失败,内购订单即将关闭',
|
|
||||||
icon:'none'
|
|
||||||
})
|
|
||||||
console.log('其他支付错误',e);
|
|
||||||
}
|
}
|
||||||
|
this.transaction = await this.requestPayment(orderInfo)
|
||||||
// that.finishTransaction(result);
|
console.log('支付后的that.transaction',this.transaction);
|
||||||
that.restoreComplateRequest()
|
|
||||||
}
|
|
||||||
);
|
|
||||||
},
|
},
|
||||||
iapCheck(result) {
|
iapCheck(result) {
|
||||||
let that = this;
|
let that = this;
|
||||||
@@ -402,11 +400,6 @@
|
|||||||
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({
|
uni.showToast({
|
||||||
title:'充值成功!',
|
title:'充值成功!',
|
||||||
icon:'success'
|
icon:'success'
|
||||||
|
|||||||
@@ -36,9 +36,6 @@
|
|||||||
</div>
|
</div>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
<view class="">
|
|
||||||
<button @click="onPageJump('pages/stsViode/index/index')">进入sts播放页面</button>
|
|
||||||
</view>
|
|
||||||
<view class="newLeve2">
|
<view class="newLeve2">
|
||||||
<view class="home_nar nomargin" style="padding: 0; background-color: #fff;">
|
<view class="home_nar nomargin" style="padding: 0; background-color: #fff;">
|
||||||
<view class="flexbox">
|
<view class="flexbox">
|
||||||
|
|||||||
@@ -11,29 +11,37 @@ const ComplateRequestArr = []
|
|||||||
|
|
||||||
|
|
||||||
var iap = {
|
var iap = {
|
||||||
// 检测支付通道
|
getProvider() {
|
||||||
getChannels(){
|
return new Promise((resolve, reject) => {
|
||||||
const that = this;
|
uni.getProvider({
|
||||||
console.log('检测支付通道')
|
service: 'payment',
|
||||||
plus.payment.getChannels(async (channels) => {
|
success: (res) => {
|
||||||
for (var i in channels) {
|
const iapChannel = res.providers.find((channel) => {
|
||||||
// 判断是否苹果支付1
|
return (channel.id === 'appleiap')
|
||||||
if (channels[i].id === "appleiap") {
|
})
|
||||||
console.log("存在苹果内购channels",channels, );
|
resolve(iapChannel);
|
||||||
that.iapChannel = channels[i];
|
// 如果 iapChannel 为 null,说明当前包没有包含iap支付模块。注意:HBuilder基座不包含 iap 通道
|
||||||
// 先检测有没有未完成的订单
|
|
||||||
that.restoreComplateRequest()
|
|
||||||
}else{
|
|
||||||
console.log('安卓客户端');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
})
|
||||||
|
},
|
||||||
|
// 检测支付通道
|
||||||
|
async getChannels(){
|
||||||
|
const that = this;
|
||||||
|
console.log('检测支付通道')
|
||||||
|
this.iapChannel = await this.getProvider()
|
||||||
|
if(this.iapChannel){
|
||||||
|
// this.requestOrder();
|
||||||
|
this.restoreComplateRequest()
|
||||||
|
}else{
|
||||||
|
console.log("不支持iap支付");
|
||||||
|
}
|
||||||
},
|
},
|
||||||
// 检测是否有未关闭订单
|
// 检测是否有未关闭订单
|
||||||
restoreComplateRequest() {
|
restoreComplateRequest() {
|
||||||
let that = this
|
let that = this
|
||||||
console.log('检测未完成订单')
|
console.log('检测未完成订单')
|
||||||
this.iapChannel.restoreComplateRequest({
|
this.iapChannel.restoreCompletedTransactions({
|
||||||
manualFinishTransaction: true
|
manualFinishTransaction: true
|
||||||
}, function(results) {
|
}, function(results) {
|
||||||
if (!that.checking) {
|
if (!that.checking) {
|
||||||
|
|||||||
Reference in New Issue
Block a user