Esempio n. 1
0
 public function actionToken()
 {
     $request = Yii::$app->getRequest();
     $params = $request->get();
     $params = array_map('htmlEntityString', $params);
     $appid = isset($params['app_id']) ? $params['app_id'] : '';
     $appkey = isset($params['app_key']) ? $params['app_key'] : '';
     if (!$appid) {
         return responseArray(1101, 'appid_params_missing', '缺失应用ID参数');
     }
     if (!$appkey) {
         return responseArray(1102, 'appkey_params_missing', '缺失应用KEY参数');
     }
     try {
         // 验证app_id app_key有效性
         $application = new ApplicationBase();
         $ret = $application->validateApp($appid, $appkey);
         if (!$ret) {
             return responseArray(2101, 'appid_appkey_invalid', '应用ID或者应用KEY无效');
         }
         $accessToken = new AccessToken();
         $tokenEntity = $accessToken->getAccessToken($appid, $appkey);
         $result = null;
         if ($tokenEntity == null || strtotime($tokenEntity->expires_in) < time()) {
             $token = generateRandString();
             // 有效期默认两小时
             $expires_in = date('Y-m-d H:i:s', time() + 7200);
             if ($tokenEntity == null) {
                 $result = $accessToken->setAccessToken($token, $appid, $appkey, $expires_in);
             } else {
                 $tokenEntity->access_token = $token;
                 $tokenEntity->expires_in = $expires_in;
                 $result = $tokenEntity->save();
             }
             //TODO:: 保存access_token失败的处理
             if (!$result) {
                 return responseArray(1, 'network_anomaly', '网络异常请稍后重试');
             }
         } else {
             $token = $tokenEntity->access_token;
             // 有效期默认两小时
             $expires_in = $tokenEntity->expires_in;
         }
         $ret = ['access_token' => $token, 'expires' => $expires_in];
         return responseArray(1, 'success', '授权成功', $ret);
     } catch (Exception $ex) {
         return responseArray(1, 'network_anomaly', '网络异常,请稍后重试');
     }
 }
Esempio n. 2
0
 public function check($data, $isISystem = false)
 {
     $requiredItems = $this->getRequiredItems($isISystem);
     foreach ($requiredItems as $key => $item) {
         if (!isset($data[$key])) {
             return $item;
         }
     }
     if (!$isISystem) {
         $mAppBase = new ApplicationBase();
         $appNO = $data['appNO'];
         $appInfo = $mAppBase->pk($appNO);
         if (!$appInfo) {
             return [2201, 'error_appno_invalid'];
         }
         $appKey = $appInfo['app_key'];
         $appID = trim(Yii::$app->util->decrypt($data['appID'], $appKey));
         if ($appID !== $appInfo['app_id']) {
             return [2202, 'error_appid_invalid'];
         }
     } else {
         $appID = $data['appID'];
     }
     $mAppService = new ServiceBinding();
     $serviceID = $this->getServiceID();
     $appService = $mAppService->getAppService($appID, $serviceID);
     if (!$appService) {
         return [2401, 'error_service_not_bound'];
     }
     if (!$isISystem) {
         $asKey = $appService['as_key'];
         if (!Yii::$app->sign->checkSign($data, $asKey)) {
             return [1201, 'error_sign'];
         }
     }
     return $this->customCheck($appID, $data, $isISystem);
 }
Esempio n. 3
0
$title = Util::getWebTitle($route);
if ($title) {
    $this->title = $title;
}
//获取session
$session = Yii::$app->session;
$sessionAvatar = $session[UserBaseInfo::SESSION_KEY_USER]['avatar'] ? $session[UserBaseInfo::SESSION_KEY_USER]['avatar'] : '';
$sessionName = $session[UserBaseInfo::SESSION_KEY_USER]['name'] ? $session[UserBaseInfo::SESSION_KEY_USER]['name'] : '';
//获取cookie
$cookies = Yii::$app->getRequest()->cookies;
$cookieAvatar = $cookies->getValue('avatar');
$avatar = $sessionAvatar ? $sessionAvatar : $cookieAvatar;
$cookieName = $cookies->getValue('username');
$avatar = $sessionAvatar ? $sessionAvatar : $cookieAvatar;
$name = $sessionName ? $sessionName : $cookieName;
$result = ApplicationBase::getApp(ApplicationBase::AUDITING_PASS_STATUS, ApplicationBase::TYPE_EXTERNAL, 6);
$this->beginPage();
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <?php 
if (Yii::$app->controller->id == 'pay') {
    ?>
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1,user-scalable=no">
    <?php 
}
?>
    <?php 
Esempio n. 4
0
 /**
  * 发放授权TOKEN
  */
 public function actionToken()
 {
     $params = Yii::$app->getRequest()->get();
     $params = array_map('htmlEntityString', $params);
     $params = array_map('trim', $params);
     $app_id = isset($params['app_id']) && $params['app_id'] ? $params['app_id'] : '';
     $app_key = isset($params['app_key']) && $params['app_key'] ? $params['app_key'] : '';
     if (!$app_id || !$app_key) {
         Yii::$app->util->formatResData(1, 'app_id和app_key不能为空', []);
     }
     try {
         $application = ApplicationBase::find()->where(['app_id' => $app_id, 'app_key' => $app_key])->asArray()->one();
         if (!$application) {
             Yii::$app->util->formatResData(2, '无效的app_id或app_key', []);
         }
         $accessToken = new AccessToken();
         $appToken = $accessToken->validateAccessToken($app_id, $app_key);
         if ($appToken) {
             // 已存在TOKEN,且没有过期
             Yii::$app->util->formatResData(3, '', $appToken);
         }
         $token = generateRandString();
         $expires_in = date('Y-m-d H:i:s', time() + self::EXPIRES_IN);
         $result = $accessToken->setAccessToken($token, $app_id, $app_key, $expires_in);
         if ($result) {
             $return['access_token'] = $token;
             $return['expires_in'] = $expires_in;
             Yii::$app->util->formatResData(0, '', $return);
         } else {
             Yii::$app->util->formatResData(4, '网络出错,请稍后重试', []);
         }
     } catch (Exception $ex) {
         Yii::$app->util->formatResData(5, '网络出错,请稍后重试', []);
     }
 }
Esempio n. 5
0
 public function actionServiceList()
 {
     $this->layout = 'uc';
     if (!$this->isLogin) {
         return $this->redirect(Url::toRoute('user/login'));
     }
     $data = ApplicationBase::getApp(ApplicationBase::AUDITING_PASS_STATUS);
     return $this->render('service_list', ['data' => $data]);
 }
Esempio n. 6
0
 /**
  * 关联ApplicationBase
  */
 public function getApp()
 {
     return $this->hasMany(ApplicationBase::className(), ['app_id' => 'app_id']);
 }