You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

41 lines
984 B

7 years ago
  1. <?php
  2. namespace App\Common;
  3. use JPush\Client as JPushMsg;
  4. use Illuminate\Support\Facades\Log;
  5. //极光推送,"jpush/jpush": "v3.5.*"
  6. class JPush
  7. {
  8. const APP_KEY = 'b82cd9fcd0cbb92866d6d726';
  9. const APP_SECRET = 'ac92d336f90842051dc12f49';
  10. //$registration_id = getenv('registration_id');
  11. public static function send($msg, $param='')
  12. {
  13. $client = new JPushMsg(self::APP_KEY, self::APP_SECRET, null);
  14. $push_payload = $client->push();
  15. $push_payload = $push_payload->setPlatform('all');
  16. if(isset($param['mobile'])){$push_payload = $push_payload->addAlias(md5($param['mobile']));}
  17. $push_payload = $push_payload->addAllAudience();
  18. $push_payload = $push_payload->setNotificationAlert($msg);
  19. try
  20. {
  21. $push_payload->send();
  22. }
  23. catch (JPushMsg\Exceptions\APIConnectionException $e)
  24. {
  25. Log::info($e);
  26. return false;
  27. }
  28. catch (JPushMsg\Exceptions\APIRequestException $e)
  29. {
  30. Log::info($e);
  31. return false;
  32. }
  33. return true;
  34. }
  35. }