From aedf5de6d18824c0dd791fb82d3c80f41e5ccaf9 Mon Sep 17 00:00:00 2001 From: HCLonely Date: Tue, 10 May 2022 11:14:17 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0NowPush,=20iGot=E6=94=AF?= =?UTF-8?q?=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 19 +++++++ dist/IGot.js | 115 +++++++++++++++++++++++++++++++++++++++ dist/NowPush.js | 118 ++++++++++++++++++++++++++++++++++++++++ dist/types/IGot.d.ts | 17 ++++++ dist/types/NowPush.d.ts | 17 ++++++ package.json | 2 +- src/IGot.ts | 96 ++++++++++++++++++++++++++++++++ src/NowPush.ts | 99 +++++++++++++++++++++++++++++++++ 8 files changed, 482 insertions(+), 1 deletion(-) create mode 100644 dist/IGot.js create mode 100644 dist/NowPush.js create mode 100644 dist/types/IGot.d.ts create mode 100644 dist/types/NowPush.d.ts create mode 100644 src/IGot.ts create mode 100644 src/NowPush.ts diff --git a/README.md b/README.md index f6759bb..76ac867 100644 --- a/README.md +++ b/README.md @@ -20,6 +20,8 @@ - [企业微信群机器人](https://open.work.weixin.qq.com/api/doc/90000/90136/91770) - [息知](https://xz.qqoq.net/#/index) - [WxPusher](https://wxpusher.zjiecode.com/docs/) +- [NowPush](https://www.nowpush.app/index.html) +- [iGot](http://hellyw.com/) ## 安装 @@ -168,6 +170,22 @@ const { PushApi } = require('all-pusher-api'); // 多平台同时推送 user_id: '******' } } + }, + { + name: 'NowPush', + config: { + key: { + token: '******' + } + } + }, + { + name: 'IGot', + config: { + key: { + token: '******' + } + } } ]) .send({ message: '测试文本' })).map((e) => (e.result.status >= 200 && e.result.status < 300) ? `${e.name} 测试成功` : e)); @@ -454,6 +472,7 @@ const results: Array<{ - QQ(go-cqhttp): 'text', 'other' - Discord: 'text', 'other' - 飞书: 'text', 'other' +- NowPush: 'text', 'other' - Server酱Turbo: 'text', 'markdown' - 息知: 'text', 'markdown' - PushDeer: 'text', 'markdown', 'other' diff --git a/dist/IGot.js b/dist/IGot.js new file mode 100644 index 0000000..1d23644 --- /dev/null +++ b/dist/IGot.js @@ -0,0 +1,115 @@ +'use strict'; + +var _defineProperty = require("@babel/runtime/helpers/defineProperty"); + +Object.defineProperty(exports, '__esModule', { + value: true +}); + +var axios = require('axios'); + +var tool = require('./tool'); + +function _interopDefaultLegacy(e) { + return e && typeof e === 'object' && 'default' in e ? e : { + 'default': e + }; +} + +var axios__default = /*#__PURE__*/_interopDefaultLegacy(axios); + +class IGot { + constructor({ + token, + key, + proxy + }) { + _defineProperty(this, "_KEY", void 0); + + _defineProperty(this, "baseURL", 'https://push.hellyw.com/'); + + _defineProperty(this, "httpsAgent", void 0); + + if (!token && !(key !== null && key !== void 0 && key.token)) { + throw new Error('Missing Parameter: token'); + } // @ts-ignore + + + this._KEY = token || key.token; + + if (proxy) { + this.httpsAgent = tool.proxy2httpsAgent(proxy); + } + } + + async send(sendOptions) { + if (!sendOptions.message && !sendOptions.customOptions) { + return { + status: 0, + statusText: 'Missing Parameter: message', + extraMessage: null + }; + } + + let iGotOptions; + + if (sendOptions.customOptions) { + iGotOptions = sendOptions.customOptions; + } else { + iGotOptions = { + title: sendOptions.title || sendOptions.message.split('\n')[0].trim().slice(0, 10), + content: sendOptions.message + }; + } + + if (sendOptions.extraOptions) { + iGotOptions = { ...iGotOptions, + ...sendOptions.extraOptions + }; + } + + const axiosOptions = { + url: `${this.baseURL}${this._KEY}`, + method: 'POST', + headers: { + 'Content-type': 'application/json' + }, + data: iGotOptions + }; + + if (this.httpsAgent) { + axiosOptions.httpsAgent = this.httpsAgent; + } + + return axios__default["default"](axiosOptions).then(response => { + if (response.data) { + if (response.data.ret === 0) { + return { + status: 200, + statusText: 'Success', + extraMessage: response + }; + } + + return { + status: 100, + statusText: 'Error', + extraMessage: response + }; + } + + return { + status: 101, + statusText: 'No Response Data', + extraMessage: response + }; + }).catch(error => ({ + status: 102, + statusText: 'Request Error', + extraMessage: error + })); + } + +} + +exports.IGot = IGot; diff --git a/dist/NowPush.js b/dist/NowPush.js new file mode 100644 index 0000000..4d36086 --- /dev/null +++ b/dist/NowPush.js @@ -0,0 +1,118 @@ +'use strict'; + +var _defineProperty = require("@babel/runtime/helpers/defineProperty"); + +Object.defineProperty(exports, '__esModule', { + value: true +}); + +var axios = require('axios'); + +var tool = require('./tool'); + +function _interopDefaultLegacy(e) { + return e && typeof e === 'object' && 'default' in e ? e : { + 'default': e + }; +} + +var axios__default = /*#__PURE__*/_interopDefaultLegacy(axios); + +class NowPush { + constructor({ + token, + key, + proxy + }) { + _defineProperty(this, "_KEY", void 0); + + _defineProperty(this, "baseURL", 'https://www.api.nowpush.app/v3/sendMessage'); + + _defineProperty(this, "httpsAgent", void 0); + + if (!token && !(key !== null && key !== void 0 && key.token)) { + throw new Error('Missing Parameter: token'); + } // @ts-ignore + + + this._KEY = token || key.token; + + if (proxy) { + this.httpsAgent = tool.proxy2httpsAgent(proxy); + } + } + + async send(sendOptions) { + if (!sendOptions.message && !sendOptions.customOptions) { + return { + status: 0, + statusText: 'Missing Parameter: message', + extraMessage: null + }; + } + + let nowPushOptions; + + if (sendOptions.customOptions) { + nowPushOptions = sendOptions.customOptions; + } else { + nowPushOptions = { + message_type: 'nowpush_note', + note: sendOptions.message + }; + } + + nowPushOptions.device_type = 'api'; + + if (sendOptions.extraOptions) { + nowPushOptions = { ...nowPushOptions, + ...sendOptions.extraOptions + }; + } + + const axiosOptions = { + url: this.baseURL, + method: 'POST', + headers: { + 'Content-type': 'application/x-www-form-urlencoded', + Authorization: `Bearer ${this._KEY}` + }, + data: tool.queryStringify(nowPushOptions) + }; + + if (this.httpsAgent) { + axiosOptions.httpsAgent = this.httpsAgent; + } + + return axios__default["default"](axiosOptions).then(response => { + if (response.data) { + if (response.data.isError === false) { + return { + status: 200, + statusText: 'Success', + extraMessage: response + }; + } + + return { + status: 100, + statusText: 'Error', + extraMessage: response + }; + } + + return { + status: 101, + statusText: 'No Response Data', + extraMessage: response + }; + }).catch(error => ({ + status: 102, + statusText: 'Request Error', + extraMessage: error + })); + } + +} + +exports.NowPush = NowPush; diff --git a/dist/types/IGot.d.ts b/dist/types/IGot.d.ts new file mode 100644 index 0000000..a1cd47a --- /dev/null +++ b/dist/types/IGot.d.ts @@ -0,0 +1,17 @@ +import { AxiosRequestConfig } from 'axios'; +import { proxy, result, sendOptions } from './tool'; +interface IGotConfig { + key?: { + token: string; + }; + token?: string; + proxy?: proxy; +} +declare class IGot { + protected _KEY: string; + readonly baseURL = "https://push.hellyw.com/"; + httpsAgent?: AxiosRequestConfig['httpsAgent']; + constructor({ token, key, proxy }: IGotConfig); + send(sendOptions: sendOptions): Promise; +} +export { IGot }; diff --git a/dist/types/NowPush.d.ts b/dist/types/NowPush.d.ts new file mode 100644 index 0000000..ddda893 --- /dev/null +++ b/dist/types/NowPush.d.ts @@ -0,0 +1,17 @@ +import { AxiosRequestConfig } from 'axios'; +import { proxy, result, sendOptions } from './tool'; +interface NowPushConfig { + key?: { + token: string; + }; + token?: string; + proxy?: proxy; +} +declare class NowPush { + protected _KEY: string; + readonly baseURL = "https://www.api.nowpush.app/v3/sendMessage"; + httpsAgent?: AxiosRequestConfig['httpsAgent']; + constructor({ token, key, proxy }: NowPushConfig); + send(sendOptions: sendOptions): Promise; +} +export { NowPush }; diff --git a/package.json b/package.json index 2368a28..121fe30 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "all-pusher-api", - "version": "1.0.2", + "version": "1.0.3", "description": "统一化推送服务API.", "main": "dist/index.js", "scripts": { diff --git a/src/IGot.ts b/src/IGot.ts new file mode 100644 index 0000000..7346207 --- /dev/null +++ b/src/IGot.ts @@ -0,0 +1,96 @@ +import axios, { AxiosRequestConfig } from 'axios'; +import { proxy2httpsAgent, proxy, result, sendOptions } from './tool'; + +interface IGotConfig { + key?: { + token: string + } + token?: string + proxy?: proxy +} +interface IGotOptions { + title: string + content: string + [name: string]: any +} + +class IGot { + protected _KEY: string; + readonly baseURL = 'https://push.hellyw.com/'; + httpsAgent?: AxiosRequestConfig['httpsAgent']; + + constructor({ token, key, proxy }: IGotConfig) { + if (!token && !key?.token) { + throw new Error('Missing Parameter: token'); + } + // @ts-ignore + this._KEY = token || key.token; + if (proxy) { + this.httpsAgent = proxy2httpsAgent(proxy); + } + } + + async send(sendOptions: sendOptions): Promise { + if (!sendOptions.message && !sendOptions.customOptions) { + return { + status: 0, + statusText: 'Missing Parameter: message', + extraMessage: null + }; + } + let iGotOptions: IGotOptions; + if (sendOptions.customOptions) { + iGotOptions = sendOptions.customOptions; + } else { + iGotOptions = { + title: sendOptions.title || sendOptions.message.split('\n')[0].trim().slice(0, 10), + content: sendOptions.message + }; + } + if (sendOptions.extraOptions) { + iGotOptions = { + ...iGotOptions, + ...sendOptions.extraOptions + }; + } + + const axiosOptions: AxiosRequestConfig = { + url: `${this.baseURL}${this._KEY}`, + method: 'POST', + headers: { + 'Content-type': 'application/json' + }, + data: iGotOptions + }; + if (this.httpsAgent) { + axiosOptions.httpsAgent = this.httpsAgent; + } + return axios(axiosOptions).then((response) => { + if (response.data) { + if (response.data.ret === 0) { + return { + status: 200, + statusText: 'Success', + extraMessage: response + }; + } + return { + status: 100, + statusText: 'Error', + extraMessage: response + }; + } + return { + status: 101, + statusText: 'No Response Data', + extraMessage: response + }; + }).catch((error) => ({ + status: 102, + statusText: 'Request Error', + extraMessage: error + })); + } +} + +export { IGot }; diff --git a/src/NowPush.ts b/src/NowPush.ts new file mode 100644 index 0000000..2cb6f66 --- /dev/null +++ b/src/NowPush.ts @@ -0,0 +1,99 @@ +import axios, { AxiosRequestConfig } from 'axios'; +import { queryStringify, proxy2httpsAgent, proxy, result, sendOptions } from './tool'; + +interface NowPushConfig { + key?: { + token: string + } + token?: string + proxy?: proxy +} +interface NowPushOptions { + message_type: string + note: string + device_type?: string + [name: string]: any +} + +class NowPush { + protected _KEY: string; + readonly baseURL = 'https://www.api.nowpush.app/v3/sendMessage'; + httpsAgent?: AxiosRequestConfig['httpsAgent']; + + constructor({ token, key, proxy }: NowPushConfig) { + if (!token && !key?.token) { + throw new Error('Missing Parameter: token'); + } + // @ts-ignore + this._KEY = token || key.token; + if (proxy) { + this.httpsAgent = proxy2httpsAgent(proxy); + } + } + + async send(sendOptions: sendOptions): Promise { + if (!sendOptions.message && !sendOptions.customOptions) { + return { + status: 0, + statusText: 'Missing Parameter: message', + extraMessage: null + }; + } + let nowPushOptions: NowPushOptions; + if (sendOptions.customOptions) { + nowPushOptions = sendOptions.customOptions; + } else { + nowPushOptions = { + message_type: 'nowpush_note', + note: sendOptions.message + }; + } + nowPushOptions.device_type = 'api'; + if (sendOptions.extraOptions) { + nowPushOptions = { + ...nowPushOptions, + ...sendOptions.extraOptions + }; + } + + const axiosOptions: AxiosRequestConfig = { + url: this.baseURL, + method: 'POST', + headers: { + 'Content-type': 'application/x-www-form-urlencoded', + Authorization: `Bearer ${this._KEY}` + }, + data: queryStringify(nowPushOptions) + }; + if (this.httpsAgent) { + axiosOptions.httpsAgent = this.httpsAgent; + } + return axios(axiosOptions).then((response) => { + if (response.data) { + if (response.data.isError === false) { + return { + status: 200, + statusText: 'Success', + extraMessage: response + }; + } + return { + status: 100, + statusText: 'Error', + extraMessage: response + }; + } + return { + status: 101, + statusText: 'No Response Data', + extraMessage: response + }; + }).catch((error) => ({ + status: 102, + statusText: 'Request Error', + extraMessage: error + })); + } +} + +export { NowPush };