修改NFC读取

This commit is contained in:
xuli
2025-12-01 18:07:02 +08:00
parent b444bcee57
commit 11990a62da
296 changed files with 3808 additions and 282 deletions

View File

@@ -0,0 +1,4 @@
## 1.0.22025-08-29
api 变更注意查看最新文档
## 1.0.02025-07-30

Binary file not shown.

View File

@@ -0,0 +1,105 @@
{
"id": "ohyes-nfc",
"displayName": "android NFC ",
"version": "1.0.2",
"description": "ohyes-nfc",
"keywords": [
"android",
"uts",
"nfc"
],
"repository": "",
"engines": {
"HBuilderX": "^4.66",
"uni-app": "^4.27",
"uni-app-x": "^4.27"
},
"dcloudext": {
"type": "uts",
"sale": {
"regular": {
"price": "1.00"
},
"sourcecode": {
"price": "3000.00"
}
},
"contact": {
"qq": "1209808782"
},
"declaration": {
"ads": "无",
"data": "无",
"permissions": "android.permission.NFC\nandroid.permission.VIBRATE"
},
"npmurl": "",
"darkmode": "x",
"i18n": "x",
"widescreen": "x"
},
"uni_modules": {
"dependencies": [],
"encrypt": [],
"platforms": {
"cloud": {
"tcb": "√",
"aliyun": "√",
"alipay": "√"
},
"client": {
"uni-app": {
"vue": {
"vue2": {
"extVersion": "1.0.1",
"minVersion": ""
},
"vue3": {
"extVersion": "1.0.1",
"minVersion": ""
}
},
"web": {
"safari": "-",
"chrome": "-"
},
"app": {
"vue": "-",
"nvue": "-",
"android": "-",
"ios": "-",
"harmony": "-"
},
"mp": {
"weixin": "-",
"alipay": "-",
"toutiao": "-",
"baidu": "-",
"kuaishou": "-",
"jd": "-",
"harmony": "-",
"qq": "-",
"lark": "-"
},
"quickapp": {
"huawei": "-",
"union": "-"
}
},
"uni-app-x": {
"web": {
"safari": "-",
"chrome": "-"
},
"app": {
"android": "-",
"ios": "-",
"harmony": "-"
},
"mp": {
"weixin": "-"
}
}
}
}
}
}

View File

