コード例 #1
0
ファイル: ApiAction.php プロジェクト: hhy5861/yii2-ticket
 /**
  * @return array|int
  */
 protected function check()
 {
     $str = '';
     foreach ($this->checkParams() as $k => $v) {
         if (!isset($this->data[$v]) || $this->data[$v] === '') {
             $str .= ',' . $v;
         }
     }
     if ($str) {
         return Format::messages(-1, 'parameters:' . substr($str, 1) . 'to pass parameters will not be empty');
     }
     return 0;
 }
コード例 #2
0
ファイル: Token.php プロジェクト: hhy5861/yii2-ticket
 /**
  *
  * @return bool|string
  */
 public function createdToken()
 {
     if ($data = $this->getAccountInfo()) {
         $rand = RandCode::getInstance();
         $tokenArr['uid'] = $data['uid'];
         $tokenArr['code'] = $rand->createCode(1, 6, 1)[0];
         $tokenArr['token'] = $rand->createCode(1, 32)[0];
         $accessToken = Encrypt::getInstance()->encrypt($tokenArr);
         $cache['key'] = TOKEN_KEY . $data['uid'];
         $cache['expire'] = TOKEN_EXPIRE;
         $status = Memcached::getInstance($cache)->set($tokenArr);
         if ($status) {
             return Format::messages(0, 'get token success', ['access_token' => $accessToken, 'expire' => TOKEN_EXPIRE]);
         }
     }
     return Format::messages(100001, 'the user has not authorized');
 }