2023-1-8
This commit is contained in:
13
uni_modules/common-pay/utils/pay.js
Normal file
13
uni_modules/common-pay/utils/pay.js
Normal file
@@ -0,0 +1,13 @@
|
||||
function pay(o) {
|
||||
// 数据源转换成字符
|
||||
let data = JSON.stringify(o)
|
||||
// 转码传输
|
||||
let value = encodeURIComponent(data)
|
||||
uni.navigateTo({
|
||||
url: '/uni_modules/common-pay/pages/pay/pay?data=' + value
|
||||
})
|
||||
}
|
||||
|
||||
export {
|
||||
pay
|
||||
}
|
||||
107
uni_modules/common-pay/utils/pay_http.js
Normal file
107
uni_modules/common-pay/utils/pay_http.js
Normal file
@@ -0,0 +1,107 @@
|
||||
/**
|
||||
* 支付专用网络请求
|
||||
* url: 绝对路径请求地址
|
||||
* token: 如需请传
|
||||
* data: 参数
|
||||
*/
|
||||
function http(options) {
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
|
||||
uni.showLoading({
|
||||
title: '加载中...',
|
||||
mask: true
|
||||
});
|
||||
|
||||
var url = options.url
|
||||
|
||||
uni.request({
|
||||
// 组装请求地址
|
||||
url: url,
|
||||
// 请求方式 POST
|
||||
method: 'POST',
|
||||
header: {
|
||||
'content-type': "application/x-www-form-urlencoded",
|
||||
'token': (options.token == undefined || options.token == '') ? "token is null" : options
|
||||
.token
|
||||
},
|
||||
// 具体参数
|
||||
data: options.data,
|
||||
success: res => {
|
||||
|
||||
// 关闭显示框
|
||||
uni.hideLoading();
|
||||
|
||||
console.log('Http网络路径', url)
|
||||
console.log('Http网络请求结果', JSON.stringify(res.data))
|
||||
|
||||
if (res.statusCode == 200) {
|
||||
|
||||
// 进行success字段检查
|
||||
|
||||
if (!res.data.success) {
|
||||
|
||||
uni.showToast({
|
||||
title: res.data.msg,
|
||||
// 保证文字长度
|
||||
icon: "none",
|
||||
duration: 3000
|
||||
})
|
||||
|
||||
// 直接返回Response
|
||||
reject(res.data)
|
||||
|
||||
} else {
|
||||
// 直接返回Response
|
||||
resolve(res.data)
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
uni.showToast({
|
||||
title: res.statusCode + ":" + res.data.error,
|
||||
// 保证文字长度
|
||||
icon: "none",
|
||||
duration: 3000
|
||||
})
|
||||
|
||||
// 返回错误数据
|
||||
reject({
|
||||
success: false,
|
||||
msg: res.data.error,
|
||||
code: '1111'
|
||||
})
|
||||
}
|
||||
|
||||
},
|
||||
fail: (err) => {
|
||||
|
||||
// 关闭显示框
|
||||
uni.hideLoading();
|
||||
|
||||
console.log("Http网络请求fail", err)
|
||||
|
||||
uni.showToast({
|
||||
title: err.errMsg,
|
||||
icon: 'none'
|
||||
})
|
||||
|
||||
// 返回错误数据
|
||||
reject({
|
||||
success: false,
|
||||
msg: err.errMsg,
|
||||
code: '1111'
|
||||
})
|
||||
},
|
||||
complete: () => {
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
export {
|
||||
http
|
||||
}
|
||||
Reference in New Issue
Block a user