ChangeOrderListener.php 1.3 KB

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