陈德本 8 år sedan
förälder
incheckning
8bde17685d
3 ändrade filer med 316 tillägg och 163 borttagningar
  1. 70 136
      .idea/workspace.xml
  2. 32 27
      App/Script/Controller/Server.php
  3. 214 0
      Library/Curl.php

+ 70 - 136
.idea/workspace.xml

@@ -2,7 +2,9 @@
 <project version="4">
   <component name="ChangeListManager">
     <list default="true" id="d417c7e2-9370-4a4d-828f-09be06adcd69" name="Default" comment="dns">
+      <change afterPath="$PROJECT_DIR$/Library/Curl.php" afterDir="false" />
       <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
+      <change beforePath="$PROJECT_DIR$/App/Script/Controller/Server.php" beforeDir="false" afterPath="$PROJECT_DIR$/App/Script/Controller/Server.php" afterDir="false" />
     </list>
     <option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
     <option name="SHOW_DIALOG" value="false" />
@@ -25,26 +27,26 @@
       <usages-collector id="statistics.file.extensions.open">
         <counts>
           <entry key="json" value="4" />
-          <entry key="php" value="27" />
+          <entry key="php" value="28" />
         </counts>
       </usages-collector>
       <usages-collector id="statistics.file.types.open">
         <counts>
           <entry key="JSON" value="4" />
-          <entry key="PHP" value="27" />
+          <entry key="PHP" value="28" />
         </counts>
       </usages-collector>
       <usages-collector id="statistics.file.extensions.edit">
         <counts>
           <entry key="json" value="44" />
-          <entry key="php" value="1346" />
+          <entry key="php" value="1596" />
           <entry key="txt" value="6" />
         </counts>
       </usages-collector>
       <usages-collector id="statistics.file.types.edit">
         <counts>
           <entry key="JSON" value="44" />
-          <entry key="PHP" value="1346" />
+          <entry key="PHP" value="1596" />
           <entry key="PLAIN_TEXT" value="6" />
         </counts>
       </usages-collector>
@@ -66,8 +68,8 @@
       <file pinned="false" current-in-tab="true">
         <entry file="file://$PROJECT_DIR$/App/Script/Controller/Server.php">
           <provider selected="true" editor-type-id="text-editor">
-            <state relative-caret-position="488">
-              <caret line="83" column="48" selection-start-line="83" selection-start-column="48" selection-end-line="83" selection-end-column="48" />
+            <state relative-caret-position="477">
+              <caret line="84" column="48" lean-forward="true" selection-start-line="84" selection-start-column="48" selection-end-line="84" selection-end-column="48" />
               <folding>
                 <element signature="e#136#155#0#PHP" expanded="true" />
               </folding>
@@ -75,6 +77,15 @@
           </provider>
         </entry>
       </file>
+      <file pinned="false" current-in-tab="false">
+        <entry file="file://$PROJECT_DIR$/Library/Curl.php">
+          <provider selected="true" editor-type-id="text-editor">
+            <state relative-caret-position="-1566">
+              <caret line="14" column="35" selection-start-line="14" selection-start-column="35" selection-end-line="14" selection-end-column="35" />
+            </state>
+          </provider>
+        </entry>
+      </file>
       <file pinned="false" current-in-tab="false">
         <entry file="file://$PROJECT_DIR$/vendor/jamesryanbell/cloudflare/src/CloudFlare/Zone/Dns.php">
           <provider selected="true" editor-type-id="text-editor">
@@ -87,10 +98,10 @@
       <file pinned="false" current-in-tab="false">
         <entry file="file://$PROJECT_DIR$/App/Api/Controller/Ping.php">
           <provider selected="true" editor-type-id="text-editor">
-            <state relative-caret-position="576">
-              <caret line="37" column="21" selection-start-line="37" selection-start-column="21" selection-end-line="37" selection-end-column="21" />
+            <state relative-caret-position="209">
+              <caret line="11" column="31" lean-forward="true" selection-start-line="11" selection-start-column="31" selection-end-line="11" selection-end-column="31" />
               <folding>
-                <element signature="e#133#164#0#PHP" expanded="true" />
+                <element signature="e#6#91#0#PHP" expanded="true" />
               </folding>
             </state>
           </provider>
@@ -105,15 +116,6 @@
           </provider>
         </entry>
       </file>
