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
2a1a6964
Commit
2a1a6964
authored
Dec 10, 2019
by
任国军
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add getUserPhone
parent
e2739a15
Pipeline
#17998
passed with stage
in 9 seconds
Changes
5
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
105 additions
and
30 deletions
+105
-30
user.js
app/controller/course/user.js
+5
-7
user.js
app/controller/course/v2/user.js
+19
-21
course_v2.js
app/router/course_v2.js
+3
-2
user.js
app/service/course/v2/user.js
+51
-0
wechat.js
app/service/course/v2/wechat.js
+27
-0
No files found.
app/controller/course/user.js
View file @
2a1a6964
...
@@ -13,11 +13,11 @@ class UserController extends Controller {
...
@@ -13,11 +13,11 @@ class UserController extends Controller {
ctx
.
failed
(
'error code'
);
ctx
.
failed
(
'error code'
);
}
}
//
请求微信授权 获取openid
//
请求微信授权 获取openid
const
wx_auth_ret
=
await
ctx
.
service
.
course
.
user
.
requestWxAuth
(
code
);
const
wx_auth_ret
=
await
ctx
.
service
.
course
.
user
.
requestWxAuth
(
code
);
const
openid
=
wx_auth_ret
.
openid
;
//
获取openid
const
openid
=
wx_auth_ret
.
openid
;
//
获取openid
//
检查是否已授权过 是否已入用户表
//
检查是否已授权过 是否已入用户表
let
user
=
await
ctx
.
classModel
.
CourseUser
.
one
({
where
:
{
openid
,
is_deleted
:
0
}
});
let
user
=
await
ctx
.
classModel
.
CourseUser
.
one
({
where
:
{
openid
,
is_deleted
:
0
}
});
if
(
!
user
||
!
user
.
uuid
)
{
if
(
!
user
||
!
user
.
uuid
)
{
const
uuid
=
uuidv4
();
const
uuid
=
uuidv4
();
...
@@ -25,7 +25,7 @@ class UserController extends Controller {
...
@@ -25,7 +25,7 @@ class UserController extends Controller {
// user.uuid = uuid;
// user.uuid = uuid;
}
}
console
.
info
(
user
);
console
.
info
(
user
);
//
存储缓存标识
//
存储缓存标识
const
user_uuid
=
user
.
uuid
;
const
user_uuid
=
user
.
uuid
;
const
key
=
'course_user_session_'
+
user_uuid
;
const
key
=
'course_user_session_'
+
user_uuid
;
await
app
.
memcache
.
set
(
key
,
{
user_uuid
,
openid
},
86400
*
180
);
await
app
.
memcache
.
set
(
key
,
{
user_uuid
,
openid
},
86400
*
180
);
...
@@ -46,7 +46,7 @@ class UserController extends Controller {
...
@@ -46,7 +46,7 @@ class UserController extends Controller {
const
input_params
=
ctx
.
request
.
body
;
const
input_params
=
ctx
.
request
.
body
;
const
{
avatar
,
nickname
,
province
,
country
,
sex
,
city
}
=
input_params
;
const
{
avatar
,
nickname
,
province
,
country
,
sex
,
city
}
=
input_params
;
//
查找用户是否存在并更新
//
查找用户是否存在并更新
const
user
=
ctx
.
classModel
.
CourseUser
.
one
({
where
:
{
uuid
}
});
const
user
=
ctx
.
classModel
.
CourseUser
.
one
({
where
:
{
uuid
}
});
await
ctx
.
classModel
.
CourseUser
.
edit
({
params
:
{
avatar
,
nickname
,
sex
},
where
:
{
uuid
}
});
await
ctx
.
classModel
.
CourseUser
.
edit
({
params
:
{
avatar
,
nickname
,
sex
},
where
:
{
uuid
}
});
let
bindphone
=
0
;
let
bindphone
=
0
;
...
@@ -136,8 +136,6 @@ class UserController extends Controller {
...
@@ -136,8 +136,6 @@ class UserController extends Controller {
}
}
}
}
module
.
exports
=
UserController
;
module
.
exports
=
UserController
;
app/controller/course/v2/user.js
View file @
2a1a6964
...
@@ -13,11 +13,12 @@ class UserController extends Controller {
...
@@ -13,11 +13,12 @@ class UserController extends Controller {
ctx
.
failed
(
'error code'
);
ctx
.
failed
(
'error code'
);
}
}
//
请求微信授权 获取openid
//
请求微信授权 获取openid
const
wx_auth_ret
=
await
ctx
.
service
.
course
.
v2
.
user
.
requestWxAuth
(
code
);
const
wx_auth_ret
=
await
ctx
.
service
.
course
.
v2
.
user
.
requestWxAuth
(
code
);
const
openid
=
wx_auth_ret
.
openid
;
//获取openid
const
openid
=
wx_auth_ret
.
openid
;
// 获取openid
const
session_key
=
wx_auth_ret
.
session_key
;
//
检查是否已授权过 是否已入用户表
//
检查是否已授权过 是否已入用户表
let
user
=
await
ctx
.
classModel
.
V2
.
CourseUser
.
one
({
where
:
{
openid
,
is_deleted
:
0
}
});
let
user
=
await
ctx
.
classModel
.
V2
.
CourseUser
.
one
({
where
:
{
openid
,
is_deleted
:
0
}
});
if
(
!
user
||
!
user
.
uuid
)
{
if
(
!
user
||
!
user
.
uuid
)
{
const
uuid
=
uuidv4
();
const
uuid
=
uuidv4
();
...
@@ -25,37 +26,30 @@ class UserController extends Controller {
...
@@ -25,37 +26,30 @@ class UserController extends Controller {
// user.uuid = uuid;
// user.uuid = uuid;
}
}
console
.
info
(
user
);
console
.
info
(
user
);
//
存储缓存标识
//
存储缓存标识
const
user_uuid
=
user
.
uuid
;
const
user_uuid
=
user
.
uuid
;
const
key
=
'course_v2_user_session_'
+
user_uuid
;
const
key
=
'course_v2_user_session_'
+
user_uuid
;
await
app
.
memcache
.
set
(
key
,
{
user_uuid
,
openid
},
86400
*
7
);
await
app
.
memcache
.
set
(
key
,
{
user_uuid
,
openid
,
session_key
},
86400
*
7
);
const
auth_token
=
ctx
.
helper
.
md5
(
openid
+
user_uuid
+
'jbwl'
);
const
auth_token
=
ctx
.
helper
.
md5
(
openid
+
user_uuid
+
'jbwl'
);
ctx
.
set
(
'uuid'
,
key
);
ctx
.
set
(
'uuid'
,
key
);
ctx
.
set
(
'auth_token'
,
auth_token
);
ctx
.
set
(
'auth_token'
,
auth_token
);
const
result
=
{
uuid
:
user_uuid
,
auth_token
};
const
result
=
{
uuid
:
user_uuid
,
auth_token
,
session_key
};
ctx
.
success
({
result
});
ctx
.
success
({
result
});
}
}
async
registerUserInfo
()
{
async
registerUserInfo
()
{
const
{
ctx
,
service
}
=
this
;
const
{
ctx
}
=
this
;
const
uuid
=
ctx
.
userUuid
;
const
input_params
=
ctx
.
request
.
body
;
const
input_params
=
ctx
.
request
.
body
;
const
{
avatar
,
nickname
,
province
,
country
,
sex
,
city
}
=
input_params
;
const
{
avatar
,
nickname
,
province
,
country
,
sex
,
city
}
=
input_params
;
const
encryptedData
=
input_params
.
encryptedData
||
''
;
const
iv
=
input_params
.
iv
||
''
;
const
params
=
{
avatar
,
nickname
,
province
,
country
,
sex
,
city
,
encryptedData
,
iv
};
//查找用户是否存在并更新
const
ret
=
await
service
.
course
.
v2
.
registerUserInfo
(
params
);
const
user
=
ctx
.
classModel
.
V2
.
CourseUser
.
one
({
where
:
{
uuid
}
});
ctx
.
success
(
ret
);
await
ctx
.
classModel
.
V2
.
CourseUser
.
edit
({
params
:
{
avatar
,
nickname
,
sex
},
where
:
{
uuid
}
});
let
bindphone
=
0
;
if
(
user
.
phone
)
{
bindphone
=
1
;
}
const
result
=
{
bindphone
};
ctx
.
success
({
result
});
}
}
/**
/**
...
@@ -135,9 +129,13 @@ class UserController extends Controller {
...
@@ -135,9 +129,13 @@ class UserController extends Controller {
ctx
.
success
({
result
});
ctx
.
success
({
result
});
}
}
// 获取用户信息
async
getUserInfo
()
{
const
{
ctx
,
service
}
=
this
;
const
ret
=
await
service
.
course
.
v2
.
user
.
getUserInfo
();
ctx
.
success
(
ret
);
}
}
}
module
.
exports
=
UserController
;
module
.
exports
=
UserController
;
app/router/course_v2.js
View file @
2a1a6964
...
@@ -19,6 +19,7 @@ module.exports = app => {
...
@@ -19,6 +19,7 @@ module.exports = app => {
router
.
post
(
'third'
,
'/user/auth'
,
'course.v2.user.auth'
);
// 微信授权登录
router
.
post
(
'third'
,
'/user/auth'
,
'course.v2.user.auth'
);
// 微信授权登录
router
.
post
(
'third'
,
'/user/register_user'
,
miniAuth
,
'course.v2.user.registerUserInfo'
);
// 授权后注册用户
router
.
post
(
'third'
,
'/user/register_user'
,
miniAuth
,
'course.v2.user.registerUserInfo'
);
// 授权后注册用户
router
.
get
(
'third'
,
'/user/info'
,
miniAuth
,
'course.v2.user.getUserInfo'
);
// 获取用户信息
router
.
get
(
'third'
,
'/user/baby'
,
miniAuth
,
'course.v2.user.getBabyInfo'
);
// 获取baby信息
router
.
get
(
'third'
,
'/user/baby'
,
miniAuth
,
'course.v2.user.getBabyInfo'
);
// 获取baby信息
router
.
post
(
'third'
,
'/user/baby'
,
miniAuth
,
'course.v2.user.saveBabyInfo'
);
// 保存baby信息
router
.
post
(
'third'
,
'/user/baby'
,
miniAuth
,
'course.v2.user.saveBabyInfo'
);
// 保存baby信息
...
@@ -34,9 +35,9 @@ module.exports = app => {
...
@@ -34,9 +35,9 @@ module.exports = app => {
router
.
get
(
'third'
,
'/comments'
,
miniAuth
,
'course.v2.institution.getComments'
);
// 评论列表
router
.
get
(
'third'
,
'/comments'
,
miniAuth
,
'course.v2.institution.getComments'
);
// 评论列表
router
.
get
(
'third'
,
'/search/hot'
,
miniAuth
,
'course.v2.institution.getHotSearch'
);
// 热搜
router
.
get
(
'third'
,
'/search/hot'
,
miniAuth
,
'course.v2.institution.getHotSearch'
);
// 热搜
router
.
get
(
'third'
,
'/search/suggest'
,
miniAuth
,
'course.v2.institution.getSuggestSearch'
);
//搜索联想
router
.
get
(
'third'
,
'/search/suggest'
,
miniAuth
,
'course.v2.institution.getSuggestSearch'
);
//
搜索联想
router
.
get
(
'third'
,
'/search'
,
miniAuth
,
'course.v2.institution.search'
);
// 搜索
router
.
get
(
'third'
,
'/search'
,
miniAuth
,
'course.v2.institution.search'
);
// 搜索
router
.
get
(
'third'
,
'/user/search'
,
miniAuth
,
'course.v2.institution.getUserSearch'
);
// 用户搜索历史
router
.
get
(
'third'
,
'/user/search'
,
miniAuth
,
'course.v2.institution.getUserSearch'
);
// 用户搜索历史
router
.
delete
(
'third'
,
'/user/search'
,
miniAuth
,
'course.v2.institution.deleteUserSearch'
);
//清空用户搜索记录
router
.
delete
(
'third'
,
'/user/search'
,
miniAuth
,
'course.v2.institution.deleteUserSearch'
);
//
清空用户搜索记录
};
};
app/service/course/v2/user.js
View file @
2a1a6964
...
@@ -118,7 +118,58 @@ class UserService extends Service {
...
@@ -118,7 +118,58 @@ class UserService extends Service {
}
}
// 获取用户信息
async
getUserInfo
()
{
const
{
ctx
}
=
this
;
const
userUuid
=
ctx
.
userUuid
;
const
userInfo
=
await
ctx
.
classModel
.
V2
.
CourseUser
.
findOne
({
where
:
{
uuid
:
userUuid
,
is_deleted
:
0
}
});
if
(
ctx
.
isEmpty
(
userInfo
))
{
ctx
.
failed
(
'用户不存在'
);
}
const
ret
=
{
bind_phone
:
ctx
.
isEmpty
(
userInfo
.
phone
)
?
0
:
1
,
};
return
ret
;
}
// 保存用户信息
async
registerUserInfo
(
input
)
{
const
{
ctx
}
=
this
;
const
userUuid
=
ctx
.
userUuid
;
const
{
avatar
,
nickname
,
province
,
country
,
sex
,
city
,
encryptedData
,
iv
}
=
input
;
// 查找用户是否存在并更新
const
user
=
ctx
.
classModel
.
V2
.
CourseUser
.
findOne
({
where
:
{
uuid
:
userUuid
,
is_deleted
:
0
}
});
if
(
ctx
.
isEmpty
(
user
))
{
ctx
.
failed
(
'用户不存在'
);
}
const
data
=
{};
if
(
!
ctx
.
isEmpty
(
avatar
))
{
data
.
avatar
=
avatar
;
}
if
(
!
ctx
.
isEmpty
(
nickname
))
{
data
.
nickname
=
nickname
;
}
if
(
!
ctx
.
isEmpty
(
encryptedData
)
&&
!
ctx
.
isEmpty
(
iv
))
{
const
decoded
=
await
ctx
.
service
.
course
.
v2
.
wechat
.
decodeData
(
encryptedData
,
iv
);
if
(
!
ctx
.
isEmpty
(
decoded
)
&&
!
ctx
.
isEmpty
(
decoded
.
phone
))
{
console
.
log
(
decoded
);
data
.
phone
=
decoded
.
phone
;
}
}
await
ctx
.
classModel
.
V2
.
CourseUser
.
update
(
data
,
{
where
:
{
id
:
user
.
id
}
});
const
ret
=
{
result
:
{
bind_phone
:
0
,
},
};
return
ret
;
}
}
}
module
.
exports
=
UserService
;
module
.
exports
=
UserService
;
app/service/course/v2/wechat.js
View file @
2a1a6964
...
@@ -4,6 +4,7 @@ const APPID = 'wx07a5f0ed5bdf4751';
...
@@ -4,6 +4,7 @@ const APPID = 'wx07a5f0ed5bdf4751';
const
SECRET
=
'a1b2d32b018988176181497bd74a0b7d'
;
const
SECRET
=
'a1b2d32b018988176181497bd74a0b7d'
;
const
fs
=
require
(
'fs'
);
const
fs
=
require
(
'fs'
);
const
request
=
require
(
'request'
);
const
request
=
require
(
'request'
);
const
crypto
=
require
(
'crypto'
);
class
WechatService
extends
Service
{
class
WechatService
extends
Service
{
async
getAccessToken
()
{
async
getAccessToken
()
{
...
@@ -136,6 +137,32 @@ class WechatService extends Service {
...
@@ -136,6 +137,32 @@ class WechatService extends Service {
return
ret
;
return
ret
;
}
}
// 解密
async
decodeData
(
encryptedData
,
iv
)
{
const
{
ctx
}
=
this
;
const
userUuid
=
ctx
.
userUuid
;
const
userInfo
=
await
ctx
.
app
.
memcache
.
get
(
'course_v2_user_session_'
+
userUuid
);
if
(
ctx
.
isEmpty
(
userInfo
)
||
ctx
.
isEmpty
(
userInfo
.
session_key
))
{
ctx
.
failed
(
'sessionKey不存在'
);
}
const
sessionKey
=
new
Buffer
(
userInfo
.
session_key
,
'base64'
);
// base64 decode
encryptedData
=
new
Buffer
(
encryptedData
,
'base64'
);
iv
=
new
Buffer
(
iv
,
'base64'
);
// 解密
const
decipher
=
crypto
.
createDecipheriv
(
'aes-128-cbc'
,
sessionKey
,
iv
);
// 设置自动 padding 为 true,删除填充补位
decipher
.
setAutoPadding
(
true
);
let
decoded
=
decipher
.
update
(
encryptedData
,
'binary'
,
'utf8'
);
decoded
+=
decipher
.
final
(
'utf8'
);
decoded
=
JSON
.
parse
(
decoded
);
return
decoded
;
}
}
}
module
.
exports
=
WechatService
;
module
.
exports
=
WechatService
;
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