支付调试

cz_dev
格调main 2026-02-27 16:48:28 +08:00
parent ff60fdf732
commit 2cb08346e1
4 changed files with 132 additions and 16 deletions

44
App.vue
View File

@ -11,6 +11,44 @@
},
onShow: function() {
console.log('App Show')
// 1. uni-app uni.getEnterOptionsSync() APIuni
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>

View File

@ -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,
})
}

View File

@ -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

View File

@ -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>