From 5893ee5d9ccf3009c80e99b77d3fcb34e0fa2a09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=99=E5=96=84=E6=98=8E?= Date: Thu, 16 May 2019 16:41:46 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E8=B4=A6=E5=8F=B7=E4=BF=A1?= =?UTF-8?q?=E6=81=AF=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bizwechat-configurator.html | 72 +++++++++++++++++++++++++++++++++++++ bizwechat-configurator.js | 17 +++++++++ bizwechat.html | 55 ++++++++++++++-------------- bizwechat.js | 14 ++++---- package.json | 4 ++- 5 files changed, 126 insertions(+), 36 deletions(-) create mode 100644 bizwechat-configurator.html create mode 100644 bizwechat-configurator.js diff --git a/bizwechat-configurator.html b/bizwechat-configurator.html new file mode 100644 index 0000000..be4bfe9 --- /dev/null +++ b/bizwechat-configurator.html @@ -0,0 +1,72 @@ + + + \ No newline at end of file diff --git a/bizwechat-configurator.js b/bizwechat-configurator.js new file mode 100644 index 0000000..8a8a516 --- /dev/null +++ b/bizwechat-configurator.js @@ -0,0 +1,17 @@ +module.exports = (RED) => { + function bizWechatConfiguratorNode(n) { + RED.nodes.createNode(this, n); + + this.name = n.name; + this.port = n.port; + this.cropid = n.cropid; + this.agentid = n.agentid; + this.token = n.token; + this.corpsecret = n.corpsecret + this.aeskey = n.aeskey; + + var node = this; + } + + RED.nodes.registerType("bizwechat-configurator", bizWechatConfiguratorNode); +} \ No newline at end of file diff --git a/bizwechat.html b/bizwechat.html index 3bf591c..ea8636f 100644 --- a/bizwechat.html +++ b/bizwechat.html @@ -10,22 +10,11 @@ name: { value: '' }, - cropid: { + bizwechat: { value: '', - required: true + type: 'bizwechat-configurator' }, - token: { - value: '', - required: true - }, - aeskey: { - value: '', - required: true - }, - port: { - value: '', - required: true - } + }, inputs: 0, outputs: 1, @@ -38,7 +27,16 @@ label() { return this.name || '输出' }, - defaults: {}, + defaults: { + name: { + value: '' + }, + bizwechat: { + value: '', + type: 'bizwechat-configurator' + }, + + }, inputs: 1, outputs: 0, icon: 'white-globe.png', @@ -47,25 +45,26 @@ + + + - \ No newline at end of file diff --git a/bizwechat.js b/bizwechat.js index bb8d516..d5aa5ce 100644 --- a/bizwechat.js +++ b/bizwechat.js @@ -93,14 +93,14 @@ module.exports = RED => { constructor(config) { const node = this RED.nodes.createNode(node, config) - console.log('in config', config) + const bizwechat = RED.nodes.getNode(config.bizwechat); + this.newConfig = Object.assign({}, bizwechat, config) // 建立server - const server = createServer(config, node, (res, req, message) => node.send({ - res, - req, - config, - message - })) + const server = createServer(this.newConfig, node, (res, req, message) => { + node.send({res, req, config: this.newConfig, message }) + } + ) + server.on('error', ({ message }) => { diff --git a/package.json b/package.json index 39dbdc3..5dda889 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,9 @@ ], "node-red": { "nodes": { - "bizwechat": "bizwechat.js" + "bizwechat": "bizwechat.js", + "bizwechat-configurator": "bizwechat-configurator.js" + } }, "author": "FlashSoft",