AgentIncomeListener.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. namespace Modules\Finance\Listeners;
  3. use Modules\Finance\Events\AgentIncome;
  4. use EasyWeChat\Factory;
  5. use Illuminate\Support\Facades\Log;
  6. use Illuminate\Queue\InteractsWithQueue;
  7. use Illuminate\Contracts\Queue\ShouldQueue;
  8. class AgentIncomeListener
  9. {
  10. protected $template_id;
  11. protected $url;
  12. /**
  13. * Create the event listener.
  14. *
  15. * @return void
  16. */
  17. public function __construct()
  18. {
  19. $this->template_id='Y5bxIakuAeNkzj1ypnhmQBP4bs0086Z5hYgAtpMiQR8';
  20. $this->url='http://api.app.jiuweiyun.cn/api/gzh';
  21. // $this->template_id='dA1a7THXIf0Pt_WpCW235XV8mw8f0HF7JLgRyk_g8_I';
  22. // $this->url='http://api.woaidakele.cn/api/gzh';
  23. }
  24. /**
  25. * Handle the event.
  26. *
  27. * @param AgentIncome $event
  28. * @return void
  29. */
  30. public function handle(AgentIncome $event)
  31. {
  32. Log::error(json_encode($event));
  33. try{
  34. $data=$event->data;
  35. $openid=$data['openid'];
  36. $config=config('wechat.official_account.default');
  37. $app = Factory::officialAccount($config);
  38. $app->template_message->send([
  39. 'touser' => $openid,
  40. 'template_id' => $this->template_id,
  41. 'url' => $this->url,
  42. 'data' => $data['data']
  43. ]);
  44. }catch (\Exception $exception){
  45. Log::error('发送模板消息出错,出错内容为'.$exception);
  46. }
  47. }
  48. }