SubscribeEvent.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. namespace App\Wechat\Official\Event;
  3. use App\Models\Company;
  4. use App\Models\Member;
  5. use Illuminate\Support\Facades\Cache;
  6. use Illuminate\Support\Str;
  7. /**
  8. * 用户关注公众号事件
  9. * Class SubscribeEvent
  10. * @package App\Wechat\Official\Event
  11. * Auth Zhong
  12. * Date 2019-05-08
  13. */
  14. class SubscribeEvent implements EventInterface
  15. {
  16. /**
  17. * @param array $wechatUser 从微信里获取的用户基本信息
  18. * @param bool|Company|Member $user 有没有绑定系统用户,false为未绑定,否则为对应的用户模型
  19. * @param array $payload 该事件的参数
  20. * @return mixed
  21. */
  22. public function handle(array $wechatUser, $user, array $payload)
  23. {
  24. if (isset($payload['EventKey']) && Str::contains($payload['EventKey'], 'qrscene_')) {
  25. $key=str_replace("qrscene_", "", $payload['EventKey']);
  26. if ($key == 'LoginEvent') {
  27. if ($user) {
  28. Cache::put($payload['Ticket'], $user, 60);
  29. $url = route('mobile.auth.thirdlogin.official.login_to_web', ['ticket'=>$payload['Ticket']]);
  30. return <<<EOT
  31. <a href='{$url}'>点此立即登录</a>
  32. EOT;
  33. } else {
  34. $url = route('mobile.auth.thirdlogin.official');
  35. $siteName=config('aix.system.site.site.site_name');
  36. return <<<EOT
  37. 欢迎关注{$siteName}!\n\n
  38. 绑定您的{$siteName}帐号,求职招聘更加方便,并实时接收提醒通知。<a href='{$url}'>点此立即绑定</a>
  39. EOT;
  40. }
  41. }
  42. }
  43. if ($user) {
  44. return "欢迎关注".config('aix.system.site.site.site_name')."! ";
  45. } else {
  46. $url = route('mobile.auth.thirdlogin.official');
  47. $siteName=config('aix.system.site.site.site_name');
  48. return <<<EOT
  49. 欢迎关注{$siteName}!\n\n
  50. 绑定您的{$siteName}帐号,求职招聘更加方便,并实时接收提醒通知。<a href='{$url}'>点此立即绑定</a>
  51. EOT;
  52. }
  53. }
  54. }