@@ -0,0 +1,174 @@
*注意iOS平台的NFC功能暂无支持计划当前版本仅支持Android平台。*
# ohyes-nfc
一个用于uni-app的NFC读取插件支持Android的NFC标签读取功能。
## 免责声明
- 源码无后门代码。
- 由第三方SDK而导致的任何损失,与作者无关。
- 使用本插件而导致的任何损失,与作者无关。
- 使用该插件即代表同意免责声明。
## 是否使用第三方SDK?
-
## 我有需求怎么办?
发送邮件到 helloword202507@163.com 感谢支持
## 功能特性
- 🔍 **NFC标签读取** - 支持多种NFC标签类型的读取
- 🏷️ **多种标签格式** - 支持NDEF、Mifare Classic、Mifare Ultralight、ISO-DEP等
- 📊 **详细信息获取** - 获取标签ID、技术列表、内容、内存使用情况等
- 🔒 **安全验证** - 支持标签签名验证和密码保护检测
## 支持的标签类型
- **NDEF标签** - NFC Forum Type 1-5
- **Mifare Classic** - 1K/4K标签
- **Mifare Ultralight** - 轻量级标签
- **ISO-DEP** - ISO14443-4标准标签
- **NFC-A/B/F/V** - 各种NFC技术标准
## 安装
将插件导入到你的uni-app项目中
1. 下载插件包
2. 将插件放入项目的`uni_modules`目录
3. 重新编译项目
## 权限配置
### Android权限
插件会自动添加以下权限到AndroidManifest.xml
```xml
<uses-feature android:name="android.hardware.nfc" android:required="true" />
<uses-permission android:name="android.permission.NFC" />
<uses-permission android:name="android.permission.VIBRATE" />
```
## 使用方法
### 基本用法
参考示例工程
## API文档
### enableNFCRead()
启用NFC读取模式
### disableNFCRead()
停用NFC读取模式
### isNFCSupported()
检查当前设备是否支持NFC功能
**返回值:**
- `boolean` - true表示设备支持NFCfalse表示不支持
### isNFCEnabled()
检查当前设备NFC功能是否已打开
**返回值:**
- `boolean` - true表示NFC已启用false表示NFC未启用
### openNFCSettings()
跳转到系统NFC设置页面用户可以手动打开NFC开关
### onNFCListener(callback:(res:NFCInfo)=>void)
监听NFC返回数据,全局唯一,重复调用会覆盖
## NFCInfo数据结构
读取成功后返回的NFC信息对象包含以下字段
```typescript
interface NFCInfo {
id: string // 标签唯一ID
techList: string[] // 支持的技术列表
type: string // 标签类型
size: number // 标签容量(字节)
isWritable: boolean // 是否可写
content: string // 标签内容
atqa: string // ATQA值NFC-A技术
sak: string // SAK值NFC-A技术
signature: string // 签名状态
passwordProtected: boolean // 是否密码保护
dataFormat: string // 数据格式
recordCount: number // NDEF记录数量
usedBytes: number // 已使用字节数
freeBytes: number // 剩余字节数
}
```
### 字段说明
- **id**: 标签的唯一标识符,通常为十六进制字符串
- **techList**: 标签支持的NFC技术如["NfcA", "Ndef", "MifareUltralight"]
- **type**: 标签类型描述,如"Type 2 (Ultralight)"
- **size**: 标签总容量,单位为字节
- **isWritable**: 标签是否支持写入操作
- **content**: 解析后的标签内容包括文本、URL等
- **atqa/sak**: NFC-A技术的技术参数
- **signature**: 标签签名验证状态
- **dataFormat**: 数据格式,如"NFC Forum Type 2"
- **recordCount**: NDEF消息中的记录数量
- **usedBytes/freeBytes**: 内存使用情况
## 支持的内容类型
插件能够解析以下类型的NFC内容
### NDEF记录类型
- **文本记录** - 纯文本内容,支持多语言
- **URI记录** - 网址、电话、邮箱等链接
- **MIME记录** - 多媒体内容
- **外部类型** - 自定义格式
### 非NDEF标签
- **Mifare Classic** - 读取扇区和块数据
- **Mifare Ultralight** - 读取页面数据
- **ISO-DEP** - 读取历史字节和高层响应
## 平台支持
| 平台 | 支持状态 | 说明 |
|------|----------|------|
| Android | ✅ 完全支持 | 支持所有NFC功能包括多种标签类型 |
## 注意事项
1. **设备要求**: 设备必须支持NFC功能
2. **权限**: Android需要NFC权限iOS需要在设置中启用NFC
3. **距离**: NFC读取需要设备与标签距离很近通常<4cm
4. **性能**: 读取大容量标签时可能需要较长时间
5. **兼容性**: 不同厂商的NFC标签可能有细微差异
## 错误处理
常见错误及处理方法
- **"NFC不可用"** - 检查设备是否支持NFC并已启用
- **"读取超时"** - 确保标签与设备距离足够近
- **"标签格式不支持"** - 标签可能损坏或使用了不支持的格式
- **"权限被拒绝"** - 检查应用是否有NFC权限
## 更新日志
### v1.0.0
- 初始版本发布
- 支持Android平台NFC读取
- 支持多种标签类型和格式
- 提供详细的标签信息

View File

@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools"
package="com.ohyes.nfc">
<uses-feature android:name="android.hardware.nfc" android:required="true" />
<uses-permission android:name="android.permission.NFC" />
<uses-permission android:name="android.permission.VIBRATE" />
</manifest>

View File

@@ -0,0 +1,3 @@
{
"minSdkVersion": "21"
}

