From cadb529588b0dc5b29008b134fc5896fbe52fd5b Mon Sep 17 00:00:00 2001 From: cssxsh <32539286+cssxsh@users.noreply.github.com> Date: Sat, 12 Feb 2022 20:47:19 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=BA=E7=94=9F=E6=88=90=E7=9A=84=20IMEI=20?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=A0=A1=E9=AA=8C=E4=BD=8D=20(#1855)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: luhn * fix: China Country Code 86 * fix: China Country Code 86 * fix: China Country Code 86 --- .../src/commonMain/kotlin/utils/DeviceInfo.kt | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/mirai-core-api/src/commonMain/kotlin/utils/DeviceInfo.kt b/mirai-core-api/src/commonMain/kotlin/utils/DeviceInfo.kt index d19e7136e..af9bb6922 100644 --- a/mirai-core-api/src/commonMain/kotlin/utils/DeviceInfo.kt +++ b/mirai-core-api/src/commonMain/kotlin/utils/DeviceInfo.kt @@ -152,10 +152,28 @@ public class DeviceInfo( wifiBSSID = "02:00:00:00:00:00".toByteArray(), wifiSSID = "".toByteArray(), imsiMd5 = getRandomByteArray(16, random).md5(), - imei = getRandomIntString(15, random), + imei = "86${getRandomIntString(12, random)}".let { it + luhn(it) }, apn = "wifi".toByteArray() ) } + + /** + * 计算 imei 校验位 + */ + private fun luhn(imei: String): Int { + var odd = false + val zero = '0' + val sum = imei.sumOf { char -> + odd = !odd + if (odd) { + char.code - zero.code + } else { + val s = (char.code - zero.code) * 2 + s % 10 + s / 10 + } + } + return (10 - sum % 10) % 10 + } } /**