PushMessage.php 782 B

12345678910111213141516171819202122232425262728293031323334
  1. <?php
  2. namespace App\Traits;
  3. use GuzzleHttp\Client;
  4. trait PushMessage
  5. {
  6. public function push($data)
  7. {
  8. //发送消息请求
  9. $client = new Client();
  10. $client->get(config('custom.PUSH_MESSAGE_URL'),[
  11. 'query'=>[
  12. 'type'=>'publish',
  13. 'to'=>$data['accept_uuid'],
  14. 'title'=>$data['title'],
  15. 'content'=>$data['content']
  16. ]
  17. ]);
  18. //写入数据库
  19. $message = \App\Models\Message::create([
  20. 'title' => $data['title'],
  21. 'content' => $data['content'],
  22. 'send_uuid' => $data['send_uuid'],
  23. 'accept_uuid' => $data['accept_uuid'],
  24. 'flag' => $data['flag']
  25. ]);
  26. return $message;
  27. }
  28. }