'支付调试'

This commit is contained in:
gonghaoxing 2025-10-21 17:33:05 +08:00
parent 7d1afd7d80
commit 33393bc31e
11 changed files with 284 additions and 45 deletions

View File

@ -1,8 +1,8 @@
# 正式环境接口域名
SHOPRO_BASE_URL = https://v3.shopro.top
SHOPRO_BASE_URL = https://admin.fengketrade.com
# 开发环境接口域名
SHOPRO_DEV_BASE_URL = https://v3.shopro.top
SHOPRO_DEV_BASE_URL = https://admin.fengketrade.com
# 开发环境运行端口
SHOPRO_DEV_PORT = 3000

View File

@ -132,11 +132,10 @@
});
}
//
// -
function onPay(orderSN) {
sheep.$router.go('/pages/pay/index', {
orderSN,
});
//
sheep.$platform.pay('ccb', 'goods', orderSN);
}
//

View File

@ -263,13 +263,16 @@
sheep.$store('cart').submitUpdateList();
}
if (data.status === 'paid') {
//
sheep.$router.redirect('/pages/pay/result', {
orderSN: data.order_sn,
payState: 'success',
orderType: 'goods',
});
} else {
sheep.$router.redirect('/pages/pay/index', {
orderSN: data.order_sn,
});
//
//
sheep.$platform.pay('ccb', 'goods', data.order_sn);
}
}
}

View File

@ -369,11 +369,10 @@
});
return refundFee;
});
//
// -
function onPay(orderSN) {
sheep.$router.go('/pages/pay/index', {
orderSN,
});
//
sheep.$platform.pay('ccb', 'goods', orderSN);
}
function onGoodsDetail(id) {

View File

@ -316,11 +316,10 @@
});
}
//
// -
function onPay(orderSN) {
sheep.$router.go('/pages/pay/index', {
orderSN,
});
//
sheep.$platform.pay('ccb', 'goods', orderSN);
}
//

View File

