|
|
@@ -2,6 +2,7 @@
|
|
|
|
|
|
namespace mobile\controllers;
|
|
|
|
|
|
+use biz\merchant\services\MerchantService;
|
|
|
use biz\user\services\UserService;
|
|
|
use Yii;
|
|
|
use common\components\util;
|
|
|
@@ -16,6 +17,8 @@ use common\components\weixinUtil;
|
|
|
class AuthController extends PublicController
|
|
|
{
|
|
|
|
|
|
+ public $enableCsrfValidation = false;
|
|
|
+
|
|
|
public function actionGetUserInfo()
|
|
|
{
|
|
|
$get = Yii::$app->request->get();
|
|
|
@@ -41,6 +44,9 @@ class AuthController extends PublicController
|
|
|
if (empty($account) && preg_match('/\/account\/(\d+)/', $suffixUrl, $match)) {
|
|
|
$account = $match[1];
|
|
|
}
|
|
|
+ if (empty($account)) {
|
|
|
+ $account = isset($get['account']) ? $get['account'] : 0;
|
|
|
+ }
|
|
|
if (empty($account)) {
|
|
|
util::stop('商店ID不存在!');
|
|
|
}
|
|
|
@@ -65,18 +71,18 @@ class AuthController extends PublicController
|
|
|
$access_token = $data['access_token'];
|
|
|
$user = UserService::getByOpenId($openId, $merchantId);
|
|
|
//用户来源
|
|
|
- $userSource = Yii::$app->dict->getValue('userSourceGetId','official');
|
|
|
+ $userSource = Yii::$app->dict->getValue('userSourceGetId', 'official');
|
|
|
$source = $userSource['name'];
|
|
|
if (empty($user)) {
|
|
|
//$authScope snsapi_base 公众号菜单打开网页(已经关注公众号,有完整信息)、打开付款页(有些客户只付款,没有后续可以不用登记完整信息),只需要获取openid
|
|
|
$originalInfo = [];
|
|
|
$originalInfo['openId'] = $openId;
|
|
|
$originalInfo['merchantId'] = $merchantId;
|
|
|
-
|
|
|
+
|
|
|
//没有关注公众号,需要获取用户完整信息的情况,则通过弹框授权
|
|
|
if ($authScope == 'snsapi_userinfo') {
|
|
|
$baseInfo = weixinUtil::authGetUserInfo($openId, $access_token);
|
|
|
- $originalInfo = array_merge($baseInfo,$originalInfo);
|
|
|
+ $originalInfo = array_merge($baseInfo, $originalInfo);
|
|
|
$originalInfo['isFull'] = 1;
|
|
|
$originalInfo['unionId'] = $baseInfo['unionid'];
|
|
|
$originalInfo['headImgUrl'] = $baseInfo['headimgurl'];
|
|
|
@@ -98,7 +104,7 @@ class AuthController extends PublicController
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
//这个登陆没有经过父类方法配置全局变量,这里重新设置一次
|
|
|
Yii::$app->params['userId'] = $user['id'];
|
|
|
Yii::$app->params['user'] = $user;
|
|
|
@@ -111,4 +117,32 @@ class AuthController extends PublicController
|
|
|
$this->redirect($url);
|
|
|
}
|
|
|
|
|
|
+ //准备授权 shish 2019.11.19
|
|
|
+ public function actionPrepare()
|
|
|
+ {
|
|
|
+ $post = Yii::$app->request->post();
|
|
|
+ $authScope = isset($post['authScope']) ? $post['authScope'] : 'snsapi_base';
|
|
|
+ $url = isset($post['url']) && !empty($post['url']) ? $post['url'] : '';
|
|
|
+ if (empty($url)) {
|
|
|
+ util::fail('没有网址');
|
|
|
+ }
|
|
|
+ $account = isset($post['account']) ? $post['account'] : 0;
|
|
|
+ $merchant = MerchantService::getById($account);
|
|
|
+ if (empty($merchant)) {
|
|
|
+ util::fail('商家无效');
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * authScope 参数的说明
|
|
|
+ * 1.用户通过公众号菜单打开网页,因为已经关注过了公众号,已经生成过用户信息,所以只要使用snsapi_base静默方式拿到openid就可以
|
|
|
+ * 2.为了保证付款页的访问速度,暂时只要通过snsapi_base静默方式拿到openid先生成可以用的用户信息即可
|
|
|
+ * 3.其它情况需要获取用户完整信息的,使用snsapi_userinfo让用户授权获取信息即可
|
|
|
+ * 4.snsapi_base静默方式使用的场景更多,所以参数authScope默认使用snsapi_base
|
|
|
+ */
|
|
|
+ $authScope = isset($post['authScope']) ? $post['authScope'] : 'snsapi_base';
|
|
|
+ $redirectUrl = base64_encode($url);echo $redirectUrl;die;
|
|
|
+ $url = 'http://' . $_SERVER['HTTP_HOST'] . '/auth/get-user-info?params=' . $redirectUrl . '&authScope=' . $authScope;
|
|
|
+ weixinUtil::getToken($url, $merchant, $authScope);
|
|
|
+ util::end();
|
|
|
+ }
|
|
|
+
|
|
|
}
|