feat:适配支付,第三方app
This commit is contained in:
1 parent
196ed0285a
commit
7ec67acded
22 files changed
+173
-119
No files matched your search
@@ -1,59 +1,28 @@
|
||||
import { router } from ".."
|
||||
import { APPENV } from "../constant"
|
||||
import { getAppInfo, isDevEnv } from "../utils/app"
|
||||
import { getUrlParamsObj } from "../utils/app"
|
||||
|
||||
export function useScanCode(actModalShow) {
|
||||
async function scanCodeAction(): Promise<string | undefined> {
|
||||
const appInfo = await getAppInfo()
|
||||
if (isDevEnv() && appInfo != APPENV.APP) {
|
||||
// 开发环境模拟扫码
|
||||
// const testQrCode = "eyJpZCI6IjE5MDU4ODg4NjQ0NTQ1MzMxMjEiLCJuYW1lIjoi6ICB5Y6/5bqc6aOf5aCCIn0=" // 测试线上-老县府食堂-收款二维码
|
||||
// const testQrCode = "eyJoYXJkRG9vcklkIjoiMTkxNDIxNTYwODQzNzQxMTg0MSIsImNhYmluZXRObyI6IjEifQ==" // 测试线上-智能柜-收款二维码
|
||||
// const testQrCode = "eyJpZCI6IjE5MDU4MTY3NTEwNDM0NTI5MzAiLCJuYW1lIjoi5paw5Y6/5bqc6LaF5biCIn0=" // 邓本地-测试环境-新县府超市收款二维码
|
||||
// const testQrCode = "eyJoYXJkRG9vcklkIjoiMTkxMzE1NzA4MDQxODI5NTgwOSIsImNhYmluZXRObyI6IjEifQ==" // 邓本地-测试单门智能柜柜门二维码
|
||||
// const testQrCode = "http://192.168.101.45:8889/h5/#/pages/pay/scanPay?id=1905816751043452930&name=测试新县府超市" // 邓本地-测试环境-新县府超市收款二维码
|
||||
// const testQrCode = "http://192.168.101.45:8889/h5/#/pages/pay/scanPay?hardDoorId=1913157080418295809&cabinetNo=1" // 测试智能柜柜门二维码
|
||||
const testQrCode = "eyJjYW5jZWxJZCI6IjE5ODQyNDA4MzM5NDMyMDc5MzcifQ==" // 测试商户活动核销
|
||||
uni.showModal({ content: "开发环境不是浙政钉和诗画环境,扫码仅供测试" })
|
||||
return Promise.resolve(testQrCode)
|
||||
}
|
||||
if (appInfo == APPENV.APP) {
|
||||
const scanResult = await new Promise<string>((resolve, reject) => {
|
||||
uni.scanCode({
|
||||
success: (res) => {
|
||||
console.log("APP扫码成功:", JSON.stringify(res))
|
||||
resolve(res.result || "")
|
||||
},
|
||||
fail: (err) => {
|
||||
console.error("APP扫码失败", JSON.stringify(err))
|
||||
resolve("")
|
||||
},
|
||||
})
|
||||
const scanResult = await new Promise<string>((resolve, reject) => {
|
||||
uni.scanCode({
|
||||
success: (res) => {
|
||||
console.log("uniapp扫码成功:", JSON.stringify(res))
|
||||
resolve(res.result || "")
|
||||
},
|
||||
fail: (err) => {
|
||||
console.error("uniapp扫码失败", JSON.stringify(err))
|
||||
resolve("")
|
||||
},
|
||||
})
|
||||
return scanResult
|
||||
}
|
||||
if (appInfo == APPENV.ZZD) {
|
||||
// 浙政钉扫码
|
||||
const res: any = await (window as any).dd.scan({ type: "all" })
|
||||
return res.text || ""
|
||||
}
|
||||
if (appInfo == APPENV.SH) {
|
||||
// 诗画扫码
|
||||
const res = await (window as any).CP2.showScanQr({ needResult: 1 })
|
||||
if (res.code == 1) return res.data.qrCode || ""
|
||||
return ""
|
||||
}
|
||||
uni.showToast({ title: "当前环境未知", icon: "none" })
|
||||
})
|
||||
return scanResult
|
||||
}
|
||||
|
||||
// 处理url扫码结果
|
||||
function processUrlScanResult(url: string) {
|
||||
if (!url) return
|
||||
const searchParams = new URL(url).searchParams
|
||||
const paramsObj: Record<string, string> = {}
|
||||
searchParams.forEach((value, key) => (paramsObj[key] = value))
|
||||
const { hardDoorId, cabinetNo, action, id, name } = paramsObj
|
||||
|
||||
const searchParams = getUrlParamsObj(url)
|
||||
const { hardDoorId, cabinetNo, action, id, name } = searchParams
|
||||
// 智能柜扫码
|
||||
if (hardDoorId && cabinetNo) {
|
||||
router.jump("/pages/cabinet/buy", { hardDoorId, cabinetNo })
|
||||
@@ -61,7 +30,7 @@ export function useScanCode(actModalShow) {
|
||||
}
|
||||
// 扫收款机上生成的码支付
|
||||
if (action === "harQrCodeScanPay") {
|
||||
const { mchId, orderId } = paramsObj
|
||||
const { mchId, orderId } = searchParams
|
||||
router.jump("/pages/pay/scanPay", { action, mchId, orderId })
|
||||
return
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user