예제 #1
0
 public function before()
 {
     parent::before();
     if (!\Session::get('store', false)) {
         $store = \Model_Store::find(1);
         if (!$store) {
             die;
         }
         \Session::set('store', $store);
     }
 }
예제 #2
0
파일: token.php 프로젝트: wxl2012/wx
 /**
  * 获取token
  */
 public function action_index()
 {
     $data = ['status' => 'err', 'msg' => '缺少必要参数', 'errcode' => 90001];
     $user_id = \Input::get('user_id', false);
     $wechat_id = \Input::get('wechat_id', false);
     $open_id = \Input::get('open_id', false);
     $store_id = \Input::get('store_id', false);
     $wx_account_id = \Input::get('wx_account_id', false);
     if (!$user_id || !$wechat_id || !$open_id || !$store_id || !$wx_account_id) {
         return $this->response($data, 403);
     }
     $user = false;
     $wechat = false;
     $openid = false;
     $store = false;
     $account = false;
     if ($user_id) {
         $user = \Model_User::find($user_id);
     }
     if ($wechat_id) {
         $wechat = \Model_Wechat::find($wechat_id);
     }
     if ($open_id) {
         $openid = \Model_WechatOpenid::find($open_id);
     }
     if ($store_id) {
         $store = \Model_Store::find($store_id);
     }
     if ($wx_account_id) {
         $account = \Model_WXAccount::find($wx_account_id);
     }
     if (!$user || !$wechat || !$openid || !$store || !$account) {
         return $this->response($data, 403);
     }
     $params = ['user_id' => $user_id, 'store_id' => $store_id, 'wechat_id' => $wechat_id, 'openid_id' => $open_id, 'wx_account_id' => $wx_account_id];
     $token = \Model_ApiToken::forge(['token' => md5("{$user_id}{$wechat_id}{$open_id}{$store_id}{$wx_account_id}" . time()), 'expire_at' => time() + 7200, 'data' => serialize((object) $params)]);
     $token->save();
     $data = ['status' => 'succ', 'msg' => 'ok', 'errcode' => 0, 'expires_in' => 7200, 'access_token' => base64_encode($token->token)];
     $this->response($data, 200);
 }
예제 #3
0
 public function auth()
 {
     $flag = false;
     if (!\Input::get('access_token', false)) {
         return $flag;
     }
     $token = \Model_ApiToken::query()->where('token', base64_decode(\Input::get('access_token')))->get_one();
     if (!$token) {
         return false;
     } else {
         if ($token->expire_at < time()) {
             return false;
         }
     }
     $data = unserialize($token->data);
     $this->user = \Model_User::find($data->user_id);
     if (\Input::param('store_id', false)) {
         $this->store = \Model_Store::find(\Input::param('store_id'));
         $this->seller = $this->wx_account->seller;
     }
     if (\Input::param('wechat_id', false)) {
         $this->wechat = \Model_Wechat::find(\Input::param('wechat_id'));
     }
     if (\Input::param('openid_id', false)) {
         $this->store = \Model_WechatOpenid::find(\Input::param('openid_id'));
     }
     if (\Input::param('account_id', false)) {
         $this->wx_account = \Model_WXAccount::find(\Input::param('account_id'));
         $this->seller = $this->wx_account->seller;
     }
     if (\Input::param('seller_id', false)) {
         $this->seller = \Model_Seller::find(\Input::param('seller_id'));
     }
     //解析access_token,并查询access_token有效期
     //有效返回true否则返回false
     return $this->user ? true : false;
 }