-      <file pinned="false" current-in-tab="false">
-        <entry file="file://$PROJECT_DIR$/App/Api/Package/Database/File.php">
-          <provider selected="true" editor-type-id="text-editor">
-            <state relative-caret-position="171">
-              <caret line="9" column="8" selection-start-line="9" selection-start-column="8" selection-end-line="9" selection-end-column="8" />
-            </state>
-          </provider>
-        </entry>
-      </file>
       <file pinned="false" current-in-tab="false">
         <entry file="file://$PROJECT_DIR$/App/Api/Controller/Aip.php">
           <provider selected="true" editor-type-id="text-editor">
@@ -192,7 +194,6 @@
   <component name="IdeDocumentHistory">
     <option name="CHANGED_PATHS">
       <list>
-        <option value="$PROJECT_DIR$/Library/AipOcr.php" />
         <option value="$PROJECT_DIR$/Config/Postgres/Core.php" />
         <option value="$PROJECT_DIR$/Frame/Package/Database/Medoo.php" />
         <option value="$PROJECT_DIR$/Frame/Package/Database/Postgres.php" />
@@ -242,6 +243,7 @@
         <option value="$PROJECT_DIR$/App/Api/Package/Database/File.php" />
         <option value="$PROJECT_DIR$/App/Api/Package/Database/Server.php" />
         <option value="$PROJECT_DIR$/App/Api/Controller/Ping.php" />
+        <option value="$PROJECT_DIR$/Library/Curl.php" />
         <option value="$PROJECT_DIR$/App/Script/Controller/Server.php" />
       </list>
     </option>
@@ -341,89 +343,7 @@
             <path>
               <item name="sphinx" type="b2602c69:ProjectViewProjectNode" />
               <item name="sphinx" type="462c0819:PsiDirectoryNode" />
-              <item name="App" type="462c0819:PsiDirectoryNode" />
-            </path>
-            <path>
-              <item name="sphinx" type="b2602c69:ProjectViewProjectNode" />
-              <item name="sphinx" type="462c0819:PsiDirectoryNode" />
-              <item name="App" type="462c0819:PsiDirectoryNode" />
-              <item name="Api" type="462c0819:PsiDirectoryNode" />
-            </path>
-            <path>
-              <item name="sphinx" type="b2602c69:ProjectViewProjectNode" />
-              <item name="sphinx" type="462c0819:PsiDirectoryNode" />
-              <item name="App" type="462c0819:PsiDirectoryNode" />
-              <item name="Api" type="462c0819:PsiDirectoryNode" />
-              <item name="Controller" type="462c0819:PsiDirectoryNode" />
-            </path>
-            <path>
-              <item name="sphinx" type="b2602c69:ProjectViewProjectNode" />
-              <item name="sphinx" type="462c0819:PsiDirectoryNode" />
-              <item name="App" type="462c0819:PsiDirectoryNode" />
-              <item name="Api" type="462c0819:PsiDirectoryNode" />
-              <item name="Package" type="462c0819:PsiDirectoryNode" />
-            </path>
-            <path>
-              <item name="sphinx" type="b2602c69:ProjectViewProjectNode" />
-              <item name="sphinx" type="462c0819:PsiDirectoryNode" />
-              <item name="App" type="462c0819:PsiDirectoryNode" />
-              <item name="Api" type="462c0819:PsiDirectoryNode" />
-              <item name="Package" type="462c0819:PsiDirectoryNode" />
-              <item name="Database" type="462c0819:PsiDirectoryNode" />
-            </path>
-            <path>
-              <item name="sphinx" type="b2602c69:ProjectViewProjectNode" />
-              <item name="sphinx" type="462c0819:PsiDirectoryNode" />
-              <item name="App" type="462c0819:PsiDirectoryNode" />
-              <item name="Script" type="462c0819:PsiDirectoryNode" />
-            </path>
-            <path>
-              <item name="sphinx" type="b2602c69:ProjectViewProjectNode" />
-              <item name="sphinx" type="462c0819:PsiDirectoryNode" />
-              <item name="App" type="462c0819:PsiDirectoryNode" />
-              <item name="Script" type="462c0819:PsiDirectoryNode" />
-              <item name="Controller" type="462c0819:PsiDirectoryNode" />
-            </path>
-            <path>
-              <item name="sphinx" type="b2602c69:ProjectViewProjectNode" />
-              <item name="sphinx" type="462c0819:PsiDirectoryNode" />
-              <item name="Config" type="462c0819:PsiDirectoryNode" />
-            </path>
-            <path>
-              <item name="sphinx" type="b2602c69:ProjectViewProjectNode" />
-              <item name="sphinx" type="462c0819:PsiDirectoryNode" />
-              <item name="Config" type="462c0819:PsiDirectoryNode" />
-              <item name="MySQL" type="462c0819:PsiDirectoryNode" />
-            </path>
-            <path>
-              <item name="sphinx" type="b2602c69:ProjectViewProjectNode" />
-              <item name="sphinx" type="462c0819:PsiDirectoryNode" />
-              <item name="Config" type="462c0819:PsiDirectoryNode" />
-              <item name="Postgres" type="462c0819:PsiDirectoryNode" />
-            </path>
-            <path>
-              <item name="sphinx" type="b2602c69:ProjectViewProjectNode" />
-              <item name="sphinx" type="462c0819:PsiDirectoryNode" />
-              <item name="Config" type="462c0819:PsiDirectoryNode" />
-              <item name="Sphinx" type="462c0819:PsiDirectoryNode" />
-            </path>
-            <path>
-              <item name="sphinx" type="b2602c69:ProjectViewProjectNode" />
-              <item name="sphinx" type="462c0819:PsiDirectoryNode" />
-              <item name="env" type="462c0819:PsiDirectoryNode" />
-            </path>
-            <path>
-              <item name="sphinx" type="b2602c69:ProjectViewProjectNode" />
-              <item name="sphinx" type="462c0819:PsiDirectoryNode" />
-              <item name="env" type="462c0819:PsiDirectoryNode" />
-              <item name="product" type="462c0819:PsiDirectoryNode" />
-            </path>
-            <path>
-              <item name="sphinx" type="b2602c69:ProjectViewProjectNode" />
-              <item name="sphinx" type="462c0819:PsiDirectoryNode" />
-              <item name="env" type="462c0819:PsiDirectoryNode" />
-              <item name="product" type="462c0819:PsiDirectoryNode" />
-              <item name="mysql" type="462c0819:PsiDirectoryNode" />
+              <item name="Library" type="462c0819:PsiDirectoryNode" />
             </path>
           </expand>
           <select />