@ -10,7 +10,8 @@
<view class="num-title">当前余额</view>
<view class="wallet-num">{{ userInfo.money }}</view>
</view>
<button class="ss-reset-button log-btn" @tap="sheep.$router.go('/pages/pay/recharge-log')">充值记录</button>
<!-- 充值记录入口已注释 -->
<!-- <button class="ss-reset-button log-btn" @tap="sheep.$router.go('/pages/pay/recharge-log')">充值记录</button> -->
</view>
<view class="recharge-box">
<view class="recharge-card-box" v-if="state.data.status">
@ -77,10 +78,8 @@ async function onConfirm() {
// #ifdef MP
sheep.$platform.useProvider('wechat').subscribeMessage('money_change');
// #endif
sheep.$router.go('/pages/pay/index', {
orderSN: data.order_sn,
type: 'recharge',
});
//
sheep.$platform.pay('ccb', 'recharge', data.order_sn);
}
}
onLoad(() => {

View File

@ -13,9 +13,10 @@
</view>
<view class="ss-flex ss-row-between ss-col-center ss-m-t-64">
<view class="money-num">{{ state.showMoney ? userInfo.money : '*****' }}</view>
<button class="ss-reset-button topup-btn" @tap="sheep.$router.go('/pages/pay/recharge')">
<!-- 充值功能已注释 -->
<!-- <button class="ss-reset-button topup-btn" @tap="sheep.$router.go('/pages/pay/recharge')">
充值
</button>
</button> -->
</view>
</view>
</view>

View File

@ -1,6 +1,7 @@
<template>
<view class="ss-wallet-menu-wrap ss-flex ss-col-center">
<view
<!-- 账户余额入口已注释 -->
<!-- <view
class="menu-item ss-flex-1 ss-flex-col ss-row-center ss-col-center"
@tap="sheep.$router.go('/pages/user/wallet/money')"
>
@ -9,7 +10,7 @@
<view class="unit-text ss-m-l-6"></view>
</view>
<view class="menu-title ss-m-t-28">账户余额</view>
</view>
</view> -->
<!-- <view class="menu-item ss-flex-1 ss-flex-col ss-row-center ss-col-center"
@tap="sheep.$router.go('/pages/user/wallet/commission')">
<view class="value-box ss-flex ss-col-bottom">
@ -42,7 +43,8 @@
</view>
<view class="menu-title ss-m-t-28">优惠券</view>
</view>
<view
<!-- 我的钱包入口已注释 -->
<!-- <view
class="menu-item ss-flex-col ss-row-center ss-col-center menu-wallet"
@tap="sheep.$router.go('/pages/user/wallet/money')"
>
@ -53,7 +55,7 @@
>
</image>
<view class="menu-title ss-m-t-30">我的钱包</view>
</view>
</view> -->
</view>
</template>

View File

@ -25,6 +25,9 @@ export default class SheepPay {
}
payAction() {
// 调试日志:打印当前平台和支付方式
console.log('[支付调试] 当前平台:', sheep.$platform.name, '支付方式:', this.payment);
const payAction = {
WechatOfficialAccount: {
wechat: () => {
@ -99,7 +102,43 @@ export default class SheepPay {
this.offlinePay();
}
},
// ⭐ 建行生活平台CcbLife
CcbLife: {
wechat: () => {
this.ccbPay(); // 在建行生活内使用建行支付
},
alipay: () => {
sheep.$helper.toast('请使用建行支付');
},
ccb: () => {
this.ccbPay(); // 建行支付
},
money: () => {
this.moneyPay();
},
offline: () => {
this.offlinePay();
}
},
};
// 防御性检查:确保平台配置存在
if (!payAction[sheep.$platform.name]) {
console.error('[支付错误] 未知平台:', sheep.$platform.name);
sheep.$helper.toast('当前平台不支持该支付方式');
return;
}
// 防御性检查:确保支付方式存在
if (!payAction[sheep.$platform.name][this.payment]) {
console.error('[支付错误] 平台不支持该支付方式:', {
platform: sheep.$platform.name,
payment: this.payment
});
sheep.$helper.toast(`当前平台不支持${this.payment}支付`);
return;
}
return payAction[sheep.$platform.name][this.payment]();
}
@ -290,41 +329,86 @@ export default class SheepPay {
// 建行生活支付
async ccbPay() {
let that = this;
console.log('[建行支付] ========== 开始建行支付流程 ==========');
console.log('[建行支付] 订单号:', this.orderSN);
console.log('[建行支付] 订单类型:', this.orderType);
// 检查是否在建行App内
console.log('[建行支付] 检查建行App环境...');
console.log('[建行支付] isInCcbApp:', CcbLifePlatform.isInCcbApp);
console.log('[建行支付] User Agent:', navigator.userAgent);
console.log('[建行支付] URL参数:', location.search);
if (!CcbLifePlatform.isInCcbApp) {
console.error('[建行支付] ❌ 不在建行App内');
sheep.$helper.toast('请在建行生活App内使用建行支付');
return;
}
console.log('[建行支付] ✅ 确认在建行App内');
// 获取订单ID从订单号查询
const orderInfo = await sheep.$api.order.detail(this.orderSN);
if (!orderInfo || orderInfo.code !== 1) {
sheep.$helper.toast('获取订单信息失败');
return;
}
console.log('[建行支付] 步骤1: 查询订单信息...');
try {
const orderInfo = await sheep.$api.order.detail(this.orderSN);
console.log('[建行支付] 订单查询结果:', orderInfo);
if (!orderInfo || orderInfo.code !== 1) {
console.error('[建行支付] ❌ 获取订单信息失败:', orderInfo);
sheep.$helper.toast('获取订单信息失败');
return;
}
const orderId = orderInfo.data.id;
const orderId = orderInfo.data.id;
console.log('[建行支付] ✅ 订单ID:', orderId);
console.log('[建行支付] 订单金额:', orderInfo.data.pay_fee);
console.log('[建行支付] 订单状态:', orderInfo.data.status);
// 调用后端生成支付串
const paymentResult = await ccbApi.createPayment(orderId);
// 调用后端生成支付串
console.log('[建行支付] 步骤2: 调用后端生成支付串...');
console.log('[建行支付] 请求参数:', { order_id: orderId });
const paymentResult = await ccbApi.createPayment(orderId);
console.log('[建行支付] 支付串生成结果:', paymentResult);
if (paymentResult.code !== 1) {
sheep.$helper.toast(paymentResult.msg || '生成支付串失败');
if (paymentResult.code !== 1) {
console.error('[建行支付] ❌ 生成支付串失败:', paymentResult);
console.error('[建行支付] 错误信息:', paymentResult.msg);
console.error('[建行支付] 完整响应:', JSON.stringify(paymentResult));
sheep.$helper.toast(paymentResult.msg || '生成支付串失败');
return;
}
console.log('[建行支付] ✅ 支付串生成成功');
console.log('[建行支付] 支付串长度:', paymentResult.data.payment_string?.length);
console.log('[建行支付] 支付流水号:', paymentResult.data.pay_flow_id);
console.log('[建行支付] 支付金额:', paymentResult.data.amount);
} catch (error) {
console.error('[建行支付] ❌ 异常:', error);
console.error('[建行支付] 错误堆栈:', error.stack);
sheep.$helper.toast('支付准备失败: ' + error.message);
return;
}
// 调起建行支付
console.log('[建行支付] 步骤3: 调起建行收银台...');
try {
const result = await CcbLifePlatform.payment({
const paymentParams = {
payment_string: paymentResult.data.payment_string,
order_id: orderId,
order_sn: this.orderSN
};
console.log('[建行支付] 调起参数:', {
order_id: paymentParams.order_id,
order_sn: paymentParams.order_sn,
payment_string_length: paymentParams.payment_string?.length
});
const result = await CcbLifePlatform.payment(paymentParams);
console.log('[建行支付] 收银台调起结果:', result);
if (result.code === 0) {
// ✅ 支付调起成功,开始轮询查询订单状态
console.log('[建行支付] 支付调起成功,开始轮询查询订单状态');
console.log('[建行支付] 支付调起成功,开始轮询查询订单状态');
// 显示加载提示
uni.showLoading({
@ -339,23 +423,31 @@ export default class SheepPay {
const pollPaymentStatus = async () => {
pollCount++;
console.log(`[建行支付] 轮询查询 ${pollCount}/${MAX_POLL_COUNT} 次...`);
try {
const statusResult = await ccbApi.queryPaymentStatus(orderId);
console.log('[建行支付] 查询结果:', statusResult);
if (statusResult.code === 1 && statusResult.data.is_paid) {
// ✅ 支付成功
uni.hideLoading();
console.log('[建行支付] 订单已支付 order_id:' + orderId);
console.log('[建行支付] ✅ 订单已支付 order_id:' + orderId);
console.log('[建行支付] 支付时间:', statusResult.data.paid_time);
that.payResult('success');
return;
}
console.log('[建行支付] 订单状态:', statusResult.data.status);
console.log('[建行支付] 是否已支付:', statusResult.data.is_paid);
// 未支付,继续轮询
if (pollCount < MAX_POLL_COUNT) {
console.log(`[建行支付] ${POLL_INTERVAL/1000}秒后继续查询...`);
setTimeout(pollPaymentStatus, POLL_INTERVAL);
} else {
// 超时
console.warn('[建行支付] ⚠️ 轮询超时,可能支付未完成');
uni.hideLoading();
uni.showModal({
title: '提示',
@ -369,7 +461,8 @@ export default class SheepPay {
});
}
} catch (error) {
console.error('[建行支付] 查询状态失败:', error);
console.error('[建行支付] ❌ 查询状态失败:', error);
console.error('[建行支付] 错误详情:', error.message);
// 继续轮询(网络错误不中断)
if (pollCount < MAX_POLL_COUNT) {
@ -387,18 +480,26 @@ export default class SheepPay {
} else {
// 支付失败或取消
console.error('[建行支付] ❌ 支付未成功:', result);
if (result.msg && result.msg.includes('取消')) {
console.log('[建行支付] 用户取消支付');
sheep.$helper.toast('支付已取消');
} else {
console.error('[建行支付] 支付失败原因:', result.msg);
sheep.$helper.toast(result.msg || '支付失败');
that.payResult('fail');
}
}
} catch (error) {
console.error('[建行支付] 错误:', error);
sheep.$helper.toast('支付失败');
console.error('[建行支付] ❌ 异常错误:', error);
console.error('[建行支付] 错误类型:', error.name);
console.error('[建行支付] 错误信息:', error.message);
console.error('[建行支付] 错误堆栈:', error.stack);
sheep.$helper.toast('支付失败: ' + error.message);
that.payResult('fail');
}
console.log('[建行支付] ========== 建行支付流程结束 ==========');
}
// 支付结果跳转,success:成功fail:失败

View File

@ -45,6 +45,7 @@ const ccbApi = {
* 用于调起建行收银台
*/
createPayment: (orderId) => {
console.log('[建行API] 调用createPayment接口, order_id:', orderId);
return request({
url: '/ccbpayment/createPayment',
method: 'POST',
@ -55,6 +56,12 @@ const ccbApi = {
showLoading: true,
auth: true
}
}).then(res => {
console.log('[建行API] createPayment响应:', res);
return res;
}).catch(err => {
console.error('[建行API] createPayment错误:', err);
return err;
});
},

View File

@ -42,6 +42,8 @@ const CcbLifePlatform = {
* 初始化
*/
init() {
console.log('[CcbLife] ========== 建行生活平台初始化 ==========');
// 检测环境
this.detectEnvironment();
@ -50,29 +52,43 @@ const CcbLifePlatform = {
// this.setupBridge();
// }
console.log('[CcbLife] 初始化完成, 是否在建行App内:', this.isInCcbApp);
console.log('[CcbLife] ✅ 初始化完成');
console.log('[CcbLife] 是否在建行App内:', this.isInCcbApp);
console.log('[CcbLife] 平台标识:', this.platform);
console.log('[CcbLife] ===========================================');
},
/**
* 检测运行环境
*/
detectEnvironment() {
console.log('[CcbLife] 开始检测运行环境...');
// #ifdef H5
const ua = navigator.userAgent.toLowerCase();
console.log('[CcbLife] User-Agent:', ua);
// 检查User-Agent
if (ua.indexOf('ccblife') > -1 || ua.indexOf('ccb') > -1) {
console.log('[CcbLife] ✅ 通过UA检测到建行App');
this.isInCcbApp = true;
return;
}
// 检查URL参数
const urlParams = this.getUrlParams();
console.log('[CcbLife] URL参数:', urlParams);
if (urlParams.ccbParamSJ || urlParams.from === 'ccblife') {
console.log('[CcbLife] ✅ 通过URL参数检测到建行App');
console.log('[CcbLife] ccbParamSJ:', urlParams.ccbParamSJ ? '存在' : '不存在');
console.log('[CcbLife] from:', urlParams.from);
this.isInCcbApp = true;
return;
}
console.log('[CcbLife] ❌ 未检测到建行App环境');
// ⚠️ 已移除 JSBridge 检查(目前不需要)
// if (window.WebViewJavascriptBridge || window.mbspay) {
// this.isInCcbApp = true;
@ -83,10 +99,12 @@ const CcbLifePlatform = {
// #ifdef APP-PLUS
// 在APP中也可能通过插件方式集成建行SDK
// TODO: 检测建行SDK插件
console.log('[CcbLife] App环境检测建行SDK插件...');
// #endif
// #ifdef MP-WEIXIN
// 小程序环境不支持建行生活
console.log('[CcbLife] 小程序环境,不支持建行生活');
this.isInCcbApp = false;
// #endif
},
@ -424,6 +442,117 @@ const CcbLifePlatform = {
// // #endif
// },
/**
* 调起建行收银台
* 根据建行App服务方接入文档使用支付串调起收银台
*
* @param {Object} options - 支付参数
* @param {String} options.payment_string - 支付串
* @param {Number} options.order_id - 订单ID
* @param {String} options.order_sn - 订单号
* @returns {Promise<Object>} - 返回支付结果
*/
async payment(options) {
console.log('[建行收银台] ========== 调起建行收银台 ==========');
console.log('[建行收银台] 参数:', {
order_id: options.order_id,
order_sn: options.order_sn,
payment_string_length: options.payment_string?.length
});
return new Promise((resolve, reject) => {
if (!this.isInCcbApp) {
console.error('[建行收银台] ❌ 不在建行生活App内');
reject({
code: -1,
msg: '不在建行生活App内'
});
return;
}
if (!options.payment_string) {
console.error('[建行收银台] ❌ 缺少支付串参数');
reject({
code: -1,
msg: '缺少支付串参数'
});
return;
}
console.log('[建行收银台] 支付串前100字符:', options.payment_string.substring(0, 100));
try {
// #ifdef H5
const isIOS = this.isIOS();
console.log('[建行收银台] 设备类型:', isIOS ? 'iOS' : 'Android');
if (isIOS) {
// iOS: 使用 URL Scheme 调起支付
console.log('[建行收银台] iOS: 使用URL Scheme调起');
const payUrl = 'mbspay://direct?' + options.payment_string;
console.log('[建行收银台] 跳转URL长度:', payUrl.length);
window.location.href = payUrl;
// iOS调起后认为成功实际支付结果通过异步通知获取
setTimeout(() => {
console.log('[建行收银台] ✅ iOS收银台已调起');
resolve({
code: 0,
msg: '已调起建行支付'
});
}, 500);
} else {
// Android: 调用 JSBridge 方法
console.log('[建行收银台] Android: 检查mbspay对象...');
console.log('[建行收银台] window.mbspay存在:', !!window.mbspay);
console.log('[建行收银台] mbspay.directpay存在:', !!(window.mbspay && window.mbspay.directpay));
if (window.mbspay && typeof window.mbspay.directpay === 'function') {
console.log('[建行收银台] 调用mbspay.directpay()...');
window.mbspay.directpay(options.payment_string);
// Android调起后认为成功实际支付结果通过异步通知获取
setTimeout(() => {
console.log('[建行收银台] ✅ Android收银台已调起');
resolve({
code: 0,
msg: '已调起建行支付'
});
}, 500);
} else {
console.error('[建行收银台] ❌ mbspay对象不存在或directpay方法不存在');
console.error('[建行收银台] window对象键:', Object.keys(window).filter(k => k.toLowerCase().includes('pay') || k.toLowerCase().includes('ccb')));
reject({
code: -1,
msg: '建行支付环境异常请更新建行生活App'
});
}
}
// #endif
// #ifndef H5
console.error('[建行收银台] ❌ 非H5环境');
reject({
code: -1,
msg: '仅支持H5环境'
});
// #endif
} catch (error) {
console.error('[建行收银台] ❌ 调起失败:', error);
console.error('[建行收银台] 错误类型:', error.name);
console.error('[建行收银台] 错误信息:', error.message);
console.error('[建行收银台] 错误堆栈:', error.stack);
reject({
code: -1,
msg: error.message || '调起支付失败'
});
}
console.log('[建行收银台] ===========================================');
});
},
/**
* 判断是否iOS
*/