uniapp中使用百度ocr识别引入项目

uniapp中使用百度ocr识别引入项目

官网申请地址
在这里插入图片描述
orcAPI文档地址
在这里插入图片描述
1.先获取token

	const getToken = () => {
		uni.request({
			url: 'https://aip.baidubce.com/oauth/2.0/token',
			method: 'POST',
			data: {
				grant_type: 'client_credentials',
				client_id: '**', apikey
				client_secret: '**', skey
			},
			header: {
				'Content-Type': 'application/x-www-form-urlencoded',
			},
			success: res => {
				uni.setStorageSync('access_token', res.data.access_token); // 获取到token存起来 后面调用 api要用
			},
		});
	};

2.根据需求调用api

	const identification = () => {
		// 测试身份证识别
		uni.request({
			url: 'https://aip.baidubce.com/rest/2.0/ocr/v1/idcard?access_token=' + uni.getStorageSync('access_token'), 
			method: 'POST',
			data: {
				url: '****',
				id_card_side: 'front',
			},
			header: {
				'Content-Type': 'application/x-www-form-urlencoded',
			},
			success: res => {
				console.log(res); //读取结束 json
			},
		});
	};

相关推荐

  1. 地图再vue引入方式

    2024-06-08 16:46:04       66 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-06-08 16:46:04       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-06-08 16:46:04       100 阅读
  3. 在Django里面运行非项目文件

    2024-06-08 16:46:04       82 阅读
  4. Python语言-面向对象

    2024-06-08 16:46:04       91 阅读

热门阅读

  1. 计算机网络时延计算的单位换算问题

    2024-06-08 16:46:04       26 阅读
  2. 基于MBD开发汽车软件

    2024-06-08 16:46:04       29 阅读
  3. 贪心算法例子

    2024-06-08 16:46:04       30 阅读
  4. What floors can electric dust carts be used to clean?

    2024-06-08 16:46:04       30 阅读
  5. adb多设备多屏幕调试

    2024-06-08 16:46:04       25 阅读
  6. 【词法分析概要】

    2024-06-08 16:46:04       30 阅读
  7. 《计算机网络》

    2024-06-08 16:46:04       22 阅读