OrderPayListener.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?php
  2. namespace Modules\Finance\Listeners;
  3. use Modules\Finance\Events\OrderPay;
  4. use EasyWeChat\Factory;
  5. use Illuminate\Support\Facades\Log;
  6. use Illuminate\Queue\InteractsWithQueue;
  7. use Illuminate\Contracts\Queue\ShouldQueue;
  8. class OrderPayListener
  9. {
  10. protected $template_id;
  11. protected $url;
  12. //注册完成 再次提交注册信息后 提示邀请人
  13. public function __construct()
  14. {
  15. // $this->template_id='eeNJUDz0Pn32JuF3kQ165NA_pNSvNeUCNrbmtiJNb0c';
  16. $this->template_id='3PGRr84zGsleaJYLqQjgr6G9XAmCLjC2YmardI6RBAo';
  17. $this->url='http://api.app.jiuweiyun.cn/api/gzh';
  18. // $this->template_id='eeNJUDz0Pn32JuF3kQ165NA_pNSvNeUCNrbmtiJNb0c';
  19. // $this->url='http://api.woaidakele.cn/api/gzh';
  20. }
  21. public function handle(OrderPay $event)
  22. {
  23. try{
  24. $data=$event->data;
  25. $openid=$data['openid'];
  26. $config=config('wechat.official_account.default');
  27. $app = Factory::officialAccount($config);
  28. $app->template_message->send([
  29. 'touser' => $openid,
  30. 'template_id' => $this->template_id,
  31. 'url' => $this->url,
  32. 'data' => $data['data']
  33. ]);
  34. }catch (\Exception $exception){
  35. Log::error('发送模板消息出错,出错内容为'.$exception);
  36. }
  37. }
  38. }