Commit 4f72086d by 杨昕

Merge branch 'test' into 'master'

Test

See merge request !28
parents 50f494cd ef3726d4
Pipeline #13151 passed with stages
in 43 seconds
......@@ -297,6 +297,8 @@ function generateRandomNum( $len = 32, $md5 = true ) {
# Create random token at the specified length
for ( $i=0; $i<$len; $i++ )
$token .= $chars[ mt_rand(0, $numChars) ];
$time = microtime(true);
# Should token be run through md5?
if ( $md5 ) {
# Number of 32 char chunks
......@@ -305,8 +307,9 @@ function generateRandomNum( $len = 32, $md5 = true ) {
for ( $i=1; $i<=$chunks; $i++ )
$md5token .= md5( substr($token, $i * 32 - 32, 32) );
# Trim the token
$token = substr($md5token, 0, $len);
$token = md5($time.substr($md5token, 0, $len));
}
return $token;
}
......
......@@ -177,7 +177,7 @@ class MediaController extends Controller
$params = array(
'media_id' => 'mda-'.generateRandomNum(16),
'media_id' => MediaModel::getMediaId(),
'media_type'=> '5efa9cb5d16f5a214671fd86',//默认,中公网校
'start_time'=> $data_time,
'end_time' => $data_time,
......
......@@ -801,7 +801,32 @@ class MediaModel extends Eloquent
}
/**
* @return string
* @throws DatabaseException
*/
public static function getMediaId(){
try{
$i = 0;
do {
$media_id = "mda-".generateRandomNum(16);
$media = MediaModel::find($media_id);
$i ++;
} while ($i < 3 && !empty($media) );
if ($i == 3){
throw new \Exception('获取媒资编号失败');
}
}catch (\Exception $exception){
throw new DatabaseException($exception->getMessage());
}
return $media_id;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment