ReceiveSmsCc.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <?php
  2. namespace Heanup\Library\Sms;
  3. use Heanup\App\Api\Config\Code;
  4. use Heanup\App\Api\Package\Database\Num;
  5. use Heanup\Library\Curl;
  6. use QL\QueryList;
  7. class ReceiveSmsCc implements Sms
  8. {
  9. /**
  10. * @return string[]
  11. */
  12. public function getCountry(): array
  13. {
  14. $url = "https://receive-sms.cc/Countries/";
  15. $ql = (new QueryList)->get($url);
  16. $range = ".number-boxes-item";
  17. $rules = [
  18. 'country' => [".number-boxes-item-country", "text"],
  19. 'img' => [".number-boxes-item-ico", "src"],
  20. 'link' => [".number-boxes-item-button", "href"]
  21. ];
  22. $data = $ql->range($range)->rules($rules)->query()->getData()->all();
  23. $data = array_map(function ($a) {
  24. $a['link'] = "https://receive-sms.cc" . $a['link'];
  25. $a['img'] = "https://receive-sms.cc" . $a['img'];
  26. return $a;
  27. }, $data);
  28. return $data;
  29. }
  30. /**
  31. * @param $link
  32. * @return array
  33. */
  34. public function getPhoneNums($link): array
  35. {
  36. $ql = (new QueryList)->get($link);
  37. $data = $ql->find(".number-boxes-item-number")->texts()->all();
  38. if ($data) {
  39. $this->insert($link, $data);
  40. $end_page_link = $ql->find(".pagination a:contains(End)")->attr("href");
  41. preg_match("#\d+#", $end_page_link, $all_page);
  42. $all_page = $all_page[0];
  43. if ($all_page > 0) {
  44. for ($i = 2; $i <= $all_page; $i++) {
  45. $url = sprintf($link . "Page/%s", $i);
  46. $_ql = (new QueryList)->get($url);
  47. $_data = $_ql->find(".number-boxes-item-number")->texts()->all();
  48. if ($_data) {
  49. $this->insert($link, $_data);
  50. $data = array_merge($data, $_data);
  51. } else {
  52. echo "总页数:" . $all_page;
  53. echo "处理异常: " . $url . PHP_EOL;
  54. }
  55. }
  56. }
  57. }
  58. return $data;
  59. }
  60. public function getMessage($country, $phone_num): array
  61. {
  62. $info = Num::getOne(['country' => $country, 'phone' => $phone_num]);
  63. if ($info) {
  64. $response = Curl::get($info['url'], "myhome.97admin.com:34185");
  65. $ql = (new QueryList)->setHtml($response);
  66. $range = ".table-hover:gt(0)";
  67. $rules = [
  68. 'from' => [".col-xs-12 > .mobile_hide", "text"],
  69. 'time' => [".col-xs-0", "text"],
  70. 'message' => [".col-md-8", "text"]
  71. ];
  72. $ql->find(".mobile_hide:contains(Ads)")->parent()->parent()->remove();
  73. $msgs = $ql->range($range)->rules($rules)->query()->getData()->all();
  74. return $msgs;
  75. }
  76. }
  77. private function insert($link, $data)
  78. {
  79. foreach ($data as $val) {
  80. echo sprintf("正在写入号码:\t\t %s", $val) . PHP_EOL;
  81. $num = explode(" ", $val);
  82. $_num = str_replace(['+', ' '], ['', ''], $val);
  83. $config = Code::getData($num[0]);
  84. $insert = [
  85. 'country' => $num[0],
  86. 'country_name_zh' => $config['cn'],
  87. 'country_name_en' => $config['en'],
  88. 'phone' => $num[1],
  89. 'site' => 'receive-sms.cc',
  90. 'url' => $link . $_num
  91. ];
  92. Num::insert($insert);
  93. }
  94. }
  95. }