企微考试提交
This commit is contained in:
@@ -3,6 +3,6 @@ module.exports = {
|
|||||||
user: "root",
|
user: "root",
|
||||||
port: 3306,
|
port: 3306,
|
||||||
password: "Cwy@2019",
|
password: "Cwy@2019",
|
||||||
database: "dvcp_oms_dev",
|
database: "dvcp_v2_dev",
|
||||||
multipleStatements: true
|
multipleStatements: true
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,8 @@ module.exports = {
|
|||||||
log(`${chalk.bgBlue.black(" REST ")} ${rest.action}`)
|
log(`${chalk.bgBlue.black(" REST ")} ${rest.action}`)
|
||||||
if (rest.method == "post") {
|
if (rest.method == "post") {
|
||||||
ins.post(rest.action, (req, res) => rest.execute(req, res))
|
ins.post(rest.action, (req, res) => rest.execute(req, res))
|
||||||
|
} else if (rest.method == "get") {
|
||||||
|
ins.get(rest.action, (req, res) => rest.execute(req, res))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
20
src/rest/wxtest/action.js
Normal file
20
src/rest/wxtest/action.js
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
const {getSignature, decrypt} = require("@wecom/crypto");
|
||||||
|
const {addOrUpdate} = require("../../utils/dbUitls");
|
||||||
|
const token = "pnYAdXEHYzYhIyzE6Qbs2L"
|
||||||
|
const encodingAESKey = "fHkOHrUGSVUmPjFmshLEFN2XbaqF3OxsuYgnJu6DB1G"
|
||||||
|
module.exports = {
|
||||||
|
action: "/node/wxtest/action",
|
||||||
|
method: "post",
|
||||||
|
execute: (request, response) => {
|
||||||
|
const {msg_signature, timestamp, nonce, echostr} = request.query
|
||||||
|
const signature = getSignature(token, timestamp, nonce, echostr);
|
||||||
|
if (msg_signature == signature) {
|
||||||
|
const context = decrypt(encodingAESKey, echostr)
|
||||||
|
const {name, mobile: phone, email, userId} = context
|
||||||
|
addOrUpdate({
|
||||||
|
table: "sys_user", form: {name, email, phone, userId}
|
||||||
|
})
|
||||||
|
response.send({code: 0, message: "success"})
|
||||||
|
}else response.send({code: 1, message: "error"})
|
||||||
|
}
|
||||||
|
}
|
||||||
18
src/rest/wxtest/actionGet.js
Normal file
18
src/rest/wxtest/actionGet.js
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
const {getSignature, decrypt} = require("@wecom/crypto");
|
||||||
|
const token = "pnYAdXEHYzYhIyzE6Qbs2L"
|
||||||
|
const encodingAESKey = "fHkOHrUGSVUmPjFmshLEFN2XbaqF3OxsuYgnJu6DB1G"
|
||||||
|
module.exports = {
|
||||||
|
action: "/node/wxtest/action",
|
||||||
|
method: "get",
|
||||||
|
execute: (request, response) => {
|
||||||
|
const {msg_signature, timestamp, nonce, Encrypt} = request.query
|
||||||
|
const signature = getSignature(token, timestamp, nonce, Encrypt);
|
||||||
|
console.log(msg_signature, signature)
|
||||||
|
if (msg_signature == signature) {
|
||||||
|
const context = decrypt(encodingAESKey, Encrypt)
|
||||||
|
response.send(context)
|
||||||
|
} else {
|
||||||
|
response.send({code: 1, message: "验证不通过"})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
16
src/rest/wxtest/add.js
Normal file
16
src/rest/wxtest/add.js
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
const dbUtils = require("../../utils/dbUitls");
|
||||||
|
module.exports = {
|
||||||
|
action: "/node/duty/addOrUpdate",
|
||||||
|
method: "post",
|
||||||
|
execute: (request, response) => {
|
||||||
|
let {id, dutyUserId,dutyUserName,dutyStartTime,dutyEndTime} = request.body
|
||||||
|
dbUtils.addOrUpdate({
|
||||||
|
table: 'node_wx_test_duty',
|
||||||
|
form: {id, dutyUserId,dutyUserName,dutyStartTime,dutyEndTime}
|
||||||
|
}).then(data => {
|
||||||
|
response.send({code: 0, data})
|
||||||
|
}).catch(err => {
|
||||||
|
response.send({code: 1, err: err?.sqlMessage || err || ""})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
38
src/rest/wxtest/getUserInfo.js
Normal file
38
src/rest/wxtest/getUserInfo.js
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
const axios = require("axios");
|
||||||
|
const CORPID = "ww596787bb70f08288"
|
||||||
|
const SECRET = "Bh3GT11_bzxSm03xZBY8otjw_WLWeLsduzDQweUohAY"
|
||||||
|
/**
|
||||||
|
* 获取access_token
|
||||||
|
*/
|
||||||
|
const getAccessToken = (corpid = CORPID, secret = SECRET) => {
|
||||||
|
const url = `https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=${corpid}&corpsecret=${secret}`
|
||||||
|
return axios.get(url).then(res => {
|
||||||
|
return res.data?.access_token
|
||||||
|
})
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 获取 userId及其他信息
|
||||||
|
*/
|
||||||
|
const getUserInfo = (accessToken, code) => {
|
||||||
|
return axios.get(`https://qyapi.weixin.qq.com/cgi-bin/user/getuserinfo`, {
|
||||||
|
params: {access_token: accessToken, code}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
module.exports = {
|
||||||
|
action: "/node/wxtest/token",
|
||||||
|
method: "post",
|
||||||
|
execute: (request, response) => {
|
||||||
|
const {code} = request.query
|
||||||
|
getAccessToken().then(token => getUserInfo(token, code)).then(res => {
|
||||||
|
if (res?.data?.data) {
|
||||||
|
response.send({code: 0, data: res.data.data})
|
||||||
|
} else {
|
||||||
|
console.log(res.data)
|
||||||
|
response.send({code: 1, err: res.data})
|
||||||
|
}
|
||||||
|
}).catch(err => {
|
||||||
|
console.log(err)
|
||||||
|
response.send({code: 1, err})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
16
src/rest/wxtest/list.js
Normal file
16
src/rest/wxtest/list.js
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
const dbUtils = require("../../utils/dbUitls");
|
||||||
|
module.exports = {
|
||||||
|
action: "/node/duty/list",
|
||||||
|
method: "post",
|
||||||
|
execute: (request, response) => {
|
||||||
|
let {size, current} = request.query
|
||||||
|
dbUtils.list({
|
||||||
|
table: 'node_wx_test_duty',
|
||||||
|
search: {size, current}, sort: 'dutyStartTime', con: "dutyUserName"
|
||||||
|
}).then(data => {
|
||||||
|
response.send({code: 0, data})
|
||||||
|
}).catch(err => {
|
||||||
|
response.send({code: 1, err: err?.sqlMessage || err || ""})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -9,7 +9,7 @@ const getAccessToken = (corpid = CORPID, secret = SECRET) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
action: "/wxwork/addressBook/token",
|
action: "/node/wxtest/token",
|
||||||
method: "post",
|
method: "post",
|
||||||
execute: (request, response) => {
|
execute: (request, response) => {
|
||||||
getAccessToken().then(token => {
|
getAccessToken().then(token => {
|
||||||
@@ -18,5 +18,6 @@ module.exports = {
|
|||||||
console.log(err)
|
console.log(err)
|
||||||
response.send({code: 1, err})
|
response.send({code: 1, err})
|
||||||
})
|
})
|
||||||
}
|
},
|
||||||
|
getAccessToken
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user