@@ -441,9 +361,9 @@
   </component>
   <component name="RecentsManager">
     <key name="CopyFile.RECENT_KEYS">
+      <recent name="$PROJECT_DIR$/Library" />
       <recent name="$PROJECT_DIR$/App/Api/Package/Database" />
       <recent name="$PROJECT_DIR$/Config" />
-      <recent name="$PROJECT_DIR$/Library" />
       <recent name="$PROJECT_DIR$/App/Script/Controller" />
       <recent name="$PROJECT_DIR$/App/Script" />
     </key>
@@ -554,7 +474,7 @@
       <workItem from="1526268446293" duration="12711000" />
       <workItem from="1528527970342" duration="845000" />
       <workItem from="1529074202261" duration="35000" />
-      <workItem from="1535705721105" duration="9568000" />
+      <workItem from="1535705721105" duration="10614000" />
     </task>
     <task id="LOCAL-00001" summary="telegram">
       <created>1519284784104</created>
@@ -696,7 +616,21 @@
       <option name="project" value="LOCAL" />
       <updated>1535729557826</updated>
     </task>
-    <option name="localTasksCounter" value="21" />
+    <task id="LOCAL-00021" summary="dns">
+      <created>1535729990196</created>
+      <option name="number" value="00021" />
+      <option name="presentableId" value="LOCAL-00021" />
+      <option name="project" value="LOCAL" />
+      <updated>1535729990196</updated>
+    </task>
+    <task id="LOCAL-00022" summary="dns">
+      <created>1535730178766</created>
+      <option name="number" value="00022" />
+      <option name="presentableId" value="LOCAL-00022" />
+      <option name="project" value="LOCAL" />
+      <updated>1535730178766</updated>
+    </task>
+    <option name="localTasksCounter" value="23" />
     <servers />
   </component>
   <component name="TestHistory">
@@ -714,7 +648,7 @@
     </history-entry>
   </component>
   <component name="TimeTrackingManager">
-    <option name="totallyTimeSpent" value="161729000" />
+    <option name="totallyTimeSpent" value="162775000" />
   </component>
   <component name="TodoView">
     <todo-panel id="selected-file">
@@ -732,19 +666,19 @@
       <window_info content_ui="combo" id="Project" order="0" weight="0.25035766" />
       <window_info id="Structure" order="1" weight="0.25" />
       <window_info id="Favorites" order="2" side_tool="true" />
