写NFC标签支持Android安卓Ohos纯血鸿蒙唤醒微信小程序

本示例使用的发卡器:https://item.taobao.com/item.htm?spm=a21dvs.23580594.0.0.52de2c1b8bEEGz&ft=t&id=61539185785 

Python

languagecodestr = "en".encode('gbk')
titlestr=self.lineEdit_title.text().strip().encode('gbk')
uriheaderindex = self.comboBox_headindex.currentIndex()
uristr=self.lineEdit_uri.text().strip().encode('gbk')
status = Objdll.tagbuf_adduri(languagecodestr, len(languagecodestr), titlestr, len(titlestr), uriheaderindex,uristr, len(uristr)) % 256apptypestr="ohos.com:pkg".encode('gbk')
packagestr = "weixin://dl/business/?ticket=la0041f2cedf9630c9c7cc8c8715ac0c6".encode('gbk')
status = Objdll.tagbuf_addapp1(packagestr, len(packagestr),apptypestr,len(apptypestr)) % 256self.WriteTag('NDEF缓冲区数据')def WriteTag(self,funcname):     #将NDEF缓冲区数据写入各种不同类型的NFC标签,清除标签内NDEF数据mypiccserial = bytes(8)mypiccseriallen=bytes(1)try:cardtyep = self.checkcardtype()  #判断发卡器上的标签类型if(cardtyep==1):        #写forumtype2 Ntag2标签if self.checkBox_before.isChecked():myctrlword = 16else:myctrlword = 0status = Objdll.forumtype2_write_ndeftag(myctrlword, mypiccserial, oldpicckey) % 256if (status == 0):Objdll.pcdbeep(38)cardno = 'ForumType2,UID:'for num in range(0, 7):cardno = cardno + '%02X' % (mypiccserial[num])self.ListBottom('NDEF缓冲区数据写入标签成功!标签类型:'+cardno)if (self.checkBox_before.isChecked() and not self.checkBox_later.isChecked()) or (not self.checkBox_before.isChecked() and self.checkBox_later.isChecked() or (self.checkBox_before.isChecked() and self.checkBox_later.isChecked())):self.NtagkeyEn()else:self.ListErrInf(status)elif(cardtyep==2):       #写forumtype5 15693标签myctrlword = 0afi=0status = Objdll.forumtype5_write_ndeftag(myctrlword,afi, mypiccserial) % 256if (status == 0):Objdll.pcdbeep(38)cardno = 'ForumType5,UID:'for num in range(0, 8):cardno = cardno + '%02X' % (mypiccserial[num])if self.checkBox_later.isChecked():    #15693卡锁定块数据后只能读取不可再修改,为防止卡片锁死,请谨慎锁定Objdll.iso15693lockblock(0,1,mypiccserial)self.ListBottom('NDEF缓冲区数据写入标签成功!标签类型:' + cardno)else:self.ListErrInf(status)elif (cardtyep == 3):  # 写MifareClassic标签if(funcname=='NDEF_Clear'):if self.checkBox_before.isChecked():myctrlword = 210else:myctrlword = 146status = Objdll.piccclear_ndeftag(myctrlword, mypiccserial, oldpicckey) % 256else:if self.checkBox_before.isChecked():myctrlword = 210else:myctrlword = 146if self.checkBox_later.isChecked():  #写标签后给标签加密保护myctrlword=myctrlword+4status = Objdll.piccwrite_ndeftag(myctrlword, mypiccserial, oldpicckey,newpicckey) % 256if (status == 0):Objdll.pcdbeep(38)cardno = 'MifareClass,UID:'for num in range(0, 4):cardno = cardno + '%02X' % (mypiccserial[num])self.ListBottom('NDEF缓冲区数据写入标签成功!标签类型:' + cardno)else:self.ListErrInf(status)elif(cardtyep==4):       #写forumtype4 标签if self.checkBox_before.isChecked():myctrlword = 64else:myctrlword = 0status = Objdll.forumtype4_write_ndeftag(myctrlword, mypiccserial,mypiccseriallen,newpicckey) % 256if (status == 0):Objdll.pcdbeep(38)cardno = 'ForumType4,UID:'for num in range(0, mypiccseriallen[0]):cardno = cardno + '%02X' % (mypiccserial[num])self.ListBottom('NDEF缓冲区数据写入标签成功!标签类型:' + cardno)else:self.ListErrInf(status)elif (cardtyep == 23):self.ListErrInf(23)else:self.ListErrInf(8)except:self.ListErrInf(8)

