|
|
@ -15,6 +15,49 @@ function showLongToast(title, duration = 2000) { |
|
|
uni.showToast({ title: content, icon: 'none', duration }) |
|
|
uni.showToast({ title: content, icon: 'none', duration }) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function getErrorMessage(error, fallback) { |
|
|
|
|
|
if (!error) return fallback |
|
|
|
|
|
if (typeof error === 'string') return error |
|
|
|
|
|
return error.message || error.msg || error.errMsg || fallback |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function isUserCancel(error) { |
|
|
|
|
|
const message = getErrorMessage(error, '').toLowerCase() |
|
|
|
|
|
return message.indexOf('cancel') !== -1 || message.indexOf('取消') !== -1 |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function isCameraPermissionError(error) { |
|
|
|
|
|
const message = getErrorMessage(error, '').toLowerCase() |
|
|
|
|
|
return message.indexOf('auth') !== -1 |
|
|
|
|
|
|| message.indexOf('permission') !== -1 |
|
|
|
|
|
|| message.indexOf('deny') !== -1 |
|
|
|
|
|
|| message.indexOf('denied') !== -1 |
|
|
|
|
|
|| message.indexOf('scope.camera') !== -1 |
|
|
|
|
|
|| message.indexOf('权限') !== -1 |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function showCameraPermissionGuide() { |
|
|
|
|
|
return new Promise(resolve => { |
|
|
|
|
|
uni.showModal({ |
|
|
|
|
|
title: '需要摄像头权限', |
|
|
|
|
|
content: '实名认证需要拍摄本人正脸照。请点击“去设置”开启小程序摄像头权限;如果 iPhone 系统仍拦截,请到系统设置 > 微信 > 相机中开启。', |
|
|
|
|
|
confirmText: '去设置', |
|
|
|
|
|
cancelText: '取消', |
|
|
|
|
|
success: res => { |
|
|
|
|
|
if (res.confirm && uni.openSetting) { |
|
|
|
|
|
uni.openSetting({ |
|
|
|
|
|
success: () => resolve(), |
|
|
|
|
|
fail: () => resolve() |
|
|
|
|
|
}) |
|
|
|
|
|
return |
|
|
|
|
|
} |
|
|
|
|
|
resolve() |
|
|
|
|
|
}, |
|
|
|
|
|
fail: () => resolve() |
|
|
|
|
|
}) |
|
|
|
|
|
}) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
function showInfoModal(title, content, confirmText = '知道了') { |
|
|
function showInfoModal(title, content, confirmText = '知道了') { |
|
|
return new Promise(resolve => { |
|
|
return new Promise(resolve => { |
|
|
uni.showModal({ |
|
|
uni.showModal({ |
|
|
@ -59,6 +102,17 @@ function chooseImage(sourceType = ['camera'], camera = 'front') { |
|
|
const file = res.tempFiles && res.tempFiles[0] |
|
|
const file = res.tempFiles && res.tempFiles[0] |
|
|
resolve((file && (file.tempFilePath || file.path)) || (res.tempFilePaths && res.tempFilePaths[0]) || '') |
|
|
resolve((file && (file.tempFilePath || file.path)) || (res.tempFilePaths && res.tempFilePaths[0]) || '') |
|
|
} |
|
|
} |
|
|
|
|
|
const fail = error => { |
|
|
|
|
|
if (isUserCancel(error)) { |
|
|
|
|
|
resolve('') |
|
|
|
|
|
return |
|
|
|
|
|
} |
|
|
|
|
|
if (isCameraPermissionError(error)) { |
|
|
|
|
|
reject(new Error('未获得摄像头权限,请在微信设置中允许摄像头权限后重试')) |
|
|
|
|
|
return |
|
|
|
|
|
} |
|
|
|
|
|
reject(error) |
|
|
|
|
|
} |
|
|
if (uni.chooseMedia) { |
|
|
if (uni.chooseMedia) { |
|
|
uni.chooseMedia({ |
|
|
uni.chooseMedia({ |
|
|
count: 1, |
|
|
count: 1, |
|
|
@ -66,7 +120,7 @@ function chooseImage(sourceType = ['camera'], camera = 'front') { |
|
|
sourceType, |
|
|
sourceType, |
|
|
camera, |
|
|
camera, |
|
|
success, |
|
|
success, |
|
|
fail: reject |
|
|
fail |
|
|
}) |
|
|
}) |
|
|
return |
|
|
return |
|
|
} |
|
|
} |
|
|
@ -74,7 +128,7 @@ function chooseImage(sourceType = ['camera'], camera = 'front') { |
|
|
count: 1, |
|
|
count: 1, |
|
|
sourceType, |
|
|
sourceType, |
|
|
success, |
|
|
success, |
|
|
fail: reject |
|
|
fail |
|
|
}) |
|
|
}) |
|
|
}) |
|
|
}) |
|
|
} |
|
|
} |
|
|
@ -209,8 +263,21 @@ async function chooseFacePictureBase64() { |
|
|
'请拍摄本人清晰正脸照片用于身份证三要素核验,照片只用于本次认证并会压缩到50KB以内。' |
|
|
'请拍摄本人清晰正脸照片用于身份证三要素核验,照片只用于本次认证并会压缩到50KB以内。' |
|
|
) |
|
|
) |
|
|
if (!confirmed) return '' |
|
|
if (!confirmed) return '' |
|
|
const path = await chooseImage(['camera'], 'front') |
|
|
let path = '' |
|
|
if (!path) return '' |
|
|
try { |
|
|
|
|
|
path = await chooseImage(['camera'], 'front') |
|
|
|
|
|
} catch (e) { |
|
|
|
|
|
if (isCameraPermissionError(e)) { |
|
|
|
|
|
await showCameraPermissionGuide() |
|
|
|
|
|
} else { |
|
|
|
|
|
showLongToast(getErrorMessage(e, '无法打开相机,请检查摄像头权限后重试'), 3000) |
|
|
|
|
|
} |
|
|
|
|
|
return '' |
|
|
|
|
|
} |
|
|
|
|
|
if (!path) { |
|
|
|
|
|
showLongToast('未拍摄实名核验照片,已取消认证', 2200) |
|
|
|
|
|
return '' |
|
|
|
|
|
} |
|
|
uni.showLoading({ title: '照片处理中\n正在压缩图片', mask: true }) |
|
|
uni.showLoading({ title: '照片处理中\n正在压缩图片', mask: true }) |
|
|
const compressOptions = [ |
|
|
const compressOptions = [ |
|
|
{ quality: 70, width: 480, height: 480 }, |
|
|
{ quality: 70, width: 480, height: 480 }, |
|
|
@ -409,7 +476,7 @@ export async function ensureIeVerifiedBeforeAction(options = {}) { |
|
|
} |
|
|
} |
|
|
return true |
|
|
return true |
|
|
} catch (e) { |
|
|
} catch (e) { |
|
|
showLongToast((e && e.message) || '认证未完成,请稍后重试', 2000) |
|
|
showLongToast(getErrorMessage(e, '认证未完成,请稍后重试'), 2000) |
|
|
return false |
|
|
return false |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|