This repository was archived by the owner on Jan 10, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 308
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: 🎸 增加checklogin api接口和token生成机制
- Loading branch information
chentianyu
committed
Oct 7, 2023
1 parent
d8d8237
commit 1b64d1e
Showing
9 changed files
with
102 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
PORT=3001 | ||
# 如果想自己处理收到消息的逻辑,在下面填上你的API地址, 默认为空 | ||
LOCAL_RECVD_MSG_API= | ||
LOCAL_RECVD_MSG_API= | ||
# 登录地址Token访问地址: http://localhost:3001/loginCheck?token=[LOCAL_LOGIN_API_TOKEN] | ||
# 生成规则:src/utils/index.js | ||
LOCAL_LOGIN_API_TOKEN= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
// 给 shell 调用使用 | ||
const { generateToken } = require('../src/utils/index') | ||
|
||
console.log(generateToken()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
// 此处批量管理注册的webhook | ||
const registerMsgPusherRouter = require('./msg') | ||
const registerLoginCheck = require('./loginCheck') | ||
|
||
module.exports = function registerRoute({app, bot}) { | ||
registerMsgPusherRouter({app, bot}) | ||
registerLoginCheck({app, bot}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// 登录 | ||
module.exports = function registerLoginCheck({ app, bot }) { | ||
let message, | ||
success = false | ||
|
||
bot | ||
.on('scan', qrcode => { | ||
message = 'https://wechaty.js.org/qrcode/' + encodeURIComponent(qrcode) | ||
success = false | ||
}) | ||
.on('login', user => { | ||
message = user + 'is already login' | ||
success = true | ||
}) | ||
.on('logout', user => { | ||
message = '' | ||
success = false | ||
}) | ||
|
||
// 处理 POST 请求 | ||
app.get('/loginCheck', async (req, res) => { | ||
|
||
// getLoginApiToken | ||
const { token } = req.query | ||
|
||
if (token !== process.env.globalLoginToken) { | ||
return res.status(401).json({ | ||
success: false, | ||
message: 'Unauthorized: Access is denied due to invalid credentials.' | ||
}); | ||
} | ||
|
||
try { | ||
res.status(200).json({ | ||
success, | ||
message | ||
}) | ||
|
||
} catch (error) { | ||
console.error('Error handling POST request:', error); | ||
res.status(500).json({ success: false, message: 'Internal server error.' }); | ||
} | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters