ChangeOrderListener.php 1.4 KB

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