This commit is contained in:
Xu Chang 2023-12-05 17:33:51 +08:00
commit 435c5c52ac
47 changed files with 362 additions and 231 deletions

2
es/SmsSdk.d.ts vendored
View File

@ -4,7 +4,7 @@ declare class SmsSDK {
tencentMap: Record<string, TencentSmsInstance>;
aliMap: Record<string, AliSmsInstance>;
constructor();
getInstance(origin: 'ali' | 'tencent', accessKey: string, accessSecret: string, region: string, endpoint: string, apiVersion?: string): TencentSmsInstance | AliSmsInstance;
getInstance(origin: 'ali' | 'tencent', accessKey: string, accessSecret: string, endpoint: string, region?: string, apiVersion?: string): TencentSmsInstance | AliSmsInstance;
}
declare const SDK: SmsSDK;
export default SDK;

View File

@ -8,7 +8,7 @@ class SmsSDK {
this.tencentMap = {};
this.aliMap = {};
}
getInstance(origin, accessKey, accessSecret, region, endpoint, apiVersion //阿里云独有
getInstance(origin, accessKey, accessSecret, endpoint, region, apiVersion //阿里云独有
) {
if (origin === 'tencent') {
if (this.tencentMap[accessKey]) {
@ -21,13 +21,13 @@ class SmsSDK {
return instance;
}
else if (origin === 'ali') {
if (!apiVersion) {
assert(false, '阿里云短信apiVersion必须传入');
}
// if (!apiVersion) {
// assert(false, '阿里云短信apiVersion必须传入');
// }
if (this.aliMap[accessKey]) {
return this.aliMap[accessKey];
}
const instance = new AliSmsInstance(accessKey, accessSecret, region, endpoint, apiVersion);
const instance = new AliSmsInstance(accessKey, accessSecret, endpoint);
Object.assign(this.aliMap, {
[accessKey]: instance,
});

View File

@ -1,20 +1,18 @@
import Core from '@alicloud/pop-core/lib/rpc';
import Dysmsapi20170525, * as $Dysmsapi20170525 from '@alicloud/dysmsapi20170525';
type SendSmsRequest = {
PhoneNumbers: string[];
TemplateCode: string;
SignName: string;
TemplateParam?: Record<string, string>;
SmsUpExtendCode?: string;
OutId?: string;
phoneNumbers: string[];
templateCode: string;
signName: string;
templateParam?: Record<string, string>;
smsUpExtendCode?: string;
outId?: string;
};
export declare class AliSmsInstance {
accessKeyId: string;
accessKeySecret: string;
regionId: string;
endpoint: string;
apiVersion: string;
client: Core;
constructor(accessKeyId: string, accessKeySecret: string, regionId: string, endpoint: string, apiVersion: string);
sendSms(params: SendSmsRequest): Promise<void>;
client: Dysmsapi20170525;
constructor(accessKeyId: string, accessKeySecret: string, endpoint?: string);
sendSms(params: SendSmsRequest): Promise<$Dysmsapi20170525.SendSmsResponseBody>;
}
export {};

View File

@ -1,47 +1,42 @@
import Core from '@alicloud/pop-core/lib/rpc';
import Dysmsapi20170525, * as $Dysmsapi20170525 from '@alicloud/dysmsapi20170525';
import * as $OpenApi from '@alicloud/openapi-client';
import * as $Util from '@alicloud/tea-util';
export class AliSmsInstance {
accessKeyId;
accessKeySecret;
regionId;
endpoint;
apiVersion;
client;
constructor(accessKeyId, accessKeySecret, regionId, endpoint, apiVersion) {
constructor(accessKeyId, accessKeySecret, endpoint) {
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.endpoint = endpoint || 'dysmsapi.aliyuncs.com'; // 目前国内终端域名相同
let config = new $OpenApi.Config({
// 必填,您的 AccessKey ID
accessKeyId: accessKeyId,
// 必填,您的 AccessKey Secret
accessKeySecret: accessKeySecret,
endpoint: this.endpoint,
});
this.client = new Dysmsapi20170525(config);
}
async sendSms(params) {
const { PhoneNumbers, TemplateParam = {}, TemplateCode, SignName, } = params;
const param = Object.assign({
regionId: this.regionId,
}, {
PhoneNumbers: PhoneNumbers.join(','),
TemplateParam: JSON.stringify(TemplateParam),
TemplateCode: TemplateCode,
SignName: SignName,
const { phoneNumbers, templateParam = {}, templateCode, signName, } = params;
let sendSmsRequest = new $Dysmsapi20170525.SendSmsRequest({
phoneNumbers: (phoneNumbers instanceof Array) ? phoneNumbers.join(',') : phoneNumbers,
templateParam: JSON.stringify(templateParam),
templateCode: templateCode,
signName: signName,
});
try {
// const data = await this.client.request<SendSmsResponse>(
// 'SendSms',
// param,
// {
// method: 'POST',
// }
// );
// return data;
const data = await this.client.sendSmsWithOptions(sendSmsRequest, new $Util.RuntimeOptions({}));
const { statusCode, body } = data;
if (statusCode != 200) {
throw new Error(`ali.sendSms接口返回状态码错误${statusCode}`);
}
return body;
}
catch (err) {
console.error(err);
throw err;
catch (error) {
throw error;
}
}
}

View File

@ -23,7 +23,7 @@ export class AliSmsInstance {
};
}
async sendSms(params) {
console.log('native走不到这里');
console.log('react-native走不到这里[ali/sms.native');
return {};
}
}

View File

@ -23,7 +23,7 @@ const CTYun_ENDPOINT_LIST = {
ul: 'oos-gzgy.ctyunapi.cn',
},
hbwh: {
ul: 'oos-gslz.ctyunapi.cn',
ul: 'oos-hbwh.ctyunapi.cn',
},
xzls: {
ul: 'oos-xzls.ctyunapi.cn',
@ -50,11 +50,9 @@ export class CTYunInstance {
}
getUploadInfo(bucket, zone, key, actions) {
try {
// const uploadToken = this.getToken(zone, bucket, actions);
const signInfo = this.getSignInfo(bucket, actions);
return {
key,
// uploadToken,
accessKey: this.accessKey,
policy: signInfo.encodePolicy,
signature: signInfo.signature,

View File

@ -4,6 +4,7 @@ import { Md5 } from 'ts-md5';
import { Buffer } from 'buffer';
import { stringify } from 'querystring';
import { OakExternalException, OakNetworkException, } from 'oak-domain/lib/types/Exception';
import { url as URL } from 'oak-domain/lib/utils/url/index';
/**
* qiniu endpoint list
* https://developer.qiniu.com/kodo/1671/region-endpoint-fq

View File

@ -1,5 +1,5 @@
import { Client } from 'tencentcloud-sdk-nodejs/tencentcloud/services/sms/v20210111/sms_client';
import { SendSmsRequest, SendSmsResponse } from 'tencentcloud-sdk-nodejs/tencentcloud/services/sms/v20210111/sms_models';
import { SendSmsRequest, SendSmsResponse, DescribeSmsTemplateListRequest, DescribeSmsTemplateListResponse } from 'tencentcloud-sdk-nodejs/tencentcloud/services/sms/v20210111/sms_models';
export declare class TencentSmsInstance {
secretId: string;
secretKey: string;
@ -8,4 +8,5 @@ export declare class TencentSmsInstance {
client: Client;
constructor(secretId: string, secretKey: string, region: string, endpoint: string);
sendSms(params: SendSmsRequest): Promise<SendSmsResponse>;
syncTemplate(params: DescribeSmsTemplateListRequest): Promise<DescribeSmsTemplateListResponse>;
}

View File

@ -27,15 +27,19 @@ export class TencentSmsInstance {
this.client = new SmsClient(clientConfig);
}
async sendSms(params) {
// const params: SendSmsRequest = {
// PhoneNumberSet: [],
// TemplateParamSet: [],
// SmsSdkAppId: '',
// TemplateId: '',
// };
try {
const data = await this.client.SendSms(params);
return data;
const result = await this.client.SendSms(params);
return result;
}
catch (err) {
console.error(err);
throw err;
}
}
async syncTemplate(params) {
try {
const result = await this.client.DescribeSmsTemplateList(params);
return result;
}
catch (err) {
console.error(err);

View File

@ -1,6 +1,6 @@
export class TencentSmsInstance {
async sendSms(params) {
console.log('native走不到这里');
console.log('react-native走不到这里[tencent/sms.native]');
return {};
}
}

View File

@ -90,6 +90,27 @@ export declare class WechatMpInstance {
mediaId: string;
}): Promise<any>;
sendServeMessage(options: ServeMessageOption): Promise<any>;
getAllPrivateTemplate(): Promise<{
priTmplId: string;
title: string;
type: number;
content: string;
example: string;
keywordEnumValueList?: {
keywordCode: string;
enumValueList: Array<string>;
}[] | undefined;
}[]>;
private isJson;
getURLScheme(options: {
jump_wxa: {
path?: string;
query?: string;
env_version?: string;
};
expireType?: number;
expiresAt?: number;
expireInterval?: number;
}): Promise<any>;
}
export {};

View File

@ -304,6 +304,17 @@ export class WechatMpInstance {
}
return Object.assign({ success: false }, result);
}
async getAllPrivateTemplate() {
const myInit = {
method: 'GET',
headers: {
'Content-Type': 'application/json',
},
};
const token = await this.getAccessToken();
const result = (await this.access(`https://api.weixin.qq.com/wxaapi/newtmpl/gettemplate?access_token=${token}`, myInit));
return result.data;
}
isJson(data) {
try {
JSON.parse(data);
@ -313,4 +324,19 @@ export class WechatMpInstance {
return false;
}
}
async getURLScheme(options) {
const { jump_wxa, expiresAt, expireType = 0, expireInterval } = options;
const token = await this.getAccessToken();
const result = await this.access(`https://api.weixin.qq.com/wxa/generatescheme?access_token=${token}`, {
method: 'POST',
body: JSON.stringify({
jump_wxa: jump_wxa,
is_expire: true,
expire_type: expireType,
expire_time: expiresAt,
expire_interval: expireInterval,
}),
});
return result;
}
}

View File

@ -186,15 +186,13 @@ export declare class WechatPublicInstance {
}): Promise<any>;
getTicket(): Promise<string>;
getAllPrivateTemplate(): Promise<{
template_list: {
template_id: string;
title: string;
primary_industry: string;
deputy_industry: string;
content: string;
example: string;
}[];
}>;
template_id: string;
title: string;
primary_industry: string;
deputy_industry: string;
content: string;
example: string;
}[]>;
private isJson;
decryptData(sessionKey: string, encryptedData: string, iv: string, signature: string): any;
private randomString;

View File

@ -673,7 +673,7 @@ export class WechatPublicInstance {
};
const token = await this.getAccessToken();
const result = (await this.access(`https://api.weixin.qq.com/cgi-bin/template/get_all_private_template?access_token=${token}`, myInit));
return result;
return result.template_list;
}
isJson(data) {
try {

View File

@ -1 +1,2 @@
"use strict";
global.fetch = fetch;

View File

@ -1,2 +1,5 @@
declare const formData: {};
declare const formData: {
new (form?: HTMLFormElement | undefined, submitter?: HTMLElement | null | undefined): FormData;
prototype: FormData;
};
export default formData;

View File

@ -1,3 +1,2 @@
// native不支持FormData
const formData = {};
const formData = FormData;
export default formData;

2
lib/SmsSdk.d.ts vendored
View File

@ -4,7 +4,7 @@ declare class SmsSDK {
tencentMap: Record<string, TencentSmsInstance>;
aliMap: Record<string, AliSmsInstance>;
constructor();
getInstance(origin: 'ali' | 'tencent', accessKey: string, accessSecret: string, region: string, endpoint: string, apiVersion?: string): TencentSmsInstance | AliSmsInstance;
getInstance(origin: 'ali' | 'tencent', accessKey: string, accessSecret: string, endpoint: string, region?: string, apiVersion?: string): TencentSmsInstance | AliSmsInstance;
}
declare const SDK: SmsSDK;
export default SDK;

View File

@ -13,7 +13,7 @@ class SmsSDK {
this.tencentMap = {};
this.aliMap = {};
}
getInstance(origin, accessKey, accessSecret, region, endpoint, apiVersion //阿里云独有
getInstance(origin, accessKey, accessSecret, endpoint, region, apiVersion //阿里云独有
) {
if (origin === 'tencent') {
if (this.tencentMap[accessKey]) {
@ -26,13 +26,13 @@ class SmsSDK {
return instance;
}
else if (origin === 'ali') {
if (!apiVersion) {
(0, assert_1.assert)(false, '阿里云短信apiVersion必须传入');
}
// if (!apiVersion) {
// assert(false, '阿里云短信apiVersion必须传入');
// }
if (this.aliMap[accessKey]) {
return this.aliMap[accessKey];
}
const instance = new Sms_2.AliSmsInstance(accessKey, accessSecret, region, endpoint, apiVersion);
const instance = new Sms_2.AliSmsInstance(accessKey, accessSecret, endpoint);
Object.assign(this.aliMap, {
[accessKey]: instance,
});

View File

@ -1,20 +1,18 @@
import Core from '@alicloud/pop-core/lib/rpc';
import Dysmsapi20170525, * as $Dysmsapi20170525 from '@alicloud/dysmsapi20170525';
type SendSmsRequest = {
PhoneNumbers: string[];
TemplateCode: string;
SignName: string;
TemplateParam?: Record<string, string>;
SmsUpExtendCode?: string;
OutId?: string;
phoneNumbers: string[];
templateCode: string;
signName: string;
templateParam?: Record<string, string>;
smsUpExtendCode?: string;
outId?: string;
};
export declare class AliSmsInstance {
accessKeyId: string;
accessKeySecret: string;
regionId: string;
endpoint: string;
apiVersion: string;
client: Core;
constructor(accessKeyId: string, accessKeySecret: string, regionId: string, endpoint: string, apiVersion: string);
sendSms(params: SendSmsRequest): Promise<void>;
client: Dysmsapi20170525;
constructor(accessKeyId: string, accessKeySecret: string, endpoint?: string);
sendSms(params: SendSmsRequest): Promise<$Dysmsapi20170525.SendSmsResponseBody>;
}
export {};

View File

@ -2,50 +2,45 @@
Object.defineProperty(exports, "__esModule", { value: true });
exports.AliSmsInstance = void 0;
const tslib_1 = require("tslib");
const rpc_1 = tslib_1.__importDefault(require("@alicloud/pop-core/lib/rpc"));
const dysmsapi20170525_1 = tslib_1.__importStar(require("@alicloud/dysmsapi20170525")), $Dysmsapi20170525 = dysmsapi20170525_1;
const $OpenApi = tslib_1.__importStar(require("@alicloud/openapi-client"));
const $Util = tslib_1.__importStar(require("@alicloud/tea-util"));
class AliSmsInstance {
accessKeyId;
accessKeySecret;
regionId;
endpoint;
apiVersion;
client;
constructor(accessKeyId, accessKeySecret, regionId, endpoint, apiVersion) {
constructor(accessKeyId, accessKeySecret, endpoint) {
this.accessKeyId = accessKeyId;
this.accessKeySecret = accessKeySecret;
this.regionId = regionId;
this.endpoint = endpoint;
this.apiVersion = apiVersion;
this.client = new rpc_1.default({
accessKeyId: this.accessKeyId,
accessKeySecret: this.accessKeySecret,
endpoint: this.endpoint || 'dysmsapi.aliyuncs.com',
apiVersion: this.apiVersion,
this.endpoint = endpoint || 'dysmsapi.aliyuncs.com'; // 目前国内终端域名相同
let config = new $OpenApi.Config({
// 必填,您的 AccessKey ID
accessKeyId: accessKeyId,
// 必填,您的 AccessKey Secret
accessKeySecret: accessKeySecret,
endpoint: this.endpoint,
});
this.client = new dysmsapi20170525_1.default(config);
}
async sendSms(params) {
const { PhoneNumbers, TemplateParam = {}, TemplateCode, SignName, } = params;
const param = Object.assign({
regionId: this.regionId,
}, {
PhoneNumbers: PhoneNumbers.join(','),
TemplateParam: JSON.stringify(TemplateParam),
TemplateCode: TemplateCode,
SignName: SignName,
const { phoneNumbers, templateParam = {}, templateCode, signName, } = params;
let sendSmsRequest = new $Dysmsapi20170525.SendSmsRequest({
phoneNumbers: (phoneNumbers instanceof Array) ? phoneNumbers.join(',') : phoneNumbers,
templateParam: JSON.stringify(templateParam),
templateCode: templateCode,
signName: signName,
});
try {
// const data = await this.client.request<SendSmsResponse>(
// 'SendSms',
// param,
// {
// method: 'POST',
// }
// );
// return data;
const data = await this.client.sendSmsWithOptions(sendSmsRequest, new $Util.RuntimeOptions({}));
const { statusCode, body } = data;
if (statusCode != 200) {
throw new Error(`ali.sendSms接口返回状态码错误${statusCode}`);
}
return body;
}
catch (err) {
console.error(err);
throw err;
catch (error) {
throw error;
}
}
}

View File

@ -26,7 +26,7 @@ class AliSmsInstance {
};
}
async sendSms(params) {
console.log('native走不到这里');
console.log('react-native走不到这里[ali/sms.native');
return {};
}
}

View File

@ -27,7 +27,7 @@ const CTYun_ENDPOINT_LIST = {
ul: 'oos-gzgy.ctyunapi.cn',
},
hbwh: {
ul: 'oos-gslz.ctyunapi.cn',
ul: 'oos-hbwh.ctyunapi.cn',
},
xzls: {
ul: 'oos-xzls.ctyunapi.cn',
@ -54,11 +54,9 @@ class CTYunInstance {
}
getUploadInfo(bucket, zone, key, actions) {
try {
// const uploadToken = this.getToken(zone, bucket, actions);
const signInfo = this.getSignInfo(bucket, actions);
return {
key,
// uploadToken,
accessKey: this.accessKey,
policy: signInfo.encodePolicy,
signature: signInfo.signature,

View File

@ -8,6 +8,7 @@ const ts_md5_1 = require("ts-md5");
const buffer_1 = require("buffer");
const querystring_1 = require("querystring");
const Exception_1 = require("oak-domain/lib/types/Exception");
const index_1 = require("oak-domain/lib/utils/url/index");
/**
* qiniu endpoint list
* https://developer.qiniu.com/kodo/1671/region-endpoint-fq
@ -343,7 +344,7 @@ class QiniuCloudInstance {
/**
* web/server环境测试通过小程序没测by Xc
*/
const url = new URL(`https://${host}${path}`);
const url = new index_1.url(`https://${host}${path}`);
if (process.env.NODE_ENV === 'development' && mockData) {
console.warn(`mocking access qiniu api: url: ${url.toString()}, body: ${JSON.stringify(body)}, method: ${method}`, mockData);
return mockData;

View File

@ -1,5 +1,5 @@
import { Client } from 'tencentcloud-sdk-nodejs/tencentcloud/services/sms/v20210111/sms_client';
import { SendSmsRequest, SendSmsResponse } from 'tencentcloud-sdk-nodejs/tencentcloud/services/sms/v20210111/sms_models';
import { SendSmsRequest, SendSmsResponse, DescribeSmsTemplateListRequest, DescribeSmsTemplateListResponse } from 'tencentcloud-sdk-nodejs/tencentcloud/services/sms/v20210111/sms_models';
export declare class TencentSmsInstance {
secretId: string;
secretKey: string;
@ -8,4 +8,5 @@ export declare class TencentSmsInstance {
client: Client;
constructor(secretId: string, secretKey: string, region: string, endpoint: string);
sendSms(params: SendSmsRequest): Promise<SendSmsResponse>;
syncTemplate(params: DescribeSmsTemplateListRequest): Promise<DescribeSmsTemplateListResponse>;
}

View File

@ -30,15 +30,19 @@ class TencentSmsInstance {
this.client = new SmsClient(clientConfig);
}
async sendSms(params) {
// const params: SendSmsRequest = {
// PhoneNumberSet: [],
// TemplateParamSet: [],
// SmsSdkAppId: '',
// TemplateId: '',
// };
try {
const data = await this.client.SendSms(params);
return data;
const result = await this.client.SendSms(params);
return result;
}
catch (err) {
console.error(err);
throw err;
}
}
async syncTemplate(params) {
try {
const result = await this.client.DescribeSmsTemplateList(params);
return result;
}
catch (err) {
console.error(err);

View File

@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
exports.TencentSmsInstance = void 0;
class TencentSmsInstance {
async sendSms(params) {
console.log('native走不到这里');
console.log('react-native走不到这里[tencent/sms.native]');
return {};
}
}

View File

@ -90,6 +90,27 @@ export declare class WechatMpInstance {
mediaId: string;
}): Promise<any>;
sendServeMessage(options: ServeMessageOption): Promise<any>;
getAllPrivateTemplate(): Promise<{
priTmplId: string;
title: string;
type: number;
content: string;
example: string;
keywordEnumValueList?: {
keywordCode: string;
enumValueList: Array<string>;
}[] | undefined;
}[]>;
private isJson;
getURLScheme(options: {
jump_wxa: {
path?: string;
query?: string;
env_version?: string;
};
expireType?: number;
expiresAt?: number;
expireInterval?: number;
}): Promise<any>;
}
export {};

View File

@ -308,6 +308,17 @@ class WechatMpInstance {
}
return Object.assign({ success: false }, result);
}
async getAllPrivateTemplate() {
const myInit = {
method: 'GET',
headers: {
'Content-Type': 'application/json',
},
};
const token = await this.getAccessToken();
const result = (await this.access(`https://api.weixin.qq.com/wxaapi/newtmpl/gettemplate?access_token=${token}`, myInit));
return result.data;
}
isJson(data) {
try {
JSON.parse(data);
@ -317,5 +328,20 @@ class WechatMpInstance {
return false;
}
}
async getURLScheme(options) {
const { jump_wxa, expiresAt, expireType = 0, expireInterval } = options;
const token = await this.getAccessToken();
const result = await this.access(`https://api.weixin.qq.com/wxa/generatescheme?access_token=${token}`, {
method: 'POST',
body: JSON.stringify({
jump_wxa: jump_wxa,
is_expire: true,
expire_type: expireType,
expire_time: expiresAt,
expire_interval: expireInterval,
}),
});
return result;
}
}
exports.WechatMpInstance = WechatMpInstance;

View File

@ -186,15 +186,13 @@ export declare class WechatPublicInstance {
}): Promise<any>;
getTicket(): Promise<string>;
getAllPrivateTemplate(): Promise<{
template_list: {
template_id: string;
title: string;
primary_industry: string;
deputy_industry: string;
content: string;
example: string;
}[];
}>;
template_id: string;
title: string;
primary_industry: string;
deputy_industry: string;
content: string;
example: string;
}[]>;
private isJson;
decryptData(sessionKey: string, encryptedData: string, iv: string, signature: string): any;
private randomString;

View File

@ -677,7 +677,7 @@ class WechatPublicInstance {
};
const token = await this.getAccessToken();
const result = (await this.access(`https://api.weixin.qq.com/cgi-bin/template/get_all_private_template?access_token=${token}`, myInit));
return result;
return result.template_list;
}
isJson(data) {
try {

View File

@ -1 +1,2 @@
"use strict";
global.fetch = fetch;

View File

@ -1,2 +1,5 @@
declare const formData: {};
declare const formData: {
new (form?: HTMLFormElement | undefined, submitter?: HTMLElement | null | undefined): FormData;
prototype: FormData;
};
export default formData;

View File

@ -1,5 +1,4 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
// native不支持FormData
const formData = {};
const formData = FormData;
exports.default = formData;

View File

@ -25,12 +25,13 @@
"typescript": "^5.2.2"
},
"dependencies": {
"@alicloud/dysmsapi20170525": "^2.0.24",
"@alicloud/pop-core": "^1.7.12",
"aws-sdk": "^2.1499.0",
"cheerio": "^1.0.0-rc.12",
"isomorphic-fetch": "^3.0.0",
"oak-domain": "file:../oak-domain",
"tencentcloud-sdk-nodejs": "^4.0.686",
"tencentcloud-sdk-nodejs": "^4.0.746",
"ts-md5": "^1.3.1"
}
}

View File

@ -1,5 +1,4 @@
import { QiniuCloudInstance } from './service/qiniu/QiniuCloud';
import { QiniuZone } from './types/Qiniu';
class QiniuSDK {
qiniuMap: Record<string, QiniuCloudInstance>;

View File

@ -15,8 +15,8 @@ class SmsSDK {
origin: 'ali' | 'tencent',
accessKey: string,
accessSecret: string,
region: string,
endpoint: string,
region?: string,
apiVersion?: string //阿里云独有
) {
if (origin === 'tencent') {
@ -26,26 +26,24 @@ class SmsSDK {
const instance = new TencentSmsInstance(
accessKey,
accessSecret,
region,
endpoint
region!,
endpoint!,
);
Object.assign(this.tencentMap, {
[accessKey]: instance,
});
return instance;
} else if (origin === 'ali') {
if (!apiVersion) {
assert(false, '阿里云短信apiVersion必须传入');
}
// if (!apiVersion) {
// assert(false, '阿里云短信apiVersion必须传入');
// }
if (this.aliMap[accessKey]) {
return this.aliMap[accessKey];
}
const instance = new AliSmsInstance(
accessKey,
accessSecret,
region,
endpoint,
apiVersion
);
Object.assign(this.aliMap, {
[accessKey]: instance,

View File

@ -47,7 +47,7 @@ export class AliSmsInstance {
}
async sendSms(params: SendSmsRequest) {
console.log('native走不到这里');
console.log('react-native走不到这里[ali/sms.native');
return {} as SendSmsResponse;
}
}

View File

@ -1,12 +1,15 @@
import Core from '@alicloud/pop-core/lib/rpc';
import Dysmsapi20170525, * as $Dysmsapi20170525 from '@alicloud/dysmsapi20170525';
import OpenApi, * as $OpenApi from '@alicloud/openapi-client';
import Util, * as $Util from '@alicloud/tea-util';
import * as $tea from '@alicloud/tea-typescript';
type SendSmsRequest = {
PhoneNumbers: string[];
TemplateCode: string;
SignName: string;
TemplateParam?: Record<string, string>;
SmsUpExtendCode?: string;
OutId?: string;
phoneNumbers: string[];
templateCode: string;
signName: string;
templateParam?: Record<string, string>;
smsUpExtendCode?: string;
outId?: string;
};
type SendSmsResponse = {
@ -19,63 +22,49 @@ type SendSmsResponse = {
export class AliSmsInstance {
accessKeyId: string;
accessKeySecret: string;
regionId: string;
endpoint: string;
apiVersion: string;
client: Core;
client: Dysmsapi20170525;
constructor(
accessKeyId: string,
accessKeySecret: string,
regionId: string,
endpoint: string,
apiVersion: string
endpoint?: string,
) {
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.endpoint = endpoint || 'dysmsapi.aliyuncs.com'; // 目前国内终端域名相同
let config = new $OpenApi.Config({
// 必填,您的 AccessKey ID
accessKeyId: accessKeyId,
// 必填,您的 AccessKey Secret
accessKeySecret: accessKeySecret,
endpoint: this.endpoint,
});
this.client = new Dysmsapi20170525(config);
}
async sendSms(params: SendSmsRequest) {
const {
PhoneNumbers,
TemplateParam = {},
TemplateCode,
SignName,
phoneNumbers,
templateParam = {},
templateCode,
signName,
} = params;
const param = Object.assign(
{
regionId: this.regionId,
},
{
PhoneNumbers: PhoneNumbers.join(','),
TemplateParam: JSON.stringify(TemplateParam),
TemplateCode: TemplateCode,
SignName: SignName,
}
);
let sendSmsRequest = new $Dysmsapi20170525.SendSmsRequest({
phoneNumbers: (phoneNumbers instanceof Array) ? phoneNumbers.join(',') : phoneNumbers,
templateParam: JSON.stringify(templateParam),
templateCode: templateCode,
signName: signName,
});
try {
// const data = await this.client.request<SendSmsResponse>(
// 'SendSms',
// param,
// {
// method: 'POST',
// }
// );
// return data;
} catch (err) {
console.error(err);
throw err;
const data = await this.client.sendSmsWithOptions(sendSmsRequest, new $Util.RuntimeOptions({}));
const { statusCode, body } = data;
if (statusCode != 200) {
throw new Error(`ali.sendSms接口返回状态码错误${statusCode}`);
}
return body;
} catch (error) {
throw error;
}
}
}

View File

@ -25,7 +25,7 @@ const CTYun_ENDPOINT_LIST = {
ul: 'oos-gzgy.ctyunapi.cn',
},
hbwh: {
ul: 'oos-gslz.ctyunapi.cn',
ul: 'oos-hbwh.ctyunapi.cn',
},
xzls: {
ul: 'oos-xzls.ctyunapi.cn',
@ -42,7 +42,7 @@ const CTYun_ENDPOINT_LIST = {
sh2: {
ul: 'oos-sh2.ctyunapi.cn',
},
}
};
export class CTYunInstance {
private accessKey: string;
@ -55,11 +55,9 @@ export class CTYunInstance {
getUploadInfo(bucket: string, zone: CTYunZone, key?: string, actions?: Action[]) {
try {
// const uploadToken = this.getToken(zone, bucket, actions);
const signInfo = this.getSignInfo(bucket, actions);
return {
key,
// uploadToken,
accessKey: this.accessKey,
policy: signInfo.encodePolicy,
signature: signInfo.signature,

View File

@ -1,6 +1,5 @@
require('../../utils/fetch');
import crypto from 'crypto';
import { UrlObject } from 'url';
import { Md5 } from 'ts-md5';
import { Buffer } from 'buffer';
import { stringify } from 'querystring';
@ -8,6 +7,7 @@ import {
OakExternalException,
OakNetworkException,
} from 'oak-domain/lib/types/Exception';
import { url as URL, urlObject as UrlObject } from 'oak-domain/lib/utils/url/index';
import { QiniuZone } from '../../types/Qiniu';
/**

View File

@ -5,7 +5,7 @@ import {
export class TencentSmsInstance {
async sendSms(params: SendSmsRequest) {
console.log('native走不到这里');
console.log('react-native走不到这里[tencent/sms.native]');
return {} as SendSmsResponse;
}
}

View File

@ -1,5 +1,5 @@
import { Client } from 'tencentcloud-sdk-nodejs/tencentcloud/services/sms/v20210111/sms_client';
import { SendSmsRequest, SendSmsResponse } from 'tencentcloud-sdk-nodejs/tencentcloud/services/sms/v20210111/sms_models';
import { SendSmsRequest, SendSmsResponse, DescribeSmsTemplateListRequest, DescribeSmsTemplateListResponse } from 'tencentcloud-sdk-nodejs/tencentcloud/services/sms/v20210111/sms_models';
const SmsClient = Client;
@ -39,15 +39,18 @@ export class TencentSmsInstance {
}
async sendSms(params: SendSmsRequest) {
// const params: SendSmsRequest = {
// PhoneNumberSet: [],
// TemplateParamSet: [],
// SmsSdkAppId: '',
// TemplateId: '',
// };
try {
const data: SendSmsResponse = await this.client.SendSms(params);
return data;
const result: SendSmsResponse = await this.client.SendSms(params);
return result;
} catch (err) {
console.error(err);
throw err;
}
}
async syncTemplate(params: DescribeSmsTemplateListRequest) {
try {
const result: DescribeSmsTemplateListResponse = await this.client.DescribeSmsTemplateList(params);
return result
} catch (err) {
console.error(err);
throw err;

View File

@ -473,6 +473,33 @@ export class WechatMpInstance {
return Object.assign({ success: false }, result);
}
async getAllPrivateTemplate() {
const myInit = {
method: 'GET',
headers: {
'Content-Type': 'application/json',
},
};
const token = await this.getAccessToken();
const result = (await this.access(
`https://api.weixin.qq.com/wxaapi/newtmpl/gettemplate?access_token=${token}`,
myInit
)) as {
data: {
priTmplId: string;
title: string;
type: number;
content: string;
example: string;
keywordEnumValueList?: Array<{
keywordCode: string;
enumValueList: Array<string>;
}>;
}[];
};
return result.data;
}
private isJson(data: string) {
try {
JSON.parse(data);
@ -481,4 +508,29 @@ export class WechatMpInstance {
return false;
}
}
async getURLScheme(options: {
jump_wxa: { path?: string; query?: string; env_version?: string };
expireType?: number;
expiresAt?: number;
expireInterval?: number;
}) {
const { jump_wxa, expiresAt, expireType = 0, expireInterval } = options;
const token = await this.getAccessToken();
const result = await this.access(
`https://api.weixin.qq.com/wxa/generatescheme?access_token=${token}`,
{
method: 'POST',
body: JSON.stringify({
jump_wxa: jump_wxa,
is_expire: true,
expire_type: expireType, //默认是零,到期失效的 scheme 码失效类型失效时间类型0失效间隔天数类型1
expire_time: expiresAt,
expire_interval: expireInterval,
}),
}
);
return result;
}
}

View File

@ -993,7 +993,7 @@ export class WechatPublicInstance {
example: string;
}[];
};
return result;
return result.template_list;
}
private isJson(data: string) {

View File

@ -0,0 +1 @@
global.fetch = fetch;

View File

@ -1,4 +1,4 @@
// native不支持FormData
const formData = {};
const formData = FormData;
export default formData;