uniapp实现身份证实名认证
百度智能云身份证识别API:https://cloud.baidu.com/doc/OCR/s/rk3h7xzck
身份证识别每天免费调取次数500次
<template><view class="content"><view class="uni-common-mt"><view class="uni-form-item uni-column option"><view class="title msg-left">姓名:</view><input class="uni-input msg-right" placeholder="请输入真实姓名" v-model="name"/></view><view class="uni-form-item uni-column option"><view class="title msg-left">身份证号码:</view><input class="uni-input msg-right" type="number" placeholder="请输入身份证号码" v-model="IdNumber"/></view><view class="uni-form-item uni-column img"><view class="title">上传身份证:</view><image class="img" :src="src" @tap="scan()"></image></view></view><view><button type="primary" @click="getIDCard()">点击认证身份信息</button></view></view>
</template><script>var that;const card = uni.requireNativePlugin('DC-CardRecognize');export default{data() {return {title: 'input',focus: false,name: "",IdNumber:"",src:"../../../../static/me/photo.png",httpUrl:"https://aip.baidubce.com/rest/2.0/ocr/v1/general?access_token=",imageBase64Str:"",access_token:""}},onLoad() {that=this;//token验证this.getAccess_token();},methods: {getAccess_token(){var accessToken= that.cache("accessToken",null,null);console.log(accessToken)if(!accessToken){uni.request({method: 'POST',header: {'Content-Type': 'application/x-www-form-urlencoded'},url: "https://aip.baidubce.com/oauth/2.0/token",data:{grant_type:"client_credentials",client_id:this.APIKey,client_secret:this.SecretKey},success: function(res) {console.log(res.data.access_token);//uni.setStorageSync("Baidu",res.data);that.access_token=res.data.access_token;that.cache("accessToken",res.data.access_token,null);}})}else{that.access_token=accessToken;}},//缓存,默认有效期28天cache:function(key, value, seconds) {var timestamp = Date.parse(new Date()) / 1000console.log(timestamp+"==="+key)if (key && value === null) {//删除缓存//获取缓存var val = uni.getStorageSync(key);var tmp = val.split("|")if (!tmp[1] || timestamp >= tmp[1]) {console.log("key已失效")uni.removeStorageSync(key)return ""} else {console.log("key未失效")return tmp[0]}} else if (key && value) {//设置缓存if (!seconds) {var expire = timestamp + (3600 * 24 * 28)}else{var expire = timestamp + seconds}value = value + "|" + expireuni.setStorageSync(key, value);} else {console.log("key不能空")}},getIDCard() {var flag=this.verifyData();if(flag){console.log("==")//百度名片识别接口处理开始uni.showLoading({mask: true,title: "识别中,请等待"});uni.request({url: "https://aip.baidubce.com/rest/2.0/ocr/v1/idcard?access_token="+that.access_token,method: 'POST',header: {'Content-Type': 'application/x-www-form-urlencoded'},data: {image: that.imageBase64Str,id_card_side:"front"},success: function(res) {console.log(res);var IdCard=res.data.words_result.公民身份号码.words;var userName=res.data.words_result.姓名.words;console.log(res.data.words_result.公民身份号码.words)if(IdCard==that.IdNumber&&userName==that.name){console.log("身份验证成功");uni.showToast({icon: 'success',title: '身份验证成功'});}else{uni.showToast({icon: 'none',title: '身份信息有误请审核信息'});}},complete() { uni.hideLoading();}})}},//校验输入的数据verifyData() {var flag = true;if (!this.name) {flag = false;uni.showToast({icon: 'none',title: '姓名不能为空'});return false;}if (!this.IdNumber) {flag = false;uni.showToast({icon: 'none',title: '身份证号不能为空'});return false;}var re15 = /^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$/;var re18 = /^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{4}$/;var res = (re15.test(this.IdNumber) || re18.test(this.IdNumber)); if(res==false){flag = false;uni.showToast({icon: 'none',title: '身份证号填写有误'}); return false; } if(!this.imageBase64Str){flag = false;uni.showToast({icon: 'none',title: '请上传身份证含照片一面'}); return false; }return flag;},scan() {var me = this;uni.chooseImage({count: 1,sizeType: ['compressed'],sourceType: ['album', 'camera'],success: function(res) {var tempFilePath = res.tempFilePaths[0];me.tempFile = tempFilePath;plus.io.resolveLocalFileSystemURL(me.tempFile, function(entry) {entry.file(function(file) {var fileReader = new plus.io.FileReader();fileReader.readAsDataURL(file);fileReader.onloadend = function(evt) {//console.log("=="+evt.target.result);that.imageBase64Str = evt.target.result.split(",")[1];that.src=evt.target.result;}})})}})}}}
</script><style>.option{display: flex;margin-top: 4%;margin-left: 30upx;padding-bottom: 30upx;border-bottom: #333333 solid 0.5upx;}.msg-left {flex: 5;display: flex;justify-content: flex-start;align-items: center;}.msg-right {flex: 2;display: flex;justify-content: center;text-align: center;margin-right: 15upx;border-bottom: #000000 solid 0.5upx;}.img {display: flex;margin-top: 4%;margin-left: 30upx;padding-bottom: 30upx;}.img image {justify-content: center;margin-top: 8%;width: 300upx;height: 300upx;}
</style>
uniapp实现身份证实名认证相关推荐
- 如何对接身份证实名认证?
阿里云身份证实名认证免费体验 身份证实名认证[最新版]_实名认证接口/API_数据API_电商-云市场-阿里云 Java代码如下 public static void main(String[] ar ...
- 发票查验|身份证实名认证增强版API开发文档
一.接口简介 1.版权说明: 未经翔云人工智能开放平台授权,不得擅自进行使用. 2.调用客户端运行环境 当客户端使用的编程语言为Java时,请使用1.5及以上版本JRE. 3.服务主要功能描述 翔云身 ...
- 免费体验,快速对接身份证实名认证API接口说明
为了让您更清晰了解身份证二要素实名认证接口的功能与使用.深智恒际特意列了以下5个方面,引导您便捷对接API接口.即使是非技术人员,也可以借用postman工具进行调试使用. 目录: 身份证实名认证接口 ...
- 身份证实名认证-身份实名认证-身份证核验
身份证实名认证是一种通过验证身份证上的个人信息进行身份证真实性核实的过程.在今天的数字化社会中,越来越多的网站和应用程序需要用户进行身份认证,以便保护用户信息和提供更安全的服务.因此,身份证实名认证也 ...
- excel如何批量完成员工身份证实名认证?
今天跟大家分享一下excel如何批量完成员工身份证实名认证? 1.首先我们打开excel软件,点击[DIY工具箱] 2.点击[身份证]选择[身份证实名认证] 3.选择弹出对话框中的新建 4.在表格中快 ...
- 如何使用身份证实名认证API接口?
实名认证(identity verification)是对用户资料真实性进行的一种验证审核,有助于建立完善可靠的互联网信用基础,一般有两种方式,可以预防一部分网络咋骗. 如何实现身份证实名认证-身份实 ...
- 如何批量完成新入职员工身份证实名认证?
今天跟大家分享一下如何批量完成新入职员工身份证实名认证? 1.首先我们打开Excel软件,新建一个空白工作簿,点击[DIY工具箱] 2.接着我们点击[身份证],选择[身份证实名认证] 3.鼠标点击 ...
- 身份证实名认证数据API可以这样获取和使用
随着网络实名制的实行落地,越来越多的平台需要身份证实名认证接口,这类接口如何获取?价格如何?怎么使用?很多人都存在疑问. 今天以天元数据网(tdata.cn)上的身份证实名认证数据API为例为大家介绍 ...
- SpringBoot实现身份证实名认证(阿里云实现)
文章目录 1.功能展示 2.购买API 3. API 文档 4.SpringBoot集成身份认证 4.1.IdProperties 4.2.IdAutoConfiguration 4.3.完成身份认证 ...
- 身份证实名认证api
身份证实名认证api: 身份证实名认证API上线,通过该接口可以判别身份证号码与真实姓名是否一致 详情:http://www.haoservice.com/docs/65 返回示例: { &q ...
最新文章
- python 关联表_python学习------9.13----约束、表之间的关联关系
- php有lambda表达式吗,Python中lambda表达式的简单介绍(附示例)
- 2019年3月计算机考试操作,2019年3月计算机二级C++操作练习题(一)
- 吴恩达《机器学习》第十二章:支持向量机SVM
- 上有程序员删库跑路,这次是程序员锁死服务器,600万打水漂,创始人负债数百万!
- 在wex5平台grid里面的gridselect下拉不能显示汉字问题
- android module驱动编程及通信
- Go指南练习_Reader
- matlab求动力学模型,MATLAB/Simulink动力学系统建模与仿真
- 交换机端口mtu值最大_思科交换机基本配置命令全集-mtu值怎么设置
- Jetpack Compose UI组件入门教程
- 全电动梅赛德斯EQS年底将在曼谷生产下线;麦格纳突破车尾照明技术2023年可投入生产 | 美通企业日报...
- 软件开发经验总结(容错性)
- uefi启动 多硬盘gtp_UEFI+GPT双硬盘安装Win10+Ubuntu16.04双系统
- 牛逼!腾讯竟然打响了反对996的第一枪....
- quartus 使用技巧
- 【激光雷达】之点云数据滤波处理
- 上海大学计算机工程与科学学院院长,李三立
- numpy的squeeze函数
- 临平职高计算机专业高职考大学,临平职高的她考了全省第一!还有很多省前10都在这里!...