NewOrderListeners.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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.cliu.cc/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. 'miniprogram' => [ //与公众号绑定的小程序(选传)
  35. 'appid' => config('wechat.mini_program.default.app_id'),//小程序id
  36. 'pagepath' => 'pages/order-manage/order-manage',//跳转页面
  37. ],
  38. ]);
  39. }catch (\Exception $exception){
  40. Log::error('发送模板消息出错,出错内容为'.$exception);
  41. }
  42. }
  43. }