{"id":2049,"date":"2023-04-01T21:10:10","date_gmt":"2023-04-01T13:10:10","guid":{"rendered":"https:\/\/www.appblog.cn\/?p=2049"},"modified":"2023-04-07T06:06:37","modified_gmt":"2023-04-06T22:06:37","slug":"id-verification-algorithm","status":"publish","type":"post","link":"https:\/\/www.appblog.cn\/index.php\/2023\/04\/01\/id-verification-algorithm\/","title":{"rendered":"\u8eab\u4efd\u8bc1\u9a8c\u8bc1\u7b97\u6cd5"},"content":{"rendered":"<h2>18\u4f4d\u8eab\u4efd\u8bc1\u53f7\u7801\u7ed3\u6784<\/h2>\n<p>\u516c\u6c11\u8eab\u4efd\u8bc1\u53f7\u7801\u662f\u7279\u5f81\u7ec4\u5408\u7801\uff0c\u7531\u5341\u4e03\u4f4d\u6570\u5b57\u672c\u4f53\u7801\u548c\u4e00\u4f4d\u6821\u9a8c\u7801\u7ec4\u6210\u3002<\/p>\n<p>\u6392\u5217\u987a\u5e8f\u4ece\u5de6\u81f3\u53f3\u4f9d\u6b21\u4e3a\uff1a6\u4f4d\u6570\u5b57\u5730\u5740\u7801\uff0c8\u4f4d\u6570\u5b57\u51fa\u751f\u65e5\u671f\u7801\uff0c3\u4f4d\u6570\u5b57\u987a\u5e8f\u7801\u548c1\u4f4d\u6821\u9a8c\u7801\u3002<\/p>\n<p><!-- more --><\/p>\n<ol>\n<li>\n<p><strong>\u5730\u5740\u7801<\/strong>\uff1a\u8868\u793a\u7f16\u7801\u5bf9\u8c61\u5e38\u4f4f\u6237\u53e3\u6240\u5728\u53bf(\u5e02\u3001\u65d7\u3001\u533a)\u7684\u884c\u653f\u533a\u57df\u5212\u5206\u4ee3\u7801\uff0c\u6309GB\/T2260\u7684\u89c4\u5b9a\u6267\u884c\u3002<\/p>\n<\/li>\n<li>\n<p><strong>\u51fa\u751f\u65e5\u671f\u7801<\/strong>\uff1a\u8868\u793a\u7f16\u7801\u5bf9\u8c61\u51fa\u751f\u7684\u5e74\u3001\u6708\u3001\u65e5\uff0c\u6309GB\/T7408\u7684\u89c4\u5b9a\u6267\u884c\uff0c\u5e74\u3001\u6708\u3001\u65e5\u4ee3\u7801\u4e4b\u95f4\u4e0d\u7528\u5206\u9694\u7b26\u3002<\/p>\n<\/li>\n<li>\n<p><strong>\u987a\u5e8f\u7801<\/strong>\uff1a\u8868\u793a\u5728\u540c\u4e00\u5730\u5740\u7801\u6240\u6807\u8bc6\u7684\u533a\u57df\u8303\u56f4\u5185\uff0c\u5bf9\u540c\u5e74\u3001\u540c\u6708\u3001\u540c\u65e5\u51fa\u751f\u7684\u4eba\u7f16\u5b9a\u7684\u987a\u5e8f\u53f7\uff0c\u987a\u5e8f\u7801\u7684\u5947\u6570\u5206\u914d\u7ed9\u7537\u6027\uff0c\u5076\u6570\u5206\u914d\u7ed9\u5973\u6027\u3002<\/p>\n<\/li>\n<li>\n<p><strong>\u6821\u9a8c\u7801<\/strong><\/p>\n<\/li>\n<\/ol>\n<h2>\u6821\u9a8c\u7801\u8ba1\u7b97\u6b65\u9aa4<\/h2>\n<ul>\n<li>(1) 17\u4f4d\u6570\u5b57\u672c\u4f53\u7801\u52a0\u6743\u6c42\u548c\u516c\u5f0f<\/li>\n<\/ul>\n<p><code>S = Sum(Ai * Wi), i = 0, \u2026 , 16<\/code> \uff0c\u5148\u5bf9\u524d17\u4f4d\u6570\u5b57\u7684\u6743\u6c42\u548c<\/p>\n<p>Ai: \u8868\u793a\u7b2ci\u4f4d\u7f6e\u4e0a\u7684\u8eab\u4efd\u8bc1\u53f7\u7801\u6570\u5b57\u503c(0~9)<\/p>\n<p>Wi: <code>7 9 10 5 8 4 2 1 6 3 7 9 10 5 8 4 2<\/code> \uff08\u8868\u793a\u7b2ci\u4f4d\u7f6e\u4e0a\u7684\u52a0\u6743\u56e0\u5b50\uff09<\/p>\n<ul>\n<li>(2) \u8ba1\u7b97\u6a21<\/li>\n<\/ul>\n<p><code>Y = mod(S, 11)<\/code><\/p>\n<ul>\n<li>(3) \u6839\u636e\u6a21\uff0c\u67e5\u627e\u5f97\u5230\u5bf9\u5e94\u7684\u6821\u9a8c\u7801<\/li>\n<\/ul>\n<table>\n<thead>\n<tr>\n<th style=\"text-align: center;\"><\/th>\n<th style=\"text-align: center;\"><\/th>\n<th style=\"text-align: center;\"><\/th>\n<th style=\"text-align: center;\"><\/th>\n<th style=\"text-align: center;\"><\/th>\n<th style=\"text-align: center;\"><\/th>\n<th style=\"text-align: center;\"><\/th>\n<th style=\"text-align: center;\"><\/th>\n<th style=\"text-align: center;\"><\/th>\n<th style=\"text-align: center;\"><\/th>\n<th style=\"text-align: center;\"><\/th>\n<th style=\"text-align: center;\"><\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"text-align: center;\">\u6a21\u503cY<\/td>\n<td style=\"text-align: center;\">0<\/td>\n<td style=\"text-align: center;\">1<\/td>\n<td style=\"text-align: center;\">2<\/td>\n<td style=\"text-align: center;\">3<\/td>\n<td style=\"text-align: center;\">4<\/td>\n<td style=\"text-align: center;\">5<\/td>\n<td style=\"text-align: center;\">6<\/td>\n<td style=\"text-align: center;\">7<\/td>\n<td style=\"text-align: center;\">8<\/td>\n<td style=\"text-align: center;\">9<\/td>\n<td style=\"text-align: center;\">10<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">\u6821\u9a8c\u7801<\/td>\n<td style=\"text-align: center;\">1<\/td>\n<td style=\"text-align: center;\">0<\/td>\n<td style=\"text-align: center;\">X<\/td>\n<td style=\"text-align: center;\">9<\/td>\n<td style=\"text-align: center;\">8<\/td>\n<td style=\"text-align: center;\">7<\/td>\n<td style=\"text-align: center;\">6<\/td>\n<td style=\"text-align: center;\">7<\/td>\n<td style=\"text-align: center;\">4<\/td>\n<td style=\"text-align: center;\">3<\/td>\n<td style=\"text-align: center;\">2<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>JavaScript\u6821\u9a8c\u7b97\u6cd5\u5b9e\u4f8b<\/h2>\n<pre><code class=\"language-javascript\">var validateID = function (id) {\n  id = id.replace(\/^\\s*|\\s*$\/g, &#039;&#039;)\n  id = id.replace(\/x\/g, &#039;X&#039;)\n  var city = {11: &#039;\u5317\u4eac&#039;, 12: &#039;\u5929\u6d25&#039;, 13: &#039;\u6cb3\u5317&#039;, 14: &#039;\u5c71\u897f&#039;, 15: &#039;\u5185\u8499\u53e4&#039;, 21: &#039;\u8fbd\u5b81&#039;, 22: &#039;\u5409\u6797&#039;, 23: &#039;\u9ed1\u9f99\u6c5f &#039;, 31: &#039;\u4e0a\u6d77&#039;, 32: &#039;\u6c5f\u82cf&#039;, 33: &#039;\u6d59\u6c5f&#039;, 34: &#039;\u5b89\u5fbd&#039;, 35: &#039;\u798f\u5efa&#039;, 36: &#039;\u6c5f\u897f&#039;, 37: &#039;\u5c71\u4e1c&#039;, 41: &#039;\u6cb3\u5357&#039;, 42: &#039;\u6e56\u5317 &#039;, 43: &#039;\u6e56\u5357&#039;, 44: &#039;\u5e7f\u4e1c&#039;, 45: &#039;\u5e7f\u897f&#039;, 46: &#039;\u6d77\u5357&#039;, 50: &#039;\u91cd\u5e86&#039;, 51: &#039;\u56db\u5ddd&#039;, 52: &#039;\u8d35\u5dde&#039;, 53: &#039;\u4e91\u5357&#039;, 54: &#039;\u897f\u85cf &#039;, 61: &#039;\u9655\u897f&#039;, 62: &#039;\u7518\u8083&#039;, 63: &#039;\u9752\u6d77&#039;, 64: &#039;\u5b81\u590f&#039;, 65: &#039;\u65b0\u7586&#039;, 71: &#039;\u53f0\u6e7e&#039;, 81: &#039;\u9999\u6e2f&#039;, 82: &#039;\u6fb3\u95e8&#039;}\n  if (!id || !\/^\\d{6}(18|19|20)?\\d{2}(0[1-9]|1[012])(0[1-9]|[12]\\d|3[01])\\d{3}(\\d|X)$\/i.test(id)) {\n    return false\n  }\n  if (!city[id.substring(0, 2)]) {\n    return false\n  }\n  if (id.length === 18) {\n    var idArr = id.split(&#039;&#039;)\n    var factor = [ 7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2 ]\n    var parity = [ &#039;1&#039;, &#039;0&#039;, &#039;X&#039;, &#039;9&#039;, &#039;8&#039;, &#039;7&#039;, &#039;6&#039;, &#039;5&#039;, &#039;4&#039;, &#039;3&#039;, &#039;2&#039; ]\n    var sum = 0\n    for (var i = 0; i &lt; 17; i++) {\n      sum += idArr[i] * factor[i]\n    }\n    if (parity[sum % 11] !== idArr[17]) {\n      return false\n    }\n  }\n  return true\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>18\u4f4d\u8eab\u4efd\u8bc1\u53f7\u7801\u7ed3\u6784 \u516c\u6c11\u8eab\u4efd\u8bc1\u53f7\u7801\u662f\u7279\u5f81\u7ec4\u5408\u7801\uff0c\u7531\u5341\u4e03\u4f4d\u6570\u5b57\u672c\u4f53\u7801\u548c\u4e00\u4f4d\u6821\u9a8c\u7801\u7ec4\u6210\u3002 \u6392\u5217\u987a\u5e8f\u4ece\u5de6\u81f3\u53f3\u4f9d\u6b21\u4e3a [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[44],"tags":[],"class_list":["post-2049","post","type-post","status-publish","format-standard","hentry","category-data-structure-algorithm"],"_links":{"self":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/2049","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/comments?post=2049"}],"version-history":[{"count":0,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/2049\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/media?parent=2049"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/categories?post=2049"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/tags?post=2049"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}