测试版
This commit is contained in:
67
utils/download.js
Normal file
67
utils/download.js
Normal file
@@ -0,0 +1,67 @@
|
||||
import { mapState, mapMutations } from 'vuex'
|
||||
import { sizeFormate } from '@/utils/formate.js'
|
||||
const downloadStates = [
|
||||
{
|
||||
androidCode: 0,
|
||||
iosCode: 0,
|
||||
text: '未下载'
|
||||
},
|
||||
{
|
||||
androidCode: 100,
|
||||
iosCode: 1,
|
||||
text: '等待中'
|
||||
},
|
||||
{
|
||||
androidCode: 200,
|
||||
iosCode: 2,
|
||||
text: '下载中'
|
||||
},
|
||||
{
|
||||
androidCode: 300,
|
||||
iosCode: 3,
|
||||
text: '已暂停'
|
||||
},
|
||||
{
|
||||
androidCode: 400,
|
||||
iosCode: 4,
|
||||
text: '已完成'
|
||||
},
|
||||
{
|
||||
androidCode: 500,
|
||||
iosCode: 5,
|
||||
text: '下载失败'
|
||||
},
|
||||
]
|
||||
|
||||
const { platform } = uni.getSystemInfoSync()
|
||||
|
||||
const download = {
|
||||
data () {
|
||||
return {
|
||||
syncCount: 3, // 同时下载的视频个数
|
||||
downLoadListQueue: [] , // 视频队列
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
...mapState({
|
||||
downLoadListQueueInit: state => state.downLoadListQueueInit,
|
||||
// userId: state => state.baseInfo.userId,
|
||||
// apiKey: state => state.baseInfo.apiKey,
|
||||
verificationCode: state => state.baseInfo.verificationCode,
|
||||
downloadList: state => state.downloadList,
|
||||
finishedDownloadList: state => state.finishedDownloadList
|
||||
}),
|
||||
},
|
||||
methods: {
|
||||
...mapMutations([
|
||||
'initDownLoadListQueue',
|
||||
'makeDownloadList',
|
||||
'addDownloadItem',
|
||||
'addFinishedDownloadItem',
|
||||
'removeDownloadItem',
|
||||
'setPlayLocalVideoInfo'
|
||||
])
|
||||
}
|
||||
}
|
||||
|
||||
export default download;
|
||||
24
utils/formate.js
Normal file
24
utils/formate.js
Normal file
@@ -0,0 +1,24 @@
|
||||
|
||||
export function secondFormate (seconds) {
|
||||
let minute,second;
|
||||
seconds = Math.abs(seconds)
|
||||
minute = Math.floor(seconds / 60);
|
||||
minute = minute > 9 ? minute : '0' + minute;
|
||||
second = Math.floor(seconds % 60);
|
||||
second = second > 9 ? second : '0' + second;
|
||||
return `${minute}:${second}`;
|
||||
}
|
||||
|
||||
export function range(num, min, max) {
|
||||
return Math.min(Math.max(num, min), max);
|
||||
}
|
||||
|
||||
export function addNumber(num1, num2) {
|
||||
const cardinal = 10 ** 10;
|
||||
return Math.round((num1 + num2) * cardinal) / cardinal;
|
||||
}
|
||||
|
||||
export function sizeFormate (size) {
|
||||
const per = 1024 * 1024;
|
||||
return size >= per ? Number(size / per).toFixed(2) + 'M' : Number(size / 1024).toFixed(2) + 'KB';
|
||||
}
|
||||
141
utils/myIapCheck.js
Normal file
141
utils/myIapCheck.js
Normal file
@@ -0,0 +1,141 @@
|
||||
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 = {
|
||||
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 getChannels(){
|
||||
const that = this;
|
||||
console.log('检测支付通道')
|
||||
this.iapChannel = await this.getProvider()
|
||||
if(this.iapChannel){
|
||||
// this.requestOrder();
|
||||
this.restoreComplateRequest()
|
||||
}else{
|
||||
console.log("不支持iap支付");
|
||||
}
|
||||
},
|
||||
// 检测是否有未关闭订单
|
||||
restoreComplateRequest() {
|
||||
let that = this
|
||||
console.log('检测未完成订单')
|
||||
this.iapChannel.restoreCompletedTransactions({
|
||||
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);
|
||||
uni.showModal({
|
||||
title: "提示",
|
||||
cancelColor:'#0081ff',
|
||||
content: `您的账户下存在验证异常的订单(订单编号为:${e.data.orderId}),可尝试稍后重启app,如不能解决您的问题,可联系官方客服`,
|
||||
cancelText:'已验证关闭订单',
|
||||
confirmText:'知道了',
|
||||
success: function(res) {
|
||||
if (res.confirm) {
|
||||
console.log("用户点击确定");
|
||||
}else{
|
||||
console.log('点了取消')
|
||||
that.finishTransaction(result);
|
||||
}
|
||||
},
|
||||
});
|
||||
// that.finishTransaction(result);
|
||||
});
|
||||
},
|
||||
}
|
||||
module.exports = {iap}
|
||||
|
||||
20
utils/tool.js
Normal file
20
utils/tool.js
Normal file
@@ -0,0 +1,20 @@
|
||||
const { platform } = uni.getSystemInfoSync()
|
||||
|
||||
export function setFullScreen(isFullScreen) {
|
||||
const ori = isFullScreen ? 'landscape-primary' : 'portrait-primary';
|
||||
plus.screen.unlockOrientation();
|
||||
if (platform === 'android') {
|
||||
setTimeout(() => {
|
||||
plus.screen.lockOrientation(ori);
|
||||
}, 500)
|
||||
} else {
|
||||
plus.screen.lockOrientation(ori);
|
||||
}
|
||||
// 控制顶部状态栏展示
|
||||
plus.navigator.setFullscreen(isFullScreen);
|
||||
if (isFullScreen) {
|
||||
plus.navigator.hideSystemNavigation();
|
||||
} else {
|
||||
plus.navigator.showSystemNavigation();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user