C#

string languagecodestr = "en";  //语言编码,英文为en,中文为zh
int languagecodestrlen = languagecodestr.Length;string titlestr = ""; //标题
int titlestrlen = System.Text.Encoding.GetEncoding(936).GetBytes(titlestr).Length; //标题长度int uriheaderindex = 0;   //前缀string uristr = "weixin://dl/business/?ticket=la0041f2cedf9630c9c7cc8c8715ac0c6";   //uri
int uristrlen = System.Text.Encoding.GetEncoding(936).GetBytes(uristr).Length; //uri长度string packagestr = "com.tencent.mm" ;   //APP名称            
int packagestrlen = System.Text.Encoding.GetEncoding(936).GetBytes(packagestr).Length; //APP名称长度string apptypestr="ohos.com:pkg";
int apptypelen=System.Text.Encoding.GetEncoding(936).GetBytes(apptypestr).Length; byte status0 = tagbuf_adduri(languagecodestr, languagecodestrlen, titlestr, titlestrlen, uriheaderindex, uristr, uristrlen);	
byte status1=  tagbuf_addapp1(packagestr, packagestrlen,apptypestr,apptypelen);
if (status0 +status1==0 ){bool havelock = checkBox1.Checked;             //卡片是否已加锁  bool KeyEn = checkBox2.Checked; ;               //是否启用密码保护NDEF信息WriteDataBufToTag("NDEF组合标签", havelock, KeyEn);
}private void WriteDataBufToTag(string NDEFinfo, bool havelock, bool keyEn)
{byte status;byte afi;byte myctrlword;//控制字byte[] mypiccserial = new byte[8];//卡序列号byte[] mypiccseriallen = new byte[1];byte[] oldpicckey = new byte[6];  //卡片旧密码byte[] newpicckey = new byte[6];  //卡片新密码oldpicckey[0] = 0x19; oldpicckey[1] = 0x74; oldpicckey[2] = 0x02; oldpicckey[3] = 0x02; oldpicckey[4] = 0x01; oldpicckey[5] = 0x11;//为防止测试中忘记以设定的密码,标签统一用此组密码加密,客户可自行设置其他的标签保护密码newpicckey[0] = 0x19; newpicckey[1] = 0x74; newpicckey[2] = 0x02; newpicckey[3] = 0x02; newpicckey[4] = 0x01; newpicckey[5] = 0x11;int cardtype = checkcardtype();switch (cardtype){case 1:     //Ntag2x标签if (havelock) { myctrlword = 0x10; } else { myctrlword = 0; }status = forumtype2_write_ndeftag(myctrlword, mypiccserial, oldpicckey);if (status == 0){NtagKeyEn(mypiccserial);   //开启或关闭Ntag2x标签密码保护功能//if (KeyEn) { NtagPageLock(); }  锁定Ntag2标签数据块,锁定后不可再改修改,请谨慎使用pcdbeep(38);string carduid = "Ntag2UID:";for (int i = 0; i < 7; i++){carduid = carduid + mypiccserial[i].ToString("X02");}MessageBox.Show(carduid + ",NDEF智能海报写入成功!!", "示例提示", MessageBoxButtons.OK, MessageBoxIcon.Information);}else { disperrinf(status); }break;case 2:     //15693标签myctrlword = 0;afi = 0;status = forumtype5_write_ndeftag(myctrlword, afi, mypiccserial);if (status == 0){//if (KeyEn)    //15693卡锁定块数据后只能读取不可再修改,为防止卡片锁死,仅在确定需要才开启此段代码。//{//    status = iso15693lockblock(34, 1, mypiccserial);//}pcdbeep(38);string carduid = "15693UID:";for (int i = 0; i < 8; i++){carduid = carduid + mypiccserial[i].ToString("X02");}MessageBox.Show(carduid + ",NDEF智能海报写入成功!!", "示例提示", MessageBoxButtons.OK, MessageBoxIcon.Information);}else { disperrinf(status); }break;case 3:             //MifareClass标签if (havelock) { myctrlword = 0x80 + 0x40 + 0x10; } else { myctrlword = 0x80 + 0x10; }if (keyEn) { myctrlword = (byte)(myctrlword + 0x04); }status = piccwrite_ndeftag(myctrlword, mypiccserial, oldpicckey, newpicckey);if (status == 0){pcdbeep(38);string carduid = "MifareClassUID:";for (int i = 0; i < 4; i++){carduid = carduid + mypiccserial[i].ToString("X02");}MessageBox.Show(carduid + ",NDEF智能海报写入成功!!", "示例提示", MessageBoxButtons.OK, MessageBoxIcon.Information);}else { disperrinf(status); }break;case 4:     //ForumType4标签myctrlword = 0;     //0表示标签无密码,如设置密码取值  &H40 ,mypicckey 存放密码status = forumtype4_write_ndeftag(myctrlword, mypiccserial, mypiccseriallen, newpicckey);if (status == 0){pcdbeep(38);string carduid = "ForumType4UID:";for (int i = 0; i < mypiccseriallen[0]; i++){carduid = carduid + mypiccserial[i].ToString("X02");}MessageBox.Show(carduid + ",NDEF智能海报写入成功!!", "示例提示", MessageBoxButtons.OK, MessageBoxIcon.Information);}else { disperrinf(status); }break;default:MessageBox.Show("请刷有效的NFC标签!", "示例提示", MessageBoxButtons.OK, MessageBoxIcon.Error);break;}
}

