SubmitOrderInfoListener.php 1.4 KB

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