فهرست منبع

新增SmsFree

陈德本 5 سال پیش
والد
کامیت
110a412e6c
2فایلهای تغییر یافته به همراه125 افزوده شده و 0 حذف شده
  1. 1 0
      App/Api/Config/SiteRule.php
  2. 124 0
      Library/Sms/SmsFree.php

+ 1 - 0
App/Api/Config/SiteRule.php

@@ -12,6 +12,7 @@ class SiteRule extends Config
         'receive-sms-free.net'=>'ReceiveSmsFree',
         'receive-sms.cc'=>'ReceiveSmsCc',
         'google_voice'=>'GoogleVoice',
+        'smsfree.cc'=>'SmsFree',
     ];
 
 }

+ 124 - 0
Library/Sms/SmsFree.php

@@ -0,0 +1,124 @@
+<?php
+
+
+namespace Heanup\Library\Sms;
+
+
+use Heanup\App\Api\Config\Code;
+use Heanup\App\Api\Package\Database\Num;
+use Heanup\Config\Proxy;
+use Heanup\Library\Curl;
+use QL\QueryList;
+
+class SmsFree implements Sms
+{
+
+
+    /**
+     * @return array|false|string|string[]
+     */
+    public function getCountry()
+    {
+        $url = "https://smsfree.cc/api/";
+        $data = [
+            'do' => "Home"
+        ];
+        $result = Curl::post($url, $data);
+        $result = json_decode($result, true);
+        return $result['Country'];
+    }
+
+    /**
+     * @param $link
+     * @return array
+     */
+    public function getPhoneNums($link): array
+    {
+
+        $url = "https://smsfree.cc/api/";
+        $data = [
+            'country' => $link,
+            'do' => "List"
+        ];
+        $result = Curl::post($url, $data, "host.docker.internal:7777");
+        $result = json_decode($result, true);
+        $response = $result['Phone'];
+        $this->insert($link, $result['Phone']);
+        $total = $result['End'];
+        for ($i = 2; $i <= $total; $i++) {
+            $temp = $data;
+            $temp['page'] = $i;
+            $result = Curl::post($url, $temp, "host.docker.internal:7777");
+            $result = json_decode($result, true);
+            if ($result) {
+                $this->insert($link, $result['Phone']);
+                $response = array_merge($response, $result['Phone']);
+            }
+
+        }
+        return $response;
+
+//
+//        $ql = (new QueryList)->get($link);
+//        $end_page_link = $ql->find(".pagination  a:contains(End)")->attr("href");
+//        preg_match("#\d+#", $end_page_link, $all_page);
+//        $all_page = $all_page[0];
+//        $data = $ql->find(".h2 span")->texts()->all();
+//        $this->insert($link, $data);
+//        if ($all_page > 0) {
+//            for ($i = 2; $i <= $all_page; $i++) {
+//                $url = sprintf($link . "%s.html", $i);
+//                $_ql = (new QueryList)->get($url);
+//                $_data = $_ql->find(".h2 span")->texts()->all();
+//                if ($_data) {
+//                    $this->insert($link, $_data);
+//                    $data = array_merge($data, $_data);
+//                } else {
+//                    echo "总页数:" . $all_page;
+//                    echo "处理异常: " . $url . PHP_EOL;
+//                }
+//            }
+//        }
+//        return $data;
+    }
+
+    public function getMessage($country, $phone_num): array
+    {
+        $url = "https://smsfree.cc/api/";
+        $_num = str_replace(['+', ' '], ['', ''], $country.$phone_num);
+        $data = [
+            'page' => 1,
+            'phone' => $_num,
+            'do' => "Message",
+        ];
+        $result = Curl::post($url, $data);
+        $result = json_decode($result, true);
+        $response=array_map(function ($a) {
+            return [
+                'from' => $a['from'],
+                'time' => date("Y-m-d H:i:s",intval($a['time'])),//date("Y-m-d H:i:s",a['time']),
+                'message' => $a['data'],
+            ];
+        }, $result['Message']);
+        return $response;
+    }
+
+    private function insert($link, $data)
+    {
+        foreach ($data as $val) {
+            echo sprintf("正在写入号码:\t\t %s", $val['format']) . PHP_EOL;
+            $num = explode(" ", $val['format']);
+//            $_num = str_replace(['+', ' '], ['', ''], $val);
+            $config = Code::getData($num[0]);
+            $insert = [
+                'country' => $num[0],
+                'country_name_zh' => $config['cn'],
+                'country_name_en' => $config['en'],
+                'phone' => $num[1],
+                'site' => 'smsfree.cc',
+                'url' => ""
+            ];
+            Num::insert($insert);
+        }
+    }
+}