Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
media-resource
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
杨昕
media-resource
Commits
4f72086d
Commit
4f72086d
authored
Jan 07, 2021
by
杨昕
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'test' into 'master'
Test See merge request
!28
parents
50f494cd
ef3726d4
Pipeline
#13151
passed with stages
in 43 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
30 additions
and
2 deletions
+30
-2
functions.php
app/Helpers/functions.php
+4
-1
MediaController.php
app/Http/Controllers/Api/MediaController.php
+1
-1
MediaModel.php
app/Model/MediaModel.php
+25
-0
No files found.
app/Helpers/functions.php
View file @
4f72086d
...
...
@@ -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
;
}
...
...
app/Http/Controllers/Api/MediaController.php
View file @
4f72086d
...
...
@@ -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
,
...
...
app/Model/MediaModel.php
View file @
4f72086d
...
...
@@ -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
;
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment