WechatMessageListener.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. namespace App\Listeners;
  3. use App\Events\WechatMessageEvent;
  4. use Illuminate\Queue\Listener;
  5. use Illuminate\Support\Facades\Log;
  6. class WechatMessageListener {
  7. /**
  8. * Create the event listener.
  9. *
  10. * @return void
  11. */
  12. public function __construct()
  13. {
  14. // $this->data=$data;
  15. }
  16. /**
  17. * Handle the event.
  18. *
  19. * @param WechatMessageEvent $event
  20. * @return void
  21. */
  22. public function handle(WechatMessageEvent $event)
  23. {
  24. Log::error(1);
  25. Log::error(json_encode($event));
  26. try{
  27. $data=$event->data;
  28. $openid=$data['openid'];
  29. $template_id='gfaNWrBCALMcS-SzguP5aaDzYQHxoHs_doejgMFZIr4';
  30. // $template_id='MfqZmLlo0LqD2cq6HvIkc9LRTO-8V2p7Bqzbvp9vBA8';
  31. $url='http://api.app.jiuweiyun.cn/api/gzh';
  32. $app=app('wechat.official_account');
  33. $app->template_message->send([
  34. 'touser' => $openid,
  35. 'template_id' => $template_id,
  36. 'url' => $url,
  37. 'data' => $data['data']
  38. ]);
  39. }catch (\Exception $exception){
  40. Log::error('发送模板消息出错,出错内容为'.$exception);
  41. }
  42. }
  43. }