diff --git a/pages.json b/pages.json index 04f8faf16dcc3f40a3fb130d68ea4f0b73827dbd..efd02ed34117dad1c12950b6096cd399ea478886 100644 --- a/pages.json +++ b/pages.json @@ -1220,6 +1220,20 @@ "enablePullDownRefresh": false } }, + { + "path": "pages/API/get-univerify-manager/univerify-custom-page", + "style": { + "navigationBarTextStyle":"black", + "navigationStyle": "custom" + } + }, + { + "path": "pages/API/get-univerify-manager/univerify-privacy-page", + "style": { + "navigationBarTextStyle":"black", + "navigationStyle": "custom" + } + }, // #endif // #ifdef APP-ANDROID || APP-IOS || WEB || MP-WEIXIN { diff --git a/pages/API/get-univerify-manager/get-univerify-manager.uvue b/pages/API/get-univerify-manager/get-univerify-manager.uvue index 0f7db071f61703aafa6f1400c84c2e31a9057aa7..49c76efede6bb53e1ffdf53a561fcdeb0ae36041 100644 --- a/pages/API/get-univerify-manager/get-univerify-manager.uvue +++ b/pages/API/get-univerify-manager/get-univerify-manager.uvue @@ -8,6 +8,9 @@ + + + @@ -17,27 +20,40 @@ data() { return { title: '一键登录', - univerifyManager: null as UniverifyManager | null + univerifyManager: null as UniverifyManager | null, + phone: '', + slogan: '', + privacyName: '', + privacyUrl: '' + // phone: '176****6657', + // slogan: '认证服务由中国联通提供', + // privacyName: '中国联通认证服务条款', + // privacyUrl: 'https://opencloud.wostore.cn/authz/resource/html/disclaimer.html?fromsdk=true' } }, onLoad() { this.univerifyManager = uni.getUniverifyManager(); // 预登录 - this.univerifyManager?.preLogin({ - success: () => { - console.log("pre login success"); - }, - fail: (err : PreLoginFail) => { - console.error("pre login fail => " + JSON.stringify(err)); - uni.showModal({ - title: '预登录失败', - content: JSON.parseObject(err.cause?.cause?.message ?? "")?.getString("errorDesc") ?? err.errMsg, - showCancel: false - }); - } - } as PreLoginOptions); + this.preLogin(() => { }); }, methods: { + customLoginIn() { + const isPreLoginValid = this.univerifyManager?.isPreLoginValid() ?? false; + if (isPreLoginValid) { + this.pushCustomPage(); + } else { + this.preLogin(() => { + this.pushCustomPage(); + }) + } + }, + pushCustomPage() { + const url = '/pages/API/get-univerify-manager/univerify-custom-page?phone=' + this.phone + '&slogan=' + this.slogan + '&name=' + this.privacyName + '&link=' + this.privacyUrl; + uni.navigateTo({ + url: url, + animationType: "slide-in-bottom", + }) + }, verify(fullScreen : boolean) { // 校验预登录是否有效 const isPreLoginValid = this.univerifyManager?.isPreLoginValid() ?? false; @@ -46,72 +62,84 @@ this.login(fullScreen); } else { // 预登录无效,执行预登录 - this.univerifyManager?.preLogin({ - success: () => { - console.log("pre login success"); - this.login(fullScreen); - }, - fail: (err : PreLoginFail) => { - console.error("pre login fail => " + JSON.stringify(err)); - uni.showModal({ - title: '预登录失败', - content: JSON.parseObject(err.cause?.cause?.message ?? "")?.getString("errorDesc") ?? err.errMsg, - showCancel: false - }); - } - } as PreLoginOptions); + this.preLogin(() => { + this.login(fullScreen); + }) } }, - login(fullScreen : boolean) { - this.univerifyManager?.login({ - // 登录页样式 - univerifyStyle: { - fullScreen: fullScreen, - backgroundColor: "#FFFFFF", - loginBtnText: "一键登录", - logoPath: "/static/logo.png" - } as UniverifyStyle, - success: (res : LoginSuccess) => { - console.log("login success => " + JSON.stringify(res)); - // 云函数取号 - uniCloud.callFunction({ - name: 'univerify', - data: { - access_token: res.accessToken, // 客户端一键登录接口返回的access_token - openid: res.openId // 客户端一键登录接口返回的openid - } - }).then(res => { - // 关闭登录页 - this.univerifyManager?.close(); - setTimeout(() => { - uni.showModal({ - title: '取号成功', - content: res.result.getJSON("res")?.getString("phoneNumber"), - showCancel: false - }); - }, 100); - }).catch(err => { - console.error(JSON.stringify(err)); - // 关闭登录页 - this.univerifyManager?.close(); - setTimeout(() => { - uni.showModal({ - title: '取号失败', - content: (err as Error).message, - showCancel: false - }); - }, 100); - }); + preLogin(callback) { + this.univerifyManager?.preLogin({ + success: (res) => { + this.phone = res.number; + this.slogan = res.slogan; + this.privacyName = res.privacyName; + this.privacyUrl = res.privacyUrl; + console.log("pre login success"); + callback(); }, - fail: (err : LoginFail) => { - console.error("login fail => " + err); + fail: (err : PreLoginFail) => { + console.error("pre login fail => " + JSON.stringify(err)); uni.showModal({ - title: '登录失败', + title: '预登录失败', content: JSON.parseObject(err.cause?.cause?.message ?? "")?.getString("errorDesc") ?? err.errMsg, showCancel: false }); } - } as LoginOptions); + } as PreLoginOptions); + }, + login(fullScreen : boolean) { + this.univerifyManager?.login({ + univerifyStyle:{ + fullScreen: fullScreen, + backgroundColor: "#FFFFFF", + loginBtnText: "一键登录", + logoPath: "/static/logo.png" + }, + success: (res : LoginSuccess) => { + console.log("login success => " + JSON.stringify(res)); + this.takePhoneNumber(res.accessToken,res.openId); + }, + fail: (err : LoginFail) => { + console.error("login fail => " + err); + uni.showModal({ + title: '登录失败', + content: JSON.parseObject(err.cause?.cause?.message ?? "")?.getString("errorDesc") ?? err.errMsg, + showCancel: false + }); + } + }); + }, + takePhoneNumber(accessToken : string, openId : string) { + // 云函数取号 + uniCloud.callFunction({ + name: 'univerify', + data: { + access_token: accessToken, // 客户端一键登录接口返回的access_token + openid: openId // 客户端一键登录接口返回的openid + } + }).then(res => { + // 关闭登录页 + this.univerifyManager?.close(); + setTimeout(() => { + uni.showModal({ + title: '取号成功', + content: res.result.getJSON("res")?.getString("phoneNumber"), + showCancel: false + }); + }, 100); + }).catch(err => { + console.error(JSON.stringify(err)); + // 关闭登录页 + this.univerifyManager?.close(); + setTimeout(() => { + uni.showModal({ + title: '取号失败', + content: (err as Error).message, + showCancel: false + }); + }, 100); + }); + } } } @@ -119,4 +147,4 @@ +/style> diff --git a/pages/API/get-univerify-manager/univerify-custom-page.uvue b/pages/API/get-univerify-manager/univerify-custom-page.uvue new file mode 100644 index 0000000000000000000000000000000000000000..b654c3e9e9743fe03ea896acf280cecff25af0cd --- /dev/null +++ b/pages/API/get-univerify-manager/univerify-custom-page.uvue @@ -0,0 +1,223 @@ + + + + + diff --git a/pages/API/get-univerify-manager/univerify-privacy-page.uvue b/pages/API/get-univerify-manager/univerify-privacy-page.uvue new file mode 100644 index 0000000000000000000000000000000000000000..95be8d4da2c6ceeda682fe8b7de737f2f7520ca7 --- /dev/null +++ b/pages/API/get-univerify-manager/univerify-privacy-page.uvue @@ -0,0 +1,73 @@ + + + + +