ReceivingListener.php 1.1 KB

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