AuthRefundTipListeners.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. $this->url='https://weidian.cliu.cc/web/user';
  23. }
  24. /**
  25. * Handle the event.
  26. *
  27. * @param TipSend $event
  28. * @return void
  29. */
  30. public function handle(AuthRefundTip $event)
  31. {
  32. try{
  33. $data=$event->data;
  34. $openid=$data['openid'];
  35. $config=config('wechat.official_account.daweiboshi');
  36. $app = Factory::officialAccount($config);
  37. $app->template_message->send([
  38. 'touser' => $openid,
  39. 'template_id' => $this->templateId,
  40. 'url' => $this->url,
  41. 'data' => $data['data']
  42. ]);
  43. }catch (\Exception $exception){
  44. Log::error('发送模板消息出错,出错内容为'.$exception);
  45. }
  46. }
  47. }