-      <window_info anchor="bottom" id="Database Changes" show_stripe_button="false" />
-      <window_info anchor="bottom" id="Message" order="0" />
-      <window_info anchor="bottom" id="Find" order="1" weight="0.3292683" />
-      <window_info anchor="bottom" id="Run" order="2" weight="0.35873982" />
-      <window_info anchor="bottom" id="Debug" order="3" weight="0.399361" />
-      <window_info anchor="bottom" id="Cvs" order="4" weight="0.25" />
-      <window_info anchor="bottom" id="Inspection" order="5" weight="0.4" />
-      <window_info anchor="bottom" id="TODO" order="6" sideWeight="0.49574015" weight="0.3292683" />
-      <window_info anchor="bottom" id="Docker" order="7" />
-      <window_info anchor="bottom" id="Version Control" order="8" />
-      <window_info anchor="bottom" id="Terminal" order="9" weight="0.32957748" />
-      <window_info anchor="bottom" id="Event Log" order="10" sideWeight="0.5042598" side_tool="true" weight="0.3292683" />
-      <window_info anchor="bottom" id="Messages" order="11" />
+      <window_info anchor="bottom" id="Database Changes" order="0" show_stripe_button="false" />
+      <window_info anchor="bottom" id="Message" order="1" />
+      <window_info anchor="bottom" id="Find" order="2" weight="0.3292683" />
+      <window_info anchor="bottom" id="Run" order="3" weight="0.35873982" />
+      <window_info anchor="bottom" id="Debug" order="4" weight="0.399361" />
+      <window_info anchor="bottom" id="Cvs" order="5" weight="0.25" />
+      <window_info anchor="bottom" id="Inspection" order="6" weight="0.4" />
+      <window_info anchor="bottom" id="TODO" order="7" sideWeight="0.49574015" weight="0.3292683" />
+      <window_info anchor="bottom" id="Docker" order="8" />
+      <window_info anchor="bottom" id="Version Control" order="9" />
+      <window_info anchor="bottom" id="Terminal" order="10" weight="0.32957748" />
+      <window_info anchor="bottom" id="Event Log" order="11" sideWeight="0.5042598" side_tool="true" weight="0.3292683" />
+      <window_info anchor="bottom" id="Messages" order="12" />
       <window_info anchor="right" id="Commander" order="0" weight="0.4" />
       <window_info anchor="right" id="Ant Build" order="1" weight="0.25" />
       <window_info anchor="right" content_ui="combo" id="Hierarchy" order="2" weight="0.25" />
@@ -753,7 +687,7 @@
       <window_info anchor="right" id="Database" order="5" />
     </layout>
     <layout-to-restore>
-      <window_info content_ui="combo" id="Project" order="0" visible="true" weight="0.25035766" />
+      <window_info active="true" content_ui="combo" id="Project" order="0" visible="true" weight="0.25035766" />
       <window_info id="Structure" order="1" weight="0.25" />
       <window_info id="Favorites" order="2" side_tool="true" />
       <window_info anchor="bottom" id="Database Changes" order="0" show_stripe_button="false" />
@@ -766,7 +700,7 @@
       <window_info anchor="bottom" id="TODO" order="7" sideWeight="0.49574015" weight="0.3292683" />
       <window_info anchor="bottom" id="Docker" order="8" />
       <window_info anchor="bottom" id="Version Control" order="9" />
-      <window_info active="true" anchor="bottom" id="Terminal" order="10" visible="true" weight="0.32957748" />
+      <window_info anchor="bottom" id="Terminal" order="10" visible="true" weight="0.32957748" />
       <window_info anchor="bottom" id="Event Log" order="11" sideWeight="0.5042598" side_tool="true" weight="0.3292683" />
       <window_info anchor="bottom" id="Messages" order="12" />
       <window_info anchor="right" id="Commander" order="0" weight="0.4" />
@@ -815,13 +749,6 @@
     </breakpoint-manager>
   </component>
   <component name="editorHistoryManager">
-    <entry file="file://$PROJECT_DIR$/index.php">
-      <provider selected="true" editor-type-id="text-editor">
-        <state relative-caret-position="38">
-          <caret line="2" column="43" selection-start-line="2" selection-start-column="43" selection-end-line="2" selection-end-column="43" />
-        </state>
-      </provider>
-    </entry>
     <entry file="jar://$APPLICATION_HOME_DIR$/plugins/php/lib/php.jar!/stubs/Core/Core.php">
       <provider selected="true" editor-type-id="text-editor">
         <state relative-caret-position="290">
@@ -1137,27 +1064,34 @@
         </state>
       </provider>
     </entry>
