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
640b7af1
Commit
640b7af1
authored
Feb 28, 2020
by
Hsinli
Browse files
Options
Browse Files
Download
Plain Diff
add
parents
b1984a2c
7c3a4e01
Pipeline
#19702
passed with stage
in 2 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
47 additions
and
1 deletion
+47
-1
user.js
app/controller/course/v4/user.js
+1
-1
wechat.js
app/service/course/v4/wechat.js
+46
-0
No files found.
app/controller/course/v4/user.js
View file @
640b7af1
...
...
@@ -19,7 +19,7 @@ class UserController extends Controller {
const
session_key
=
wx_auth_ret
.
session_key
;
// 检查是否已授权过 是否已入用户表
let
user
=
await
ctx
.
classModel
.
V4
.
CourseUser
.
one
({
where
:
{
openid
,
is_deleted
:
0
}
});
let
user
=
await
ctx
.
classModel
.
V4
.
CourseUser
.
findOne
({
where
:
{
openid
,
is_deleted
:
0
},
order
:
[[
'id'
,
'asc'
]]
});
if
(
!
user
||
!
user
.
uuid
)
{
const
uuid
=
uuidv4
();
user
=
await
ctx
.
classModel
.
V4
.
CourseUser
.
create
({
uuid
,
openid
});
...
...
app/service/course/v4/wechat.js
View file @
640b7af1
...
...
@@ -31,6 +31,52 @@ class WechatService extends Service {
}
async
sendMsg
(
data
)
{
const
{
ctx
}
=
this
;
ctx
.
logger
.
info
(
'111'
);
if
(
ctx
.
isEmpty
(
data
)
||
ctx
.
isEmpty
(
data
.
MsgType
))
{
ctx
.
logger
.
info
(
JSON
.
stringify
(
data
));
return
;
}
ctx
.
logger
.
info
(
data
.
MsgType
);
if
(
data
.
MsgType
===
'miniprogrampage'
)
{
ctx
.
logger
.
info
(
'------------miniprogrampage---------'
);
await
this
.
sendImage
(
data
);
}
else
if
(
data
.
MsgType
===
'text'
)
{
ctx
.
logger
.
info
(
'------------sendText------'
);
await
this
.
sendText
(
data
);
}
return
;
}
async
sendText
(
data
)
{
const
{
ctx
}
=
this
;
if
(
ctx
.
isEmpty
(
data
)
||
ctx
.
isEmpty
(
data
.
Content
)
||
!
data
.
Content
.
includes
(
'在线课程编号:'
))
{
ctx
.
logger
.
info
(
data
.
Content
);
ctx
.
logger
.
info
(
data
.
Content
.
includes
(
'在线课程编号:'
));
return
;
}
const
id
=
data
.
Content
.
replace
(
'在线课程编号:'
,
''
);
const
classInfo
=
await
ctx
.
classModel
.
V4
.
CourseOnlineClass
.
findOne
({
where
:
{
id
}
});
ctx
.
logger
.
info
(
'course_v4: '
+
JSON
.
stringify
(
classInfo
));
const
content
=
ctx
.
isEmpty
(
classInfo
)
||
ctx
.
isEmpty
(
classInfo
.
channel
)
?
''
:
classInfo
.
channel
;
const
token
=
await
this
.
getAccessToken
();
const
url
=
'https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token='
+
token
;
const
params
=
{
access_token
:
token
,
touser
:
data
.
FromUserName
,
msgtype
:
'text'
,
text
:
{
content
},
};
ctx
.
logger
.
info
(
'course_wechat_v4_param: '
+
JSON
.
stringify
(
params
));
const
resp
=
await
ctx
.
helper
.
send_request
(
url
,
params
,
{
method
:
'POST'
});
ctx
.
logger
.
info
(
'course_wechat_v4_resp: '
+
JSON
.
stringify
(
resp
));
return
;
}
async
sendImage
(
data
)
{
const
{
ctx
,
app
}
=
this
;
if
(
ctx
.
isEmpty
(
data
))
{
...
...
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