SubscribeEvent.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. file_put_contents('/data/wwwroot/jucai/public/test.log',json_encode($payload));
  25. if (isset($payload['EventKey']) && Str::contains($payload['EventKey'], 'qrscene_')) {
  26. $key=str_replace("qrscene_", "", $payload['EventKey']);
  27. if ($key == 'LoginEvent') {
  28. if ($user) {
  29. Cache::put($payload['Ticket'], $user, 60);
  30. $url = route('mobile.auth.thirdlogin.official.login_to_web', ['ticket'=>$payload['Ticket']]);
  31. return <<<EOT
  32. <a href='{$url}'>点此立即登录</a>
  33. EOT;
  34. } else {
  35. $url = route('mobile.auth.thirdlogin.official');
  36. $siteName=config('aix.system.site.site.site_name');
  37. return <<<EOT
  38. 欢迎关注{$siteName}!\n\n
  39. 绑定您的{$siteName}帐号,求职招聘更加方便,并实时接收提醒通知。<a href='{$url}'>点此立即绑定</a>
  40. EOT;
  41. }
  42. }
  43. }
  44. if ($user) {
  45. return "欢迎关注".config('aix.system.site.site.site_name')."! ";
  46. } else {
  47. $url = route('mobile.auth.thirdlogin.official');
  48. $siteName=config('aix.system.site.site.site_name');
  49. return <<<EOT
  50. 欢迎关注{$siteName}!\n\n
  51. 绑定您的{$siteName}帐号,求职招聘更加方便,并实时接收提醒通知。<a href='{$url}'>点此立即绑定</a>
  52. EOT;
  53. }
  54. }
  55. }