コード例 #1
0
ファイル: Wzs2Auth.php プロジェクト: gtyd/jira
 protected function getAuthAccountId()
 {
     $appId = I('appId');
     $entCode = I('entCode');
     $sign = I('sign');
     if (!empty($appId) && !empty($entCode) && !empty($sign)) {
         $curl = $this->curl ? $this->curl : new \mysoft\http\Curl();
         $wzs2_site = $this->wzs2_site ? $this->wzs2_site : \mysoft\pubservice\Conf::getConfig('wzs2_api_site');
         $ret = $curl->get($wzs2_site . '/api/Enterprise/GetAppKey', ['entcode' => $entCode, 'appId' => $appId]);
         if (empty($ret)) {
             throw new AuthException('wzs2 get_app_key接口无法访问');
         } else {
             $ret = json_decode($ret, true);
         }
         //get_app_key返回为{'data':'xxx'}
         if (!isset($ret['data']) || empty($ret['data'])) {
             throw new AuthException('wzs2 get_app_key返回值为空');
         } else {
             $key = $ret['data'];
         }
         $userinfo = \mysoft\helpers\AesHelper::decrypt($sign, $key);
         $userinfo = json_decode($userinfo, true);
         if (empty($userinfo) || !isset($userinfo['userCode'])) {
             throw new AuthException('sign无法解密出usercode');
         } else {
             if (!isset($userinfo['timeStamp']) || time() * 1000 - $userinfo['timeStamp'] > 24 * 60 * 60) {
                 throw new AuthException('时间戳已经过期');
             } else {
                 $usercode = $userinfo['userCode'];
             }
         }
         if (empty($user_code)) {
             $user_code = cookie('user_code@' . $this->orgcode);
         } else {
             cookie('user_code@' . $this->orgcode, $user_code, time() + 30 * 24 * 60 * 60);
         }
         return $usercode;
     } else {
         throw new AuthException('wzs2 验证方式缺乏必要的appId,entCode,sign参数');
     }
 }
コード例 #2
0
ファイル: FxtAuth.php プロジェクト: gtyd/jira
 protected function getAuthAccountId()
 {
     $params = $this->params ? $this->params : \mysoft\pubservice\BasicParams::get($this->orgcode, 'third_app_user_code_params');
     if (empty($params)) {
         throw new AuthException("未设置第三方应用集成标识,无法被第三方应用集成");
     } else {
         $authcode = I($params);
     }
     if (empty($authcode)) {
         $usercode = cookie('user_code@' . $this->orgcode);
         if (!empty($usercode)) {
             return $usercode;
         } else {
             throw new AuthException('authcode不存在');
         }
     } else {
         $authcode = \mysoft\helpers\AesHelper::decrypt($authcode);
         $authcode = json_decode($authcode, true);
         if (!empty($authcode) && isset($authcode['user_code']) && isset($authcode['timestamp']) && isset($authcode['orgcode'])) {
             if (time() - $authcode['timestamp'] > self::FXT_EXPIRE) {
                 throw new AuthException('authcode已经过期');
             }
             if ($authcode['orgcode'] !== $this->orgcode) {
                 throw new AuthException('租户ID不匹配');
             }
             cookie('user_code@' . $this->orgcode, $authcode['user_code'], time() + 24 * 60 * 60);
             //复兴通的cookie只存一天
             if (YII_ENV != 'unittest') {
                 $query = \Yii::$app->request->getQueryParams();
                 if (isset($query[$params])) {
                     unset($query[$params]);
                 }
                 \Yii::$app->response->redirect(\Yii::$app->request->getHostInfo() . \Yii::$app->params['static_host'] . '/' . \Yii::$app->request->getPathInfo() . "?" . http_build_query($query))->send();
                 //return false;
             }
             return $authcode['user_code'];
         } else {
             throw new AuthException('authcode解析失败');
         }
     }
 }
コード例 #3
0
ファイル: ThirdAuth.php プロジェクト: gtyd/jira
 protected function getAuthAccountId()
 {
     $params = $this->params !== null ? $this->params : \mysoft\pubservice\BasicParams::get($this->orgcode, 'third_app_user_code_params');
     $secret = $this->secret !== null ? $this->secret : \mysoft\pubservice\BasicParams::get($this->orgcode, 'third_app_auth_secret');
     if (empty($params)) {
         throw new AuthException("未设置third_app_user_code_params参数,无法被第三方应用集成");
     } else {
         $usercode = I($params);
     }
     if (empty($user_code)) {
         $user_code = cookie('user_code@' . $this->orgcode);
     } else {
         if (!empty($secret)) {
             $user_code = \mysoft\helpers\AesHelper::decrypt($user_code, $secret);
         }
         cookie('user_code@' . $this->orgcode, $user_code, time() + 30 * 24 * 60 * 60);
     }
     if (empty($usercode)) {
         throw new AuthException("无法从参数{$params}中获取用户code");
     } else {
         return $usercode;
     }
 }