扫二维码码支付
This commit is contained in:
1 parent
8dc692796c
commit
8bff006f5a
5 files changed
+154
-63
No files matched your search
+42
-4
@@ -177,11 +177,28 @@ const doLogout = async () => {
|
||||
|
||||
// 扫一扫
|
||||
const doScanCode = async () => {
|
||||
usePayStore().setPayData({})
|
||||
try {
|
||||
const res: any = await (window as any).dd.scan({ type: "all", sourceType: ["camera"], scanType: ["cameraScan"] })
|
||||
console.log(res)
|
||||
usePayStore().setPayData(res.text)
|
||||
router.jump("/pages/pay/scanPay")
|
||||
// const res: any = await (window as any).dd.scan({ type: "all", sourceType: ["camera"], scanType: ["cameraScan"] })
|
||||
const decodedString = decodeBase64("eyJpZCI6MTg4OTQ4MzkzODQ4NDUzMTIwMSwibmFtZSI6Iua1i+ivlei2heW4giJ9")
|
||||
// const decodedString = decodeBase64(res.text)
|
||||
if (decodedString) {
|
||||
const decodedJson = JSON.parse(decodedString)
|
||||
if (decodedJson?.id && decodedJson?.name) {
|
||||
usePayStore().setPayData(decodedJson)
|
||||
router.jump("/pages/pay/scanPay")
|
||||
} else {
|
||||
uni.showToast({
|
||||
title: "无效的二维码",
|
||||
icon: "none",
|
||||
})
|
||||
}
|
||||
} else {
|
||||
uni.showToast({
|
||||
title: "无效的二维码",
|
||||
icon: "none",
|
||||
})
|
||||
}
|
||||
} catch (error: any) {
|
||||
if (error) {
|
||||
uni.showToast({
|
||||
@@ -207,6 +224,27 @@ const onTabMenu = async (v: MenuItem, i: number) => {
|
||||
}
|
||||
}
|
||||
|
||||
// 解码base64
|
||||
const decodeBase64 = (base64String: string) => {
|
||||
try {
|
||||
const decodedBinaryString = atob(base64String)
|
||||
const uint8Array = new Uint8Array(decodedBinaryString.length)
|
||||
for (let i = 0; i < decodedBinaryString.length; i++) {
|
||||
uint8Array[i] = decodedBinaryString.charCodeAt(i)
|
||||
}
|
||||
const decoder = new TextDecoder("utf-8")
|
||||
const decodedString = decoder.decode(uint8Array)
|
||||
console.log("解码结果", decodedString)
|
||||
return decodedString
|
||||
} catch (error) {
|
||||
console.error("Base64 解码失败:", error)
|
||||
uni.showToast({
|
||||
title: "解码失败,无效的二维码",
|
||||
icon: "none",
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
const getStorageUserInfo = () => {
|
||||
const tokenKey = constant.storageConstant.TOKEN
|
||||
const userInfoKey = constant.storageConstant.USERINFO
|
||||
|
||||
Reference in new issue
Block a user