/**
  * 获得用户app key,若未指定$user_id,则取当前用户
  * 
  * @param 	$user_id 	string
  * @return 	string
  */
 public static function get_appkey($user_id = null)
 {
     if ($user_id) {
         $business_user = BusinessUser::find($user_id);
     } else {
         $business_user = BusinessUser::find(Sentry::getUser()->user_id);
     }
     if (!isset($business_user)) {
         throw new Exception('非企业用户', 31);
     }
     return $business_user->app_key;
 }
Example #2
0
 public static function token()
 {
     if (Cache::get('app_token') != null) {
         return Cache::get('app_token');
     }
     //获取token的链接
     $url = Config::get('domain.server') . '/token';
     $business_user = BusinessUser::find(Sentry::getUser()->user_id);
     //获取token的参数
     $appkey = $business_user->app_key;
     $secretkey = $business_user->app_secret;
     $parm = 'appkey=' . urlencode($appkey) . '&secretkey=' . urlencode($secretkey);
     // dd($secretkey);
     $token = json_decode(CurlController::post($url, $parm), true);
     if ($token['errCode'] != 0) {
         Log::info($token);
         return Response::json(array('errCode' => 1, 'message' => 'token获取失败'));
     }
     Cache::put('app_token', $token['token'], 100);
     return $token['token'];
 }
 public function agency()
 {
     if (!Session::has('violations')) {
         return Redirect::to('/serve-center/agency/pages/search_violation');
     }
     $violations = Session::get('violations');
     $sign = Input::get('sign');
     if (!array_key_exists(Input::get('sign'), $violations)) {
         return Response::make('参数错误');
     }
     $user = Sentry::getUser();
     $agency_user_attr = '';
     if ($user->is_common_user()) {
         $agency_user_attr = $user->login_account;
     } else {
         if ($user->is_business_user()) {
             $agency_user_attr = BusinessUser::find($user->user_id)->business_name;
         }
     }
     return View::make('pages.serve-center.business.agency', ['sign' => $sign, 'agency_user_attr' => $agency_user_attr, 'agency_info' => $violations[$sign]['info']]);
 }
Example #4
0
 /**
  * 获得access token
  *
  * @return string
  */
 public static function getAccessToken($user = null)
 {
     /*
        未设置$user,默认为普通用户,
        token均从缓存中获取, 从缓存中获取失败,则从远程服务器中获取
        对于普通用户,app_key和app_secret用通用的, token获取的key为:token
        对于企业用户,app_key和app_secret每个用户均不相同, token获取的key为:'token_' + user_id,比如 'token_yhxx1231231231231231231231'
     */
     if ($user == null || $user->is_common_user()) {
         // 从本地缓存中获取token
         $token = static::getAccessTokenFromCache();
         // 从缓存中获取失败,则从远程服务器获取
         if (empty($token)) {
             $cheshang_config = Config::get('domain');
             // 从远程服务器获取
             $token = static::getAccessTokenFromRemote($cheshang_config['app_key'], $cheshang_config['app_secret']);
             // 保存到缓存中并设置过期时间
             static::putAccessTokenIntoCache($token);
         }
         return $token;
         // 企业用户
     } else {
         if ($user->is_business_user()) {
             // 从本地缓存中获取token
             $token = static::getAccessTokenFromCache($user->user_id);
             // 从缓存中获取失败,则从远程服务器中获取
             if (empty($token)) {
                 // 获取企业用户信息
                 $user_bussiness_info = BusinessUser::find($user->user_id);
                 // 从远程服务器获取
                 $token = static::getAccessTokenFromRemote($user_bussiness_info->app_key, $user_bussiness_info->app_secret);
                 static::putAccessTokenIntoCache($token, $user->user_id);
             }
             return $token;
         }
     }
     return null;
 }
Example #5
0
 public function displayCompanyRegisterInfo()
 {
     $display_code = Input::get('display_code');
     $user = Sentry::findUserById(Sentry::getUser()->user_id);
     if ($user->checkResetPasswordCode($display_code)) {
         $business_user = BusinessUser::find($user->user_id);
         $app_key = $business_user->app_key;
         $app_secret = $business_user->app_secret;
         return Response::json(array('errCode' => 0, 'message' => '显示开发者信息', 'app_key' => $app_key, 'app_secret' => $app_secret));
     } else {
         return Response::json(array('errCode' => 21, 'message' => '验证码不正确'));
     }
 }