diff --git a/routers/index.js b/routers/index.js index da140cd..0cb67ec 100644 --- a/routers/index.js +++ b/routers/index.js @@ -2,7 +2,9 @@ const express = require('express'); const router = express.Router(); const { User } = require('../models'); const { tokenStore } = require('../common/token'); -const { requestToken } = require('../common/wechat'); +const requestWeChatToken = require('../common/wechat').requestToken; +const requestCorpToken = require('../common/wechat-corp').requestToken; + const { userRequired, adminRequired, @@ -117,19 +119,28 @@ router.get('/configure', userRequired, (req, res, next) => { router.post('/configure', userRequired, async (req, res, next) => { let id = req.session.user.id; let user = { + // Common username: req.body.username, password: req.body.password, accessToken: req.body.accessToken, - email: req.body.email, + defaultMethod: req.body.defaultMethod, prefix: req.body.prefix, + // WeChat public account wechatAppId: req.body.wechatAppId, wechatAppSecret: req.body.wechatAppSecret, wechatTemplateId: req.body.wechatTemplateId, wechatOpenId: req.body.wechatOpenId, wechatVerifyToken: req.body.wechatVerifyToken, + // Email + email: req.body.email, smtpServer: req.body.smtpServer, smtpUser: req.body.smtpUser, smtpPass: req.body.smtpPass, + // WeChat corp + corpId: req.body.corpId, + corpAgentId: req.body.corpAgentId, + corpAppSecret: req.body.corpAppSecret, + corpUserId: req.body.corpUserId, }; for (let field in user) { let value = user[field]; @@ -150,18 +161,35 @@ router.post('/configure', userRequired, async (req, res, next) => { if (userObj) { await userObj.update(user); } + if (userObj.prefix !== req.session.user.prefix) { + tokenStore.delete(req.session.user.prefix); + } req.session.user = userObj; tokenStore.set(userObj.prefix, { + // Common + accessToken: userObj.accessToken, + defaultMethod: userObj.defaultMethod, + // WeChat test account wechatAppId: userObj.wechatAppId, wechatAppSecret: userObj.wechatAppSecret, wechatTemplateId: userObj.wechatTemplateId, wechatOpenId: userObj.wechatOpenId, wechatVerifyToken: userObj.wechatVerifyToken, - token: await requestToken(userObj.wechatAppId, userObj.wechatAppSecret), + wechatToken: await requestWeChatToken( + userObj.wechatAppId, + userObj.wechatAppSecret + ), + // Email email: userObj.email, smtpServer: userObj.smtpServer, smtpUser: userObj.smtpUser, smtpPass: userObj.smtpPass, + // WeChat corporation account + corpId: userObj.corpId, + corpAgentId: userObj.corpAgentId, + corpAppSecret: userObj.corpAppSecret, + corpUserId: userObj.corpUserId, + corpToken: await requestCorpToken(userObj.corpId, userObj.corpAppSecret), }); message = '配置更新成功'; console.debug(tokenStore); diff --git a/views/configure.ejs b/views/configure.ejs index a736a80..6aeb7c3 100644 --- a/views/configure.ejs +++ b/views/configure.ejs @@ -1,5 +1,21 @@ <%- include('./partials/header') %> +

配置页面

@@ -13,144 +29,239 @@ 你正在使用的密码是默认密码,请尽快修改!
- <% }%> + <% } %>

注意

- 微信公众平台测试号配置链接,如果遇到问题,请仔细阅读 README,如果还不能解决,请提 issue。 -
-
- 根据你在 config.js 中填写的 href 以及你的 prefix,你的接口验证 URL为:<%- verifyUrl %>。 -
-
- 如果本项目对你有意义,请 ⭐ 该项目这是我继续维护的主要动力,谢谢 :)。 + 如果遇到问题,请仔细阅读 + README,如果还不能解决,请提 + issue。 +
+
+ 如果本项目对你有意义,请 ⭐ 该项目, + 这是我继续维护的主要动力 + ,谢谢 :)。
-
- -
- -
+ -
- -
- +
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+
+ 可选值有:test(使用微信测试号进行推送),corp(使用微信企业号进行推送),email(使用邮件进行推送) +
+
+
+ +
+
+
+ +
+
+ 前缀默认和用户名相同,如非必要,无需修改 +
+
+
+ +
+
+ +
+ +
+
+ Access Token 可防止未授权者利用本系统向你发送消息,留空则不做该检查 +
+
+
+ +
- -
- -
- -
-
- -
- -
- -
-
- -
- -
- -
-
- -
- +