GoogleVoice.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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 Heanup\Library\Redis;
  7. use PhpImap\Mailbox;
  8. use QL\QueryList;
  9. class GoogleVoice implements Sms
  10. {
  11. /**
  12. * @return string[]
  13. */
  14. public function getCountry(): array
  15. {
  16. return [];
  17. }
  18. /**
  19. * @param $link
  20. * @return array
  21. */
  22. public function getPhoneNums($link): array
  23. {
  24. return [];
  25. }
  26. public function getMessage($country, $phone_num): array
  27. {
  28. $mailbox = new Mailbox(
  29. '{mail.97admin.com:993/imap/ssl/novalidate-cert}INBOX', // IMAP server and mailbox folder
  30. "gv@a4sky.com", // Username for the before configured mailbox
  31. "6485882", // Password for the before configured username
  32. __DIR__, // Directory, where attachments will be saved (optional)
  33. 'UTF-8' // Server encoding (optional)
  34. );
  35. $mail_ids = $mailbox->searchMailbox('FROM txt.voice.google.com');
  36. rsort($mail_ids);
  37. $cache = Redis::instance();
  38. $i = 0;
  39. krsort($mail_info);
  40. foreach ($mail_ids as $mail_id) {
  41. if ($i >= 20) {
  42. break;
  43. } else {
  44. $key = "mails_gv:" . $mail_id;
  45. $temp = $cache->get($key);
  46. if (!$temp) {
  47. $detail = $mailbox->getMail($mail_id);
  48. $from_num = str_replace("Message from ", "", $detail->subject);
  49. $txt = $detail->textPlain;
  50. $rwn = explode("\r\n", $detail->headersRaw);
  51. $date = explode(": ", $rwn[2])[1];
  52. $temp = [
  53. 'from' => $from_num,
  54. 'time' => date("Y-m-d H:i:s", strtotime($date)),
  55. 'message' => $txt
  56. ];
  57. $cache->set($key, $temp);
  58. }
  59. $mail_info[] = $temp;
  60. }
  61. $i++;
  62. }
  63. // rsort($mail_info);
  64. return $mail_info;
  65. }
  66. }