UserMessageListener.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?php
  2. namespace App\Listeners;
  3. use App\Events\UserMessageEvent;
  4. use Illuminate\Queue\Listener;
  5. use Illuminate\Support\Facades\Log;
  6. class UserMessageListener {
  7. protected $template_id;
  8. protected $url;
  9. //审核通知 通知用户审核结果
  10. public function __construct()
  11. {
  12. //szXa-NqOvLHxXzIWqkwB0HiFS3Dp3vz38KXq2nCGDiQ
  13. $this->template_id='6fKG5UML7jpoQ6p43vV3InYiwH2rLWNVMwSsfSNio3U';
  14. // $this->template_id='szXa-NqOvLHxXzIWqkwB0HiFS3Dp3vz38KXq2nCGDiQ';
  15. // $this->template_id='VQY91hiknlZvhTEGfj8fCXb3Jp9ZsM0jeYD9QJ1Osjg';
  16. $this->url='http://api.app.jiuweiyun.cn/api/gzh';
  17. }
  18. public function handle(UserMessageEvent $event)
  19. {
  20. try{
  21. $data=$event->data;
  22. $openid=$data['openid'];
  23. $app=app('wechat.official_account');
  24. $a=$app->template_message->send([
  25. 'touser' => $openid,
  26. 'template_id' => $this->template_id,
  27. 'url' => $this->url,
  28. 'data' => $data['data']
  29. ]);
  30. Log::info(json_encode($a,JSON_UNESCAPED_UNICODE));
  31. }catch (\Exception $exception){
  32. Log::error('发送模板消息出错,出错内容为'.$exception);
  33. }
  34. }
  35. }