|
|
@@ -1,50 +1,43 @@
|
|
|
<?php
|
|
|
+
|
|
|
namespace backend\controllers;
|
|
|
+
|
|
|
+use biz\merchant\services\AdminService;
|
|
|
+use biz\platform\services\WxOpenService;
|
|
|
+use common\components\jwt;
|
|
|
use common\services\xhAdminService;
|
|
|
use common\components\util;
|
|
|
use Yii;
|
|
|
-use yii\web\Controller;
|
|
|
-use common\services\xhMerchantService;
|
|
|
-use common\services\xhUserService;
|
|
|
-use common\components\weixinUtil;
|
|
|
-use common\components\configDict;
|
|
|
use common\components\stringUtil;
|
|
|
-use common\services\xhWxOpenService;
|
|
|
|
|
|
/**
|
|
|
- * 微信 oauth 授权相关
|
|
|
+ * 登陆验证 shish 2019.11.23
|
|
|
*/
|
|
|
-class AuthController extends PublicController{
|
|
|
-
|
|
|
- public function actionGetUserInfo()
|
|
|
+class AuthController extends PublicController
|
|
|
+{
|
|
|
+
|
|
|
+ //登陆并拿到token shish 2019.11.23
|
|
|
+ public function actionLogin()
|
|
|
{
|
|
|
- $get = Yii::$app->request->get();
|
|
|
- $code = isset($get['code']) ? $get['code'] : '';
|
|
|
- if(isset($get['state']) && $get['state'] == 'authdeny'){
|
|
|
- util::stop('auth fail');
|
|
|
+ $get = Yii::$app->request->get();
|
|
|
+ $mobile = isset($get['mobile']) ? $get['mobile'] : 0;
|
|
|
+ if (stringUtil::isMobieNumber($mobile) == false) {
|
|
|
+ util::fail('请填写正常的手机号');
|
|
|
+ }
|
|
|
+ $password = isset($get['password']) && !empty($get['password']) ? $get['password'] : '';
|
|
|
+ if (empty($password)) {
|
|
|
+ util::fail('请输入密码');
|
|
|
}
|
|
|
- $account = '';
|
|
|
- $params = $get['params'];
|
|
|
- $suffixUrl = base64_decode($params);
|
|
|
- $openMerchant = xhWxOpenService::getMerchant();
|
|
|
- $user = [];
|
|
|
- $baseInfo = [];
|
|
|
- $data = weixinUtil::getOpenId($code,$openMerchant);//没关注公众号,用户授权获取openId
|
|
|
- $openId = $data['openid'];
|
|
|
- $access_token = $data['access_token'];
|
|
|
- $admin = xhAdminService::getByOpenId($openId);
|
|
|
- if(empty($admin)){
|
|
|
- if($get['authScope'] == 'snsapi_userinfo'){
|
|
|
- //经测试,已经关注公众号的粉丝直接点击菜单上的链接时,不走下面的静默自动方式,走这条,也会以静默自动的方式处理获取openId;
|
|
|
- $baseInfo = weixinUtil::authGetUserInfo($openId,$access_token);//用户授权方式获取用户信息
|
|
|
- }else{
|
|
|
- $baseInfo = weixinUtil::autoGetUserInfo($openId,$openMerchant);//静默自动方式获取用户信息
|
|
|
- }
|
|
|
- $admin = xhAdminService::generateAdmin($baseInfo);
|
|
|
+ $admin = AdminService::getByCondition(['mobile' => $mobile]);
|
|
|
+ if ($admin['password'] != md5($password)) {
|
|
|
+ util::fail('密码错误');
|
|
|
}
|
|
|
- xhAdminService::loginByThird($admin);
|
|
|
- $url = 'http://'.$_SERVER['HTTP_HOST'].$suffixUrl;
|
|
|
- $this->redirect($url);
|
|
|
+ $adminId = $admin['id'];
|
|
|
+ //来源
|
|
|
+ $sourceId = WxOpenService::getSourceId();
|
|
|
+ //获取token
|
|
|
+ $token = jwt::get($sourceId, $adminId);
|
|
|
+ util::success(['token' => $token]);
|
|
|
}
|
|
|
|
|
|
public function actionLogout()
|