DestoryOrderListener.php 1.4 KB

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