📄 mod_ccms.bas
字号:
For i = 0 To 9
boperresult = MIFARE_WriteValueBlock(9, siValue(0)) '钱包初始化
If boperresult = 0 Then Exit For
Next i
If boperresult <> 0 Then GoTo errS1
For i = 0 To 9
boperresult = MIFARE_WriteValueBlock(10, siValue(0)) '钱包初始化
If boperresult = 0 Then Exit For
Next i
If boperresult <> 0 Then GoTo errS1
For i = 0 To 5
DataBuff32(i) = aKEY2(i)
Next i
For i = 0 To 5
DataBuff32(i + 10) = bKEY2(i)
Next i
DataBuff32(6) = &H18
DataBuff32(7) = &H77
DataBuff32(8) = &H8E
DataBuff32(9) = &H69
For i = 0 To 9
boperresult = MIFARE_WriteDataBlock(11, DataBuff32(0)) '更新S2控制块
If boperresult = 7 Or boperresult = 13 Then Exit For
Next i
If boperresult = 7 Or boperresult = 13 Then
Else
GoTo errS1
End If
For i = 0 To 9
boperresult = MIFARE_SelectCard(SerialNum(0))
boperresult = MIFARE_LoginSector(2, 0, aKEY2(0))
If boperresult = 0 Then Exit For
Next i
If boperresult <> 0 Then GoTo errS1
For i = 0 To 9
boperresult = MIFARE_SelectCard(SerialNum(0)) '---------------月票区初始化
boperresult = MIFARE_LoginSector(3, 0, mKEY(0)) '
If boperresult = 0 Then Exit For
Next i
If boperresult <> 0 Then GoTo errS2
For i = 0 To 9
boperresult = MIFARE_WriteDataBlock(12, DataBuff0(0))
If boperresult = 0 Then Exit For
Next i
If boperresult <> 0 Then GoTo errS2
For i = 0 To 9
boperresult = MIFARE_WriteDataBlock(13, DataBuff0(0))
If boperresult = 0 Then Exit For
Next i
If boperresult <> 0 Then GoTo errS2
For i = 0 To 9
boperresult = MIFARE_WriteDataBlock(14, DataBuff0(0))
If boperresult = 0 Then Exit For
Next i
If boperresult <> 0 Then GoTo errS2
For i = 0 To 9
boperresult = MIFARE_WriteDataBlock(15, DataBuff32(0))
If boperresult = 7 Or boperresult = 13 Then Exit For
Next i
If boperresult = 7 Or boperresult = 13 Then
Else
GoTo errS2
End If
For i = 0 To 9
boperresult = MIFARE_SelectCard(SerialNum(0))
boperresult = MIFARE_LoginSector(3, 0, aKEY2(0))
If boperresult = 0 Then Exit For
Next i
If boperresult <> 0 Then GoTo errS2
R_Cardsell = True
Exit Function
errS1:
For i = 0 To 9
boperresult = MIFARE_SelectCard(SerialNum(0))
boperresult = MIFARE_LoginSector(1, 0, aKEY1(0))
If boperresult = 0 Then Exit For
Next i
If boperresult <> 0 Then sp_String = "ERR 1002": GoTo err
For i = 0 To 9
boperresult = MIFARE_WriteDataBlock(7, DataBuffc(0)) '更新S1控制块
If boperresult = 7 Or boperresult = 13 Then Exit For
Next i
If boperresult = 7 Or boperresult = 13 Then
Else
sp_String = "ERR 1003": GoTo err
End If
Exit Function
errS2:
For i = 0 To 9
boperresult = MIFARE_SelectCard(SerialNum(0))
boperresult = MIFARE_LoginSector(1, 0, aKEY1(0))
If boperresult = 0 Then Exit For
Next i
If boperresult <> 0 Then sp_String = "ERR 1002": GoTo err
For i = 0 To 9
boperresult = MIFARE_WriteDataBlock(7, DataBuffc(0)) '更新S1控制块
If boperresult = 7 Or boperresult = 13 Then Exit For
Next i
If boperresult = 7 Or boperresult = 13 Then
Else
sp_String = "ERR 1003": GoTo err
End If
For i = 0 To 9
boperresult = MIFARE_SelectCard(SerialNum(0))
boperresult = MIFARE_LoginSector(2, 1, bKEY2(0))
If boperresult = 0 Then Exit For
Next i
If boperresult <> 0 Then sp_String = "ERR 1002": GoTo err
For i = 0 To 9
boperresult = MIFARE_WriteDataBlock(11, DataBuffc(0)) '更新S2控制块
If boperresult = 7 Or boperresult = 13 Then Exit For
Next i
If boperresult = 7 Or boperresult = 13 Then
Else
sp_String = "ERR 1003": GoTo err
End If
Exit Function
err:
R_Cardsell = False
End Function
'sp_cardid 卡流水号
'sp_string 返回值
'sp_zk 折扣信息
'1111 计算密码错误
Function R_Cardsell34(sp_CardidD As Long, sp_Cardtype As Integer, sp_LimtDate As String, sp_Zk As String, sp_String As String) As Boolean '售卡
Dim spKeyPI(8) As Byte '加密因子
Dim spKeyID(8) As Byte '密码因子
Dim spKeyLA(8) As Byte '密码
'Dim sp_Cardid As String
Dim stNow As String
Dim i As Integer
Dim n As Integer
Dim SerialNumTmp(3) As Byte
''sTest = hex(CDbl(Val(sp_CardidD)))
''If Len(sTest) <= 8 Then
'' Do While Not Len(sTest) = 8
'' sTest = "0" + sTest
'' Loop
''End If
''stCardNo(3) = "&H" + Mid(sTest, 1, 2)
''stCardNo(2) = "&H" + Mid(sTest, 3, 2)
''stCardNo(1) = "&H" + Mid(sTest, 5, 2)
''stCardNo(0) = "&H" + Mid(sTest, 7, 2)
sTest = Format(sp_CardidD, "00000000")
stCardNo(0) = "&h" + Mid(sTest, 1, 2)
stCardNo(1) = "&h" + Mid(sTest, 3, 2)
stCardNo(2) = "&h" + Mid(sTest, 5, 2)
stCardNo(3) = "&h" + Mid(sTest, 7, 2)
boperresult = MIFARE_SelectCard(SerialNumTmp(0))
If boperresult <> 0 Then sp_String = "ERR 1000": GoTo err
For n = 0 To 3
If SerialNumTmp(n) <> SerialNum(n) Then sp_String = "ERR 1001": GoTo err '(与验卡操作不是同一张卡)
Next n
boperresult = MIFARE_LoginSector(1, 0, mKEY(0)) '
If boperresult <> 0 Then sp_String = "ERR 1002": GoTo err
DataBuff32(0) = "&H" & Mid(sKey, 1, 2) '密码因子前4字节
DataBuff32(1) = "&H" & Mid(sKey, 3, 2)
DataBuff32(2) = "&H" & Mid(sKey, 5, 2)
DataBuff32(3) = "&H" & Mid(sKey, 7, 2)
DataBuff32(4) = stCardNo(0) '卡流水号
DataBuff32(5) = stCardNo(1)
DataBuff32(6) = stCardNo(2)
DataBuff32(7) = stCardNo(3)
DataBuff32(8) = "&H" & Mid(sKey, 9, 2) '密码因子后4字节
DataBuff32(9) = "&H" & Mid(sKey, 11, 2)
DataBuff32(10) = "&H" & Mid(sKey, 13, 2)
DataBuff32(11) = "&H" & Mid(sKey, 15, 2)
DataBuff32(12) = &H2 '启用标志,1未启用 2 启用
DataBuff32(13) = sp_Cardtype '卡类
DataBuff32(14) = &H1 '密钥版本
DataBuff32(15) = &H0 'XOR
For n = 0 To 14
DataBuff32(15) = DataBuff32(15) Xor DataBuff32(n)
Next n
boperresult = MIFARE_WriteDataBlock(4, DataBuff32(0)) '发行区信息
If boperresult <> 0 Then sp_String = "ERR 1003": GoTo err
stNow = Format(Now, "yyyymmdd")
DataBuff32(0) = "&H" + Mid(stNow, 1, 2)
DataBuff32(1) = "&H" + Mid(stNow, 3, 2)
DataBuff32(2) = "&H" + Mid(stNow, 5, 2)
DataBuff32(3) = "&H" + Mid(stNow, 7, 2)
If sp_LimtDate = "" Then
DataBuff32(4) = &H20
DataBuff32(5) = &H20
DataBuff32(6) = &H1
DataBuff32(7) = &H1
Else
DataBuff32(4) = "&H" + Mid(sp_LimtDate, 1, 2)
DataBuff32(5) = "&H" + Mid(sp_LimtDate, 3, 2)
DataBuff32(6) = "&H" + Mid(sp_LimtDate, 5, 2)
DataBuff32(7) = "&H" + Mid(sp_LimtDate, 7, 2)
End If
DataBuff32(8) = DataBuff32(0)
DataBuff32(9) = DataBuff32(1)
DataBuff32(10) = DataBuff32(2)
DataBuff32(11) = DataBuff32(3)
DataBuff32(12) = &H0
DataBuff32(13) = &H0
DataBuff32(14) = &H0
DataBuff32(15) = &H0 'XOR
For n = 0 To 14
DataBuff32(15) = DataBuff32(15) Xor DataBuff32(n)
Next n
boperresult = MIFARE_WriteDataBlock(5, DataBuff32(0)) '发行日期、有效期、启用日期 卡压金(2)
If boperresult <> 0 Then sp_String = "ERR 1003": GoTo err
For i = 0 To 5
DataBuff32(i) = aKEY1(i)
DataBuff32(i + 10) = aKEY1(i)
Next i
DataBuff32(6) = &HFF
DataBuff32(7) = &H7
DataBuff32(8) = &H80
DataBuff32(9) = &H69
boperresult = MIFARE_WriteDataBlock(7, DataBuff32(0)) '更新S1控制块
If boperresult <> 7 Then sp_String = "ERR 1003": GoTo err
boperresult = MIFARE_SelectCard(SerialNum(0))
boperresult = MIFARE_LoginSector(1, 0, aKEY1(0))
If boperresult <> 0 Then sp_String = "ERR 1002": GoTo err
'-----------------------------------------------------------------
boperresult = MIFARE_SelectCard(SerialNum(0))
If boperresult <> 0 Then sp_String = "ERR 1000": GoTo err
boperresult = MIFARE_LoginSector(2, 0, mKEY(0)) '
If boperresult <> 0 Then sp_String = "ERR 1002": GoTo err
n = 1
For i = 0 To 15
DataBuff32(i) = "&h" & Mid(sp_Zk, n, 2)
n = n + 2
Next i
boperresult = MIFARE_WriteDataBlock(9, DataBuff32(0)) '折扣0-15
If boperresult <> 0 Then sp_String = "ERR 1003": GoTo err
n = 33
For i = 0 To 15
DataBuff32(i) = "&h" & Mid(sp_Zk, n, 2)
n = n + 2
Next i
boperresult = MIFARE_WriteDataBlock(10, DataBuff32(0)) '折扣16-31
If boperresult <> 0 Then sp_String = "ERR 1003": GoTo err
For i = 0 To 5
DataBuff32(i) = aKEY2(i)
Next i
For i = 0 To 5
DataBuff32(i + 10) = bKEY2(i)
Next i
DataBuff32(6) = &H18
DataBuff32(7) = &H77
DataBuff32(8) = &H8E
DataBuff32(9) = &H69
boperresult = MIFARE_WriteDataBlock(11, DataBuff32(0)) '更新S1控制块
If boperresult = 7 Or boperresult = 13 Then
Else
sp_String = "ERR 1003": GoTo err
End If
boperresult = MIFARE_SelectCard(SerialNum(0))
boperresult = MIFARE_LoginSector(2, 0, aKEY2(0))
If boperresult <> 0 Then
boperresult = MIFARE_SelectCard(SerialNum(0))
If boperresult <> 0 Then sp_String = "ERR 1000": GoTo err
boperresult = MIFARE_LoginSector(1, 0, aKEY1(0)) '
If boperresult <> 0 Then sp_String = "ERR 1002": GoTo err
boperresult = MIFARE_WriteDataBlock(7, DataBuffc(0)) '更新S1控制块
If boperresult = 7 Or boperresult = 13 Then
Else
sp_String = "ERR 1003": GoTo err
End If
GoTo err
End If
For i = 0 To 9
boperresult = MIFARE_SelectCard(SerialNum(0)) '---------------月票区初始化
boperresult = MIFARE_LoginSector(3, 0, mKEY(0)) '
If boperresult = 0 Then Exit For
Next i
If boperresult <> 0 Then GoTo err
For i = 0 To 9
boperresult = MIFARE_WriteDataBlock(12, DataBuff0(0))
If boperresult = 0 Then Exit For
Next i
If boperresult <> 0 Then GoTo err
For i = 0 To 9
boperresult = MIFARE_WriteDataBlock(13, DataBuff0(0))
If boperresult = 0 Then Exit For
Next i
If boperresult <> 0 Then GoTo err
For i = 0 To 9
boperresult = MIFARE_WriteDataBlock(14, DataBuff0(0))
If boperresult = 0 Then Exit For
Next i
If boperresult <> 0 Then GoTo err
For i = 0 To 9
boperresult = MIFARE_WriteDataBlock(15, DataBuff32(0))
If boperresult = 7 Or boperresult = 13 Then Exit For
Next i
If boperresult = 7 Or boperresult = 13 Then
Else
GoTo err
End If
R_Cardsell34 = True
Exit Function
err:
R_Cardsell34 = False
End Function
'sp_key 密码因子8字节,
'sp_string 返回值
'1111 计算密码错误
Function R_Carddel(sp_String As String) As Boolean '删除卡
Dim spKeyPI(8) As Byte '加密因子
Dim spKeyID(8) As Byte '密码因子
Dim spKeyLA(8) As Byte '密码
Dim spKey(16) As Byte
Dim stNow As String
Dim i As Integer
Dim n As Integer
Dim SerialNumTmp(3) As Byte
For i = 0 To 5
spKey(i) = aKEY2(i)
spKey(i + 10) = bKEY2(i)
Next i
spKey(6) = &H18
spKey(7) = &H77
spKey(8) = &H8E
spKey(9) = &H69
boperresult = MIFARE_SelectCard(SerialNumTmp(0))
If boperresult <> 0 Then sp_String = "ERR 1000": GoTo err
For n = 0 To 3
If SerialNumTmp(n) <> SerialNum(n) Then sp_String = "ERR 1001": GoTo err '(与验卡操作不是同一张卡)
Next n
For i = 0 To 9 '恢复钱包区出厂值密码
boperresult = MIFARE_LoginSector(2, 1, bKEY2(0))
If boperresult = 0 Then Exit For
Next i
If boperresult <> 0 Then GoTo err
For i = 0 To 9
boperresult = MIFARE_WriteDataBlock(11, DataBuffc(0))
If boperresult = 7 Or boperresult = 13 Then Exit For
Next i
If boperresult = 7 Or boperresult = 13 Then
Else
sp_String = "ERR 1003": GoTo err
End If
For i = 0 To 9 '恢复月票区出厂值密码
boperresult = MIFARE_SelectCard(SerialNumTmp(0))
boperresult = MIFARE_LoginSector(3, 1, bKEY2(0))
If boperresult = 0 Then Exit For
Next i
If boperresult <> 0 Then GoTo errS1
For i = 0 To 9
boperresult = MIFARE_WriteDataBlock(15, DataBuffc(0))
If boperresult = 7 Or boperresult = 13 Then Exit For
Next i
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -