MimoUtility.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. namespace App\Utility;
  3. class MimoUtility
  4. {
  5. public static function getToken()
  6. {
  7. $curl = curl_init();
  8. curl_setopt_array($curl, array(
  9. CURLOPT_URL => '52.30.114.86:8080/mimosms/v1/user/login',
  10. CURLOPT_RETURNTRANSFER => true,
  11. CURLOPT_ENCODING => '',
  12. CURLOPT_MAXREDIRS => 10,
  13. CURLOPT_TIMEOUT => 0,
  14. CURLOPT_FOLLOWLOCATION => true,
  15. CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  16. CURLOPT_CUSTOMREQUEST => 'POST',
  17. CURLOPT_POSTFIELDS =>'{
  18. "username": "'.env('MIMO_USERNAME').'",
  19. "password": "'.env('MIMO_PASSWORD').'"
  20. }',
  21. CURLOPT_HTTPHEADER => array(
  22. 'Content-Type: application/json'
  23. ),
  24. ));
  25. $response = curl_exec($curl);
  26. curl_close($curl);
  27. return json_decode($response)->token;
  28. }
  29. public static function sendMessage($text, $to, $token)
  30. {
  31. $curl = curl_init();
  32. $fields = array(
  33. "sender" => env("MIMO_SENDER_ID"),
  34. "text" => $text,
  35. "recipients" => $to
  36. );
  37. // dd($to);
  38. curl_setopt_array($curl, array(
  39. CURLOPT_URL => '52.30.114.86:8080/mimosms/v1/message/send?token='.$token,
  40. CURLOPT_RETURNTRANSFER => true,
  41. CURLOPT_ENCODING => '',
  42. CURLOPT_MAXREDIRS => 10,
  43. CURLOPT_TIMEOUT => 0,
  44. CURLOPT_FOLLOWLOCATION => true,
  45. CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  46. CURLOPT_CUSTOMREQUEST => 'POST',
  47. CURLOPT_POSTFIELDS => json_encode($fields),
  48. CURLOPT_HTTPHEADER => array(
  49. 'Content-Type: application/json'
  50. ),
  51. ));
  52. $response = curl_exec($curl);
  53. // dd($response);
  54. curl_close($curl);
  55. return 1;
  56. }
  57. public static function logout($token)
  58. {
  59. // dd('Hello world');
  60. $curl = curl_init();
  61. curl_setopt_array($curl, array(
  62. CURLOPT_URL => '52.30.114.86:8080/mimosms/v1/user/logout?token='.$token,
  63. CURLOPT_RETURNTRANSFER => true,
  64. CURLOPT_ENCODING => '',
  65. CURLOPT_MAXREDIRS => 10,
  66. CURLOPT_TIMEOUT => 0,
  67. CURLOPT_FOLLOWLOCATION => true,
  68. CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  69. CURLOPT_CUSTOMREQUEST => 'GET',
  70. ));
  71. $response = curl_exec($curl);
  72. curl_close($curl);
  73. // dd($response, $token);
  74. }
  75. }