WithdrawalListener.php 1.1 KB

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