WithdrawalListener.php 1.1 KB

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