From 08b00b6a0e8ffcd9646fd1278bf40da511abf5e3 Mon Sep 17 00:00:00 2001 From: unknown <331404948@qq.com> Date: Fri, 22 Dec 2023 18:40:20 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BA=BA=E8=84=B8=E6=A0=B8=E8=BA=ABsdk?= =?UTF-8?q?=E4=BD=BF=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- App.vue | 2 ++ mp_ecard_sdk/constants/log.js | 1 + mp_ecard_sdk/globalConfig.js | 1 + mp_ecard_sdk/index.css | 1 + mp_ecard_sdk/index/index.js | 1 + mp_ecard_sdk/index/index.vue | 24 ++++++++++++++++++++++++ mp_ecard_sdk/main.js | 1 + mp_ecard_sdk/utils/http.js | 1 + mp_ecard_sdk/utils/index.js | 1 + mp_ecard_sdk/utils/validate.js | 1 + pages.json | 9 ++++++++- project.config.json | 2 +- 12 files changed, 43 insertions(+), 2 deletions(-) create mode 100644 mp_ecard_sdk/constants/log.js create mode 100644 mp_ecard_sdk/globalConfig.js create mode 100644 mp_ecard_sdk/index.css create mode 100644 mp_ecard_sdk/index/index.js create mode 100644 mp_ecard_sdk/index/index.vue create mode 100644 mp_ecard_sdk/main.js create mode 100644 mp_ecard_sdk/utils/http.js create mode 100644 mp_ecard_sdk/utils/index.js create mode 100644 mp_ecard_sdk/utils/validate.js diff --git a/App.vue b/App.vue index bb9b0e2..c276233 100644 --- a/App.vue +++ b/App.vue @@ -1,8 +1,10 @@ + + diff --git a/mp_ecard_sdk/main.js b/mp_ecard_sdk/main.js new file mode 100644 index 0000000..e3dd26b --- /dev/null +++ b/mp_ecard_sdk/main.js @@ -0,0 +1 @@ +import validate from"./utils/validate";import Log from"./constants/log";import globalConfig from"./globalConfig";import{navigateToEid}from"./utils/index";const EIDAppID="wx0e2cb0b052a91c92";function initEid(e="https://eid.faceid.qq.com",o="release",n="https://eid-enhance.faceid.qq.com"){uni.eidBaseUrl=e,uni.eidEnvVersion=o,uni.eidBackUpUrl=n;uni.onAppShow(e=>{console.log("!!!!!!监听onshow事件",e,wx.eidTokenToCallback);var{scene:e,referrerInfo:o}=e,{appId:o,extraData:n}=o||{},{token:i,verifyDone:t}=n||{};1038===e&&o===EIDAppID&&uni.eidTokenToCallback&&(o=i||uni.eidTokenToCallback,uni.reportLogToEid({token:o,event:Log.navigateBackFromEid,errMsg:`从EID核身完成返回,核验未完成或者没有处理核验完成的函数,token:${o},verifyDone:${t},scene:`+e}),uni.eidTokenToCallback)&&uni.eidTokenToCallback===i&&t&&uni.handleEidVerifyDone&&uni.handleEidVerifyDone(n),uni.eidTokenToCallback=""});e=uni.getSystemInfoSync();const d=e["version"];uni.reportLogToEid=function(e){var{token:e="",event:o="",errCode:n="",errMsg:i="",data:t={}}=e,r=new Date;const a={Token:e,SourceType:Log.SourceType,SourceVersion:Log.version,EnvVersion:d,Timestamp:r.getTime(),Event:o,ErrorCode:"number"==typeof n?n.toString():n,ErrorMsg:i,Data:JSON.stringify(t)};console.log("开始上报日志:",a),uni.request({url:uni.eidBaseUrl+"/api/common/ReportEvent",method:"POST",data:a,success(e){console.log("上报日志完成:","payload:",a,"res:",e)}})}}function startEid(e){const{data:o,verifyDoneCallback:n}=e;if(!o||!n)return uni.reportLogToEid({token:i,event:Log.startEidFail,errMsg:"传入的参数有误"}),void uni.showModal({title:"提示",content:"传入的参数有误",showCancel:!1});const{token:i,needJumpPage:t=!1}=o;validate.isValidateToken(i)?(uni.handleEidVerifyDone=e=>{const o=e["token"];t?uni.navigateBack({success(){uni.reportLogToEid({token:o,event:Log.EidVerifyDone,errMsg:"验证完成,token:"+o}),n({token:o,verifyDone:!0})}}):(uni.reportLogToEid({token:o,event:Log.EidVerifyDone,errMsg:"验证完成,token:"+o}),n({token:o,verifyDone:!0}))},t?uni.navigateTo({url:`${globalConfig.normalPath}/mp_ecard_sdk/index/index?token=${i}&needJumpPage=`+t}):navigateToEid(i)):(uni.reportLogToEid({token:i,event:Log.startEidFail,errMsg:"传入的token有误,token:"+i}),uni.showModal({title:"提示",content:"传入的token有误",showCancel:!1}))}export{initEid,startEid}; \ No newline at end of file diff --git a/mp_ecard_sdk/utils/http.js b/mp_ecard_sdk/utils/http.js new file mode 100644 index 0000000..8cb4831 --- /dev/null +++ b/mp_ecard_sdk/utils/http.js @@ -0,0 +1 @@ +import Log from"../constants/log.js";const request=function(e,t){const{token:o="",url:a,method:r="POST",data:s,reTry:d,header:u={"Content-Type":"application/json"}}=e;try{uni.request({url:uni.eidBaseUrl+a,method:r,data:s,header:u,success(r){console.log("request success:",r),200===r.statusCode&&r.data?0==r.data.ErrorCode||0==r.data.code?t({ErrorCode:0,ErrorMsg:r.data.ErrorMsg,Data:r.data.Data||r.data.data,reTry:d}):t({ErrorCode:r.data.ErrorCode,ErrorMsg:r.data.ErrorMsg,Data:r.data.Data||r.data.data}):t({ErrorCode:-101,ErrorMsg:"请求错误,请稍后重试"})},fail(r){console.log("request error:",r),d&&d.tryCount&&0{request(e,t)},d.retryDelay||0)):t({ErrorCode:-107,ErrorMsg:"request请求异常,请稍后重试"}),uni.reportLogToEid({token:o,event:Log.requestFail,errCode:"-1",errMsg:"requestFail 调用失败",data:{url:""+(uni.eidBaseUrl+a),err:r}})}})}catch(r){console.log("request error:",r),t({ErrorCode:-109,ErrorMsg:"request方法异常,请稍后重试"}),uni.reportLogToEid({token:o,event:Log.requestCatch,errCode:"-1",errMsg:"requestFail 调用失败",data:{url:""+(uni.eidBaseUrl+a),err:r}})}},$http=request;export{$http}; \ No newline at end of file diff --git a/mp_ecard_sdk/utils/index.js b/mp_ecard_sdk/utils/index.js new file mode 100644 index 0000000..f15932a --- /dev/null +++ b/mp_ecard_sdk/utils/index.js @@ -0,0 +1 @@ +import Log from"../constants/log";const navigateToEid=o=>{console.log("navigateToEid",uni.eidEnvVersion),uni.navigateToMiniProgram({appId:"wx0e2cb0b052a91c92",path:"pages/huiyan/index",envVersion:uni.eidEnvVersion,extraData:{useHuiyan:!0,huiyanToken:o},success(){uni.eidTokenToCallback=o},fail(e){console.log("err",e),uni.eidTokenToCallback=""},complete(e){uni.reportLogToEid({token:o,event:Log.navigateToEid,errMsg:e.errMsg})}})};export{navigateToEid}; \ No newline at end of file diff --git a/mp_ecard_sdk/utils/validate.js b/mp_ecard_sdk/utils/validate.js new file mode 100644 index 0000000..99f0b1d --- /dev/null +++ b/mp_ecard_sdk/utils/validate.js @@ -0,0 +1 @@ +function isValidateToken(e){return/^[a-zA-Z0-9-]{36}$/.test(e)}export default{isValidateToken:isValidateToken}; \ No newline at end of file diff --git a/pages.json b/pages.json index f15e39e..12ab1ad 100644 --- a/pages.json +++ b/pages.json @@ -26,7 +26,14 @@ "enablePullDownRefresh": true, "backgroundTextStyle": "dark" } - } + }, + { + "path": "mp_ecard_sdk/index/index", + "style": { + "navigationBarTitleText": "腾讯云E证通授权" + } + } + ], "subPackages": [ { diff --git a/project.config.json b/project.config.json index fa74469..c8edcb4 100644 --- a/project.config.json +++ b/project.config.json @@ -1,5 +1,5 @@ { - "appid": "wx0820ae1a0b635ae2", + "appid": "wx847c1140cf78a201", "compileType": "miniprogram", "libVersion": "2.32.2", "packOptions": {