Easemob.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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 = config('easemob');
  10. $appKey = $easemob_config['appkey'];
  11. $clientIdOrAppID = $easemob_config['client_id'];
  12. $clientSecretOrAppCertificate = $easemob_config['client_secret'];
  13. $this->auth = new Auth($appKey,$clientIdOrAppID,$clientSecretOrAppCertificate);
  14. }
  15. //////////////////消息推送//////////////////////////
  16. public function push_text($uid,$title,$msg){
  17. $message = new Push($this->auth);
  18. $pushMessage =
  19. [
  20. 'title'=> $title,
  21. // 'subTitle'=> '',
  22. 'content'=> $msg,
  23. // 'ext'=> [],
  24. /* 'config'=> [
  25. 'clickAction'=> [
  26. 'url'=>'',
  27. 'action'=>'',
  28. 'activity'=>'',
  29. ],
  30. 'badge'=> [
  31. 'addNum'=> 1,
  32. 'setNum'=> 0,
  33. ],
  34. ],*/
  35. ///'easemob'=>[],
  36. /*'apns'=> [
  37. 'badge'=> 1,
  38. ],*/
  39. /*'fcm'=> [],
  40. 'fcmV1'=>[],
  41. 'huawei'=> [],
  42. 'meizu'=> [],
  43. 'oppo'=> [],
  44. 'vivo'=> [],
  45. 'xiaomi'=> [],
  46. 'honor'=>[]*/
  47. ];
  48. $rs = $message->push_sync($uid,$pushMessage);
  49. //dump($rs);
  50. }
  51. public function push_all($title,$msg){
  52. $message = new Push($this->auth);
  53. $pushMessage =
  54. [
  55. 'title'=> $title,
  56. // 'subTitle'=> '',
  57. 'content'=> $msg,
  58. // 'ext'=> [],
  59. /* 'config'=> [
  60. 'clickAction'=> [
  61. 'url'=>'',
  62. 'action'=>'',
  63. 'activity'=>'',
  64. ],
  65. 'badge'=> [
  66. 'addNum'=> 1,
  67. 'setNum'=> 0,
  68. ],
  69. ],*/
  70. ///'easemob'=>[],
  71. /*'apns'=> [
  72. 'badge'=> 1,
  73. ],*/
  74. /*'fcm'=> [],
  75. 'fcmV1'=>[],
  76. 'huawei'=> [],
  77. 'meizu'=> [],
  78. 'oppo'=> [],
  79. 'vivo'=> [],
  80. 'xiaomi'=> [],
  81. 'honor'=>[]*/
  82. ];
  83. $rs = $message->push_task($pushMessage);
  84. //dump($rs);
  85. }
  86. }