VB源码 

Dim dispstr As String
Dim status As Byte
Dim status1 As Byte
Dim afi As Byte
Dim myctrlword As Byte
Dim mypiccserial(0 To 7) As Byte
Dim mypicckey(0 To 15) As Byte
Dim mypiccseriallen(1) As ByteDim languagecodestr As String
Dim languagecodestrlen As Long
Dim titlestr As String
Dim titlestrlen As Long
Dim uriheaderindex As Long
Dim uristr As String
Dim uristrlen As LongDim taginfstr As StringDim packagestr As String
Dim packagestrlen As Longlanguagecodestr = "en"      '语言编码,英文为en,中文为zh
languagecodestrlen = 2noteinf = ""
If isexcel Thengetexcelinf2
End IfIf Trim(Text18.Text) = "" And Trim(Text5.Text) = "" ThenexcelclosMsgBox "请输入要写入的URL!", vbCritical + vbOKOnly, "提示"Text18.SetFocusExit Sub
End IfCheckCardTypetitlestr = Trim(Text4.Text)     '标题
titlestrlen = LenB(StrConv(titlestr, vbFromUnicode))uriheaderindex = Combo2.ListIndex   '链接前缀uristr = Trim(Text18.Text)  '链接
If Check4.Value > 0 Then uristr = uristr + cardstr
uristrlen = LenB(StrConv(uristr, vbFromUnicode))
If Combo2.ListIndex > 0 Then taginfstr = Trim(Combo2.Text) + uristr Else taginfstr = uristrpackagestr = Trim(Text5.Text)
packagestrlen = LenB(StrConv(packagestr, vbFromUnicode))
If packagestrlen > 0 Then taginfstr = taginfstr + "," + packagestr Else taginfstr = taginfstr + ","taginfstr = noteinf + "," + taginfstr + "," + cardstrIf Len(Trim(outnote1.Text)) > 0 Then taginfstr = taginfstr + "," + Trim(outnote1.Text) Else taginfstr = taginfstr + ",  "
If Len(Trim(outnote2.Text)) > 0 Then taginfstr = taginfstr + "," + Trim(outnote2.Text) Else taginfstr = taginfstr + ",  "
If Len(Trim(outnote3.Text)) > 0 Then taginfstr = taginfstr + "," + Trim(outnote3.Text) Else taginfstr = taginfstr + ",  "If CardType = 1 Then    'ForumType2、Ntag2tagbuf_forumtype4_clearIf uristrlen > 0 Then status = tagbuf_adduri(languagecodestr, languagecodestrlen, titlestr, titlestrlen, uriheaderindex, uristr, uristrlen) Else status = 0If packagestrlen > 0 Then status1 = tagbuf_addapp(packagestr, packagestrlen) Else status1 = 0If (status + status1 = 0) ThenIf Check3.Value > 0 Then myctrlword = &H10 Else myctrlword = 0status = forumtype2_write_ndeftag(myctrlword, mypiccserial(0), oldpicckey(0))dispstr = "NFC_Forum_Type2Uid:" + cardstr + ",写入Url+App包名"dispriv dispstr, status'        WritDevBufferInf taginfstrWritDevBufferCSV taginfstrIf (Check3.Value > 0 And Check2.Value < 1) Or (Check3.Value < 1 And Check2.Value > 0) Then NtagKeyEnElsedispstr = "NFC_Forum_Type2Uid:" + cardstr + ",生成Url+App包名NDEF记录"dispriv dispstr, statusEnd IfElseIf CardType = 2 Then    'ForumType5、15693tagbuf_forumtype4_clearIf uristrlen > 0 Then status = tagbuf_adduri(languagecodestr, languagecodestrlen, titlestr, titlestrlen, uriheaderindex, uristr, uristrlen) Else status = 0If packagestrlen > 0 Then status1 = tagbuf_addapp(packagestr, packagestrlen) Else status1 = 0If (status + status1 = 0) Thenmyctrlword = 0afi = 0status = forumtype5_write_ndeftag(myctrlword, afi, mypiccserial(0))dispstr = "NFC_Forum_Type5Uid:" + cardstr + ",写入Url+App包名"dispriv dispstr, status'        WritDevBufferInf taginfstrWritDevBufferCSV taginfstrIf Check2.Value > 0 Then status = iso15693lockblock(0, 1, VarPtr(mypiccserial(0)))  '15693卡锁定块数据后只能读取不可再修改,为防止卡片锁死,请谨慎锁定Elsedispstr = "NFC_Forum_Type5Uid:" + cardstr + ",生成Url+App包名NDEF记录"dispriv dispstr, statusEnd IfElseIf CardType = 3 Then    'MifareClassIctagbuf_clearIf uristrlen > 0 Then status = tagbuf_adduri(languagecodestr, languagecodestrlen, titlestr, titlestrlen, uriheaderindex, uristr, uristrlen) Else status = 0If packagestrlen > 0 Then status1 = tagbuf_addapp(packagestr, packagestrlen) Else status1 = 0If (status + status1 = 0) ThenIf Check3.Value > 0 Then myctrlword = &H80 + &H40 + &H10 + &H2 Else myctrlword = &H80 + &H10 + &H2  'MifareClass卡是否已经加有保护密码If Check2.Value > 0 Then myctrlword = myctrlword + &H4  '写入NDEF数据后 并加上保护密码status = piccwrite_ndeftag(myctrlword, mypiccserial(0), oldpicckey(0), newpicckey(0))dispstr = "MifareClassUid:" + cardstr + ",写入Url+App包名"'        WritDevBufferInf taginfstrWritDevBufferCSV taginfstrdispriv dispstr, statusElsedispstr = "MifareClassUid:" + cardstr + ",生成Url+App包名NDEF记录"dispriv dispstr, statusEnd IfElseIf CardType = 4 Then    'ForumType4tagbuf_forumtype4_clearIf uristrlen > 0 Then status = tagbuf_adduri(languagecodestr, languagecodestrlen, titlestr, titlestrlen, uriheaderindex, uristr, uristrlen) Else status = 0If packagestrlen > 0 Then status1 = tagbuf_addapp(packagestr, packagestrlen) Else status1 = 0If (status + status1 = 0) ThenIf Check3.Value > 0 Then myctrlword = &H40 Else myctrlword = 0status = forumtype4_write_ndeftag(myctrlword, mypiccserial(0), mypiccseriallen(0), mypicckey(0))dispstr = "NFC_Forum_Type4Uid:" + cardstr + ",写入Url+App包名"'        WritDevBufferInf taginfstrWritDevBufferCSV taginfstrdispriv dispstr, statusElsedispstr = "NFC_Forum_Type4Uid:" + cardstr + ",生成Url+App包名NDEF记录"dispriv dispstr, statusEnd If
End If

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.rhkb.cn/news/485523.html