Binary file not shown.

View File

@@ -0,0 +1,3 @@
{
"deploymentTarget": "12"
}

Binary file not shown.

View File

@@ -0,0 +1,29 @@
export type NFCEnableReadMode = () => void
export type NFCDisableReadMode = () => void
export type NFCIsSupported = () => boolean
export type NFCIsEnabled = () => boolean
export type NFCOpenSettings = () => void
export type NFCListener = (info : NFCInfo) => void
export type NFCReadOptions = {
resolve : (res : NFCInfo) => void
reject : (e : String) => void
}
export type NFCInfo = {
id : string,
techList : Array<string>,
type : string,
size : number,
isWritable : boolean,
content : string,
atqa : string,
sak : string,
signature : string,
passwordProtected : boolean,
dataFormat : string,
recordCount : number,
usedBytes : number,
freeBytes : number
}

View File

@@ -0,0 +1,18 @@
## 1.0.82025-07-22
修复uniapp x打包报错AndroidManifest.xml 需要显式声明 android:exported="true"
## 1.0.72025-06-26
修改BUG
## 1.0.62024-07-24
更新刷卡监听界面背景透明化,提高界面友好度
## 1.0.52024-07-24
更新刷新提示窗体
## 1.0.42024-05-14
修改BUG
## 1.0.32024-05-11
优化
## 1.0.22024-05-11
更换图标
## 1.0.12024-04-12
增加设备支持与NFC启用判断
## 1.0.02024-04-12
提交插件

View File

