NewOrderListeners.php 1.1 KB

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