如若内容造成侵权/违法违规/事实不符,请联系长河编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

51c自动驾驶~合集39

我自己的原文哦~ https://blog.51cto.com/whaosoft/12707676 #DiffusionDrive 大幅超越所有SOTA&#xff01;地平线DiffusionDrive&#xff1a;生成式方案或将重塑端到端格局&#xff1f; 近年来&#xff0c;由于感知模型的性能持续进步&#xff0c;端到端自动驾驶受到了来…

沃德云商协系统微信小程序PHP+Uniapp

“多组织”的云服务平台&#xff0c;打造总商会、总协会、总校友会、工商联等多组织无障碍沟通合作平台&#xff0c;让各大分会、各大分校友会、分组织实现轻松管理&#xff0c;线上宣传展示、商机挖掘、会员管理、会员服务、跨界交流等, 借助沃德云商协平台系统&#xff0c;让…

网页设计--axios作业

根据以下mock地址中的json数据&#xff0c;使用axios异步方式获取并显示在页面中。 https://apifoxmock.com/m1/3761592-3393136-default/peotfindAll?apifoxApiId171582689 {"code": 1,"msg": "success","data": [{"id": …

【uni-app 微信小程序】新版本发布提示用户进行更新

知识准备 uni.getUpdateManager文档介绍 不支持APP与H5&#xff0c;所以在使用的时候要做好平台类型的判断&#xff0c;如何判断&#xff0c;参考条件编译处理多端差异 代码参考 export const updateApp () > {const updateManager uni.getUpdateManager()updateManag…