@@ -0,0 +1 @@
<EFBFBD>,<2C>P<EFBFBD><50>=<3D>[&<26>۸<>6<EFBFBD><36>z<EFBFBD>s<EFBFBD>+<2B>g<02><>_<EFBFBD><5F>ϭ<EFBFBD><12><><EFBFBD><EFBFBD><EBA580>e<EFBFBD>$<24>,<14><><EFBFBD><EFBFBD>s`<60>_<><5F><07>B<EFBFBD><42><EFBFBD><EFBFBD>Wa<57><61>8W <0C><><EFBFBD>t<EFBFBD>O<EFBFBD><4F>{_Hf<48><66>ڎ@<15>-u+UX<55><02>*<2A><><EFBFBD>zl0f<30>U8K^G<><47><EFBFBD>0<14><><17><><EFBFBD>hpj<70><6A><EFBFBD><EFBFBD><EFBFBD>]^?

View File

@@ -0,0 +1,102 @@
{
"id": "read-nfc",
"displayName": "read-nfc",
"version": "1.0.8",
"description": "读取NFC卡号 read-nfc",
"keywords": [
"read-nfc"
],
"repository": "",
"engines": {
"uni-app": "^4.06",
"uni-app-x": "^4.07"
},
"dcloudext": {
"type": "uts",
"sale": {
"regular": {
"price": "50.00"
},
"sourcecode": {
"price": "200.00"
}
},
"contact": {
"qq": ""
},
"declaration": {
"ads": "无",
"data": "插件不采集任何数据",
"permissions": "<uses-permission android:name=\"android.permission.NFC\" /> \r\n<uses-feature android:name=\"android.hardware.nfc\" android:required=\"true\" />"
},
"npmurl": "",
"darkmode": "x",
"i18n": "x",
"widescreen": "x"
},
"uni_modules": {
"dependencies": [],
"encrypt": [],
"platforms": {
"cloud": {
"tcb": "√",
"aliyun": "√",
"alipay": "√"
},
"client": {
"uni-app": {
"vue": {
"vue2": "√",
"vue3": "√"
},
"web": {
"safari": "-",
"chrome": "-"
},
"app": {
"vue": "√",
"nvue": "-",
"android": {
"extVersion": "1.0.0",
"minVersion": "21"
},
"ios": "-",
"harmony": "-"
},
"mp": {
"weixin": "-",
"alipay": "-",
"toutiao": "-",
"baidu": "-",
"kuaishou": "-",
"jd": "-",
"harmony": "-",
"qq": "-",
"lark": "-"
},
"quickapp": {
"huawei": "-",
"union": "-"
}
},
"uni-app-x": {
"web": {
"safari": "-",
"chrome": "-"
},
"app": {
"android": {
"extVersion": "1.0.0",
"minVersion": "21"
},
"ios": "-",
"harmony": "-"
},
"mp": {
"weixin": "-"
}
}
}
}
}
}

View File

@@ -0,0 +1,52 @@
# read-nfc
## 插件示例
1、通过插件市场“使用 HBuilderX 导入示例项目”下载插件示例项目
2、通过插件市场“试用”导入插件到示例项目中
3、打包并运行自定义基座
使用了NFC的Android原生库需要打包使用自定义基座
## 引入插件对象
```
import * as nfc from "@/uni_modules/read-nfc";
```
## 调起NFC识别
```
data() {
return {
title: '读取NFC监听',
nfcCode:''
}
},
onLoad() {
this.gotoNfcActivity();//调起NFC识别并监听回调
},
methods: {
gotoNfcActivity() {
let that=this;
nfc.gotoNfcActivity(function(result){
that.nfcCode=result.message;
uni.showModal({
title: '提示',
content: result.message,
confirmText:'继续',
success: function (res) {
if (res.confirm) {
that.gotoNfcActivity();//继续识别
console.log('用户点击继续!');
} else if (res.cancel) {
console.log('用户点击取消!');
}
}
});
console.log('NFC',result);
});
}
}
```

View File

@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools"
package="io.dcloud.uni_modules.read_nfc">
<!--获取NFC权限-->
<uses-permission android:name="android.permission.NFC" />
<uses-feature android:name="android.hardware.nfc" android:required="true" />
<application>
<activity android:name="uts.sdk.modules.readNfc.NfcActivity" android:exported="true" android:launchMode="singleTop" android:theme="@android:style/Theme.Translucent">
<intent-filter>
<action android:name="android.nfc.action.NDEF_DISCOVERED" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
</intent-filter>
<intent-filter>
<action android:name="android.nfc.action.TAG_DISCOVERED" />
<data android:mimeType="text/plain" />
</intent-filter>
</activity>
</application>
</manifest>

View File

@@ -0,0 +1,3 @@
{
"minSdkVersion": "21"
}

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.9 KiB

View File

@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:orientation="vertical">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:orientation="vertical">
<ImageView
android:id="@+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="请靠近NFC卡"
android:gravity="center_horizontal"
android:src="@drawable/nfc" />
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal"
android:gravity="center_horizontal"
android:text="请靠近NFC卡"
android:textColor="#000"
android:textSize="20sp" />
</LinearLayout>
</RelativeLayout>

View File

@@ -0,0 +1,45 @@
/**
* interface.uts
* uts插件接口定义文件按规范定义接口文件可以在HBuilderX中更好的做到语法提示
*/
/**
* myApi 异步函数的参数在type里定义函数需要的参数以及api成功、失败的相关回调函数。
*/
export type MyApiOptions = {
paramA : boolean
success ?: (res : MyApiResult) => void
fail ?: (res : MyApiFail) => void
complete ?: (res : any) => void
}
/**
* 函数返回结果
* 可以是void, 基本数据类型自定义type, 或者其他类型。
* [可选实现]
*/
export type MyApiResult = {
fieldA : number,
fieldB : boolean,
fieldC : string
}
/**
* 错误码
* 根据uni错误码规范要求建议错误码以90开头以下是错误码示例
* - 9010001 错误信息1
* - 9010002 错误信息2
*/
export type MyApiErrorCode = 9010001 | 9010002;
/**
* myApi 的错误回调参数
*/
export interface MyApiFail extends IUniError {
errCode : MyApiErrorCode
};
/* 异步函数定义 */
export type MyApi = (options : MyApiOptions) => void
/* 同步函数定义 */
export type MyApiSync = (paramA : boolean) => MyApiResult

Binary file not shown.