{"id":1269,"date":"2020-11-26T15:53:40","date_gmt":"2020-11-26T07:53:40","guid":{"rendered":"https:\/\/www.siediyer.cn\/?p=1269"},"modified":"2020-11-26T15:53:40","modified_gmt":"2020-11-26T07:53:40","slug":"%e5%88%86%e4%ba%ab%e5%87%a0%e7%a7%8d%e5%a5%bd%e7%94%a8%e7%9a%84php%e8%87%aa%e5%ae%9a%e4%b9%89%e5%8a%a0%e5%af%86%e5%87%bd%e6%95%b0%e5%8f%af%e9%80%86-%e4%b8%8d%e5%8f%af%e9%80%86","status":"publish","type":"post","link":"https:\/\/www.siediyer.cn\/?p=1269","title":{"rendered":"\u5206\u4eab\u51e0\u79cd\u597d\u7528\u7684PHP\u81ea\u5b9a\u4e49\u52a0\u5bc6\u51fd\u6570(\u53ef\u9006\/\u4e0d\u53ef\u9006)"},"content":{"rendered":"<p><strong>\u4e00\u3001\u7b2c\u4e00\u79cd\u9488\u5bf9\u4e8eID\u7684\u53ef\u9006\u52a0\u5bc6\u51fd\u6570\uff0c\u4e5f\u53ef\u4ee5\u7528\u4f5c\u4e8e\u9080\u8bf7\u7801\u4e4b\u7c7b\u7684\uff0c\u89e3\u5bc6\u540e\u7684\u6570\u636e\u6bd4\u8f83\u7b80\u5355<\/strong><\/p>\n<p>\u793a\u4f8b\uff1alockcode(28)=\u300b000X unlockcode(&#8216;000X&#8217;)=\u300b28<\/p>\n<pre class=\"lang:default decode:true \">\/\/\u52a0\u5bc6\u51fd\u6570\r\nfunction lockcode($code) {\r\n static $source_string = 'E5FCDG3HQA4B1NOPIJ2RSTUV67MWX89KLYZ';\r\n $num = $code;\r\n $code = '';\r\n while ( $num &gt; 0) {\r\n  $mod = $num % 35;\r\n  $num = ($num - $mod) \/ 35;\r\n  $code = $source_string[$mod].$code;\r\n }\r\n if(empty($code[3]))\r\n  $code = str_pad($code,4,'0',STR_PAD_LEFT);\r\n return $code;\r\n}\r\n\/\/\u89e3\u5bc6\u51fd\u6570\r\nfunction unlockcode($code) {\r\n static $source_string = 'E5FCDG3HQA4B1NOPIJ2RSTUV67MWX89KLYZ';\r\n if (strrpos($code, '0') !== false)\r\n  $code = substr($code, strrpos($code, '0')+1);\r\n $len = strlen($code);\r\n $code = strrev($code);\r\n $num = 0;\r\n for ($i=0; $i &lt; $len; $i++) {\r\n  $num += strpos($source_string, $code[$i]) * pow(35, $i);\r\n }\r\n return $num;\r\n}<\/pre>\n<p><strong>\u4e8c\u3001\u7b2c\u4e8c\u79cd\u662f\u52a0\u5bc6\u51fd\u6570\u662f\u6211\u5728\u7f51\u4e0a\u641c\u7d22\u6765\u7684\uff0c\u5f88\u597d\u7528\uff0c\u53ef\u9006\u52a0\u5bc6\uff0c\u652f\u6301\u76d0\u503c\u53c2\u6570<\/strong><\/p>\n<p>\u793a\u4f8b\uff1aencrypt(&#8216;abcd&#8217;,&#8217;1234&#8242;)=\u300bnkiV93IfJ decrypt(&#8216;nkiV93IfJ&#8217;,&#8217;1234&#8242;)=\u300babcd<\/p>\n<pre class=\"lang:default decode:true \">\/\/\u52a0\u5bc6\u51fd\u6570 \r\nfunction encrypt($data,$key='CHENI'){ \r\n $chars = \"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789\"; \r\n $nh = rand(0,64); \r\n $ch = $chars[$nh]; \r\n $mdKey = md5($key.$ch); \r\n $mdKey = substr($mdKey,$nh%8, $nh%8+7); \r\n $data= base64_encode($data); \r\n $tmp = ''; \r\n $i=0;$j=0;$k = 0; \r\n for ($i=0; $i&lt;strlen($data); $i++) { \r\n  $k = $k == strlen($mdKey) ? 0 : $k; \r\n  $j = ($nh+strpos($chars,$data[$i])+ord($mdKey[$k++]))%64; \r\n  $tmp .= $chars[$j]; \r\n } \r\n return urlencode($ch.$tmp); \r\n}\r\n\/\/\u89e3\u5bc6\u51fd\u6570 \r\nfunction decrypt($data,$key='CHENI'){\r\n $txt = urldecode($data); \r\n $chars = \"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789\"; \r\n $ch = $txt[0]; \r\n $nh = strpos($chars,$ch); \r\n $mdKey = md5($key.$ch); \r\n $mdKey = substr($mdKey,$nh%8, $nh%8+7); \r\n $txt = substr($txt,1); \r\n $tmp = ''; \r\n $i=0;$j=0; $k = 0; \r\n for ($i=0; $i&lt;strlen($txt); $i++) { \r\n  $k = $k == strlen($mdKey) ? 0 : $k; \r\n  $j = strpos($chars,$txt[$i])-$nh - ord($mdKey[$k++]); \r\n  while ($j&lt;0) $j+=64; \r\n  $tmp .= $chars[$j]; \r\n } \r\n return base64_decode($tmp); \r\n}<\/pre>\n<p><strong>\u4e09\u3001\u7b2c\u4e09\u79cd\u8ddf\u4e0a\u9762\u7684\u6bd4\u8f83\u7c7b\u4f3c\uff0c\u4e5f\u652f\u6301\u76d0\u503c\u53c2\u6570<\/strong><\/p>\n<p>\u793a\u4f8b\uff1aencrypt(&#8216;abcd&#8217;,&#8217;1234&#8242;)=\u300bmZPHxw== decrypt(&#8216;mZPHxw==&#8217;,&#8217;1234&#8242;)=\u300babcd<\/p>\n<pre class=\"lang:default decode:true \">function encrypt($data, $key) { \r\n $char=\"\";\r\n $str=\"\";\r\n $key = md5($key); \r\n $x  = 0; \r\n $len = strlen($data); \r\n $l  = strlen($key); \r\n for ($i = 0; $i &lt; $len; $i++) { \r\n  if ($x == $l) { $x = 0; } \r\n  $char .= $key{$x}; \r\n  $x++; \r\n } \r\n for ($i = 0; $i &lt; $len; $i++){ \r\n  $str .= chr(ord($data{$i}) + (ord($char{$i})) % 256); \r\n } \r\n return base64_encode($str); \r\n} \r\nfunction decrypt($data, $key) { \r\n $key = md5($key); \r\n $x = 0; \r\n $data = base64_decode($data); \r\n $len = strlen($data); \r\n $l = strlen($key); \r\n for ($i = 0; $i &lt; $len; $i++) { \r\n  if ($x == $l){ $x = 0;} \r\n  $char .= substr($key, $x, 1); \r\n  $x++; \r\n } \r\n for ($i = 0; $i &lt; $len; $i++){ \r\n  if (ord(substr($data, $i, 1)) &lt; ord(substr($char, $i, 1))){ \r\n   $str .= chr((ord(substr($data, $i, 1)) + 256) - ord(substr($char, $i, 1))); \r\n  }else{ \r\n   $str .= chr(ord(substr($data, $i, 1)) - ord(substr($char, $i, 1))); \r\n  } \r\n } \r\n return $str; \r\n}<\/pre>\n<p><strong>\u56db\u3001\u8fd9\u4e2a\u662f\u6211\u7528\u8fc7\u6700\u597d\u7528\u7684\u4e00\u4e2a\u4e86\uff0cdiscuz\u4e2d\u4f7f\u7528\u7684\u52a0\u5bc6\u89e3\u5bc6\u7b97\u6cd5<\/strong><\/p>\n<pre class=\"lang:default decode:true \">\/\/\u52a0\u5bc6\u7b97\u6cd5\r\n function authcode($string,$key='',$operation=false,$expiry=0){\r\n  $ckey_length = 4;\r\n  $key = md5($key ? $key : DEFAULT_KEYS);\r\n  $keya = md5(substr($key, 0, 16));\r\n  $keyb = md5(substr($key, 16, 16));\r\n  $keyc = $ckey_length ? ($operation? substr($string, 0, $ckey_length):substr(md5(microtime()), -$ckey_length)) : '';\r\n  $cryptkey = $keya.md5($keya.$keyc);\r\n  $key_length = strlen($cryptkey);\r\n  $string = $operation? base64_decode(substr($string, $ckey_length)) :\r\n  sprintf('%010d', $expiry ? $expiry + time() : 0).substr(md5($string.$keyb), 0, 16).$string;\r\n  $string_length = strlen($string);\r\n  $result = '';\r\n  $box = range(0, 255);\r\n  $rndkey = array();\r\n  for($i = 0; $i &lt;= 255; $i++) {\r\n   $rndkey[$i] = ord($cryptkey[$i % $key_length]);\r\n  }\r\n  for($j = $i = 0; $i &lt; 256; $i++) {\r\n   $j = ($j + $box[$i] + $rndkey[$i]) % 256;\r\n   $tmp = $box[$i];\r\n   $box[$i] = $box[$j];\r\n   $box[$j] = $tmp;\r\n  }\r\n  for($a = $j = $i = 0; $i &lt; $string_length; $i++) {\r\n   $a = ($a + 1) % 256;\r\n   $j = ($j + $box[$a]) % 256;\r\n   $tmp = $box[$a];\r\n   $box[$a] = $box[$j];\r\n   $box[$j] = $tmp;\r\n   $result .= chr(ord($string[$i]) ^ ($box[($box[$a] + $box[$j]) % 256]));\r\n  }\r\n  if($operation) {\r\n   if((substr($result, 0, 10) == 0 || substr($result, 0, 10) - time() &gt; 0) &amp;&amp;\r\n    substr($result, 10, 16) == substr(md5(substr($result, 26).$keyb), 0, 16)) {\r\n    return substr($result, 26);\r\n   } else {\r\n    return '';\r\n   }\r\n  } else {\r\n   return $keyc.str_replace('=', '', base64_encode($result));\r\n  }\r\n }\r\n echo authcode('123456','key');\r\n echo '&lt;br&gt;';\r\n echo authcode('7d49kn9k07uSBZvha8as+\/qm4UoLfpy88PFg12glPeDtlzc','key',true);<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e00\u3001\u7b2c\u4e00\u79cd\u9488\u5bf9\u4e8eID\u7684\u53ef\u9006\u52a0\u5bc6\u51fd\u6570\uff0c\u4e5f\u53ef\u4ee5\u7528\u4f5c\u4e8e\u9080\u8bf7\u7801\u4e4b\u7c7b\u7684\uff0c\u89e3\u5bc6\u540e\u7684\u6570\u636e\u6bd4\u8f83\u7b80\u5355 \u793a\u4f8b\uff1alockcode(2 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[],"class_list":["post-1269","post","type-post","status-publish","format-standard","hentry","category-php"],"_links":{"self":[{"href":"https:\/\/www.siediyer.cn\/index.php?rest_route=\/wp\/v2\/posts\/1269","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.siediyer.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.siediyer.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.siediyer.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.siediyer.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1269"}],"version-history":[{"count":1,"href":"https:\/\/www.siediyer.cn\/index.php?rest_route=\/wp\/v2\/posts\/1269\/revisions"}],"predecessor-version":[{"id":1270,"href":"https:\/\/www.siediyer.cn\/index.php?rest_route=\/wp\/v2\/posts\/1269\/revisions\/1270"}],"wp:attachment":[{"href":"https:\/\/www.siediyer.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1269"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.siediyer.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1269"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.siediyer.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1269"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}