ip地址显示本地局域网什么意思?ip地址冲突怎么解决

在日常使用网络的过程中&#xff0c;我们可能会遇到IP地址显示“本地局域网”的情况&#xff0c;同时&#xff0c;局域网内IP地址冲突也是一个常见且令人头疼的问题。本文将首先解释IP地址显示本地局域网的含义&#xff0c;随后详细探讨局域网IP地址冲突的解决方法&#xff0c;…

超清4K视频素材哪里找?优质下载资源网站分享

我是你们的自媒体UP主小李。现在是高清、4K视频大行其道的时代&#xff0c;想要制作出吸引眼球的优质内容&#xff0c;超清4K视频素材必不可少。今天就为大家分享几个宝藏网站&#xff0c;让你的视频创作更轻松、更出彩&#xff01; 蛙学网 首先推荐 蛙学网&#xff0c;这是国内…

Qt Qtablewidget 标题 QHeaderView 增加可选框 QcheckBox

创建自定义QHeaderView #pragma once#include <QObject> #include <QHeaderView> #include <QPainter> #include <QMouseEvent>class SSHeaderView : public QHeaderView {Q_OBJECTprivate:bool isChecked;int m_checkColIdx; public:SSHeaderView(i…

关于Chrome自动同步书签的解决办法

前言 并不一定适用所有用户&#xff0c; 目前我在网上搜集了一些资料&#xff0c;也做了一些尝试。 就我个人总结的经验来讲&#xff0c;分享大家以下几种办法&#xff1a; 1.书签同步插件 点击如下&#x1f517;&#xff1a; Chrome书签同步https://bm.famend.cn/ …

MFC扩展库BCGControlBar Pro v36.0新版亮点:黑色主题中的自动反转图标

BCGControlBar库拥有500多个经过全面设计、测试和充分记录的MFC扩展类。 我们的组件可以轻松地集成到您的应用程序中&#xff0c;并为您节省数百个开发和调试时间。 BCGControlBar专业版 v36.0已全新发布了&#xff0c;这个版本在黑暗主题中添加自动图标反转、新增一个全新的S…

调用大模型api 批量处理图像 保存到excel

最近需要调用大模型&#xff0c;并将结果保存到excel中&#xff0c;效果如下&#xff1a; 代码&#xff1a; import base64 from zhipuai import ZhipuAI import os import pandas as pd from openpyxl import Workbook from openpyxl.drawing.image import Image from io i…

debian ubuntu armbian部署asp.net core 项目 开机自启动

