{"id":127301,"date":"2020-06-06T19:16:22","date_gmt":"2020-06-06T11:16:22","guid":{"rendered":"http:\/\/4563.org\/?p=127301"},"modified":"2020-06-06T19:16:22","modified_gmt":"2020-06-06T11:16:22","slug":"go-map-%e6%8c%89%e5%ad%97%e5%85%b8%e5%8d%87%e5%ba%8f%e6%8e%92%e5%ba%8f%e5%90%8e%e8%bd%ac-json-md5-%e4%b8%8e-php-%e4%b8%8d%e4%b8%80%e8%87%b4","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=127301","title":{"rendered":"go map \u6309\u5b57\u5178\u5347\u5e8f\u6392\u5e8f\u540e\u8f6c JSON md5 \u4e0e PHP \u4e0d\u4e00\u81f4"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  go map \u6309\u5b57\u5178\u5347\u5e8f\u6392\u5e8f\u540e\u8f6c JSON md5 \u4e0e PHP \u4e0d\u4e00\u81f4               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : Nick66 <\/span>  <span><i><\/i> 10<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<p>\u6e90\u7801\u5982\u4e0b<\/p>\n<pre><code>package main  import (     \"fmt\"     \"sort\"     \"encoding\/json\"     \"crypto\/md5\"     \"encoding\/hex\"     \"bytes\" )  func main() {      params := make(map[string]string)     params[\"name\"] = \"111\"     params[\"domain\"] = \"www.baidu.com?name=1&amp;id=1\"      \/\/ \u6392\u5e8f     keys := make([]string, len(params))     i := 0     for k, _ := range params {         keys[i] = k         i++     }     sort.Strings(keys)      for _, k := range keys {         fmt.Println(k)     }      byteBuf := bytes.NewBuffer([]byte{})     encoder := json.NewEncoder(byteBuf)     \/\/ \u7279\u6b8a\u5b57\u7b26\u4e0d\u8f6c\u4e49     encoder.SetEscapeHTML(false)     err := encoder.Encode(params)     if err != nil {         panic(err)     }     data := byteBuf.String()     fmt.Println(data)     h := md5.New()     \/\/ \u4e0e php \u4e00\u81f4     h.Write([]byte(`{\"domain\":\"www.baidu.com?name=1&amp;id=1\",\"name\":\"111\"}`))     \/\/ \u4e0d\u4e00\u81f4     \/\/ h.Write([]byte(data))     fmt.Println(hex.EncodeToString(h.Sum(nil)))     \/\/ php \u7ed3\u679c\u4e3a 06820973e7b8d3acdb4763264a803620  } <\/code><\/pre>\n<\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>12<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"2075646\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : also24 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u8bf4\u4e2a\u9898\u5916\u8bdd\uff1a<br \/>\u4e5f\u4e0d\u77e5\u9053\u8c01\u5e26\u8d77\u7684\u8fd9\u79cd\u98ce\u6c14\uff0c\u7528\u8fd9\u79cd\u65b9\u5f0f\u6765\u8fdb\u884c\u68c0\u9a8c\u3002<\/p>\n<p> JSON \u5e8f\u5217\u5316\u7684\u65f6\u5019\uff0c\u662f\u5426\u6362\u884c\uff0c\u662f\u5426\u7f29\u8fdb\uff0c\u662f\u5426\u8f6c\u4e49\u90fd\u4f1a\u9020\u6210\u5e8f\u5217\u5316\u7ed3\u679c\u5b57\u7b26\u4e32\u7684\u5dee\u5f02\u3002<\/p>\n<p>\u6b63\u786e\u7684\u505a\u6cd5\u662f\u76f4\u63a5\u4f20\u8f93\u5e8f\u5217\u5316\u540e\u7684 JSON String\uff0c\u8ba1\u7b97 hash \u7684\u65f6\u5019\u4e5f\u76f4\u63a5\u9488\u5bf9\u6574\u4e2a JSON String                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"2075647\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : Nick66 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @also24 \u786e\u5b9e\u662f\u8fd9\u6837\uff0c\u73b0\u5728\u8fd9\u4e2a\u529f\u80fd\u5c31\u4e3a\u4e86\u628a\u53c2\u6570 md5 \u4e4b\u540e\u4f5c\u4e3a\u7b7e\u540d\u53c2\u6570\u7528                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"2075648\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : marquina <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             json \u5728\u6211\u8fd9\u4e2a pythoner \u773c\u91cc\u5c31\u662f\u4e00\u4e2a dict\uff0c\u6211\u4e5f\u4ece\u6765\u4e0d\u4f1a\u5bf9 json \u5e8f\u5217\u5316\u3001\u53cd\u5e8f\u5217\u5316\u65f6 key \u7684\u987a\u5e8f\u6709\u4efb\u4f55\u671f\u5f85\uff0c\u66f4\u522b\u63d0\u7b97 md5 \u8fd9\u79cd\u64cd\u4f5c\u4e86                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"2075649\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : Nick66 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @marquina \u63a5\u624b\u9879\u76ee\u7684\u65f6\u5019\u5c31\u662f\u8fd9\u6837\uff0c\u6211\u4e5f\u65e0\u6cd5\u6539\u53d8\uff0c\u53ea\u80fd\u60f3\u529e\u6cd5\u89e3\u51b3\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"2075650\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : haiyang416 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @Nick66 https:\/\/github.com\/golang\/go\/commit\/6f25f1d4c901417af1da65e41992d71c30f64f8f<\/p>\n<p>strings.Trim \u4e00\u4e0b\u3002                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"2075651\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : chinvo <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u7b7e\u540d\u7684\u6b63\u786e\u73a9\u6cd5\u662f\u5bf9 http body \u7b7e\u540d\uff0c\u7b7e\u540d\u7ed3\u679c\u653e\u5230 header \u91cc<\/p>\n<p>\u8fd9\u6837\u5c31\u4e0d\u6d89\u53ca\u6392\u5e8f\u95ee\u9898                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"2075652\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : Nick66 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @haiyang416 \u611f\u8c22\uff0c\u89e3\u51b3\u4e86\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"2075653\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : Vegetable <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             byteBuf.Bytes()<br \/>[123 34 100 111 109 97 105 110 34 58 34 119 119 119 46 98 97 105 100 117 46 99 111 109 63 110 97 109 101 61 49 38 105 100 61 49 34 44 34 110 97 109 101 34 58 34 49 49 49 34 125 10]<\/p>\n<p>\u6700\u540e\u591a\u4e86\u4e00\u4e2a 0010\uff0c\u6362\u884c\u7b26\u3002trim \u6389\u5c31\u4e00\u6837\u4e86<br \/>h.Write(bytes.TrimSpace(byteBuf.Bytes()))<br \/>fmt.Println(hex.EncodeToString(h.Sum(nil)))<br \/>06820973e7b8d3acdb4763264a803620                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"2075654\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : janxin <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @also24 \u539f\u56e0\u5728\u4e8e API \u7f51\u5173\u53ef\u80fd\u6700\u5f00\u59cb\u6ca1\u652f\u6301\u8fd9\u73a9\u610f                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"2075655\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : also24 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @janxin #9 <br \/>\u90a3\u4e5f\u53ef\u4ee5\u901a\u8fc7\u5bf9\u6574\u4e2a http body \u8fdb\u884c hash\uff0c\u7b7e\u540d\u653e\u8fdb header \u7684\u65b9\u5f0f\u6765\u5904\u7406\u3002<\/p>\n<p>\u6216\u8005\u5c06\u539f\u6709 body \u6574\u4e2a\u5305\u88c5\u8fdb\u4e00\u4e2a JSON String \u5b57\u6bb5\u6765\u89e3\u51b3\uff0c\u90fd\u53ef\u4ee5\u907f\u514d\u5b57\u6bb5\u4e71\u5e8f\u6216\u5e8f\u5217\u5316\u65b9\u5f0f\u4e0d\u7edf\u4e00\u9020\u6210\u7684\u95ee\u9898\u3002                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"2075656\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : shawndev <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             prettyprinted \u8bbe\u7f6e\u4e0d\u540c                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"2075657\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : jifengg <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u6211\u5c31\u559c\u6b22\u5bf9\u6574\u4e2a body \u7b7e\u540d\u7684\u8fd9\u79cd\uff0c\u4e0d\u7528\u7ba1\u4ec0\u4e48\u53c2\u6570\u6392\u5e8f\u7684\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>go map \u6309\u5b57\u5178\u5347\u5e8f\u6392\u5e8f\u540e\u8f6c &hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/127301"}],"collection":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=127301"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/127301\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=127301"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=127301"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=127301"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}