OrderPayInfoListener.php 1.2 KB

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