提交支付宝支付
This commit is contained in:
parent
e291af7fb9
commit
66fed95370
|
|
@ -32,6 +32,8 @@ const testing = {
|
||||||
wxAppId: 'wx0e33d80d35e4a3b1'
|
wxAppId: 'wx0e33d80d35e4a3b1'
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// 根据环境变量选择对应配置
|
// 根据环境变量选择对应配置
|
||||||
let currentEnv = testing;
|
let currentEnv = testing;
|
||||||
|
|
||||||
|
|
|
||||||
29
common/platform/AppPlatform.js
Normal file
29
common/platform/AppPlatform.js
Normal file
|
|
@ -0,0 +1,29 @@
|
||||||
|
import BasePlatform from './BasePlatform';
|
||||||
|
class AppPlatform extends BasePlatform {
|
||||||
|
constructor() {
|
||||||
|
super();
|
||||||
|
this.code = 'APP_ANDROID';
|
||||||
|
this.env = 'app';
|
||||||
|
}
|
||||||
|
getPayData(url,data) {
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
pay({ data }) {
|
||||||
|
return new Promise((resolve) => {
|
||||||
|
console.log(`App支付:${data.amount}分,订单号:${data.orderId}`);
|
||||||
|
// 模拟调用H5支付SDK
|
||||||
|
// window.H5PaySDK?.pay(data.amount, data.orderId, resolve);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
share({ title, desc, image, url }) {
|
||||||
|
console.log(`H5分享:${title} - ${desc}`);
|
||||||
|
// 调用浏览器原生分享(如果可用)
|
||||||
|
if (navigator.share) {
|
||||||
|
return navigator.share({ title, text: desc, url });
|
||||||
|
}
|
||||||
|
// 降级方案
|
||||||
|
alert(`请手动分享:${url}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
export default AppPlatform;
|
||||||
46
common/platform/BasePlatform.js
Normal file
46
common/platform/BasePlatform.js
Normal file
|
|
@ -0,0 +1,46 @@
|
||||||
|
/**
|
||||||
|
* 多端平台抽象基类(父类)
|
||||||
|
* 定义所有端必须实现的方法
|
||||||
|
*/
|
||||||
|
class BasePlatform {
|
||||||
|
constructor() {
|
||||||
|
if (new.target === BasePlatform) {
|
||||||
|
throw new Error('BasePlatform 是抽象类,不能直接实例化');
|
||||||
|
}
|
||||||
|
this.code = ''; // 平台代码(WEB/MP/APP)
|
||||||
|
this.env = ''; // 运行环境标识
|
||||||
|
}
|
||||||
|
|
||||||
|
getPayData(url,data) {
|
||||||
|
throw new Error('子类必须实现 getPayData 方法');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 支付方法(子类必须实现)
|
||||||
|
* @param {number} amount - 支付金额(分)
|
||||||
|
* @param {string} orderId - 订单号
|
||||||
|
*/
|
||||||
|
pay({ data }) {
|
||||||
|
throw new Error('子类必须实现 pay 方法');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分享方法(子类必须实现)
|
||||||
|
* @param {object} params - 分享参数 { title, desc, image, url }
|
||||||
|
*/
|
||||||
|
share({ title, desc, link, image }) {
|
||||||
|
throw new Error('子类必须实现 share 方法');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通用方法(所有端共用)
|
||||||
|
*/
|
||||||
|
getPlatformInfo() {
|
||||||
|
return {
|
||||||
|
code: this.code,
|
||||||
|
env: this.env,
|
||||||
|
ua: navigator?.userAgent || ''
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
export default BasePlatform;
|
||||||
48
common/platform/H5Platform.js
Normal file
48
common/platform/H5Platform.js
Normal file
|
|
@ -0,0 +1,48 @@
|
||||||
|
import BasePlatform from './BasePlatform';
|
||||||
|
|
||||||
|
class H5Platform extends BasePlatform {
|
||||||
|
constructor() {
|
||||||
|
super();
|
||||||
|
this.code = 'WEB_H5';
|
||||||
|
this.env = 'h5';
|
||||||
|
}
|
||||||
|
getPayData(url, data) {
|
||||||
|
|
||||||
|
data['quitUrl']=escape(window.location.href);
|
||||||
|
data['returnUrl']=escape(window.location.href);
|
||||||
|
console.log('处理数据',data);
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
pay({ data }) {
|
||||||
|
console.log('支付1111');
|
||||||
|
|
||||||
|
return new Promise((resolve) => {
|
||||||
|
console.log(data);
|
||||||
|
// 创建一个临时div元素
|
||||||
|
const tempDiv = document.createElement('div');
|
||||||
|
// 将data作为HTML插入到div中(假设data是表单的HTML字符串)
|
||||||
|
tempDiv.innerHTML = data;
|
||||||
|
// 将表单添加到body中
|
||||||
|
document.body.appendChild(tempDiv.firstChild);
|
||||||
|
// 获取表单并提交
|
||||||
|
const form = document.getElementById('alipaysubmit');
|
||||||
|
if (form) {
|
||||||
|
form.submit();
|
||||||
|
resolve({ success: true });
|
||||||
|
} else {
|
||||||
|
resolve({ success: false, message: '表单创建失败' });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
share({ title, desc, image, url }) {
|
||||||
|
console.log(`H5分享:${title} - ${desc}`);
|
||||||
|
// 调用浏览器原生分享(如果可用)
|
||||||
|
if (navigator.share) {
|
||||||
|
return navigator.share({ title, text: desc, url });
|
||||||
|
}
|
||||||
|
// 降级方案
|
||||||
|
alert(`请手动分享:${url}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
export default H5Platform;
|
||||||
64
common/platform/MiniProgramPlatform.js
Normal file
64
common/platform/MiniProgramPlatform.js
Normal file
|
|
@ -0,0 +1,64 @@
|
||||||
|
import BasePlatform from './BasePlatform';
|
||||||
|
/**
|
||||||
|
* 小程序平台
|
||||||
|
*/
|
||||||
|
class MiniProgramPlatform extends BasePlatform {
|
||||||
|
constructor() {
|
||||||
|
super();
|
||||||
|
this.code = 'MP-WEIXIN';
|
||||||
|
this.env = 'miniProgram';
|
||||||
|
}
|
||||||
|
getPayData(url, data) {
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
pay({ data }) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
let provider = "weixin";
|
||||||
|
uni.requestPayment({
|
||||||
|
provider,
|
||||||
|
...data,
|
||||||
|
success: res => {
|
||||||
|
// console.log(res)
|
||||||
|
},
|
||||||
|
fail: err => {
|
||||||
|
// console.log('common.wxMpPay-error', err)
|
||||||
|
},
|
||||||
|
complete: res => {
|
||||||
|
console.log('complete (res)', res)
|
||||||
|
if (res.errMsg == 'requestPayment:fail cancel') {
|
||||||
|
this.toast({
|
||||||
|
title: '取消支付',
|
||||||
|
icon: 'none',
|
||||||
|
duration: 500,
|
||||||
|
success: () => {
|
||||||
|
/* 取消订单 */
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
resolve('cancel')
|
||||||
|
}
|
||||||
|
if (res.errMsg == 'requestPayment:ok') {
|
||||||
|
this.toast({
|
||||||
|
title: '支付成功',
|
||||||
|
icon: 'success',
|
||||||
|
duration: 500,
|
||||||
|
success: () => {
|
||||||
|
resolve('success')
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
share({ title, desc, image, url }) {
|
||||||
|
wx.showShareMenu({
|
||||||
|
withShareTicket: true,
|
||||||
|
menus: ['shareAppMessage', 'shareTimeline']
|
||||||
|
});
|
||||||
|
// 监听用户点击分享按钮
|
||||||
|
wx.onShareAppMessage(() => ({ title, imageUrl: image }));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
export default MiniProgramPlatform;
|
||||||
29
common/platform/PlatformFactory.js
Normal file
29
common/platform/PlatformFactory.js
Normal file
|
|
@ -0,0 +1,29 @@
|
||||||
|
import MiniProgramPlatform from './MiniProgramPlatform';
|
||||||
|
import AppPlatform from './AppPlatform';
|
||||||
|
import H5Platform from './H5Platform';
|
||||||
|
|
||||||
|
class PlatformFactory {
|
||||||
|
static create() {
|
||||||
|
// 判断小程序环境
|
||||||
|
//#ifdef MP-WEIXIN
|
||||||
|
return new MiniProgramPlatform();
|
||||||
|
//#endif
|
||||||
|
|
||||||
|
// 判断 App 环境
|
||||||
|
//#ifdef APP-ANDROID
|
||||||
|
return new AppPlatform();
|
||||||
|
//#endif
|
||||||
|
// 判断 H5 环境
|
||||||
|
//#ifdef WEB
|
||||||
|
return new H5Platform();
|
||||||
|
//#endif
|
||||||
|
|
||||||
|
// 默认返回 小程序
|
||||||
|
return new MiniProgramPlatform();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 使用示例
|
||||||
|
const platform = PlatformFactory.create();
|
||||||
|
console.log(platform.env);
|
||||||
|
export { platform };
|
||||||
|
|
@ -8,6 +8,7 @@ import md5 from 'js-md5'
|
||||||
import ConfigManager from '@/common/config.js'
|
import ConfigManager from '@/common/config.js'
|
||||||
import { apiWhiteList } from '@/common/config.js'
|
import { apiWhiteList } from '@/common/config.js'
|
||||||
import RouterManager from '@/common/router.js'
|
import RouterManager from '@/common/router.js'
|
||||||
|
import { platform } from '@/common/platform/PlatformFactory'
|
||||||
class RequestManager {
|
class RequestManager {
|
||||||
/**
|
/**
|
||||||
* 判断URL是否在白名单中
|
* 判断URL是否在白名单中
|
||||||
|
|
@ -69,18 +70,14 @@ class RequestManager {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
const url = param.url || ''
|
const url = param.url || ''
|
||||||
const method = param.method || 'POST'
|
const method = param.method || 'POST'
|
||||||
const data = param.data || {}
|
const data = param.data || {}
|
||||||
const Loading = param.Loading || false
|
const Loading = param.Loading || false
|
||||||
const token = uni.getStorageSync('token')
|
const token = uni.getStorageSync('token')
|
||||||
let client = ""
|
let client = platform.code
|
||||||
|
|
||||||
// #ifdef H5
|
|
||||||
client = "h5"
|
|
||||||
// #endif
|
|
||||||
|
|
||||||
// 获取API基础URL
|
// 获取API基础URL
|
||||||
const apiBaseUrl = EnvConfig.apiBaseUrl
|
const apiBaseUrl = EnvConfig.apiBaseUrl
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,13 @@
|
||||||
<text style="font-size: 20rpx; color: #999999;">查看更多 ></text>
|
<text style="font-size: 20rpx; color: #999999;">查看更多 ></text>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
|
<view>
|
||||||
|
<view v-if="localBossCardData && localBossCardData.king_user" class="lingzhu-img relative"
|
||||||
|
style="position: absolute;right: 12px;top: 180rpx;height: 120rpx;height: 120rpx;">
|
||||||
|
<image :src="localBossCardData.king_user.headimg" mode="aspectFill"></image>
|
||||||
|
<image :src="$img1('index/king.png')"></image>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
|
||||||
<!-- 领主弹窗 - 显示领主详细信息和挑战人数/领主记录 -->
|
<!-- 领主弹窗 - 显示领主详细信息和挑战人数/领主记录 -->
|
||||||
<uni-popup ref="bossPop" type="bottom" mask-background-color="rgba(0,0,0,0.8)">
|
<uni-popup ref="bossPop" type="bottom" mask-background-color="rgba(0,0,0,0.8)">
|
||||||
|
|
@ -324,7 +331,7 @@ export default {
|
||||||
width: 75rpx;
|
width: 75rpx;
|
||||||
height: 76rpx;
|
height: 76rpx;
|
||||||
position: absolute;
|
position: absolute;
|
||||||
bottom: 4rpx;
|
bottom: 8rpx;
|
||||||
left: 50%;
|
left: 50%;
|
||||||
transform: translateX(-50%);
|
transform: translateX(-50%);
|
||||||
z-index: 1;
|
z-index: 1;
|
||||||
|
|
|
||||||
15
main.js
15
main.js
|
|
@ -7,6 +7,7 @@ import router from '@/common/router.js'
|
||||||
import ConfigManager from '@/common/config.js'
|
import ConfigManager from '@/common/config.js'
|
||||||
import RequestManager from '@/common/request.js'
|
import RequestManager from '@/common/request.js'
|
||||||
import EnvConfig from '@/common/env.js'
|
import EnvConfig from '@/common/env.js'
|
||||||
|
import { platform } from '@/common/platform/PlatformFactory'
|
||||||
|
|
||||||
// 全局注册uni-popup组件
|
// 全局注册uni-popup组件
|
||||||
import uniPopup from '@/uni_modules/uni-popup/components/uni-popup/uni-popup.vue'
|
import uniPopup from '@/uni_modules/uni-popup/components/uni-popup/uni-popup.vue'
|
||||||
|
|
@ -22,7 +23,7 @@ Vue.prototype.$img1 = url => EnvConfig.iconBaseUrl + url
|
||||||
Vue.prototype.$sys = () => uni.getSystemInfoSync()
|
Vue.prototype.$sys = () => uni.getSystemInfoSync()
|
||||||
Vue.prototype.$loginPage = EnvConfig.loginPage
|
Vue.prototype.$loginPage = EnvConfig.loginPage
|
||||||
Vue.prototype.$wxloginPage = EnvConfig.wxLoginUrl
|
Vue.prototype.$wxloginPage = EnvConfig.wxLoginUrl
|
||||||
|
Vue.prototype.$platform = platform;
|
||||||
// 公共方法
|
// 公共方法
|
||||||
Vue.prototype.gotoPage = gotopage
|
Vue.prototype.gotoPage = gotopage
|
||||||
// 注册路由方法到Vue实例,改用自定义属性名
|
// 注册路由方法到Vue实例,改用自定义属性名
|
||||||
|
|
@ -49,11 +50,11 @@ loadScript('https://res.wx.qq.com/open/js/jweixin-1.6.0.js')
|
||||||
|
|
||||||
// #ifdef MP-WEIXIN
|
// #ifdef MP-WEIXIN
|
||||||
const updateManager = wx.getUpdateManager()
|
const updateManager = wx.getUpdateManager()
|
||||||
updateManager.onCheckForUpdate(function(res) {
|
updateManager.onCheckForUpdate(function (res) {
|
||||||
console.log(res.hasUpdate)
|
console.log(res.hasUpdate)
|
||||||
})
|
})
|
||||||
|
|
||||||
updateManager.onUpdateReady(function() {
|
updateManager.onUpdateReady(function () {
|
||||||
wx.showModal({
|
wx.showModal({
|
||||||
title: '更新提示',
|
title: '更新提示',
|
||||||
content: '新版本已经准备好,是否重启应用?',
|
content: '新版本已经准备好,是否重启应用?',
|
||||||
|
|
@ -65,7 +66,7 @@ updateManager.onUpdateReady(function() {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
updateManager.onUpdateFailed(function() {
|
updateManager.onUpdateFailed(function () {
|
||||||
// 新版本下载失败
|
// 新版本下载失败
|
||||||
})
|
})
|
||||||
// #endif
|
// #endif
|
||||||
|
|
@ -80,14 +81,14 @@ const app = new Vue({
|
||||||
|
|
||||||
// 创建全局数据对象
|
// 创建全局数据对象
|
||||||
app.globalData = {
|
app.globalData = {
|
||||||
siteBaseUrl: EnvConfig.apiBaseUrl
|
siteBaseUrl: EnvConfig.apiBaseUrl
|
||||||
}
|
}
|
||||||
|
|
||||||
// 应用启动时加载全局配置
|
// 应用启动时加载全局配置
|
||||||
ConfigManager.init().then(config => {
|
ConfigManager.init().then(config => {
|
||||||
console.log('全局配置加载完成')
|
console.log('全局配置加载完成')
|
||||||
}).catch(err => {
|
}).catch(err => {
|
||||||
console.error('全局配置加载失败', err)
|
console.error('全局配置加载失败', err)
|
||||||
})
|
})
|
||||||
|
|
||||||
app.$mount()
|
app.$mount()
|
||||||
|
|
@ -14,7 +14,7 @@
|
||||||
<image class="ml20" :src="$img1('index/suoxinag.png')" mode="aspectFit"></image>
|
<image class="ml20" :src="$img1('index/suoxinag.png')" mode="aspectFit"></image>
|
||||||
<view class="ml30">倒计时:{{ secNum }}S</view>
|
<view class="ml30">倒计时:{{ secNum }}S</view>
|
||||||
</view>
|
</view>
|
||||||
<view class="header-title center"
|
<view class="header-title center"
|
||||||
:style="{ background: 'url(' + $img1('common/chouTitle.png') + ') no-repeat 0 0 / 100% 100%' }">
|
:style="{ background: 'url(' + $img1('common/chouTitle.png') + ') no-repeat 0 0 / 100% 100%' }">
|
||||||
<text>
|
<text>
|
||||||
<template></template>
|
<template></template>
|
||||||
|
|
@ -346,6 +346,7 @@ export default {
|
||||||
onLoad(options) {
|
onLoad(options) {
|
||||||
this.optData = options;
|
this.optData = options;
|
||||||
console.log(options);
|
console.log(options);
|
||||||
|
this.getData();
|
||||||
|
|
||||||
uni.$on('chooseCoupon', data => {
|
uni.$on('chooseCoupon', data => {
|
||||||
// console.log('data', data)
|
// console.log('data', data)
|
||||||
|
|
@ -360,6 +361,10 @@ export default {
|
||||||
this.sendRuleData = res.data
|
this.sendRuleData = res.data
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
if (options != null && options['order_no'] != null) {
|
||||||
|
let order_num = options['order_no'];
|
||||||
|
this.getPrize(order_num);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
onShow() {
|
onShow() {
|
||||||
|
|
@ -368,7 +373,7 @@ export default {
|
||||||
|
|
||||||
onReady() {
|
onReady() {
|
||||||
// this.tabChange(this.tabCur)
|
// this.tabChange(this.tabCur)
|
||||||
this.getData();
|
// this.getData();
|
||||||
},
|
},
|
||||||
|
|
||||||
onHide() {
|
onHide() {
|
||||||
|
|
@ -552,15 +557,6 @@ export default {
|
||||||
};
|
};
|
||||||
|
|
||||||
let url = 'infinite_ordermoney'
|
let url = 'infinite_ordermoney'
|
||||||
console.log(type);
|
|
||||||
if (type == 1) {
|
|
||||||
url = 'infinite_orderbuy'
|
|
||||||
|
|
||||||
if (this.$refs.buyNotice.getIsShow() && !flag) {
|
|
||||||
this.$refs.buyNotice.getRule(6)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
this.buyNum = num;
|
this.buyNum = num;
|
||||||
|
|
||||||
|
|
@ -571,18 +567,33 @@ export default {
|
||||||
this.couponData = null;
|
this.couponData = null;
|
||||||
coupon_id = '';
|
coupon_id = '';
|
||||||
}
|
}
|
||||||
|
console.log(type);
|
||||||
|
|
||||||
|
|
||||||
|
let postData = {
|
||||||
|
goods_id: this.pageData.goods.id,
|
||||||
|
prize_num: this.buyNum,
|
||||||
|
use_money_is: this.useMoney ? 1 : 2,
|
||||||
|
use_integral_is: this.useIntegral ? 1 : 2,
|
||||||
|
use_money2_is: this.useMoney2 ? 1 : 2,
|
||||||
|
coupon_id: coupon_id,
|
||||||
|
};
|
||||||
|
if (type == 1) {
|
||||||
|
url = 'infinite_orderbuy'
|
||||||
|
|
||||||
|
if (this.$refs.buyNotice.getIsShow() && !flag) {
|
||||||
|
this.$refs.buyNotice.getRule(6)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
postData = this.$platform.getPayData(url, postData);
|
||||||
|
// postData['quitUrl']=window.location.href;
|
||||||
|
// postData['returnUrl']=window.location.href;
|
||||||
|
}
|
||||||
|
|
||||||
this.req({
|
this.req({
|
||||||
url,
|
url,
|
||||||
data: {
|
data: postData,
|
||||||
goods_id: this.pageData.goods.id,
|
|
||||||
prize_num: this.buyNum,
|
|
||||||
use_money_is: this.useMoney ? 1 : 2,
|
|
||||||
use_integral_is: this.useIntegral ? 1 : 2,
|
|
||||||
use_money2_is: this.useMoney2 ? 1 : 2,
|
|
||||||
coupon_id: coupon_id,
|
|
||||||
|
|
||||||
// ad_id: uni.getStorageSync('_ad_id')
|
|
||||||
},
|
|
||||||
success: async res => {
|
success: async res => {
|
||||||
if (res.status == 1) {
|
if (res.status == 1) {
|
||||||
if (type == 0) {
|
if (type == 0) {
|
||||||
|
|
@ -605,7 +616,7 @@ export default {
|
||||||
this.close('buyPop')
|
this.close('buyPop')
|
||||||
|
|
||||||
if (res.data.status == 1) {
|
if (res.data.status == 1) {
|
||||||
const status = await this.$c.wxMpPay({
|
const status = await this.$platform.pay({
|
||||||
data: res.data.res
|
data: res.data.res
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
||||||
BIN
unpackage/release/apk/20250429205226.apk
Normal file
BIN
unpackage/release/apk/20250429205226.apk
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user