{"id":68771,"date":"2020-04-19T20:02:25","date_gmt":"2020-04-19T12:02:25","guid":{"rendered":"http:\/\/4563.org\/?p=68771"},"modified":"2020-04-19T20:02:25","modified_gmt":"2020-04-19T12:02:25","slug":"%e5%9b%bd%e9%99%85-%e9%98%bf%e9%87%8c%e4%ba%91-%e6%b5%81%e9%87%8f%e5%8c%85-%e8%84%9a%e6%9c%ac-%e7%9b%91%e6%8e%a7-%e8%87%aa%e5%8a%a8%e5%85%b3%e6%9c%ba","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=68771","title":{"rendered":"\u56fd\u9645 \u963f\u91cc\u4e91 \u6d41\u91cf\u5305 \u811a\u672c \u76d1\u63a7 \u81ea\u52a8\u5173\u673a"},"content":{"rendered":"\n<p>  \t\t\t\t\t<strong>mxy123h<\/strong>  \t\t\t\t\u5927\u4f6c\u6709\u8bdd\u8bf4 : \t<\/p>\n<h3>\u56fd\u9645 \u963f\u91cc\u4e91 \u6d41\u91cf\u5305 \u811a\u672c \u76d1\u63a7 \u81ea\u52a8\u5173\u673a<\/h3>\n<p>  \t\t \u672c\u5e16\u6700\u540e\u7531 mxy123h \u4e8e 2020-4-19 20:31 \u7f16\u8f91 <\/p>\n<p> &lt;?php<br \/>  error_reporting(0);<br \/>  &nbsp; &nbsp; function percentEncode($str){<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;\/\/ \u4f7f\u7528urlencode\u7f16\u7801\u540e\uff0c\u5c06&quot;+&quot;,&quot;*&quot;,&quot;%7E&quot;\u505a\u66ff\u6362\u5373\u6ee1\u8db3ECS API\u89c4\u5b9a\u7684\u7f16\u7801\u89c4\u8303<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;$res = urlencode($str);<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;$res = preg_replace(&#8216;\/+\/&#8217;, &#8216;%20&#8217;, $res);<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;$res = preg_replace(&#8216;\/*\/&#8217;, &#8216;%2A&#8217;, $res);<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;$res = preg_replace(&#8216;\/%7E\/&#8217;, &#8216;~&#8217;, $res);<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;return $res;<br \/>  &nbsp; &nbsp; }<br \/>  &nbsp; &nbsp; function computeSignature($parameters, $accessKeySecret){<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;\/\/ \u5c06\u53c2\u6570Key\u6309\u5b57\u5178\u987a\u5e8f\u6392\u5e8f<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;ksort($parameters);<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;\/\/ \u751f\u6210\u89c4\u8303\u5316\u8bf7\u6c42\u5b57\u7b26\u4e32<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;$canonicalizedQueryString = &#8221;;<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;foreach($parameters as $key =&gt; $value)<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;{<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;$canonicalizedQueryString .= &#8216;&amp;&#8217; . percentEncode($key)<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; . &#8216;=&#8217; . percentEncode($value);<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;}<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;\/\/ \u751f\u6210\u7528\u4e8e\u8ba1\u7b97\u7b7e\u540d\u7684\u5b57\u7b26\u4e32 stringToSign<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;$stringToSign = &#8216;GET&amp;%2F&amp;&#8217; . percentencode(substr($canonicalizedQueryString, 1));<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;\/\/ \u8ba1\u7b97\u7b7e\u540d\uff0c\u6ce8\u610faccessKeySecret\u540e\u9762\u8981\u52a0\u4e0a\u5b57\u7b26&#8217;&amp;&#8217;<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;$signature = base64_encode(hash_hmac(&#8216;sha1&#8217;, $stringToSign, $accessKeySecret . &#8216;&amp;&#8217;, true));<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;return $signature;<br \/>  &nbsp; &nbsp; }<br \/>  &nbsp; &nbsp; function get_action($data,$Version,$host){<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;date_default_timezone_set(&quot;GMT&quot;);<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;$dateTimeFormat = &#8216;Y-m-dTH:i:sZ&#8217;;<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;$publicdata = array(<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;\/\/ \u516c\u5171\u53c2\u6570<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&#8216;Format&#8217; =&gt; &#8216;JSON&#8217;,<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&#8216;Version&#8217; =&gt; $Version,<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&#8216;AccessKeyId&#8217; =&gt; AccessKey ID,<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&#8216;SignatureVersion&#8217; =&gt; &#8216;1.0&#8217;,<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&#8216;SignatureMethod&#8217; =&gt; &#8216;HMAC-SHA1&#8217;,<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&#8216;SignatureNonce&#8217;=&gt; uniqid(),<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&#8216;Timestamp&#8217; =&gt; date($dateTimeFormat),<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&#8216;TimeStamp&#8217; =&gt; date($dateTimeFormat)<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;);<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;$data = array_merge($publicdata,$data);<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;$data[&#8216;Signature&#8217;] = computeSignature($data, Access Key Secret);<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;$ch = curl_init();<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;curl_setopt($ch, CURLOPT_URL, $host . http_build_query($data));<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;curl_setopt($ch, CURLOPT_HEADER, 0);<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;$res = curl_exec($ch);<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;date_default_timezone_set(&#8216;PRC&#8217;);<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; \/\/echo $res;<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;return $res;<br \/>  &nbsp; &nbsp; }<br \/>  &nbsp; &nbsp; &nbsp; &nbsp;\/\/\u6d41\u91cfJSON<br \/>  &nbsp; &nbsp; function get_(){<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;$data = array(<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#8216;Action&#8217; =&gt; &#8216;QueryResourcePackageInstances&#8217;,<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#8216;RegionId&#8217; =&gt; &#8216;ap-southeast-1&#8217;<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; );<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;<br \/>  &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; $res = (string)get_action($data,&#8217;2017-12-14&#8242;,&#8217;https:\/\/business.ap-southeast-1.aliyuncs.com\/?&#8217;);<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; \/\/echo $res;<br \/>  &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $jsonarray = json_decode($res,true);<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; if($jsonarray[&#8216;Message&#8217;]==&#8217;Successful!&#8217;){<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; echo $jsonarray[&#8216;Data&#8217;][&#8216;Instances&#8217;][&#8216;Instance&#8217;][&#8216;RemainingAmount&#8217;];<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; if($jsonarray[&#8216;Data&#8217;][&#8216;Instances&#8217;][&#8216;Instance&#8217;][&#8216;RemainingAmount&#8217;]&lt;=1120){<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; StopInstance();<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; }<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;}<br \/>  &nbsp; &nbsp; }<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; function StopInstance(){<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;$data = array(<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#8216;Action&#8217; =&gt; &#8216;StopInstance&#8217;,<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#8216;InstanceId&#8217; =&gt; \u673a\u5668ID,<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#8216;ForceStop&#8217; =&gt;&quot;true&quot;,<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#8216;StoppedMode&#8217; =&gt; &quot;keepcharging&quot;,<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#8216;ConfirmStop&#8217; =&gt; &quot;false&quot;<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; );<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;$res = (string)get_action($data,&#8217;2014-05-26&#8242;,&#8217;https:\/\/ecs.aliyuncs.com\/?&#8217;);<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; echo $res;<br \/>  &nbsp; &nbsp; }<br \/>  &nbsp; &nbsp; &nbsp; &nbsp; get_();&nbsp; &nbsp; <br \/>  ?&gt;<\/p>\n<p>  \u81ea\u884c\u66f4\u6539 \u7528\u6237AccessKey \u5730\u533a \u673a\u5668ID\t\t\t  <\/p>\n","protected":false},"excerpt":{"rendered":"<p>mxy123h \u5927\u4f6c\u6709\u8bdd\u8bf4 : \u56fd&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\/68771"}],"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=68771"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/68771\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=68771"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=68771"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=68771"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}