SendMessageOrderSendListener.php 1.3 KB

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