OAuthLogin.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. /**
  3. * Niushop商城系统 - 团队十年电商经验汇集巨献!
  4. * =========================================================
  5. * Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
  6. * ----------------------------------------------
  7. * 官方网址: https://www.niushop.com
  8. * =========================================================
  9. */
  10. namespace addon\system\Wechat\event;
  11. use addon\system\Wechat\common\model\Wechat;
  12. use liliuwei\think\Jump;
  13. /**
  14. * 应用安装
  15. */
  16. class OAuthLogin
  17. {
  18. use Jump;
  19. /**
  20. * 授权登录
  21. * @param array $params
  22. */
  23. public function handle($params = [])
  24. {
  25. if ($params['name'] == 'Wechat') {
  26. $wechat_model = new Wechat();
  27. $wechat_config = $wechat_model->getWechatConfigInfo($params['site_id']);
  28. if (empty($wechat_config['data']['value'])) {
  29. $this->error('站点未配置微信公众号');
  30. } else {
  31. $value = $wechat_config['data']['value'];
  32. if (empty($value['appid']) || empty($value['appsecret'])) {
  33. $this->error('请配置您公众号的AppID和AppSecret');
  34. } else {
  35. $redirect_url = addon_url('Wechat://common/login/callback', ['site_id' => $params['site_id']]);
  36. $get_request_code_url = 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=' . $value['appid'] . '&redirect_uri=' . $redirect_url . '&response_type=code&scope=snsapi_userinfo&state=niucloud#wechat_redirect';
  37. $this->redirect($get_request_code_url);
  38. }
  39. }
  40. }
  41. }
  42. }