{"id":60825,"date":"2020-04-08T11:00:09","date_gmt":"2020-04-08T03:00:09","guid":{"rendered":"http:\/\/4563.org\/?p=60825"},"modified":"2020-04-08T11:00:09","modified_gmt":"2020-04-08T03:00:09","slug":"%e4%b8%8d%e6%87%82%e5%b0%b1%e9%97%ae%e7%b3%bb%e5%88%97go%e8%af%ad%e8%a8%80-%e9%98%bf%e9%87%8c%e4%ba%91oss%e6%9c%8d%e5%8a%a1%e5%99%a8%e5%9b%9e%e8%b0%83%e5%a4%84%e7%90%86","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=60825","title":{"rendered":"[\u4e0d\u61c2\u5c31\u95ee\u7cfb\u5217]go\u8bed\u8a00 \u963f\u91cc\u4e91OSS\u670d\u52a1\u5668\u56de\u8c03\u5904\u7406"},"content":{"rendered":"\n<p>  \t\t\t\t\t<strong>beng<\/strong>  \t\t\t\t\u5927\u4f6c\u6709\u8bdd\u8bf4 : 2020-3-23 16:24:47\t<\/p>\n<h3>[\u4e0d\u61c2\u5c31\u95ee\u7cfb\u5217]go\u8bed\u8a00 \u963f\u91cc\u4e91OSS\u670d\u52a1\u5668\u56de\u8c03\u5904\u7406<\/h3>\n<p>  \t\tRT<\/p>\n<p>  \u7528\u6237\u76f4\u4f20OSS\uff0cOSS\u8fd4\u56de\u4e0a\u4f20\u4fe1\u606f\u5230\u56de\u8c03\u670d\u52a1\u5668\u4f7f\u7528POST\u8bf7\u6c42\u3002<\/p>\n<p>  \u6211\u7528GO\u63a5\u53d7\u8bf7\u6c42\uff0c\u83b7\u53d6\u4e0a\u4f20\u7684\u6587\u4ef6\u4fe1\u606f\uff08\u6587\u4ef6\u540d\uff0c\u6587\u4ef6\u5927\u5c0f\u7b49\uff09<\/p>\n<p>  r.Header\u6ca1\u6709\u76f8\u5173\u5b57\u6bb5 <\/p>\n<p>  r.body\u8fd4\u56de\u7684\u4fe1\u606f\u8bf7\u95ee\u5982\u4f55\u83b7\u53d6callback_body\uff1f<\/p>\n<p>  func handlerRequest(w http.ResponseWriter, r *http.Request) {<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; if r.Method == &quot;POST&quot; {<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fmt.Println(&quot;nHandle Post Request&#8230;&quot;)<\/p>\n<p>  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; \/\/ Get PublicKey bytes<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; bytePublicKey, err := getPublicKey(r)<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if err != nil {<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; responseFailed(w)<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<\/p>\n<p>  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; \/\/ Get Authorization bytes : decode from Base64String<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; byteAuthorization, err := getAuthorization(r)<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if err != nil {<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; responseFailed(w)<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<\/p>\n<p>  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; \/\/ Get MD5 bytes from Newly Constructed Authrization String.<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; byteMD5, err := getMD5FromNewAuthString(r)<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if err != nil {<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; responseFailed(w)<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<\/p>\n<p>  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; \/\/ VerifySignature and response to client<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if verifySignature(bytePublicKey, byteMD5, byteAuthorization) {<\/p>\n<p>  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; \/\/ Do something you want accoding to callback_body &#8230;<\/p>\n<p>  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; \/\/ response OK : 200<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; responseSuccess(w)<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } else {<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; \/\/ response FAILED : 400<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; responseFailed(w)<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; }<br \/>  }\t\t\t  <\/p>\n","protected":false},"excerpt":{"rendered":"<p>beng \u5927\u4f6c\u6709\u8bdd\u8bf4 : 2020&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\/60825"}],"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=60825"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/60825\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=60825"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=60825"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=60825"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}