ReceivingListener.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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. $this->url='https://weidian.cliu.cc/web/user';
  20. }
  21. public function handle(ReceivingEvent $event)
  22. {
  23. try{
  24. $data=$event->data;
  25. $openid=$data['openid'];
  26. $config=config('wechat.official_account.daweiboshi');
  27. $app = Factory::officialAccount($config);
  28. $app->template_message->send([
  29. 'touser' => $openid,
  30. 'template_id' => $this->templateId,
  31. 'url' => $this->url,
  32. 'data' => $data['data']
  33. ]);
  34. }catch (\Exception $exception){
  35. Log::error('发送模板消息出错,出错内容为'.$exception);
  36. }
  37. }
  38. }