OrderPayInfoListener.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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='FgZJgH06B14FqD1DtiKiUYDQTTgMfOCsL05qWUXkU74'; //测试
  14. // $this->template_id='a9fxKufmVgDAxqMYz_RbiuII91vsJyyD7XRVGcONHk4';
  15. $this->url='http://api.app.cliu.cc/api/gzh';
  16. // $this->url='http://api.woaidakele.cn/api/gzh'; //测试
  17. }
  18. /**
  19. * Handle the event.
  20. *
  21. * @param OrderPayInfoEvent $event
  22. * @return void
  23. */
  24. public function handle(OrderPayInfoEvent $event)
  25. {
  26. try{
  27. $data=$event->data;
  28. $openid=$data['openid'];
  29. $config=config('wechat.official_account.default');
  30. $app = Factory::officialAccount($config);
  31. $app->template_message->send([
  32. 'touser' => $openid,
  33. 'template_id' => $this->template_id,
  34. 'url' => $this->url,
  35. 'data' => $data['data']
  36. ]);
  37. }catch (\Exception $exception){
  38. Log::error('发送模板消息出错,出错内容为'.$exception);
  39. }
  40. }
  41. }