{"id":48705,"date":"2024-12-02T11:13:46","date_gmt":"2024-12-02T03:13:46","guid":{"rendered":"https:\/\/fwq.ai\/blog\/48705\/"},"modified":"2024-12-02T11:13:46","modified_gmt":"2024-12-02T03:13:46","slug":"golang-%e5%a6%82%e4%bd%95%e5%ae%9e%e7%8e%b0-php-%e4%b8%ad%e7%9a%84%e5%ad%97%e5%85%b8%e6%8e%92%e5%ba%8f%e3%80%81%e5%ba%8f%e5%88%97%e5%8c%96%e5%92%8c%e7%ad%be%e5%90%8d%e7%94%9f%e6%88%90%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/48705\/","title":{"rendered":"Golang \u5982\u4f55\u5b9e\u73b0 PHP \u4e2d\u7684\u5b57\u5178\u6392\u5e8f\u3001\u5e8f\u5217\u5316\u548c\u7b7e\u540d\u751f\u6210\uff1f"},"content":{"rendered":"<p><b><\/b> <\/p>\n<h1>Golang \u5982\u4f55\u5b9e\u73b0 PHP \u4e2d\u7684\u5b57\u5178\u6392\u5e8f\u3001\u5e8f\u5217\u5316\u548c\u7b7e\u540d\u751f\u6210\uff1f<\/h1>\n<p>\u6765\u5230\u7c73\u4e91\u7684\u5927\u5bb6\uff0c\u76f8\u4fe1\u90fd\u662f\u7f16\u7a0b\u5b66\u4e60\u7231\u597d\u8005\uff0c\u5e0c\u671b\u5728\u8fd9\u91cc\u5b66\u4e60\u6587\u7ae0\u76f8\u5173\u7f16\u7a0b\u77e5\u8bc6\u3002\u4e0b\u9762\u672c\u7bc7\u6587\u7ae0\u5c31\u6765\u5e26\u5927\u5bb6\u804a\u804a\u300aGolang \u5982\u4f55\u5b9e\u73b0 PHP \u4e2d\u7684\u5b57\u5178\u6392\u5e8f\u3001\u5e8f\u5217\u5316\u548c\u7b7e\u540d\u751f\u6210\uff1f\u300b\uff0c\u4ecb\u7ecd\u4e00\u4e0b\uff0c\u5e0c\u671b\u5bf9\u5927\u5bb6\u7684\u77e5\u8bc6\u79ef\u7d2f\u6709\u6240\u5e2e\u52a9\uff0c\u52a9\u529b\u5b9e\u6218\u5f00\u53d1\uff01<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241030\/17302585056721a64950777.jpg\" class=\"aligncenter\" title=\"Golang \u5982\u4f55\u5b9e\u73b0 PHP \u4e2d\u7684\u5b57\u5178\u6392\u5e8f\u3001\u5e8f\u5217\u5316\u548c\u7b7e\u540d\u751f\u6210\uff1f\u63d2\u56fe\" alt=\"Golang \u5982\u4f55\u5b9e\u73b0 PHP \u4e2d\u7684\u5b57\u5178\u6392\u5e8f\u3001\u5e8f\u5217\u5316\u548c\u7b7e\u540d\u751f\u6210\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>php\/python \u4ee3\u7801\u5728 golang \u4e2d\u7684\u8f6c\u6362<\/strong><\/p>\n<p>\u5728 php \u4e2d\uff0c\u5bf9\u5b57\u5178\u8fdb\u884c\u6392\u5e8f\u5e76\u5bf9\u5176\u8fdb\u884c\u5e8f\u5217\u5316\u4ee5\u751f\u6210\u7b7e\u540d\uff0c\u8fd9\u662f\u5e38\u89c1\u7684\u505a\u6cd5\u3002\u5728 golang \u4e2d\uff0c\u8fd9\u4e00\u8fc7\u7a0b\u53ef\u4ee5\u8fdb\u884c\u7c7b\u4f3c\u7684\u5b9e\u73b0\u3002<\/p>\n<p>\u9996\u5148\uff0c\u5bf9\u5b57\u5178\u7684\u952e\u8fdb\u884c\u6392\u5e8f\u3002<\/p>\n<pre>package main\n\nimport (\n    \"fmt\"\n    \"sort\"\n)\n\nfunc main() {\n    \/\/ \u539f\u59cb\u53c2\u6570\u5b57\u5178\n    params := map[string]string{\n        \"x\": \"\u6709\u4e2d\u6587\u6709\u7b26!@ 2\u53f7\u7a7a\u683chttp:\/\/aaa.com\",\n        \"y\": \"1\",\n        \"a\": \"{\\\"a1\\\":222,\\\"a2\\\":\\\"\\\\u4e2d\\\\u6587\\\"}\",\n    }\n\n    \/\/ \u5347\u5e8f\u6392\u5e8f key\n    keys := make([]string, 0, len(params))\n    for k := range params {\n        keys = append(keys, k)\n    }\n    sort.strings(keys)\n\n    fmt.println(keys)\n}<\/pre>\n<p>\u7136\u540e\uff0c\u62fc\u63a5\u6392\u5e8f\u540e\u7684\u53c2\u6570\u5e76\u8fdb\u884c url \u7f16\u7801\u3002<\/p>\n<pre>import (\n    \"net\/url\"\n)\n\n\/\/ ...\n\n    \/\/ \u62fc\u63a5\n    data := url.values{}\n    for _, k := range keys {\n        data.add(k, params[k])\n    }\n\n    \/\/ url \u7f16\u7801\n    encodedparams := data.encode()<\/pre>\n<p>\u6700\u540e\uff0c\u4f7f\u7528 md5 \u52a0\u5bc6\u8fde\u63a5\u5b57\u7b26\u3002<\/p>\n<pre>import (\n    \"crypto\/md5\"\n    \"encoding\/hex\"\n)\n\n\/\/ ...\n\n    \/\/ \u8fde\u63a5\u5b57\u7b26\n    signKey := \"abc\"\n    signData := encodedParams + signKey\n\n    \/\/ MD5 \u52a0\u5bc6\n    hash := md5.New()\n    hash.Write([]byte(signData))\n    bytes := hash.Sum(nil)\n\n    \/\/ \u8f6c\u6362\u4e3a\u5341\u516d\u8fdb\u5236\u5b57\u7b26\u4e32\n    sign := hex.EncodeToString(bytes)\n\n    fmt.Println(sign)<\/pre>\n<p><strong>\u6ce8\u610f\uff1a<\/strong><\/p>\n<ul>\n<li>php \u4e2d\u7684 uxxxx \u5b57\u7b26\u4e32\u5728 golang \u4e2d\u4f1a\u88ab\u8bc6\u522b\u4e3a unicode \u8f6c\u4e49\u5b57\u7b26\uff0c\u9700\u8981\u8fdb\u884c\u8f6c\u4e49\u3002<\/li>\n<li>\u4fdd\u6301\u4e0e php \u7684\u4e00\u81f4\u6027\uff0c\u9700\u8981\u5c06 json \u5b57\u7b26\u4e32\u8fdb\u884c\u8f6c\u4e49\u3002<\/li>\n<\/ul>\n<p>\u7406\u8bba\u8981\u638c\u63e1\uff0c\u5b9e\u64cd\u4e0d\u80fd\u843d\uff01\u4ee5\u4e0a\u5173\u4e8e\u300aGolang \u5982\u4f55\u5b9e\u73b0 PHP \u4e2d\u7684\u5b57\u5178\u6392\u5e8f\u3001\u5e8f\u5217\u5316\u548c\u7b7e\u540d\u751f\u6210\uff1f\u300b\u7684\u8be6\u7ec6\u4ecb\u7ecd\uff0c\u5927\u5bb6\u90fd\u638c\u63e1\u4e86\u5427\uff01\u5982\u679c\u60f3\u8981\u7ee7\u7eed\u63d0\u5347\u81ea\u5df1\u7684\u80fd\u529b\uff0c\u90a3\u4e48\u5c31\u6765\u5173\u6ce8\u7c73\u4e91\u516c\u4f17\u53f7\u5427\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Golang \u5982\u4f55\u5b9e\u73b0 PHP \u4e2d\u7684\u5b57\u5178\u6392\u5e8f\u3001\u5e8f\u5217\u5316\u548c\u7b7e\u540d\u751f\u6210\uff1f \u6765\u5230\u7c73\u4e91\u7684\u5927\u5bb6\uff0c\u76f8\u4fe1\u90fd\u662f\u7f16\u7a0b\u5b66\u4e60\u7231\u597d\u8005\uff0c\u5e0c\u671b\u5728\u8fd9\u91cc\u5b66\u4e60\u6587\u7ae0\u76f8\u5173\u7f16\u7a0b\u77e5\u8bc6\u3002\u4e0b\u9762\u672c\u7bc7\u6587\u7ae0\u5c31\u6765\u5e26\u5927\u5bb6\u804a\u804a\u300aGolang \u5982\u4f55\u5b9e\u73b0 PHP \u4e2d\u7684\u5b57\u5178\u6392\u5e8f\u3001\u5e8f\u5217\u5316\u548c\u7b7e\u540d\u751f\u6210\uff1f\u300b\uff0c\u4ecb\u7ecd\u4e00\u4e0b\uff0c\u5e0c\u671b\u5bf9\u5927\u5bb6\u7684\u77e5\u8bc6\u79ef\u7d2f\u6709\u6240\u5e2e\u52a9\uff0c\u52a9\u529b\u5b9e\u6218\u5f00\u53d1\uff01 php\/python \u4ee3\u7801\u5728 golang \u4e2d\u7684\u8f6c\u6362 \u5728 php \u4e2d\uff0c\u5bf9\u5b57\u5178\u8fdb\u884c\u6392\u5e8f\u5e76\u5bf9\u5176\u8fdb\u884c\u5e8f\u5217\u5316\u4ee5\u751f\u6210\u7b7e\u540d\uff0c\u8fd9\u662f\u5e38\u89c1\u7684\u505a\u6cd5\u3002\u5728 golang \u4e2d\uff0c\u8fd9\u4e00\u8fc7\u7a0b\u53ef\u4ee5\u8fdb\u884c\u7c7b\u4f3c\u7684\u5b9e\u73b0\u3002 \u9996\u5148\uff0c\u5bf9\u5b57\u5178\u7684\u952e\u8fdb\u884c\u6392\u5e8f\u3002 package main import ( &#8220;fmt&#8221; &#8220;sort&#8221; ) func main() { \/\/ \u539f\u59cb\u53c2\u6570\u5b57\u5178 params := map[string]string{ &#8220;x&#8221;: &#8220;\u6709\u4e2d\u6587\u6709\u7b26!@ 2\u53f7\u7a7a\u683chttp:\/\/aaa.com&#8221;, &#8220;y&#8221;: &#8220;1&#8221;, &#8220;a&#8221;: &#8220;{\\&#8221;a1\\&#8221;:222,\\&#8221;a2\\&#8221;:\\&#8221;\\\\u4e2d\\\\u6587\\&#8221;}&#8221;, } \/\/ \u5347\u5e8f\u6392\u5e8f key keys := make([]string, 0, len(params)) for k := range params { [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-48705","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/48705","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=48705"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/48705\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=48705"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=48705"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=48705"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}