uniapp做微信小程序身份证识别功能(百度云身份证识别api)

news/2024/7/20 4:13:01 标签: 小程序

 html:

<!-- 拍照识别 -->
		<uni-popup ref="photograph" type="center" :animation="false">
			<view class="popup-content photographCenter"
				:style="'height: '+scrollheights+'px;box-sizing: border-box;border-radius:0'">
				<uni-icons @click="$refs.photograph.close()" type="back" color="#fff" size="24"></uni-icons>
				<view class="waper flex-align-center">
					<view class="noticeTXT">请将身份证正面放入框内</view>
					<camera mode="normal" device-position="back" flash="auto" @error="error" @initdone="initdone"
						style="width: 100%; height: 400rpx">
						<cover-view class="controls">
							<cover-image v-show="coverImgFlag" class="img"
								src="@/static/images/20210126144225906.png" />
						</cover-view>
					</camera>
				</view>
				<view class="distinguish_click">
					<view class="distinguish_click_item" @click="openAlbum">
						<uni-icons type="image" color="#fff" size="30"></uni-icons>
						<text class="text">相册</text>
					</view>
					<uni-icons @click="distinguish" type="camera-filled" color="#fff" size="80"></uni-icons>
				</view>
			</view>
		</uni-popup>

css代码: 

.waper {
		width: 100%;
		height: 40vh;
		align-items: center;
		flex-direction: column;
	}

	.controls {
		position: relative;
		top: 0;
		display: flex;
		align-items: center;

		.img {
			width: 100%;
			height: 404rpx;
		}
	}

	.noticeTXT {
		text-align: center;
		margin-bottom: 100rpx;
		color: #fff;
		font-size: 40rpx;
		margin-top: 30rpx;
	}

	.takePhoto {
		width: 90%;
		margin: 0 auto
	}

	.flex-align-center {
		display: flex;
		flex-direction: column;
		justify-content: center;
	}

	.bg-brown {
		color: #fff;
		background: linear-gradient(153deg, rgba(225, 164, 70, 1) 0%, rgba(195, 144, 65, 1) 100%);
	}

	.distinguish_click {
		position: absolute;
		bottom: 4%;
		left: 0;
		right: 0;
		display: flex;
		justify-content: center;
		align-items: center;
	}

	.distinguish_click_item {
		position: absolute;
		left: 6%;
		display: flex;
		flex-direction: column;

		.text {
			color: #fff;
			margin-top: 4rpx;
		}
	}

 js代码:

//打开相册
			openAlbum() {
				uni.chooseImage({
					count: 1, // 默认9  
					sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图,默认二者都有  
					sourceType: ['album'], // 可以指定来源是相册还是相机,默认二者都有  
					success: res => {
						console.log(res.tempFilePaths[0]);
						this.pic = res.tempFilePaths[0]
						uni.showLoading({
							title: '识别中'
						});
						this.isBase64Img(res.tempFilePaths[0])
					}
				})
			},
			//点击拍照
			distinguish() {
				const ctx = wx.createCameraContext()
				ctx.takePhoto({
					quality: 'high',
					success: (res) => {
						//res.tempImagePath为拍取的相片
						this.pic = res.tempImagePath
						uni.showLoading({
							title: '识别中'
						});
						this.isBase64Img(res.tempImagePath)
					}
				})
			},
			//对图片进行base64转码
			isBase64Img(base64) {
				wx.getFileSystemManager().readFile({
					filePath: base64,
					encoding: 'base64', //编码格式
					success: res => {
						// console.log(res.data);
						this.$http({
							url: 'api/travel/usercard_checking',
							data: {
								img_path: res.data
							}
						}).then(res => {
							uni.hideLoading();
							if(res.data.status==200){
								this.userInfo.user_name = res.data.data.data.truename
								this.userInfo.user_card = res.data.data.data.num
								uni.showToast({
									title: '识别成功',
									icon: 'none',
									duration: 2000
								});
							}else{
								uni.showToast({
									title: res.data.message,
									icon: 'none',
									duration: 2000
								});
							}
							this.$refs.photograph.close();
						})
					}
				})
			},

效果图:


http://www.niftyadmin.cn/n/903019.html

相关文章

用js把百度经纬度转换成腾讯经纬度

// 百度坐标系转腾讯坐标bMapToQQMap(lng, lat) {let x_pi (3.14159265358979324 * 3000.0) / 180.0;let x lng - 0.0065;let y lat - 0.006;let z Math.sqrt(x * x y * y) - 0.00002 * Math.sin(y * x_pi);let theta Math.atan2(y, x) - 0.000003 * Math.cos(x * x_pi);…

uniapp微信小程序动态更新scroll-view标签的高度

onReady() {//精确动态计算轮播图高度//自定义tabbar获取方法uni.getSystemInfo({success: res > {const query uni.createSelectorQuery()query.select(.tabbars).boundingClientRect()query.exec(res1 > {this.scrollheight res.windowHeight - res.statusBarHeight …

uniapp小程序自定义tabbar适配个别手机底部塌陷问题

塌陷场景&#xff1a; 此处已塌陷 解决方法&#xff1a; // 适配手机底部塌陷问题 padding-bottom: env(safe-area-inset-bottom); 完整css代码&#xff1a; .tabbars {position: fixed;z-index: 99;left: 0;right: 0;bottom: 0;display: flex;justify-content: center;alig…

uni-app微信小程序封装全局判断是否登录方法结合全局变量

新建的uni-app项目会有个app.vue文件&#xff0c;在此文件下 onLaunch应用生命周期封装一个方法(把全局变量定义一下): 注意&#xff1a;onLaunch应用生命周期只会触发一次 app.vue&#xff1a; <script>export default {//全局变量globalData: {//用于判断用户是否登录…

在vue里面写一个js防抖函数(节流函数)

一般用于防止用户暴力点击&#xff0c;导致多次请求接口&#xff0c;效果是在一定时间内点击多次后只触发一次 methods: { //防抖函数(节流函数)trans: (function() {let timer null;return function() {clearTimeout(timer);timer setTimeout(() > {//处理业务逻辑conso…

uni-app微信小程序封装一个request请求接口

在uniapp项目根目录里面新建一个文件 utils: 再新建一个api.js: //你的请求地址(线上或线下) const BASE_URL https://www.baidu.com/ export const http (options) > {return new Promise((resolve, reject) > {uni.request({url: BASE_URL options.url,method: opt…

uniapp微信小程序搜索关键词在列表中高亮效果

先看效果图: 直接上代码: view片段: <view class"text" click"gsClick(item,index)" v-for"(item,index) in searchList" :key"index"><rich-text :nodes"item.companyName"></rich-text> </view&g…

javascript class类基础用法-01

//俗话说的好&#xff0c;用了js的class类之后&#xff0c;万物皆可new一个对象&#xff0c;我忘了new多少个对象了//创建一个类函数class UserInfo {//公共myName字段myName my name is 奥利给;//私有实例字段(只有在UserInfo主体里调用该字段,别处调用会报错)//前面加上#号就…