+    <entry file="file://$PROJECT_DIR$/vendor/jamesryanbell/cloudflare/src/CloudFlare/Zone/Dns.php">
+      <provider selected="true" editor-type-id="text-editor">
+        <state relative-caret-position="83">
+          <caret line="102" column="20" selection-start-line="102" selection-start-column="20" selection-end-line="102" selection-end-column="20" />
+        </state>
+      </provider>
+    </entry>
     <entry file="file://$PROJECT_DIR$/App/Api/Controller/Ping.php">
       <provider selected="true" editor-type-id="text-editor">
-        <state relative-caret-position="576">
-          <caret line="37" column="21" selection-start-line="37" selection-start-column="21" selection-end-line="37" selection-end-column="21" />
+        <state relative-caret-position="209">
+          <caret line="11" column="31" lean-forward="true" selection-start-line="11" selection-start-column="31" selection-end-line="11" selection-end-column="31" />
           <folding>
-            <element signature="e#133#164#0#PHP" expanded="true" />
+            <element signature="e#6#91#0#PHP" expanded="true" />
           </folding>
         </state>
       </provider>
     </entry>
-    <entry file="file://$PROJECT_DIR$/vendor/jamesryanbell/cloudflare/src/CloudFlare/Zone/Dns.php">
+    <entry file="file://$PROJECT_DIR$/Library/Curl.php">
       <provider selected="true" editor-type-id="text-editor">
-        <state relative-caret-position="83">
-          <caret line="102" column="20" selection-start-line="102" selection-start-column="20" selection-end-line="102" selection-end-column="20" />
+        <state relative-caret-position="-1566">
+          <caret line="14" column="35" selection-start-line="14" selection-start-column="35" selection-end-line="14" selection-end-column="35" />
         </state>
       </provider>
     </entry>
     <entry file="file://$PROJECT_DIR$/App/Script/Controller/Server.php">
       <provider selected="true" editor-type-id="text-editor">
-        <state relative-caret-position="488">
-          <caret line="83" column="48" selection-start-line="83" selection-start-column="48" selection-end-line="83" selection-end-column="48" />
+        <state relative-caret-position="477">
+          <caret line="84" column="48" lean-forward="true" selection-start-line="84" selection-start-column="48" selection-end-line="84" selection-end-column="48" />
           <folding>
             <element signature="e#136#155#0#PHP" expanded="true" />
           </folding>

+ 32 - 27
App/Script/Controller/Server.php

@@ -13,6 +13,7 @@ use Cloudflare\Api;
 use Cloudflare\Zone\Dns;
 use PhpLife\App\Script\Controller;
 use PhpLife\App\Api\Package\Database\Server as ServerTable;
