完整签名校验 + 心跳保活,生产级实现
Global SIGN_KEY, TIMESTAMP_MAX_DIFF SIGN_KEY = "你的签名密钥" ' 从后台「修改签名密钥」获取 TIMESTAMP_MAX_DIFF = 120
Function VerifyResponse(raw, xsign2) Dim pos, body, sign, ts, tsStr, lastPipe, diff, utcNow, nowTs, localSign pos = InStr(raw, "|sign=") If pos = 0 Then Exit Function body = Left(raw, pos - 1) sign = Mid(raw, pos + 6) ' MD5 签名校验 localSign = LCase(Plugin.Encrypt.Md5String(body & SIGN_KEY)) If xsign2 <> "" And LCase(localSign) = LCase(xsign2) Then ' X-Sign2 头校验通过 ElseIf LCase(localSign) = LCase(sign) Then ' sign 参数校验通过 Else Exit Function End If ' 时间戳防重放(120秒) lastPipe = InStrRev(body, "|") tsStr = Mid(body, lastPipe + 1) ts = CLng(tsStr) utcNow = DateAdd("h", -8, Now()) nowTs = DateDiff("s", "1970/01/01 00:00:00", utcNow) diff = Abs(nowTs - ts) If diff > TIMESTAMP_MAX_DIFF Then Exit Function VerifyResponse = Left(body, lastPipe - 1) End Function
Function 验证卡密(card, mac) Dim http, url, tStr tStr = Year(Now) & Right("0" & Month(Now), 2) & Right("0" & Day(Now), 2) _ & Right("0" & Hour(Now), 2) & Right("0" & Minute(Now), 2) & Right("0" & Second(Now), 2) url = "https://www.keyt.cn/kami/你的用户名/check.php?card=" & card _ & "&mac=" & mac & "&app=" & GetAppName() & "&heart=1&t=" & tStr Set http = CreateObject("WinHttp.WinHttpRequest.5.1") http.Open "GET", url, False http.setRequestHeader "Cache-Control", "no-cache" http.Send 验证卡密 = http.ResponseText ' 可同时取 X-Sign2 响应头(可选) End Function
' 获取验证开关 Function GetCardSwitch() ' 请求 ?act=get_switch&app=xxx End Function ' 心跳线程(建议 50–59 秒) Function 心跳线程() Do While True biz = 验证卡密(当前卡密, 当前机器码) If Left(biz, 3) <> "ok|" Then 连续失败次数 = 连续失败次数 + 1 If 连续失败次数 >= 5 Then ExitScript Else 连续失败次数 = 0 End If Delay 50000 Loop End Function
Function TransMsg(code) Select Case code Case "activate" : TransMsg = "激活成功" Case "valid" : TransMsg = "验证通过" Case "expired" : TransMsg = "卡密已过期" Case "banned" : TransMsg = "卡密已被禁用" Case "device_mismatch" : TransMsg = "设备不匹配" Case "online_limit_reached": TransMsg = "在线设备数已满" Case Else : TransMsg = code End Select End Function
你现有的代码已经完整可用,不需要额外简化。
👉 关键点:
GetCardSwitch 判断是否开启验证验证卡密 + VerifyResponse 提示: 实际使用时请替换 你的用户名、你的签名密钥 以及 GetAppName() 等自定义函数。完整对接流程可参考 文档首页。