AuthRefundTipListeners.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. namespace App\Listeners;
  3. use App\Events\AuthRefundTip;
  4. use EasyWeChat\Factory;
  5. use Illuminate\Support\Facades\Log;
  6. class AuthRefundTipListeners
  7. {
  8. protected $templateId;
  9. protected $url;
  10. /**
  11. * Create the event listener.
  12. *
  13. * @return void
  14. */
  15. public function __construct()
  16. {
  17. //退货提醒
  18. $this->templateId='8yrOrbG91C30LJapcBgQLINY3Lq9CZuAVbEsQMPcpnE';
  19. $this->url='';
  20. }
  21. /**
  22. * Handle the event.
  23. *
  24. * @param TipSend $event
  25. * @return void
  26. */
  27. public function handle(AuthRefundTip $event)
  28. {
  29. try{
  30. $data=$event->data;
  31. $openid=$data['openid'];
  32. $config=config('wechat.official_account.daweiboshi');
  33. $app = Factory::officialAccount($config);
  34. $app->template_message->send([
  35. 'touser' => $openid,
  36. 'template_id' => $this->templateId,
  37. 'url' => $this->url,
  38. 'data' => $data['data']
  39. ]);
  40. }catch (\Exception $exception){
  41. Log::error('发送模板消息出错,出错内容为'.$exception);
  42. }
  43. }
  44. }