GoogleVoice.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. $from_google=true;
  37. $cache=Redis::instance();
  38. $i=0;
  39. foreach ($mail_ids as $mail_id) {
  40. if ($i>=20){
  41. break;
  42. }else{
  43. $key="mails_gv:".$mail_id;
  44. $temp=$cache->get($key);
  45. if (!$temp) {
  46. $detail = $mailbox->getMail($mail_id);
  47. if ($from_google){
  48. $from_num=$detail->fromName;
  49. $txt = explode("\r\n", $detail->textPlain)[1];
  50. $date=$detail->date;
  51. }else{
  52. $from_num=str_replace("Message from ", "", $detail->subject);
  53. $txt=$detail->textPlain;
  54. $rwn=explode("\r\n", $detail->headersRaw);
  55. $date=explode(": ", $rwn[2])[1];
  56. }
  57. $temp=[
  58. 'from' =>$from_num,
  59. 'time' => date("Y-m-d H:i:s",strtotime($date)),
  60. 'message' => $txt
  61. ];
  62. $cache->set($key, $temp);
  63. }
  64. $mail_info[]=$temp;
  65. }
  66. $i++;
  67. }
  68. krsort($mail_info);
  69. return $mail_info;
  70. }
  71. }