Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
5
51business
Project
Project
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
方斌
51business
Commits
5c22fbdd
Commit
5c22fbdd
authored
Apr 18, 2020
by
任国军
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add sendVerifyCode
parent
b621cdd5
Pipeline
#21860
passed with stage
in 21 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
46 additions
and
3 deletions
+46
-3
user.js
app/controller/course/v5/user.js
+1
-1
user.js
app/service/course/v5/user.js
+45
-2
No files found.
app/controller/course/v5/user.js
View file @
5c22fbdd
...
...
@@ -24,7 +24,7 @@ class UserController extends Controller {
const
{
ctx
,
service
}
=
this
;
const
queryParams
=
ctx
.
request
.
body
;
if
(
ctx
.
isEmpty
(
queryParams
.
phone
)
||
isNaN
(
queryParams
.
phone
)
||
queryParams
.
phone
.
length
!==
11
)
{
if
(
ctx
.
isEmpty
(
queryParams
.
phone
)
||
!
ctx
.
helper
.
isPhoneNumber
(
queryParams
.
phone
)
)
{
ctx
.
failed
(
'手机号错误'
);
}
...
...
app/service/course/v5/user.js
View file @
5c22fbdd
...
...
@@ -11,10 +11,53 @@ class UserService extends Service {
async
sendVerificationCode
(
input
)
{
const
{
ctx
}
=
this
;
const
phone
=
input
.
phone
;
const
APP_ID
=
'1C1wN39F4s61w62'
;
const
APP_KEY
=
'6643BBA3-2663-4A69-BA4E-2711D6B0AED5'
;
// to do
const
redisCode
=
await
ctx
.
app
.
memcache
.
get
(
`course_verify_code_
${
phone
}
`
);
if
(
!
ctx
.
isEmpty
(
redisCode
))
{
ctx
.
failed
(
'请勿频繁操作'
);
}
if
(
!
ctx
.
helper
.
isPhoneNumber
(
phone
))
{
ctx
.
failed
(
'手机号不正确'
);
}
const
code
=
await
this
.
getRandomNumber
(
5
);
const
now
=
String
(
new
Date
().
getTime
()
-
1000
);
const
ret
=
await
ctx
.
helper
.
send_request
(
'http://b.jianbing.com/messages/index'
,
{
app_id
:
APP_ID
,
timestamp
:
now
,
sign
:
ctx
.
helper
.
md5
(
`
${
now
}
&
${
APP_KEY
}
`
),
params
:
{
phone
,
content
:
`您的验证码是:
${
code
}
,您正在登录趣选课,验证码5分内有效,请勿泄露给他人。`
,
},
},
{
method
:
'POST'
,
dataType
:
'json'
,
contentType
:
'json'
,
timeout
:
[
5000
,
60000
],
});
if
(
ret
.
status
===
200
)
{
await
ctx
.
app
.
memcache
.
set
(
`course_verify_code_
${
phone
}
`
,
code
,
300
);
}
else
{
ctx
.
logger
.
info
(
'course_send_verify_code_error: '
+
JSON
.
stringify
(
ret
.
data
));
ctx
.
failed
(
'发送验证码失败'
);
}
return
{
result
:
true
};
}
// 生成随机位数的数字串
async
getRandomNumber
(
length
)
{
let
ret
=
''
;
for
(
let
i
=
0
;
i
<
length
;
i
++
)
{
ret
+=
Math
.
floor
(
Math
.
random
()
*
10
);
}
const
ret
=
{
result
:
true
};
return
ret
;
}
...
...
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