예제 #1
0
 /**
  * 重新创建文件名
  * @return string
  */
 protected function replaceFileName()
 {
     $this->fileName = RandCode::getInstance()->createCode(1, 24, 6)[0];
     if ($this->key) {
         $arr = explode('/', $this->key);
         $arr[count($arr) - 1] = $this->fileName;
         return $this->key = implode('/', $arr);
     } else {
         return $this->key = $this->fileName;
     }
 }
예제 #2
0
 /**
  *
  * @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');
 }
예제 #3
0
 /**
  * 对明文进行加密
  *
  * @param $text
  * @param $corpid
  * @return array
  */
 public function encrypt($text, $corpid = '')
 {
     try {
         /*获得16位随机字符串,填充到明文之前*/
         $random = RandCode::getInstance()->createCode(1, 16)[0];
         $text = $random . pack("N", strlen($text)) . $text . $corpid;
         /*网络字节序*/
         mcrypt_get_block_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC);
         $module = mcrypt_module_open(MCRYPT_RIJNDAEL_128, '', MCRYPT_MODE_CBC, '');
         $iv = substr($this->key, 0, 16);
         /*使用自定义的填充方式对明文进行补位填充*/
         $text = $this->encode($text);
         mcrypt_generic_init($module, $this->key, $iv);
         /*加密*/
         $encrypted = mcrypt_generic($module, $text);
         mcrypt_generic_deinit($module);
         mcrypt_module_close($module);
         /*使用BASE64对加密后的字符串进行编码*/
         return [self::$OK, rtrim(strtr(base64_encode($encrypted), '+/', '-_'), '=')];
     } catch (Exception $e) {
         error_log(var_export($e));
         return [self::$EncryptAESError, null];
     }
 }