Easemob.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. namespace App\Common\Library;
  3. use Easemob\Auth;
  4. use Easemob\Push;
  5. class Easemob {
  6. protected $auth;
  7. public function __construct() {
  8. //环信推送 正式
  9. $easemob_config = [
  10. 'appkey' => '1137221110163975#tkenim',
  11. 'client_id' => 'YXA6DEehGBpFTb-UOcgmWtveZQ',
  12. 'client_secret' => 'YXA6KhfJfqyJYBn2I20DdgTEzWpx5Cs',
  13. ];
  14. //初始化配置
  15. // $easemob_config = config('easemob');
  16. $appKey = $easemob_config['appkey'];
  17. $clientIdOrAppID = $easemob_config['client_id'];
  18. $clientSecretOrAppCertificate = $easemob_config['client_secret'];
  19. $this->auth = new Auth($appKey,$clientIdOrAppID,$clientSecretOrAppCertificate);
  20. }
  21. //////////////////消息推送//////////////////////////
  22. public function push_text($uid,$title,$msg){
  23. $message = new Push($this->auth);
  24. $pushMessage =
  25. [
  26. 'title'=> $title,
  27. // 'subTitle'=> '',
  28. 'content'=> $msg,
  29. /*'ext'=> [],
  30. 'config'=> [
  31. 'clickAction'=> [
  32. 'url'=>'',
  33. 'action'=>'',
  34. 'activity'=>'',
  35. ],
  36. 'badge'=> [
  37. 'addNum'=> 0,
  38. 'setNum'=> 0,
  39. ],
  40. ],
  41. 'easemob'=>[],
  42. 'apns'=> [],
  43. 'fcm'=> [],
  44. 'fcmV1'=>[],
  45. 'huawei'=> [],
  46. 'meizu'=> [],
  47. 'oppo'=> [],
  48. 'vivo'=> [],
  49. 'xiaomi'=> [],
  50. 'honor'=>[]*/
  51. ];
  52. $rs = $message->push_sync($uid,$pushMessage);
  53. return $rs;
  54. //dump($rs);
  55. }
  56. }