TipSendListeners.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. namespace App\Listeners;
  3. use App\Events\TipSend;
  4. use EasyWeChat\Factory;
  5. use Illuminate\Support\Facades\Log;
  6. class TipSendListeners
  7. {
  8. protected $template_id;
  9. protected $url;
  10. /**
  11. * Create the event listener.
  12. *
  13. * @return void
  14. */
  15. public function __construct()
  16. {
  17. $this->templateId='8doG3mtkc9WJ5cI7hLm23gWS7AUk3rns_pAorWyupng';
  18. $this->url='';
  19. }
  20. public function handle(TipSend $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. 'miniprogram' => [ //与公众号绑定的小程序(选传)
  33. 'appid' => config('wechat.mini_program.default.app_id'),//小程序id
  34. 'pagepath' => 'pages/order-manage/order-manage',//跳转页面
  35. ],
  36. ]);
  37. }catch (\Exception $exception){
  38. Log::error('发送模板消息出错,出错内容为'.$exception);
  39. }
  40. }
  41. }