我本地的环境是 rk3399机器&#xff0c;安装armbian系统。 1.安装.net core 组件 sudo apt-get update && \sudo apt-get install -y dotnet-sdk-8.0或者安装运行库&#xff0c;但无法生成编译项目 sudo apt-get update && \sudo apt-get install -y aspnet…

声音克隆GPT-SoVITS

作者&#xff1a;吴业亮 博客&#xff1a;wuyeliang.blog.csdn.net 一、原理介绍 GPT-SoVITS&#xff0c;作为一款结合了GPT&#xff08;生成预训练模型&#xff09;和SoVITS&#xff08;基于变分信息瓶颈技术的歌声转换&#xff09;的创新工具&#xff0c;正在声音克隆领域掀…

记忆泡沫垫市场:解锁舒适睡眠的黄金钥匙与增长潜力的深度剖析

在当今快节奏、高压力的生活中&#xff0c;优质睡眠已成为现代人追求健康生活的重要组成部分。记忆泡沫垫&#xff0c;作为床垫和枕头领域的一次革命性创新&#xff0c;凭借其独特的材质特性和对人体工学的完美贴合&#xff0c;正逐步成为改善睡眠质量的首选解决方案。本文将从…

R语言 | 峰峦图 / 山脊图

目的&#xff1a;为展示不同数据分布的差异。 1. ggplot2 实现 # 准备数据 datmtcars[, c("mpg", "cyl")] colnames(dat)c("value", "type") head(dat) # value type #Mazda RX4 21.0 6 #Mazda RX4 Wag …

完美解决Qt Qml窗口全屏软键盘遮挡不显示

1、前提 说明&#xff1a;我使用的是第三方软键盘 QVirtualKeyboard QVirtualKeyboard: Qt5虚拟键盘支持中英文,仿qt官方的virtualkeyboard模块,但使用QWidget实现。 - Gitee.com 由于参考了几篇文章尝试但没有效果&#xff0c;链接如下&#xff1a; 文章一&#xff1a;可能…

吉林大学23级数据结构上机实验(第7周)

A 去火车站 寒假到了&#xff0c;小明准备坐火车回老家&#xff0c;现在他从学校出发去火车站&#xff0c;CC市去火车站有两种方式&#xff1a;轻轨和公交车。小明为了省钱&#xff0c;准备主要以乘坐公交为主。CC市还有一项优惠政策&#xff0c;持学生证可以免费乘坐一站轻轨&…

MATLAB 最小二乘点云拟合球 (89)

MATLAB 最小二乘点云拟合球 (89) 一、算法介绍二、算法实现1.代码2.结果这是缘,亦是最美的相见 一、算法介绍 球面拟合算法是一种通过数学方法将一组三维点(通常在三维空间中分布)拟合到一个理想的球形表面上。这个过程通常涉及使用最小二乘法来最小化实际数据点与拟合的…

短视频矩阵系统开发|技术源代码部署

短视频矩阵系统通过多账号运营管理、多平台视频智能分发等功能&#xff0c;助力企业实现视频引流、粉丝沉淀和转化。 短视频矩阵系统是一种创新的营销工具&#xff0c;它整合了多账号管理、视频智能分发、数据可视化等多种功能&#xff0c;为企业在短视频领域的发展提供了强大…

若依 ruoyi VUE el-select 直接获取 选择option 的 label和value

1、最新在研究若依这个项目&#xff0c;我使用的是前后端分离的方案&#xff0c;RuoYi-Vue-fast(后端) RuoYi-Vue-->ruoyi-ui(前端)。RuoYi-Vue-fast是单应用版本没有区分那么多的modules 自己开发起来很方便&#xff0c;这个项目运行起来很方便&#xff0c;但是需要自定义的…

【0x01】HCI_Inquiry_Complete事件详解

目录 一、事件概述 二、事件格式及参数 2.1. HCI_Inquiry_Complete事件格式 2.2. 参数 三、HCI_Inquiry_Complete事件触发机制 3.1. 基于查询命令完成的触发 3.2. 受查询环境和设备状态影响的触发 3.3. 与蓝牙协议栈内部逻辑相关的触发 四、事件处理流程 4.1. 事件接…