AuthRefundTipListeners.php 1.3 KB

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