Browse Source

配置代理

陈德本 5 years ago
parent
commit
a9eca1a565

+ 4 - 1
App/Api/Template/Message.phtml

@@ -20,7 +20,10 @@
     <div class="well  panel-info">
         <div class="panel-heading panel-title"> 当前号码:<?php
             echo $this->number_info['country'] . " " . $this->number_info['phone'];
-            ?></div>
+            if ($_GET['debug']==1){
+                echo " 页面耗时".microtime_float()-PAGE_START;
+            }
+             ?></div>
         <div class="panel-body ">
             <table class="table table-hover">
                 <thead>

+ 7 - 3
Config/Proxy.php

@@ -12,8 +12,12 @@ class Proxy extends Config
     public static function getData($section = null)
     {
 //        return "myhome.97admin.com:34185";
-//        $data=Curl::get("http://myhome.97admin.com:5010/get/");
-//        $data=json_decode($data,true);
-//        return $data['proxy'];
+        $rand=rand(1,5);
+        if ($rand==1){
+            return "myhome.97admin.com:34185";
+        }
+        $data = file_get_contents("http://myhome.97admin.com:5010/get/");
+        $data = json_decode($data, true);
+        return $data['proxy'];
     }
 }

+ 25 - 16
Library/Curl.php

@@ -23,14 +23,30 @@ class Curl
      * @param array $header header信息  array('Host: api.kingdee.meitushop.com' )设置请求的host
      * @return string
      */
-    public static function get($url, $proxy = null, $timeout = 10, $header = null, $REFERER = null)
+    public static function get($url, $proxy = null, $timeout = 30, $header = null, $REFERER = null)
     {
+
+
         if (!$url)
             return false;
         $ssl = stripos($url, 'https://') === 0;
         $curl = curl_init();
-        if (!is_null($proxy))
-            curl_setopt($curl, CURLOPT_PROXY, $proxy);
+        if (!is_null($proxy)){
+            if (is_string($proxy)){
+                curl_setopt($curl, CURLOPT_PROXY, $proxy);
+            }else{//使用猿代理
+                $proxyServer = is_string($proxy) ? $proxy : "forward.apeyun.com:9082";
+                $id = "2021012100228692034"; // 使用订单ID/APP_ID
+                $secret = "UJ1I6yMuZZ4B00b3"; // 用户SECRET
+                // 代理服务器
+                curl_setopt($curl, CURLOPT_PROXY, $proxyServer);
+                curl_setopt($curl, CURLOPT_PROXYTYPE, CURLPROXY_HTTP); //http
+                //curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5); //socks5
+                curl_setopt($curl, CURLOPT_PROXYAUTH, CURLAUTH_BASIC);
+                curl_setopt($curl, CURLOPT_PROXYUSERPWD, "$id:$secret");
+            }
+
+        }
         curl_setopt($curl, CURLOPT_URL, $url);
         if ($ssl) {
             curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0); // 对认证证书来源的检查
@@ -50,28 +66,21 @@ class Curl
         curl_setopt($curl, CURLOPT_TIMEOUT, $timeout); //设置cURL允许执行的最长秒数。
         if (is_array($header))
             curl_setopt($curl, CURLOPT_HTTPHEADER, $header); //设置请求的Header
-        if ($proxy) {
-            $proxyServer = "forward.apeyun.com:9082";
-            $id = "2021012100228692034"; // 使用订单ID/APP_ID
-            $secret = "UJ1I6yMuZZ4B00b3"; // 用户SECRET
-            // 代理服务器
-            curl_setopt($curl, CURLOPT_PROXY, $proxyServer);
-            curl_setopt($curl, CURLOPT_PROXYTYPE, CURLPROXY_HTTP); //http
-            //curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5); //socks5
-            curl_setopt($curl, CURLOPT_PROXYAUTH, CURLAUTH_BASIC);
-            curl_setopt($curl, CURLOPT_PROXYUSERPWD, "$id:$secret");
-        }
         $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;
-        }else{
-            Logger::setlog($error = sprintf("curl error=%s, errno=%d.", curl_error($curl), $curl_errno),APP_DIR."/success.log");
+        } else {
+            Logger::setlog($error = sprintf("curl error=%s, errno=%d.", curl_error($curl), $curl_errno), APP_DIR . "/success.log");
         }
 //        $this->http_code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
         curl_close($curl);
+
+        $time_end = microtime_float();
+        $time = $time_end - $time_start;
+        define("CURL_TIME", $time);
         return $content;
     }
 

+ 1 - 1
Library/Sms/ReceiveSmsCc.php

@@ -74,7 +74,7 @@ class ReceiveSmsCc implements Sms
     {
         $info = Num::getOne(['country' => $country, 'phone' => $phone_num]);
         if ($info) {
-            $response = Curl::get($info['url'],true);
+            $response = Curl::get($info['url'],Proxy::getData());
             $ql = (new QueryList)->setHtml($response);
             $range = ".table-hover";
             $rules = [

+ 1 - 1
Library/Sms/ReceiveSmsFree.php

@@ -73,7 +73,7 @@ class ReceiveSmsFree implements Sms
     {
         $info = Num::getOne(['country' => $country, 'phone' => $phone_num]);
         if ($info) {
-            $response = Curl::get($info['url'],true);
+            $response = Curl::get($info['url'],Proxy::getData());
             $ql = (new QueryList)->setHtml($response);
             $range = ".row:gt(0)";
             $rules = [

+ 9 - 0
functions.php

@@ -55,4 +55,13 @@ function getplatform()
 function push($shpath, $parrams = "")
 {
     return shell_exec("/bin/sh " . $shpath . " " . $parrams);
+}
+
+/**
+ * Simple function to replicate PHP 5 behaviour
+ */
+function microtime_float()
+{
+    list($usec, $sec) = explode(" ", microtime());
+    return ((float)$usec + (float)$sec);
 }

+ 1 - 0
public/api/index.php

@@ -4,6 +4,7 @@ use Heanup\Frame\Dispatcher;
 //use Heanup\Frame\Init;
 
 require_once dirname(dirname(__DIR__)) . '/Frame/Init.php';
+define("PAGE_START", microtime_float());
 $host = (isset($_SERVER['HTTP_HOST']) && $_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : 'www.97admin.com';
 // 设置环境变量
 //Init::setEnvironment('/www/privdata/'.$host.'/site.ini');