Browse Source

人脸核身sdk使用

master
unknown 11 months ago
parent
commit
08b00b6a0e
  1. 2
      App.vue
  2. 1
      mp_ecard_sdk/constants/log.js
  3. 1
      mp_ecard_sdk/globalConfig.js
  4. 1
      mp_ecard_sdk/index.css
  5. 1
      mp_ecard_sdk/index/index.js
  6. 24
      mp_ecard_sdk/index/index.vue
  7. 1
      mp_ecard_sdk/main.js
  8. 1
      mp_ecard_sdk/utils/http.js
  9. 1
      mp_ecard_sdk/utils/index.js
  10. 1
      mp_ecard_sdk/utils/validate.js
  11. 7
      pages.json
  12. 2
      project.config.json

2
App.vue

@ -1,8 +1,10 @@
<script>
import { initEid } from './mp_ecard_sdk/main';
export default {
onLaunch: function() {
console.log('App Launch')
// uni.hideTabBar();
initEid();
},
onShow: function() {
console.log('App Show')

1
mp_ecard_sdk/constants/log.js

@ -0,0 +1 @@
const Log={version:"uni_1.0.3",SourceType:"mp_sdk_uni",getIntoIndexPage:"START_INDEX",initSdk:"INIT_SDK",getConfig:"GET_CONFIG",getConfigRetry:"GET_CONFIG_BY_RETRY",webViewResult:"WEBVIEW_RESULT",webViewError:"WEBVIEW_ERROR",navigateToEid:"NAVIGATE_TO_EID",navigateBackFromEid:"NAVIGATE_BACK_FROM_EID",navigateBackFromEidFail:"NAVIGATE_BACK_FROM_EID_FAIL",startEid:"START_EID",startEidFail:"START_EID_FAIL",eidVerifyDone:"EID_VERIFY_DONE",requestFail:"REQUEST_FAIL",requestCatch:"REQUEST_CATCH",onAppShow:"ON_APP_SHOW"};export default Log;

1
mp_ecard_sdk/globalConfig.js

@ -0,0 +1 @@
export default{normalPath:""};

1
mp_ecard_sdk/index.css

@ -0,0 +1 @@
.auth{margin-top:128rpx;display:flex;flex-direction:column;align-items:center}.auth-logo{width:200rpx;height:200rpx}.auth-logo image{height:100%;width:100%}.title{margin-top:20rpx;font-size:36rpx;line-height:56rpx}.merchant-name{display:inline;font-weight:700}.sub-title{margin-top:8rpx;font-size:34rpx;line-height:52rpx}.button-area{margin-top:48rpx}.button-area button{width:622rpx;height:96rpx;background:#fff;border:2rpx solid #ddd;font-size:32rpx;font-weight:400;line-height:96rpx;padding:0}.redirect{margin-top:272rpx;display:flex;flex-direction:column;align-items:center}.loading{height:160rpx;width:160rpx;margin-bottom:32rpx}.loading image{height:100%;width:100%}.title{font-size:34rpx;line-height:52rpx}

1
mp_ecard_sdk/index/index.js

@ -0,0 +1 @@
import Log from"../constants/log.js";import{navigateToEid}from"../utils/index";export default{data(){return{token:""}},onLoad(e){var{token:e,needJumpPage:t}=e;this.token=e,uni.reportLogToEid({token:e,event:Log.getIntoIndexPage,errMsg:`进入配置首页,token:${e},needJumpPage:`+t})},methods:{handleStart(){navigateToEid(this.token)}}};

24
mp_ecard_sdk/index/index.vue

@ -0,0 +1,24 @@
<template>
<view class="auth">
<view class="auth-logo">
<image src="https://faceid-h5-1254418846.file.myqcloud.com/mp_verify_sdk/images/ecard/logo.png" />
</view>
<view class="title">
即将进入"eID数字身份"小程序
</view>
<view class="button-area">
<button @click='handleStart' >
确认进入
</button>
</view>
</view>
</template>
<script>
import index from "./index";
export default index;
</script>
<style>
@import url('../index.css');
</style>

1
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};

1
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<d.tryCount?(d.tryCount--,uni.eidBaseUrl=uni.eidBackUpUrl,setTimeout(()=>{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};

1
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};

1
mp_ecard_sdk/utils/validate.js

@ -0,0 +1 @@
function isValidateToken(e){return/^[a-zA-Z0-9-]{36}$/.test(e)}export default{isValidateToken:isValidateToken};

7
pages.json

@ -26,7 +26,14 @@
"enablePullDownRefresh": true,
"backgroundTextStyle": "dark"
}
},
{
"path": "mp_ecard_sdk/index/index",
"style": {
"navigationBarTitleText": "腾讯云E证通授权"
}
}
],
"subPackages": [
{

2
project.config.json

@ -1,5 +1,5 @@
{
"appid": "wx0820ae1a0b635ae2",
"appid": "wx847c1140cf78a201",
"compileType": "miniprogram",
"libVersion": "2.32.2",
"packOptions": {

Loading…
Cancel
Save