+use PhpLife\Library\Curl;
 
 class Server extends Controller
 {
@@ -22,10 +23,10 @@ class Server extends Controller
      */
     protected function main()
     {
-        $recode_data=[];
+        $recode_data = [];
         $i = 0;
-        $key="093fcd440ed453c2689c42150bdb7d5dbc4fb";
-        $zone_identifier="89a0fe0d09762c557fd0c7799efb1c9a";
+        $key = "093fcd440ed453c2689c42150bdb7d5dbc4fb";
+        $zone_identifier = "89a0fe0d09762c557fd0c7799efb1c9a";
         $client = new Api('chendeben@qq.com', $key);
         $dns = new Dns($client);
 //        $id=$dns->create($zone_identifier, "A", "test.97admin.com", "127.0.0.1");
@@ -38,51 +39,55 @@ class Server extends Controller
 
         while (true) {
             $data = ServerTable::select();
-            $str=[];
+            $str = [];
+            $ips = [];
             foreach ($data as $val) {
                 $ip = $val['ip'];
                 $port = $val['port'];
                 $status = $this->check($ip, $port);
                 if ($status == 1) {
-                    $str[]=date("Y-m-d H:i:s")."\t\t".$ip . "\t可用\r\n";
+                    $ips[] = "【" . $val['domain'] . "】" . $ip . "可用";
+                    $str[] = date("Y-m-d H:i:s") . "\t\t" . $ip . "\t可用\r\n";
 
                 }
 //                if ($val['status'] != $status) {
                 ServerTable::update(['status' => $status, "last_check" => date("Y-m-d H:i:s")], ['id' => $val['id']]);
-                if ($status==1){
-                    if (!$recode_data[$val['domain']]){
-                        $recode=$dns->list_records($zone_identifier,null,$val['domain']);
-                        $recode=json_decode(json_encode($recode),true);
-                        if ($recode['result']){
-                            $result=$recode['result'][0];
-                            $recode_data[$val['domain']]=$result;
+                if ($status == 1) {
+                    if (!$recode_data[$val['domain']]) {
+                        $recode = $dns->list_records($zone_identifier, null, $val['domain']);
+                        $recode = json_decode(json_encode($recode), true);
+                        if ($recode['result']) {
+                            $result = $recode['result'][0];
+                            $recode_data[$val['domain']] = $result;
                         }
                     }
-                    $result=$recode_data[$val['domain']];
+                    $result = $recode_data[$val['domain']];
 //                    print_r($result);
 //                    die();
-                    if (!$result){
-                        $str[]= date("Y-m-d H:i:s")."\t\t"."域名记录【".$val['domain']."】不存在,正在建立\r\n";
-                        $recode=$dns->create($zone_identifier, "A", $val['domain'], $val['ip']);
-                        $recode=json_decode(json_encode($recode),true);
-                        if ($recode['result']){
-                            $result=$recode['result'][0];
-                            $recode_data[$val['domain']]=$result;
-                            $str[]= date("Y-m-d H:i:s")."\t\t"."域名记录【".$val['domain']."】新建成功\r\n";
+                    if (!$result) {
+                        $str[] = date("Y-m-d H:i:s") . "\t\t" . "域名记录【" . $val['domain'] . "】不存在,正在建立\r\n";
+                        $recode = $dns->create($zone_identifier, "A", $val['domain'], $val['ip']);
+                        $recode = json_decode(json_encode($recode), true);
+                        if ($recode['result']) {
+                            $result = $recode['result'][0];
+                            $recode_data[$val['domain']] = $result;
+                            $str[] = date("Y-m-d H:i:s") . "\t\t" . "域名记录【" . $val['domain'] . "】新建成功\r\n";
                         }
 
                     }
-                    if ($result['content']!=$val['ip']){
-                        $str[]= date("Y-m-d H:i:s")."\t\t"."域名记录【".$val['domain']."】与数据库不一致,正在更新\r\n";
-                        $dns->update($zone_identifier, $result['id'],"A",$val['domain'],$val['ip']);
+                    if ($result['content'] != $val['ip']) {
+                        $str[] = date("Y-m-d H:i:s") . "\t\t" . "域名记录【" . $val['domain'] . "】与数据库不一致,正在更新\r\n";
+                        $dns->update($zone_identifier, $result['id'], "A", $val['domain'], $val['ip']);
                     }
                 }
 //                }
             }
-            $str[]= "第" . $i . "次执行完毕\r\n\r\n";
+            $str[] = "第" . $i . "次执行完毕\r\n\r\n";
             echo implode("\r\n", $str);
-            file_put_contents("/root/update.txt", implode("\r\n", $str),FILE_APPEND);
-            file_put_contents("/root/dns.txt", var_export($recode_data));
+
+            Curl::post("https://www.phplife.net/ping.php", ['str' => implode("\r\n", $ips)]);
+//            file_put_contents("/root/update.txt", implode("\r\n", $str),FILE_APPEND);
+//            file_put_contents("/root/dns.txt", var_export($recode_data));
             $i++;
             sleep(60);
         }

+ 214 - 0
Library/Curl.php

@@ -0,0 +1,214 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: chendeben
+ * Date: 2018/8/17
+ * Time: 下午5:26
+ */
+
+namespace PhpLife\Library;
+
+use PhpLife\Frame\Logger;
+
+class Curl
+{
+    private static $cookie_file = "curl_cookie.log";
+
+
+    /**
+     * CURL-get方式获取数据
+     * @param string $url URL
+     * @param string $proxy 是否代理
+     * @param int $timeout 请求时间
+     * @param array $header header信息  array('Host: api.kingdee.meitushop.com' )设置请求的host
+     * @return string
+     */
+    public static function get($url, $proxy = null, $timeout = 10, $header = null)
+    {
+        if (!$url)
+            return false;
+        $ssl = stripos($url, 'https://') === 0 ? true : false;
+        $curl = curl_init();
+        if (!is_null($proxy))
+            curl_setopt($curl, CURLOPT_PROXY, $proxy);
+        curl_setopt($curl, CURLOPT_URL, $url);
+        if ($ssl) {
+            curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0); // 对认证证书来源的检查
+            curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 1); // 从证书中检查SSL加密算法是否存在
+        }
+        $cookie_file = self::$cookie_file;
+        curl_setopt($curl, CURLOPT_COOKIEJAR, $cookie_file); //连接结束后保存cookie信息的文件。
+        curl_setopt($curl, CURLOPT_COOKIEFILE, $cookie_file); //包含cookie数据的文件名,cookie文件的格式可以是Netscape格式,或者只是纯HTTP头部信息存入文件。
+        curl_setopt($curl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']); //在HTTP请求中包含一个"User-Agent: "头的字符串。
+        curl_setopt($curl, CURLOPT_HEADER, 0); //启用时会将头文件的信息作为数据流输出。
+        curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1); //启用时会将服务器服务器返回的"Location: "放在header中递归的返回给服务器,使用CURLOPT_MAXREDIRS可以限定递归返回的数量。
+        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); //文件流形式
+        curl_setopt($curl, CURLOPT_TIMEOUT, $timeout); //设置cURL允许执行的最长秒数。
+        if (is_array($header))
+            curl_setopt($curl, CURLOPT_HTTPHEADER, $header); //设置请求的Header
+
+        $content = curl_exec($curl);
+        $curl_errno = curl_errno($curl);
+        if ($curl_errno > 0) {
+            Logger::setlog($error = sprintf("curl error=%s, errno=%d.", curl_error($curl), $curl_errno));
+            curl_close($curl);
+            return false;
+        }
+//        $this->http_code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
+        curl_close($curl);
+        return $content;
+    }
+
+    /**
+     * CURL-post方式获取数据
+     * @param string $url URL
+     * @param array $data POST数据
+     * @param string $proxy 是否代理
+     * @param int $timeout 请求时间
+     * @param array $header header信息
+     * @return string
+     */
+    public static function post($url, $data, $proxy = null, $timeout = 10, $header = null)
+    {
+        if (!$url)
+            return false;
+//        if ($data) {
+//            $data = http_build_query($data);
+//        }
+        $ssl = stripos($url, 'https://') === 0 ? true : false;
+        $curl = curl_init();
+        if (!is_null($proxy))
+            curl_setopt($curl, CURLOPT_PROXY, $proxy);
+        curl_setopt($curl, CURLOPT_URL, $url);
+        if ($ssl) {
+            curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0); // 对认证证书来源的检查
+            curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 1); // 从证书中检查SSL加密算法是否存在
+        }
+        $cookie_file = self::$cookie_file;
+        curl_setopt($curl, CURLOPT_COOKIEJAR, $cookie_file); //连接结束后保存cookie信息的文件。
+        curl_setopt($curl, CURLOPT_COOKIEFILE, $cookie_file); //包含cookie数据的文件名,cookie文件的格式可以是Netscape格式,或者只是纯HTTP头部信息存入文件。
+        curl_setopt($curl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']); //在HTTP请求中包含一个"User-Agent: "头的字符串。
+        curl_setopt($curl, CURLOPT_HEADER, 0); //启用时会将头文件的信息作为数据流输出。
+        curl_setopt($curl, CURLOPT_POST, true); //发送一个常规的Post请求
+        curl_setopt($curl, CURLOPT_POSTFIELDS, $data); //Post提交的数据包
+        curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1); //启用时会将服务器服务器返回的"Location: "放在header中递归的返回给服务器,使用CURLOPT_MAXREDIRS可以限定递归返回的数量。
+        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); //文件流形式
+        curl_setopt($curl, CURLOPT_TIMEOUT, $timeout); //设置cURL允许执行的最长秒数。
+        if (is_array($header))
+            curl_setopt($curl, CURLOPT_HTTPHEADER, $header); //设置请求的Header
+
+        $content = curl_exec($curl);
+        $curl_errno = curl_errno($curl);
+        if ($curl_errno > 0) {
+            Logger::setlog($error = sprintf("curl error=%s, errno=%d.", curl_error($curl), $curl_errno));
+            curl_close($curl);
+            return false;
+        }
+//        $this->http_code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
+        curl_close($curl);
+        return $content;
+    }
+
+    /**
+     * CURL-put方式获取数据
+     * @param string $url URL
+     * @param array $data POST数据
+     * @param string $proxy 是否代理
+     * @param int $timeout 请求时间
+     * @param array $header header信息
+     * @return string
+     */
+    public static function put($url, $data, $proxy = null, $timeout = 10, $header = null)
+    {
+        if (!$url)
+            return false;
+        if ($data) {
+            $data = http_build_query($data);
+        }
+        $ssl = stripos($url, 'https://') === 0 ? true : false;
+        $curl = curl_init();
+        if (!is_null($proxy))
+            curl_setopt($curl, CURLOPT_PROXY, $proxy);
+        curl_setopt($curl, CURLOPT_URL, $url);
+        if ($ssl) {
+            curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0); // 对认证证书来源的检查
+            curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 1); // 从证书中检查SSL加密算法是否存在
+        }
+        $cookie_file = self::$cookie_file;
+        curl_setopt($curl, CURLOPT_COOKIEJAR, $cookie_file); //连接结束后保存cookie信息的文件。
+        curl_setopt($curl, CURLOPT_COOKIEFILE, $cookie_file); //包含cookie数据的文件名,cookie文件的格式可以是Netscape格式,或者只是纯HTTP头部信息存入文件。
+        curl_setopt($curl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']); //在HTTP请求中包含一个"User-Agent: "头的字符串。
+        curl_setopt($curl, CURLOPT_HEADER, 0); //启用时会将头文件的信息作为数据流输出。
+        curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1); //启用时会将服务器服务器返回的"Location: "放在header中递归的返回给服务器,使用CURLOPT_MAXREDIRS可以限定递归返回的数量。
+        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); //文件流形式
+        curl_setopt($curl, CURLOPT_TIMEOUT, $timeout); //设置cURL允许执行的最长秒数
+        $data = (is_array($data)) ? http_build_query($data) : $data;
+        curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'PUT');
+        curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Length: ' . strlen($data)));
+        curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
+        if (is_array($header))
+            curl_setopt($curl, CURLOPT_HTTPHEADER, $header); //设置请求的Header
+
+        $content = curl_exec($curl);
+        $curl_errno = curl_errno($curl);
+        if ($curl_errno > 0) {
+            Logger::setlog($error = sprintf("curl error=%s, errno=%d.", curl_error($curl), $curl_errno));
+            curl_close($curl);
+            return false;
+        }
+        curl_close($curl);
+        return $content;
+    }
+
+    /**
+     * CURL-DEL方式获取数据
+     * @param string $url URL
+     * @param array $data POST数据
+     * @param string $proxy 是否代理
+     * @param int $timeout 请求时间
+     * @param array $header header信息
+     * @return string
+     */
+    public static function del($url, $data, $proxy = null, $timeout = 10, $header = null)
+    {
+        if (!$url)
+            return false;
+        if ($data) {
+            $data = http_build_query($data);
+        }
+        $ssl = stripos($url, 'https://') === 0 ? true : false;
+        $curl = curl_init();
+        if (!is_null($proxy))
+            curl_setopt($curl, CURLOPT_PROXY, $proxy);
+        curl_setopt($curl, CURLOPT_URL, $url);
+        if ($ssl) {
+            curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0); // 对认证证书来源的检查
+            curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 1); // 从证书中检查SSL加密算法是否存在
+        }
+        $cookie_file = self::$cookie_file;
+        curl_setopt($curl, CURLOPT_COOKIEJAR, $cookie_file); //连接结束后保存cookie信息的文件。
+        curl_setopt($curl, CURLOPT_COOKIEFILE, $cookie_file); //包含cookie数据的文件名,cookie文件的格式可以是Netscape格式,或者只是纯HTTP头部信息存入文件。
+        curl_setopt($curl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']); //在HTTP请求中包含一个"User-Agent: "头的字符串。
+        curl_setopt($curl, CURLOPT_HEADER, 0); //启用时会将头文件的信息作为数据流输出。
+        curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1); //启用时会将服务器服务器返回的"Location: "放在header中递归的返回给服务器,使用CURLOPT_MAXREDIRS可以限定递归返回的数量。
+        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); //文件流形式
+        curl_setopt($curl, CURLOPT_TIMEOUT, $timeout); //设置cURL允许执行的最长秒数
+        $data = (is_array($data)) ? http_build_query($data) : $data;
+        curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'DEL');
+        curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Length: ' . strlen($data)));
+        curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
+        if (is_array($header))
+            curl_setopt($curl, CURLOPT_HTTPHEADER, $header); //设置请求的Header
+
+        $content = curl_exec($curl);
+        $curl_errno = curl_errno($curl);
+        if ($curl_errno > 0) {
+            Logger::setlog($error = sprintf("curl error=%s, errno=%d.", curl_error($curl), $curl_errno));
+            curl_close($curl);
+            return false;
+        }
+        curl_close($curl);
+        return $content;
+    }
+
+}