{"id":43907,"date":"2018-09-23T15:16:17","date_gmt":"2018-09-23T07:16:17","guid":{"rendered":"http:\/\/www.xyryd.com\/?p=43907"},"modified":"2019-05-23T17:33:02","modified_gmt":"2019-05-23T09:33:02","slug":"discuz-%e7%bb%8f%e5%85%b8%e4%bb%a3%e7%a0%81-php%e5%8a%a0%e5%af%86%e8%a7%a3%e5%af%86%e5%87%bd%e6%95%b0","status":"publish","type":"post","link":"http:\/\/www.xyryd.com\/43907.html","title":{"rendered":"Discuz! \u7ecf\u5178\u4ee3\u7801 PHP\u52a0\u5bc6\u89e3\u5bc6\u51fd\u6570"},"content":{"rendered":"\n

\u52a0\u5bc6\u89e3\u5bc6\u539f\u7406\u4e00\u822c\u90fd\u662f\u901a\u8fc7\u4e00\u5b9a\u7684\u52a0\u5bc6\u89e3\u5bc6\u7b97\u6cd5\uff0c\u5c06\u5bc6\u94a5\u52a0\u5165\u5230\u7b97\u6cd5\u4e2d\uff0c\u6700\u7ec8\u5f97\u5230\u52a0\u5bc6\u89e3\u5bc6\u7ed3\u679c\u3002
\u975e\u5e38\u7ed9\u529b\u7684authcode\u52a0\u5bc6\u51fd\u6570\uff0cDiscuz!\u7ecf\u5178\u4ee3\u7801\uff08\u5e26\u8be6\u89e3\uff09\uff1a<\/p>\n\n\n\n

function _authcode($string, $operation = 'DECODE', $key = 'laoji.org', $expiry = 0) {\n\/\/ \u52a8\u6001\u5bc6\u5319\u957f\u5ea6\uff0c\u76f8\u540c\u7684\u660e\u6587\u4f1a\u751f\u6210\u4e0d\u540c\u5bc6\u6587\u5c31\u662f\u4f9d\u9760\u52a8\u6001\u5bc6\u5319 \n\t$ckey_length = 4;\n\/\/ \u5bc6\u5319 \n\t$key = md5($key ? $key : UC_KEY);\n\/\/ \u5bc6\u5319a\u4f1a\u53c2\u4e0e\u52a0\u89e3\u5bc6\n\t$keya = md5(substr($key, 0, 16));\n\/\/ \u5bc6\u5319b\u4f1a\u7528\u6765\u505a\u6570\u636e\u5b8c\u6574\u6027\u9a8c\u8bc1  \n\t$keyb = md5(substr($key, 16, 16));\n\/\/ \u5bc6\u5319c\u7528\u4e8e\u53d8\u5316\u751f\u6210\u7684\u5bc6\u6587 \n\t$keyc = $ckey_length ? ($operation == 'DECODE' ? substr($string, 0, $ckey_length): substr(md5(microtime()), -$ckey_length)) : '';\n\/\/ \u53c2\u4e0e\u8fd0\u7b97\u7684\u5bc6\u5319\n\t$cryptkey = $keya.md5($keya.$keyc);\n\t$key_length = strlen($cryptkey);\n\/\/ \u660e\u6587\uff0c\u524d10\u4f4d\u7528\u6765\u4fdd\u5b58\u65f6\u95f4\u6233\uff0c\u89e3\u5bc6\u65f6\u9a8c\u8bc1\u6570\u636e\u6709\u6548\u6027\uff0c10\u523026\u4f4d\u7528\u6765\u4fdd\u5b58$keyb(\u5bc6\u5319b)\uff0c\n\/\/\u89e3\u5bc6\u65f6\u4f1a\u901a\u8fc7\u8fd9\u4e2a\u5bc6\u5319\u9a8c\u8bc1\u6570\u636e\u5b8c\u6574\u6027 \n\/\/ \u5982\u679c\u662f\u89e3\u7801\u7684\u8bdd\uff0c\u4f1a\u4ece\u7b2c$ckey_length\u4f4d\u5f00\u59cb\uff0c\u56e0\u4e3a\u5bc6\u6587\u524d$ckey_length\u4f4d\u4fdd\u5b58 \u52a8\u6001\u5bc6\u5319\uff0c\u4ee5\u4fdd\u8bc1\u89e3\u5bc6\u6b63\u786e   \n\t$string = $operation == 'DECODE' ? base64_decode(substr($string, $ckey_length)) : sprintf('%010d', $expiry ? $expiry + time() : 0).substr(md5($string.$keyb), 0, 16).$string;\n\t$string_length = strlen($string);\n?\n\t$result = '';\n\t$box = range(0, 255);\n?\n\t$rndkey = array();\n\/\/ \u4ea7\u751f\u5bc6\u5319\u7c3f \n\tfor($i = 0; $i <= 255; $i++) {\n\t\t$rndkey[$i] = ord($cryptkey[$i % $key_length]);\n\t}\n\/\/ \u7528\u56fa\u5b9a\u7684\u7b97\u6cd5\uff0c\u6253\u4e71\u5bc6\u5319\u7c3f\uff0c\u589e\u52a0\u968f\u673a\u6027\uff0c\u597d\u50cf\u5f88\u590d\u6742\uff0c\u5b9e\u9645\u4e0a\u5bf9\u5e76\u4e0d\u4f1a\u589e\u52a0\u5bc6\u6587\u7684\u5f3a\u5ea6   \n\tfor($j = $i = 0; $i < 256; $i++) {\n\t\t$j = ($j + $box[$i] + $rndkey[$i]) % 256;\n\t\t$tmp = $box[$i];\n\t\t$box[$i] = $box[$j];\n\t\t$box[$j] = $tmp;\n\t}\n\/\/ \u6838\u5fc3\u52a0\u89e3\u5bc6\u90e8\u5206   \n\tfor($a = $j = $i = 0; $i < $string_length; $i++) {\n\t\t$a = ($a + 1) % 256;\n\t\t$j = ($j + $box[$a]) % 256;\n\t\t$tmp = $box[$a];\n\t\t$box[$a] = $box[$j];\n\t\t$box[$j] = $tmp;\n\/\/ \u4ece\u5bc6\u5319\u7c3f\u5f97\u51fa\u5bc6\u5319\u8fdb\u884c\u5f02\u6216\uff0c\u518d\u8f6c\u6210\u5b57\u7b26  \n\t\t$result .= chr(ord($string[$i]) ^ ($box[($box[$a] + $box[$j]) % 256]));\n\t}\n?\n\tif($operation == 'DECODE') {\n\/\/ \u9a8c\u8bc1\u6570\u636e\u6709\u6548\u6027\uff0c\u8bf7\u770b\u672a\u52a0\u5bc6\u660e\u6587\u7684\u683c\u5f0f   \n\t\tif((substr($result, 0, 10) == 0 || substr($result, 0, 10) - time() > 0) && substr($result, 10, 16) == substr(md5(substr($result, 26).$keyb), 0, 16)) {\n\t\t\treturn substr($result, 26);\n\t\t} else {\n\t\t\t\treturn '';\n\t\t\t}\n\t} else {\n\/\/ \u628a\u52a8\u6001\u5bc6\u5319\u4fdd\u5b58\u5728\u5bc6\u6587\u91cc\uff0c\u8fd9\u4e5f\u662f\u4e3a\u4ec0\u4e48\u540c\u6837\u7684\u660e\u6587\uff0c\u751f\u4ea7\u4e0d\u540c\u5bc6\u6587\u540e\u80fd\u89e3\u5bc6\u7684\u539f\u56e0   \n\/\/ \u56e0\u4e3a\u52a0\u5bc6\u540e\u7684\u5bc6\u6587\u53ef\u80fd\u662f\u4e00\u4e9b\u7279\u6b8a\u5b57\u7b26\uff0c\u590d\u5236\u8fc7\u7a0b\u53ef\u80fd\u4f1a\u4e22\u5931\uff0c\u6240\u4ee5\u7528base64\u7f16\u7801   \n\t\treturn $keyc.str_replace('=', '', base64_encode($result));\n\t}\n?}<\/code><\/pre>\n\n\n\n

\u4f7f\u7528\u65b9\u6cd5<\/p>\n\n\n\n

$str = 'abcdef'; \n$key = 'gdd.gd'; \n$authcode =  authcode($str,'ENCODE',$key,0); \/\/\u52a0\u5bc6 \necho $authcode;\necho authcode($authcode,'DECODE',$key,0); \/\/\u89e3\u5bc6 <\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"

\u52a0\u5bc6\u89e3\u5bc6\u539f\u7406\u4e00\u822c\u90fd\u662f\u901a\u8fc7\u4e00\u5b9a\u7684\u52a0\u5bc6\u89e3\u5bc6\u7b97\u6cd5\uff0c\u5c06\u5bc6\u94a5\u52a0\u5165\u5230\u7b97\u6cd5\u4e2d\uff0c\u6700\u7ec8\u5f97\u5230\u52a0\u5bc6\u89e3\u5bc6\u7ed3\u679c\u3002\u975e\u5e38\u7ed9\u529b\u7684authcod […]<\/p>\n","protected":false},"author":1,"featured_media":43088,"comment_status":"open","ping_status":"closed","sticky":false,"template":"single-with-sidebar","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[13],"aioseo_notices":[],"_links":{"self":[{"href":"http:\/\/www.xyryd.com\/wp-json\/wp\/v2\/posts\/43907"}],"collection":[{"href":"http:\/\/www.xyryd.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.xyryd.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.xyryd.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.xyryd.com\/wp-json\/wp\/v2\/comments?post=43907"}],"version-history":[{"count":0,"href":"http:\/\/www.xyryd.com\/wp-json\/wp\/v2\/posts\/43907\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/www.xyryd.com\/wp-json\/wp\/v2\/media\/43088"}],"wp:attachment":[{"href":"http:\/\/www.xyryd.com\/wp-json\/wp\/v2\/media?parent=43907"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.xyryd.com\/wp-json\/wp\/v2\/categories?post=43907"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.xyryd.com\/wp-json\/wp\/v2\/tags?post=43907"}],"curies":[{"name":"wp","href":"http:\/\/api.w.org\/{rel}","templated":true}]}}