适配开发环境,对fetch和sms 文件多后缀处理
This commit is contained in:
parent
27b31d4e13
commit
3d96075b34
|
|
@ -1,12 +1,10 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.AliSmsInstance = exports.TencentSmsInstance = void 0;
|
||||
var tslib_1 = require("tslib");
|
||||
var Sms_1 = require("./service/tencent/Sms");
|
||||
Object.defineProperty(exports, "TencentSmsInstance", { enumerable: true, get: function () { return Sms_1.TencentSmsInstance; } });
|
||||
var Sms_2 = require("./service/ali/Sms");
|
||||
Object.defineProperty(exports, "AliSmsInstance", { enumerable: true, get: function () { return Sms_2.AliSmsInstance; } });
|
||||
var assert_1 = tslib_1.__importDefault(require("assert"));
|
||||
var SmsSDK = /** @class */ (function () {
|
||||
function SmsSDK() {
|
||||
this.tencentMap = {};
|
||||
|
|
@ -26,7 +24,9 @@ var SmsSDK = /** @class */ (function () {
|
|||
return instance;
|
||||
}
|
||||
else if (origin === 'ali') {
|
||||
(0, assert_1.default)(apiVersion, '阿里云短信apiVersion必须传入');
|
||||
if (!apiVersion) {
|
||||
throw new Error('阿里云短信apiVersion必须传入');
|
||||
}
|
||||
if (this.aliMap[accessKey]) {
|
||||
return this.aliMap[accessKey];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,2 @@
|
|||
"use strict";
|
||||
require('isomorphic-fetch');
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
"use strict";
|
||||
global.fetch = global.fetch;
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
"use strict";
|
||||
global.fetch = fetch;
|
||||
|
|
@ -1,3 +1,4 @@
|
|||
import Core from '@alicloud/pop-core/lib/rpc';
|
||||
declare type SendSmsRequest = {
|
||||
PhoneNumbers: string[];
|
||||
TemplateCode: string;
|
||||
|
|
@ -12,6 +13,7 @@ export declare class AliSmsInstance {
|
|||
regionId: string;
|
||||
endpoint: string;
|
||||
apiVersion: string;
|
||||
client: Core;
|
||||
constructor(accessKeyId: string, accessKeySecret: string, regionId: string, endpoint: string, apiVersion: string);
|
||||
sendSms(params: SendSmsRequest): Promise<void>;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,23 +1,21 @@
|
|||
"use strict";
|
||||
// import Core from '@alicloud/pop-core/lib/rpc';
|
||||
//todo 引入阿里云的库 在前端跑的时候会出现fs模块不存在
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.AliSmsInstance = void 0;
|
||||
var tslib_1 = require("tslib");
|
||||
var rpc_1 = tslib_1.__importDefault(require("@alicloud/pop-core/lib/rpc"));
|
||||
var AliSmsInstance = /** @class */ (function () {
|
||||
// client: Core;
|
||||
function AliSmsInstance(accessKeyId, accessKeySecret, regionId, endpoint, apiVersion) {
|
||||
this.accessKeyId = accessKeyId;
|
||||
this.accessKeySecret = accessKeySecret;
|
||||
this.regionId = regionId;
|
||||
this.endpoint = endpoint;
|
||||
this.apiVersion = apiVersion;
|
||||
// this.client = new Core({
|
||||
// accessKeyId: this.accessKeyId,
|
||||
// accessKeySecret: this.accessKeySecret,
|
||||
// endpoint: this.endpoint || 'dysmsapi.aliyuncs.com',
|
||||
// apiVersion: this.apiVersion,
|
||||
// });
|
||||
this.client = new rpc_1.default({
|
||||
accessKeyId: this.accessKeyId,
|
||||
accessKeySecret: this.accessKeySecret,
|
||||
endpoint: this.endpoint || 'dysmsapi.aliyuncs.com',
|
||||
apiVersion: this.apiVersion,
|
||||
});
|
||||
}
|
||||
AliSmsInstance.prototype.sendSms = function (params) {
|
||||
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,24 @@
|
|||
declare type SendSmsRequest = {
|
||||
PhoneNumbers: string[];
|
||||
TemplateCode: string;
|
||||
SignName: string;
|
||||
TemplateParam?: Record<string, string>;
|
||||
SmsUpExtendCode?: string;
|
||||
OutId?: string;
|
||||
};
|
||||
declare type SendSmsResponse = {
|
||||
Code: 'OK' | string;
|
||||
Message: string;
|
||||
BizId: string;
|
||||
RequestId: string;
|
||||
};
|
||||
export declare class AliSmsInstance {
|
||||
secretId: string;
|
||||
secretKey: string;
|
||||
region: string;
|
||||
endpoint: string;
|
||||
client: any;
|
||||
constructor(secretId: string, secretKey: string, region: string, endpoint: string);
|
||||
sendSms(params: SendSmsRequest): Promise<SendSmsResponse>;
|
||||
}
|
||||
export {};
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.AliSmsInstance = void 0;
|
||||
var tslib_1 = require("tslib");
|
||||
var AliSmsInstance = /** @class */ (function () {
|
||||
function AliSmsInstance(secretId, secretKey, region, endpoint) {
|
||||
this.secretId = secretId;
|
||||
this.secretKey = secretKey;
|
||||
this.region = region;
|
||||
this.endpoint = endpoint;
|
||||
var clientConfig = {
|
||||
credential: {
|
||||
secretId: this.secretId,
|
||||
secretKey: this.secretKey,
|
||||
},
|
||||
region: this.region,
|
||||
profile: {
|
||||
httpProfile: {
|
||||
endpoint: this.endpoint || 'dysmsapi.aliyuncs.com',
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
AliSmsInstance.prototype.sendSms = function (params) {
|
||||
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
||||
return tslib_1.__generator(this, function (_a) {
|
||||
console.log('mp走不到这里');
|
||||
return [2 /*return*/, {}];
|
||||
});
|
||||
});
|
||||
};
|
||||
return AliSmsInstance;
|
||||
}());
|
||||
exports.AliSmsInstance = AliSmsInstance;
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
declare type SendSmsRequest = {
|
||||
PhoneNumbers: string[];
|
||||
TemplateCode: string;
|
||||
SignName: string;
|
||||
TemplateParam?: Record<string, string>;
|
||||
SmsUpExtendCode?: string;
|
||||
OutId?: string;
|
||||
};
|
||||
declare type SendSmsResponse = {
|
||||
Code: 'OK' | string;
|
||||
Message: string;
|
||||
BizId: string;
|
||||
RequestId: string;
|
||||
};
|
||||
export declare class AliSmsInstance {
|
||||
secretId: string;
|
||||
secretKey: string;
|
||||
region: string;
|
||||
endpoint: string;
|
||||
client: any;
|
||||
constructor(secretId: string, secretKey: string, region: string, endpoint: string);
|
||||
sendSms(params: SendSmsRequest): Promise<SendSmsResponse>;
|
||||
}
|
||||
export {};
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.AliSmsInstance = void 0;
|
||||
var tslib_1 = require("tslib");
|
||||
var AliSmsInstance = /** @class */ (function () {
|
||||
function AliSmsInstance(secretId, secretKey, region, endpoint) {
|
||||
this.secretId = secretId;
|
||||
this.secretKey = secretKey;
|
||||
this.region = region;
|
||||
this.endpoint = endpoint;
|
||||
var clientConfig = {
|
||||
credential: {
|
||||
secretId: this.secretId,
|
||||
secretKey: this.secretKey,
|
||||
},
|
||||
region: this.region,
|
||||
profile: {
|
||||
httpProfile: {
|
||||
endpoint: this.endpoint || 'dysmsapi.aliyuncs.com',
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
AliSmsInstance.prototype.sendSms = function (params) {
|
||||
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
||||
return tslib_1.__generator(this, function (_a) {
|
||||
console.log('web走不到这里');
|
||||
return [2 /*return*/, {}];
|
||||
});
|
||||
});
|
||||
};
|
||||
return AliSmsInstance;
|
||||
}());
|
||||
exports.AliSmsInstance = AliSmsInstance;
|
||||
|
|
@ -2,7 +2,7 @@
|
|||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.AmapInstance = void 0;
|
||||
var tslib_1 = require("tslib");
|
||||
require('isomorphic-fetch');
|
||||
require('../../fetch');
|
||||
var AmapInstance = /** @class */ (function () {
|
||||
function AmapInstance(key) {
|
||||
this.key = key;
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.QiniuCloudInstance = void 0;
|
||||
var tslib_1 = require("tslib");
|
||||
require('isomorphic-fetch');
|
||||
require('../../fetch');
|
||||
var crypto_1 = tslib_1.__importDefault(require("crypto"));
|
||||
var ts_md5_1 = require("ts-md5");
|
||||
var buffer_1 = require("buffer");
|
||||
|
|
|
|||
|
|
@ -0,0 +1,10 @@
|
|||
import { SendSmsRequest, SendSmsResponse } from 'tencentcloud-sdk-nodejs/tencentcloud/services/sms/v20210111/sms_models';
|
||||
export declare class TencentSmsInstance {
|
||||
secretId: string;
|
||||
secretKey: string;
|
||||
region: string;
|
||||
endpoint: string;
|
||||
client: any;
|
||||
constructor(secretId: string, secretKey: string, region: string, endpoint: string);
|
||||
sendSms(params: SendSmsRequest): Promise<SendSmsResponse>;
|
||||
}
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.TencentSmsInstance = void 0;
|
||||
var tslib_1 = require("tslib");
|
||||
var TencentSmsInstance = /** @class */ (function () {
|
||||
function TencentSmsInstance(secretId, secretKey, region, endpoint) {
|
||||
this.secretId = secretId;
|
||||
this.secretKey = secretKey;
|
||||
this.region = region;
|
||||
this.endpoint = endpoint;
|
||||
var clientConfig = {
|
||||
credential: {
|
||||
secretId: this.secretId,
|
||||
secretKey: this.secretKey,
|
||||
},
|
||||
region: this.region,
|
||||
profile: {
|
||||
httpProfile: {
|
||||
endpoint: this.endpoint || 'sms.tencentcloudapi.com',
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
TencentSmsInstance.prototype.sendSms = function (params) {
|
||||
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
||||
return tslib_1.__generator(this, function (_a) {
|
||||
console.log('mp走不到这里');
|
||||
return [2 /*return*/, {}];
|
||||
});
|
||||
});
|
||||
};
|
||||
return TencentSmsInstance;
|
||||
}());
|
||||
exports.TencentSmsInstance = TencentSmsInstance;
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
import { SendSmsRequest, SendSmsResponse } from 'tencentcloud-sdk-nodejs/tencentcloud/services/sms/v20210111/sms_models';
|
||||
export declare class TencentSmsInstance {
|
||||
secretId: string;
|
||||
secretKey: string;
|
||||
region: string;
|
||||
endpoint: string;
|
||||
client: any;
|
||||
constructor(secretId: string, secretKey: string, region: string, endpoint: string);
|
||||
sendSms(params: SendSmsRequest): Promise<SendSmsResponse>;
|
||||
}
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.TencentSmsInstance = void 0;
|
||||
var tslib_1 = require("tslib");
|
||||
var TencentSmsInstance = /** @class */ (function () {
|
||||
function TencentSmsInstance(secretId, secretKey, region, endpoint) {
|
||||
this.secretId = secretId;
|
||||
this.secretKey = secretKey;
|
||||
this.region = region;
|
||||
this.endpoint = endpoint;
|
||||
var clientConfig = {
|
||||
credential: {
|
||||
secretId: this.secretId,
|
||||
secretKey: this.secretKey,
|
||||
},
|
||||
region: this.region,
|
||||
profile: {
|
||||
httpProfile: {
|
||||
endpoint: this.endpoint || 'sms.tencentcloudapi.com',
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
TencentSmsInstance.prototype.sendSms = function (params) {
|
||||
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
||||
return tslib_1.__generator(this, function (_a) {
|
||||
console.log('web走不到这里');
|
||||
return [2 /*return*/, {}];
|
||||
});
|
||||
});
|
||||
};
|
||||
return TencentSmsInstance;
|
||||
}());
|
||||
exports.TencentSmsInstance = TencentSmsInstance;
|
||||
|
|
@ -2,7 +2,7 @@
|
|||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.WechatMpInstance = void 0;
|
||||
var tslib_1 = require("tslib");
|
||||
require('isomorphic-fetch');
|
||||
require('../../fetch');
|
||||
var crypto_1 = tslib_1.__importDefault(require("crypto"));
|
||||
var buffer_1 = require("buffer");
|
||||
var WechatMpInstance = /** @class */ (function () {
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.WechatPublicInstance = void 0;
|
||||
var tslib_1 = require("tslib");
|
||||
require('isomorphic-fetch');
|
||||
require('../../fetch');
|
||||
var crypto_1 = tslib_1.__importDefault(require("crypto"));
|
||||
var buffer_1 = require("buffer");
|
||||
var WechatPublicInstance = /** @class */ (function () {
|
||||
|
|
@ -240,7 +240,7 @@ var WechatPublicInstance = /** @class */ (function () {
|
|||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
}
|
||||
},
|
||||
};
|
||||
switch (type) {
|
||||
case 'text': {
|
||||
|
|
@ -266,9 +266,9 @@ var WechatPublicInstance = /** @class */ (function () {
|
|||
title: options.title,
|
||||
description: options.description,
|
||||
url: options.url,
|
||||
picurl: options.picurl
|
||||
}
|
||||
]
|
||||
picurl: options.picurl,
|
||||
},
|
||||
],
|
||||
},
|
||||
}),
|
||||
});
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.WechatWebInstance = void 0;
|
||||
var tslib_1 = require("tslib");
|
||||
require('isomorphic-fetch');
|
||||
require('../../fetch');
|
||||
var crypto_1 = tslib_1.__importDefault(require("crypto"));
|
||||
var buffer_1 = require("buffer");
|
||||
var WechatWebInstance = /** @class */ (function () {
|
||||
|
|
|
|||
|
|
@ -23,9 +23,7 @@
|
|||
"dependencies": {
|
||||
"@alicloud/pop-core": "^1.7.12",
|
||||
"isomorphic-fetch": "^3.0.0",
|
||||
"net": "^1.0.2",
|
||||
"tencentcloud-sdk-nodejs": "^4.0.525",
|
||||
"tls": "0.0.1",
|
||||
"ts-md5": "^1.3.1"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
import { TencentSmsInstance } from './service/tencent/Sms';
|
||||
import { AliSmsInstance } from './service/ali/Sms';
|
||||
import assert from 'assert';
|
||||
|
||||
class SmsSDK {
|
||||
tencentMap: Record<string, TencentSmsInstance>;
|
||||
|
|
@ -34,7 +33,9 @@ class SmsSDK {
|
|||
});
|
||||
return instance;
|
||||
} else if (origin === 'ali') {
|
||||
assert(apiVersion, '阿里云短信apiVersion必须传入');
|
||||
if (!apiVersion) {
|
||||
throw new Error('阿里云短信apiVersion必须传入');
|
||||
}
|
||||
if (this.aliMap[accessKey]) {
|
||||
return this.aliMap[accessKey];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1 @@
|
|||
global.fetch = global.fetch;
|
||||
|
|
@ -0,0 +1 @@
|
|||
require('isomorphic-fetch');
|
||||
|
|
@ -0,0 +1 @@
|
|||
global.fetch = fetch;
|
||||
|
|
@ -0,0 +1,53 @@
|
|||
type SendSmsRequest = {
|
||||
PhoneNumbers: string[];
|
||||
TemplateCode: string;
|
||||
SignName: string;
|
||||
TemplateParam?: Record<string, string>;
|
||||
SmsUpExtendCode?: string;
|
||||
OutId?: string;
|
||||
};
|
||||
|
||||
type SendSmsResponse = {
|
||||
Code: 'OK' | string;
|
||||
Message: string;
|
||||
BizId: string;
|
||||
RequestId: string;
|
||||
};
|
||||
|
||||
export class AliSmsInstance {
|
||||
secretId: string;
|
||||
secretKey: string;
|
||||
region: string;
|
||||
endpoint: string;
|
||||
client: any;
|
||||
|
||||
constructor(
|
||||
secretId: string,
|
||||
secretKey: string,
|
||||
region: string,
|
||||
endpoint: string
|
||||
) {
|
||||
this.secretId = secretId;
|
||||
this.secretKey = secretKey;
|
||||
this.region = region;
|
||||
this.endpoint = endpoint;
|
||||
|
||||
const clientConfig = {
|
||||
credential: {
|
||||
secretId: this.secretId,
|
||||
secretKey: this.secretKey,
|
||||
},
|
||||
region: this.region,
|
||||
profile: {
|
||||
httpProfile: {
|
||||
endpoint: this.endpoint || 'dysmsapi.aliyuncs.com',
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
async sendSms(params: SendSmsRequest) {
|
||||
console.log('mp走不到这里');
|
||||
return {} as SendSmsResponse;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,5 +1,4 @@
|
|||
// import Core from '@alicloud/pop-core/lib/rpc';
|
||||
//todo 引入阿里云的库 在前端跑的时候会出现fs模块不存在
|
||||
import Core from '@alicloud/pop-core/lib/rpc';
|
||||
|
||||
type SendSmsRequest = {
|
||||
PhoneNumbers: string[];
|
||||
|
|
@ -23,7 +22,7 @@ export class AliSmsInstance {
|
|||
regionId: string;
|
||||
endpoint: string;
|
||||
apiVersion: string;
|
||||
// client: Core;
|
||||
client: Core;
|
||||
|
||||
constructor(
|
||||
accessKeyId: string,
|
||||
|
|
@ -38,12 +37,12 @@ export class AliSmsInstance {
|
|||
this.endpoint = endpoint;
|
||||
this.apiVersion = apiVersion;
|
||||
|
||||
// this.client = new Core({
|
||||
// accessKeyId: this.accessKeyId,
|
||||
// accessKeySecret: this.accessKeySecret,
|
||||
// endpoint: this.endpoint || 'dysmsapi.aliyuncs.com',
|
||||
// apiVersion: this.apiVersion,
|
||||
// });
|
||||
this.client = new Core({
|
||||
accessKeyId: this.accessKeyId,
|
||||
accessKeySecret: this.accessKeySecret,
|
||||
endpoint: this.endpoint || 'dysmsapi.aliyuncs.com',
|
||||
apiVersion: this.apiVersion,
|
||||
});
|
||||
}
|
||||
|
||||
async sendSms(params: SendSmsRequest) {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,53 @@
|
|||
type SendSmsRequest = {
|
||||
PhoneNumbers: string[];
|
||||
TemplateCode: string;
|
||||
SignName: string;
|
||||
TemplateParam?: Record<string, string>;
|
||||
SmsUpExtendCode?: string;
|
||||
OutId?: string;
|
||||
};
|
||||
|
||||
type SendSmsResponse = {
|
||||
Code: 'OK' | string;
|
||||
Message: string;
|
||||
BizId: string;
|
||||
RequestId: string;
|
||||
};
|
||||
|
||||
export class AliSmsInstance {
|
||||
secretId: string;
|
||||
secretKey: string;
|
||||
region: string;
|
||||
endpoint: string;
|
||||
client: any;
|
||||
|
||||
constructor(
|
||||
secretId: string,
|
||||
secretKey: string,
|
||||
region: string,
|
||||
endpoint: string
|
||||
) {
|
||||
this.secretId = secretId;
|
||||
this.secretKey = secretKey;
|
||||
this.region = region;
|
||||
this.endpoint = endpoint;
|
||||
|
||||
const clientConfig = {
|
||||
credential: {
|
||||
secretId: this.secretId,
|
||||
secretKey: this.secretKey,
|
||||
},
|
||||
region: this.region,
|
||||
profile: {
|
||||
httpProfile: {
|
||||
endpoint: this.endpoint || 'dysmsapi.aliyuncs.com',
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
async sendSms(params: SendSmsRequest) {
|
||||
console.log('web走不到这里');
|
||||
return {} as SendSmsResponse;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
require('isomorphic-fetch');
|
||||
require('../../fetch');
|
||||
|
||||
export class AmapInstance {
|
||||
key: string;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
require('isomorphic-fetch');
|
||||
|
||||
require('../../fetch');
|
||||
import crypto from 'crypto';
|
||||
import { Md5 } from 'ts-md5';
|
||||
import { Buffer } from 'buffer';
|
||||
|
|
|
|||
|
|
@ -0,0 +1,42 @@
|
|||
import {
|
||||
SendSmsRequest,
|
||||
SendSmsResponse,
|
||||
} from 'tencentcloud-sdk-nodejs/tencentcloud/services/sms/v20210111/sms_models';
|
||||
|
||||
export class TencentSmsInstance {
|
||||
secretId: string;
|
||||
secretKey: string;
|
||||
region: string;
|
||||
endpoint: string;
|
||||
client: any;
|
||||
|
||||
constructor(
|
||||
secretId: string,
|
||||
secretKey: string,
|
||||
region: string,
|
||||
endpoint: string
|
||||
) {
|
||||
this.secretId = secretId;
|
||||
this.secretKey = secretKey;
|
||||
this.region = region;
|
||||
this.endpoint = endpoint;
|
||||
|
||||
const clientConfig = {
|
||||
credential: {
|
||||
secretId: this.secretId,
|
||||
secretKey: this.secretKey,
|
||||
},
|
||||
region: this.region,
|
||||
profile: {
|
||||
httpProfile: {
|
||||
endpoint: this.endpoint || 'sms.tencentcloudapi.com',
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
async sendSms(params: SendSmsRequest) {
|
||||
console.log('mp走不到这里');
|
||||
return {} as SendSmsResponse;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,42 @@
|
|||
import {
|
||||
SendSmsRequest,
|
||||
SendSmsResponse,
|
||||
} from 'tencentcloud-sdk-nodejs/tencentcloud/services/sms/v20210111/sms_models';
|
||||
|
||||
export class TencentSmsInstance {
|
||||
secretId: string;
|
||||
secretKey: string;
|
||||
region: string;
|
||||
endpoint: string;
|
||||
client: any;
|
||||
|
||||
constructor(
|
||||
secretId: string,
|
||||
secretKey: string,
|
||||
region: string,
|
||||
endpoint: string
|
||||
) {
|
||||
this.secretId = secretId;
|
||||
this.secretKey = secretKey;
|
||||
this.region = region;
|
||||
this.endpoint = endpoint;
|
||||
|
||||
const clientConfig = {
|
||||
credential: {
|
||||
secretId: this.secretId,
|
||||
secretKey: this.secretKey,
|
||||
},
|
||||
region: this.region,
|
||||
profile: {
|
||||
httpProfile: {
|
||||
endpoint: this.endpoint || 'sms.tencentcloudapi.com',
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
async sendSms(params: SendSmsRequest) {
|
||||
console.log('web走不到这里');
|
||||
return {} as SendSmsResponse;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,5 +1,4 @@
|
|||
require('isomorphic-fetch');
|
||||
|
||||
require('../../fetch');
|
||||
import crypto from 'crypto';
|
||||
import { Buffer } from 'buffer';
|
||||
|
||||
|
|
@ -154,5 +153,4 @@ export class WechatMpInstance {
|
|||
);
|
||||
return (await result.arrayBuffer()) as ArrayBuffer;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,22 +1,21 @@
|
|||
require('isomorphic-fetch');
|
||||
|
||||
require('../../fetch');
|
||||
import crypto from 'crypto';
|
||||
import { Buffer } from 'buffer';
|
||||
// 目前先支持text和news, 其他type文档:https://developers.weixin.qq.com/doc/offiaccount/Message_Management/Service_Center_messages.html
|
||||
// type ServeMessageType = 'text' | 'news' | 'mpnews' | 'mpnewsarticle' | 'image' | 'voice' | 'video' | 'music' | 'msgmenu';/
|
||||
type TextServeMessageOption = {
|
||||
openId: string,
|
||||
type: 'text',
|
||||
content: string,
|
||||
}
|
||||
openId: string;
|
||||
type: 'text';
|
||||
content: string;
|
||||
};
|
||||
type NewsServeMessageOption = {
|
||||
openId: string,
|
||||
type: 'news',
|
||||
title: string,
|
||||
description?: string,
|
||||
url: string,
|
||||
picurl?: string,
|
||||
}
|
||||
openId: string;
|
||||
type: 'news';
|
||||
title: string;
|
||||
description?: string;
|
||||
url: string;
|
||||
picurl?: string;
|
||||
};
|
||||
|
||||
type ServeMessageOption = TextServeMessageOption | NewsServeMessageOption;
|
||||
|
||||
|
|
@ -145,11 +144,11 @@ export class WechatPublicInstance {
|
|||
}
|
||||
const scene = sceneId
|
||||
? {
|
||||
scene_id: sceneId,
|
||||
}
|
||||
scene_id: sceneId,
|
||||
}
|
||||
: {
|
||||
scene_str: sceneStr,
|
||||
};
|
||||
scene_str: sceneStr,
|
||||
};
|
||||
let actionName = sceneId ? 'QR_SCENE' : 'QR_STR_SCENE';
|
||||
let myInit = {
|
||||
method: 'POST',
|
||||
|
|
@ -245,12 +244,11 @@ export class WechatPublicInstance {
|
|||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
}
|
||||
},
|
||||
};
|
||||
switch (type) {
|
||||
case 'text': {
|
||||
Object.assign(
|
||||
myInit, {
|
||||
Object.assign(myInit, {
|
||||
body: JSON.stringify({
|
||||
touser: openId,
|
||||
msgtype: 'text',
|
||||
|
|
@ -258,13 +256,11 @@ export class WechatPublicInstance {
|
|||
content: options.content,
|
||||
},
|
||||
}),
|
||||
}
|
||||
);
|
||||
});
|
||||
break;
|
||||
}
|
||||
case 'news': {
|
||||
Object.assign(
|
||||
myInit, {
|
||||
Object.assign(myInit, {
|
||||
body: JSON.stringify({
|
||||
touser: openId,
|
||||
msgtype: 'news',
|
||||
|
|
@ -274,17 +270,16 @@ export class WechatPublicInstance {
|
|||
title: options.title,
|
||||
description: options.description,
|
||||
url: options.url,
|
||||
picurl: options.picurl
|
||||
}
|
||||
]
|
||||
picurl: options.picurl,
|
||||
},
|
||||
],
|
||||
},
|
||||
}),
|
||||
}
|
||||
);
|
||||
});
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
throw new Error('当前消息类型暂不支持')
|
||||
throw new Error('当前消息类型暂不支持');
|
||||
}
|
||||
}
|
||||
const token = await this.getAccessToken();
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
require('isomorphic-fetch');
|
||||
|
||||
require('../../fetch');
|
||||
import crypto from 'crypto';
|
||||
import { Buffer } from 'buffer';
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue