支付调试
parent
ff60fdf732
commit
2cb08346e1
44
App.vue
44
App.vue
|
|
@ -11,6 +11,44 @@
|
|||
},
|
||||
onShow: function() {
|
||||
console.log('App Show')
|
||||
// 1. uni-app 中通过 uni.getEnterOptionsSync() 调用(和微信小程序API一致,只是前缀改为uni)
|
||||
const options = uni.getEnterOptionsSync();
|
||||
console.log("查询到的返回数据")
|
||||
console.log(options)
|
||||
|
||||
// 2. 注意:scene 返回的是数字类型,不是字符串!原生代码中写 '1038' 会导致判断失败
|
||||
if (options.scene === 1038 &&
|
||||
options.referrerInfo?.appId === 'wxef277996acc166c3') {
|
||||
|
||||
// 从收银台小程序返回的逻辑
|
||||
const extraData = options.referrerInfo.extraData;
|
||||
|
||||
if (!extraData) {
|
||||
uni.showToast({
|
||||
title: '当前通过物理按键返回,未接收到返参,建议自行查询交易结果',
|
||||
icon: 'none',
|
||||
duration: 3000
|
||||
});
|
||||
} else {
|
||||
if (extraData.code === 'success') {
|
||||
uni.showToast({
|
||||
title: '支付成功',
|
||||
icon: 'success'
|
||||
});
|
||||
} else if (extraData.code === 'cancel') {
|
||||
uni.showToast({
|
||||
title: '支付已取消',
|
||||
icon: 'none'
|
||||
});
|
||||
} else {
|
||||
uni.showToast({
|
||||
title: `支付失败:${extraData.errmsg || '未知错误'}`,
|
||||
icon: 'none',
|
||||
duration: 3000
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
onHide: function() {
|
||||
console.log('App Hide')
|
||||
|
|
@ -19,7 +57,7 @@
|
|||
// 检查登录状态
|
||||
checkLoginStatus() {
|
||||
const token = uni.getStorageSync('token')
|
||||
|
||||
|
||||
// 如果有token,且当前在登录页,则跳转到首页
|
||||
if (token) {
|
||||
// 延迟一下,确保页面已经初始化
|
||||
|
|
@ -27,7 +65,7 @@
|
|||
const pages = getCurrentPages()
|
||||
const currentPage = pages[pages.length - 1]
|
||||
const currentRoute = currentPage ? currentPage.route : ''
|
||||
|
||||
|
||||
// 如果当前在登录页,跳转到首页
|
||||
if (currentRoute === 'pages/login/login') {
|
||||
uni.switchTab({
|
||||
|
|
@ -49,4 +87,4 @@
|
|||
|
||||
<style>
|
||||
/*每个页面公共css */
|
||||
</style>
|
||||
</style>
|
||||
|
|
@ -46,4 +46,12 @@ export function getMessagePage(params = {}) {
|
|||
method: 'GET',
|
||||
data: params,
|
||||
})
|
||||
}
|
||||
// 获取支付的签名
|
||||
export function getPaySign(params = {}){
|
||||
return request({
|
||||
url: '/app-api/member/labor-union-pay-record/sign',
|
||||
method: 'GET',
|
||||
data: params,
|
||||
})
|
||||
}
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name" : "demo",
|
||||
"appid" : "wxa3c0e1381f643f59",
|
||||
"name" : "司机公会用户端",
|
||||
"appid" : "__UNI__BD011FB",
|
||||
"description" : "",
|
||||
"versionName" : "1.0.0",
|
||||
"versionCode" : "100",
|
||||
|
|
@ -52,12 +52,11 @@
|
|||
"mp-weixin" : {
|
||||
"appid" : "wxa3c0e1381f643f59",
|
||||
"setting" : {
|
||||
"urlCheck" : false
|
||||
"urlCheck" : false,
|
||||
"minified" : true
|
||||
},
|
||||
"usingComponents" : true,
|
||||
"requiredPrivateInfos" : [
|
||||
"getLocation"
|
||||
],
|
||||
"requiredPrivateInfos" : [ "getLocation" ],
|
||||
"permission" : {
|
||||
"scope.userLocation" : {
|
||||
"desc" : "你的位置信息将用于小程序位置接口的效果展示"
|
||||
|
|
@ -71,7 +70,8 @@
|
|||
"usingComponents" : true
|
||||
},
|
||||
"mp-toutiao" : {
|
||||
"usingComponents" : true
|
||||
"usingComponents" : true,
|
||||
"appid" : ""
|
||||
},
|
||||
"uniStatistics" : {
|
||||
"enable" : false
|
||||
|
|
|
|||
|
|
@ -118,7 +118,7 @@
|
|||
</template>
|
||||
|
||||
<script>
|
||||
import { getGuildStoreDetail, getGuildCoupon } from "@/api/service";
|
||||
import { getGuildStoreDetail, getGuildCoupon ,getPaySign } from "@/api/service";
|
||||
import NavHeader from "@/components/NavHeader/NavHeader.vue";
|
||||
|
||||
export default {
|
||||
|
|
@ -210,6 +210,7 @@ export default {
|
|||
|
||||
// 标记已经检查过登录状态
|
||||
this.hasCheckedLogin = true;
|
||||
|
||||
},
|
||||
methods: {
|
||||
// 加载店铺数据
|
||||
|
|
@ -305,7 +306,7 @@ export default {
|
|||
},
|
||||
|
||||
// 去结算
|
||||
handleCheckout() {
|
||||
async handleCheckout() {
|
||||
if (this.totalAmount <= 0) {
|
||||
return;
|
||||
}
|
||||
|
|
@ -323,11 +324,80 @@ export default {
|
|||
return;
|
||||
}
|
||||
|
||||
uni.showToast({
|
||||
title: "该功能正在开发中",
|
||||
icon: "none",
|
||||
});
|
||||
// uni.showToast({
|
||||
// title: "该功能正在开发中",
|
||||
// icon: "none",
|
||||
// });
|
||||
// 测试支付进行
|
||||
const reqsn = 'mini' + Date.now() + '' + Math.floor(Math.random() * 10000);
|
||||
const randomstr = Math.floor(Math.random() * 10000000);
|
||||
// 定义请求参数
|
||||
let params = {
|
||||
"appid": "00390105", //平台分配的appid
|
||||
"cusid": "56479107531MPMN" ,//"平台分配的商户号"
|
||||
"orgid": "56479107392N35H",
|
||||
"version": "12",
|
||||
"trxamt": "2",
|
||||
"reqsn": reqsn, // 建议生成唯一值(如时间戳+随机数)
|
||||
"notify_url": "http://ub6b98bb.natappfree.cc/admin-api/member/labor-union-pay-record/tlNotice",
|
||||
"body": "test",
|
||||
"remark": "remark",
|
||||
"randomstr": randomstr,
|
||||
"paytype": "W06",
|
||||
"signtype": "RSA",
|
||||
"asinfo":"cusid:56479107392N35Htype:01amount:0.01",
|
||||
"sign":""
|
||||
};
|
||||
|
||||
const sign = await getPaySign(params)
|
||||
console.log("测试返回的签名:"+sign)
|
||||
params["sign"] = sign
|
||||
|
||||
console.log(params)
|
||||
params = this.sortObjectByKey(params);
|
||||
console.log(params)
|
||||
// 统一使用 navigateToMiniProgram 跳转小程序
|
||||
uni.navigateToMiniProgram({
|
||||
appId: 'wxef277996acc166c3', // 目标小程序appid
|
||||
extraData: params, // 传递给目标小程序的参数
|
||||
success(res) {
|
||||
console.log('小程序跳转成功', res);
|
||||
},
|
||||
fail(err) {
|
||||
console.error('小程序跳转失败', err);
|
||||
// 可根据需要添加失败后的提示或兜底逻辑
|
||||
uni.showToast({
|
||||
title: '跳转失败,请稍后重试',
|
||||
icon: 'none'
|
||||
});
|
||||
},
|
||||
complete() {
|
||||
// 无论成功失败都会执行的逻辑(可选)
|
||||
}
|
||||
});
|
||||
|
||||
//---- 测试支付
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* 将对象按键的字典序排序,返回有序对象(和Java TreeMap排序逻辑一致)
|
||||
* @param {Object} obj 原始参数对象
|
||||
* @returns {Object} 按键排序后的新对象
|
||||
*/
|
||||
sortObjectByKey(obj) {
|
||||
// 1. 提取所有键并按字典序排序(和Java String自然排序规则一致)
|
||||
const sortedKeys = Object.keys(obj).sort();
|
||||
|
||||
// 2. 按排序后的键重新组装对象
|
||||
const sortedObj = {};
|
||||
sortedKeys.forEach(key => {
|
||||
sortedObj[key] = obj[key];
|
||||
});
|
||||
|
||||
return sortedObj;
|
||||
}
|
||||
|
||||
},
|
||||
};
|
||||
</script>
|
||||
|
|
|
|||
Loading…
Reference in New Issue