本示例使用的发卡器:https://item.taobao.com/item.htm?spm=a21dvs.23580594.0.0.52de2c1b8bEEGz&ft=t&id=615391857885
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 Byte
Dim 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 Long
Dim taginfstr As String
Dim packagestr As String
Dim packagestrlen As Long
languagecodestr = "en" '语言编码,英文为en,中文为zh
languagecodestrlen = 2
noteinf = ""
If isexcel Then
getexcelinf2
End If
If Trim(Text18.Text) = "" And Trim(Text5.Text) = "" Then
excelclos
MsgBox "请输入要写入的URL!", vbCritical + vbOKOnly, "提示"
Text18.SetFocus
Exit Sub
End If
CheckCardType
titlestr = 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 = uristr
packagestr = Trim(Text5.Text)
packagestrlen = LenB(StrConv(packagestr, vbFromUnicode))
If packagestrlen > 0 Then taginfstr = taginfstr + "," + packagestr Else taginfstr = taginfstr + ","
taginfstr = noteinf + "," + taginfstr + "," + cardstr
If 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、Ntag2
tagbuf_forumtype4_clear
If uristrlen > 0 Then status = tagbuf_adduri(languagecodestr, languagecodestrlen, titlestr, titlestrlen, uriheaderindex, uristr, uristrlen) Else status = 0
If packagestrlen > 0 Then status1 = tagbuf_addapp(packagestr, packagestrlen) Else status1 = 0
If (status + status1 = 0) Then
If Check3.Value > 0 Then myctrlword = &H10 Else myctrlword = 0
status = forumtype2_write_ndeftag(myctrlword, mypiccserial(0), oldpicckey(0))
dispstr = "NFC_Forum_Type2Uid:" + cardstr + ",写入Url+App包名"
dispriv dispstr, status
' WritDevBufferInf taginfstr
WritDevBufferCSV taginfstr
If (Check3.Value > 0 And Check2.Value < 1) Or (Check3.Value < 1 And Check2.Value > 0) Then NtagKeyEn
Else
dispstr = "NFC_Forum_Type2Uid:" + cardstr + ",生成Url+App包名NDEF记录"
dispriv dispstr, status
End If
ElseIf CardType = 2 Then 'ForumType5、15693
tagbuf_forumtype4_clear
If uristrlen > 0 Then status = tagbuf_adduri(languagecodestr, languagecodestrlen, titlestr, titlestrlen, uriheaderindex, uristr, uristrlen) Else status = 0
If packagestrlen > 0 Then status1 = tagbuf_addapp(packagestr, packagestrlen) Else status1 = 0
If (status + status1 = 0) Then
myctrlword = 0
afi = 0
status = forumtype5_write_ndeftag(myctrlword, afi, mypiccserial(0))
dispstr = "NFC_Forum_Type5Uid:" + cardstr + ",写入Url+App包名"
dispriv dispstr, status
' WritDevBufferInf taginfstr
WritDevBufferCSV taginfstr
If Check2.Value > 0 Then status = iso15693lockblock(0, 1, VarPtr(mypiccserial(0))) '15693卡锁定块数据后只能读取不可再修改,为防止卡片锁死,请谨慎锁定
Else
dispstr = "NFC_Forum_Type5Uid:" + cardstr + ",生成Url+App包名NDEF记录"
dispriv dispstr, status
End If
ElseIf CardType = 3 Then 'MifareClassIc
tagbuf_clear
If uristrlen > 0 Then status = tagbuf_adduri(languagecodestr, languagecodestrlen, titlestr, titlestrlen, uriheaderindex, uristr, uristrlen) Else status = 0
If packagestrlen > 0 Then status1 = tagbuf_addapp(packagestr, packagestrlen) Else status1 = 0
If (status + status1 = 0) Then
If 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 taginfstr
WritDevBufferCSV taginfstr
dispriv dispstr, status
Else
dispstr = "MifareClassUid:" + cardstr + ",生成Url+App包名NDEF记录"
dispriv dispstr, status
End If
ElseIf CardType = 4 Then 'ForumType4
tagbuf_forumtype4_clear
If uristrlen > 0 Then status = tagbuf_adduri(languagecodestr, languagecodestrlen, titlestr, titlestrlen, uriheaderindex, uristr, uristrlen) Else status = 0
If packagestrlen > 0 Then status1 = tagbuf_addapp(packagestr, packagestrlen) Else status1 = 0
If (status + status1 = 0) Then
If Check3.Value > 0 Then myctrlword = &H40 Else myctrlword = 0
status = forumtype4_write_ndeftag(myctrlword, mypiccserial(0), mypiccseriallen(0), mypicckey(0))
dispstr = "NFC_Forum_Type4Uid:" + cardstr + ",写入Url+App包名"
' WritDevBufferInf taginfstr
WritDevBufferCSV taginfstr
dispriv dispstr, status
Else
dispstr = "NFC_Forum_Type4Uid:" + cardstr + ",生成Url+App包名NDEF记录"
dispriv dispstr, status
End If
End If