{"id":28298,"date":"2020-02-07T14:24:58","date_gmt":"2020-02-07T06:24:58","guid":{"rendered":"http:\/\/4563.org\/?p=28298"},"modified":"2020-02-07T14:24:58","modified_gmt":"2020-02-07T06:24:58","slug":"%e7%99%be%e5%ba%a6%e4%ba%91%e5%8a%a0%e9%80%9f%e7%9a%84api%e7%9c%9f%e9%9a%be%e7%94%a8%e3%80%82","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=28298","title":{"rendered":"\u767e\u5ea6\u4e91\u52a0\u901f\u7684api\u771f\u96be\u7528\u3002"},"content":{"rendered":"\n<p>  \t\t\t\t\t<strong>yaoruisheng<\/strong>  \t\t\t\t\u5927\u4f6c\u6709\u8bdd\u8bf4 : 2020-1-2 14:32:31\t<\/p>\n<h3>\u767e\u5ea6\u4e91\u52a0\u901f\u7684api\u771f\u96be\u7528\u3002<\/h3>\n<p>  \t\t \u672c\u5e16\u6700\u540e\u7531 yaoruisheng \u4e8e 2020-1-2 14:46 \u7f16\u8f91 <\/p>\n<p> &lt;?php<br \/>  baidu_cache_purge(1);<br \/>  function get_permalink($postid) {<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; return &quot;https:\/\/www.example.com&quot;;<br \/>  }<\/p>\n<p>  function baidu_cache_purge($postid) {<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; $url = &#8216;https:\/\/api.su.baidu.com\/v31\/yjs\/zones\/5ddcbff1ffdc7f0fe2a58bb5\/purge_cache&#8217;;<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; $headers = array(<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#8216;files&#8217; =&gt; get_permalink($postid),<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#8216;X-Auth-Access-Key&#8217; =&gt; &#8216;mdfzr2txy3dx8cpsop1ktbdfg0empqg0&#8217;,<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#8216;X-Auth-Nonce&#8217; =&gt; random(),<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#8216;X-Auth-Path-Info&#8217; =&gt; &#8216;v31\/yjs\/zones\/5ddcbff1ffdc7f0fe2a58bb5\/purge_cache&#8217;,<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#8216;X-Auth-Signature-Method&#8217; =&gt; &#8216;HMAC-SHA1&#8217;,<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#8216;X-Auth-Timestamp&#8217; =&gt; time(),<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; );<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; <br \/>  &nbsp; &nbsp; &nbsp; &nbsp; $purgeurl = array(<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#8216;files&#8217; =&gt; get_permalink($postid)<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; );<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; $postdata = json_encode($purgeurl);<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; $signed = build_sign(&#8217;36ca1f918b8584aebccf48984eef992d&#8217;,array_merge($headers,$purgeurl));<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; $headers[&#8216;X-Auth-Sign&#8217;] = $signed;<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; $ch = curl_init();<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; curl_setopt($ch, CURLOPT_URL, $url);<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 20);<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata);<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; $f = curl_exec($ch);<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; curl_close($ch);<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; echo $f;<br \/>  }<\/p>\n<p>  function build_sign($secret_key , $all_params) {<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; ksort($all_params);<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; foreach( $all_params as $key=&gt;$value) {<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $str[] = $key .&#8217;=&#8217;. $value;<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; }<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; $str = implode(&#8216;&amp;&#8217;,$str);<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; return base64_encode(hash_hmac(&#8216;sha1&#8217;, $str, $secret_key));<br \/>  }<\/p>\n<p>  function random($length = 32, $type = &#8216;string&#8217;, $convert = 0) {<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; $config = array(<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#8216;number&#8217; =&gt; &#8216;1234567890&#8217;,<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#8216;letter&#8217; =&gt; &#8216;abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ&#8217;,<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#8216;string&#8217; =&gt; &#8216;abcdefghjkmnpqrstuvwxyzABCDEFGHJKMNPQRSTUVWXYZ23456789&#8217;,<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#8216;all&#8217; =&gt; &#8216;abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890&#8217;<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; );<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; if (!isset($config[$type]))<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $type = &#8216;string&#8217;;<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; $string = $config[$type];<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; $code = &#8221;;<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; $strlen = strlen($string) &#8211; 1;<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; for ($i = 0; $i &lt; $length; $i++) {<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $code .= $string{mt_rand(0, $strlen)};<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; }<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; if (!empty($convert)) {<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $code = ($convert &gt; 0) ? strtoupper($code) : strtolower($code);<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; }<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; return $code;<br \/>  }<br \/>  ?&gt;<\/p>\n<p>  \u8fd9\u6bb5\u4ee3\u7801 \u59cb\u7ec8\u663e\u793a\u7b7e\u540d\u9519\u8bef\u3002\u3002\u3002\u6211\u662f\u6309\u7740\u6587\u6863\u6765\u7684\uff0c\u65e2\u7136\u641e\u4e0d\u5b9a\uff0c\u65e0\u8bed\u3002<\/p>\n<p>  https:\/\/su.baidu.com\/agency\/api.html#\/7_kaifazhinan\/2_APIcankao-NEW\/1_jieruxuzhi\/1.7_qianmingsuanfashuoming.md<\/p>\n<p>  \u603b\u7b97\u627e\u5230\u4e86\u4e00\u4e2aphp\u7684demo\u4e86\u3002\u3002\u3002<\/p>\n<p>  https:\/\/su.baidu.com\/agency\/api.html#\/7_kaifazhinan\/2_APIcankao-NEW\/1_jieruxuzhi\/1.8_jieruDEMO.md\t\t\t\t<\/p>\n<p>  \t\t\t\t\t<strong>wangjianjilei<\/strong>  \t\t\t\t\u5927\u4f6c\u6709\u8bdd\u8bf4 : 2020-1-2 14:41:35\t<\/p>\n<h3><\/h3>\n<p>  \t\t\u767e\u5ea6\u7684\u4e1c\u897f\u2026\u2026\u6d6a\u8d39\u65f6\u95f4\u2026\u2026\t\t\t  <\/p>\n","protected":false},"excerpt":{"rendered":"<p>yaoruisheng \u5927\u4f6c\u6709\u8bdd\u8bf4&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\/28298"}],"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=28298"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/28298\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=28298"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=28298"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=28298"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}