tmc.js 0.3.6 → 0.3.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +24 -1
- package/lib/consumer.js +8 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -75,7 +75,7 @@ new Tmc('your_app_key', 'your_app_secret')
|
|
|
75
75
|
|
|
76
76
|
**`tmc.send(msg: Message, options?: { mask?: true, binary?: true }, cb?: (err: Error) => void) => void`**
|
|
77
77
|
|
|
78
|
-
|
|
78
|
+
自`v0.3.4`起,当自动应答确认消息无法满足需求的时候,比如消息处理失败,需要`Publisher`再次重推消息,在实例初始化时置`options.autoReplyConfirmation=false`,则在消息处理函数内,可以通过 `this.send()` 函数回复`确认`或者`失败`消息。例如:
|
|
79
79
|
|
|
80
80
|
```js
|
|
81
81
|
new Tmc('your_app_key', 'your_app_secret', { autoReplyConfirmation: false })
|
|
@@ -91,6 +91,29 @@ new Tmc('your_app_key', 'your_app_secret', { autoReplyConfirmation: false })
|
|
|
91
91
|
.connect();
|
|
92
92
|
```
|
|
93
93
|
|
|
94
|
+
也可以使用此方法发送`To淘宝`消息,`>=v0.3.4 && <v0.3.7`版本,需要自主对`$.content.content`数据做`JSON`字符串化(**特别注意:**原生`JSON`对`BigInt`类型无法处理)。自`v0.3.7`起,可直接对`$.content.content`以原生数据类型描述。例如:
|
|
95
|
+
|
|
96
|
+
```js
|
|
97
|
+
/** @see https://open.taobao.com/tmc.htm?docId=732&docType=9 */
|
|
98
|
+
.send(
|
|
99
|
+
new Mesage(MessageType.SEND, MessageKind.Data)
|
|
100
|
+
.with(MessageFields.TOPIC, 'taobao_fuwu_ElectronicInvoice')
|
|
101
|
+
.with(MessageFields.CONTENT, {
|
|
102
|
+
id: 12345678901234567n, // 支持 BigInt 类型
|
|
103
|
+
tid: 12345678901234567n,
|
|
104
|
+
oid: 12345678901234567n,
|
|
105
|
+
invoice_file: 12345678901234567n,
|
|
106
|
+
e_invoice_no: '12342243435466',
|
|
107
|
+
invoice_time: '2015-04-10 10:33:49', // 时区 +08:00
|
|
108
|
+
invoice_no: '123456',
|
|
109
|
+
invoice_code: '123456',
|
|
110
|
+
amount: '100.00',
|
|
111
|
+
})
|
|
112
|
+
// >=v0.3.4 && <v0.3.7 写法
|
|
113
|
+
// .with(MessageFields.CONTENT, '{"id":12345678901234567,"tid":12345678901234567,"amount":"100.00"}')
|
|
114
|
+
)
|
|
115
|
+
```
|
|
116
|
+
|
|
94
117
|
<details><summary>可选设置的 NODE_DEBUG=< label > 环境变量</summary>
|
|
95
118
|
|
|
96
119
|
| label | 说明 |
|
package/lib/consumer.js
CHANGED
|
@@ -99,10 +99,16 @@ class TaoMessageConsumer extends EventEmitter {
|
|
|
99
99
|
* @param {object|Function} [options] - The options
|
|
100
100
|
* @param {Function} [cb] - The Callback
|
|
101
101
|
* @returns {void}
|
|
102
|
-
* @since v0.3.4
|
|
102
|
+
* @since v0.3.4 Exposed for `send(new Message(SENDACK, Failed))` scene
|
|
103
|
+
* @since v0.3.7 The `data.content.content` can be a plain `object` now
|
|
103
104
|
*/
|
|
104
105
|
send(data, options = { mask: true, binary: true }, cb = undefined) {
|
|
105
|
-
if (data instanceof Message) {
|
|
106
|
+
if (data instanceof Message) {
|
|
107
|
+
if (typeof data[CONTENT][CONTENT] === 'object' && data[CONTENT][CONTENT] !== null) {
|
|
108
|
+
Reflect.set(data[CONTENT], CONTENT, stringify(data[CONTENT][CONTENT]));
|
|
109
|
+
}
|
|
110
|
+
this[kWebSocket]?.send(data.with(TOKEN, this[kToken]).buffer, options, cb);
|
|
111
|
+
}
|
|
106
112
|
}
|
|
107
113
|
|
|
108
114
|
onopen() {
|