SignMessageListener.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. namespace App\Listeners;
  3. use App\Events\ChangeOrder;
  4. use App\Events\SignMessageEvent;
  5. use App\Jobs\SignMessage;
  6. use EasyWeChat\Factory;
  7. use Illuminate\Queue\InteractsWithQueue;
  8. use Illuminate\Contracts\Queue\ShouldQueue;
  9. use Illuminate\Support\Facades\Log;
  10. class SignMessageListener
  11. {
  12. protected $template_id;
  13. protected $url;
  14. /**
  15. * Create the event listener.
  16. *
  17. * @return void
  18. */
  19. public function __construct()
  20. {
  21. // $this->template_id='pW9YlUaGe5-q5xQPKuaVs54FovoA4x-kEybaoKRFvK4';
  22. // $this->template_id='8e87LapU3zQRre7s2siWNYf-qZyx5wePJvvFta1zYqc';
  23. $this->template_id='zWSvr-xAV6eIQbqDnwiSfVAJiwwvI1tta0p4KMs0nug';
  24. // $this->url='http://api.app.jiuweiyun.cn/api/gzh';
  25. }
  26. /**
  27. * Handle the event.
  28. *
  29. * @param ChangeOrder $event
  30. * @return void
  31. */
  32. public function handle(SignMessageEvent $event)
  33. {
  34. try{
  35. $data=$event->data;
  36. $openid=$data['openid'];
  37. $config=config('wechat.official_account.default');
  38. $app = Factory::officialAccount($config);
  39. $app->template_message->send([
  40. 'touser' => $openid,
  41. 'template_id' => $this->template_id,
  42. "miniprogram"=>[
  43. "appid"=>"wxcf821c17589a0ec8",
  44. "pagepath"=>"pages/sign_manage/sign_manage"
  45. ],
  46. // 'url' => $this->url,
  47. 'data' => $data['data']
  48. ]);
  49. }catch (\Exception $exception){
  50. Log::error('发送模板消息出错,出错内容为'.$exception);
  51. }
  52. }
  53. }