mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2024-11-21 09:36:35 +00:00
build: v1.3.5-beta10
This commit is contained in:
parent
caa2fca4e8
commit
c2278e3536
@ -30,15 +30,15 @@ export class RequestUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 请求和回复都是JSON data传原始内容 自动编码json
|
// 请求和回复都是JSON data传原始内容 自动编码json
|
||||||
static async HttpGetJson<T>(url: string, method: string = 'GET', data?: any, headers: Record<string, string> = {}): Promise<T> {
|
static async HttpGetJson<T>(url: string, method: string = 'GET', data?: any, headers: Record<string, string> = {}, isJsonRet: boolean = true): Promise<T> {
|
||||||
let option = new URL(url);
|
let option = new URL(url);
|
||||||
const protocol = url.startsWith('https://') ? https : http;
|
const protocol = url.startsWith('https://') ? https : http;
|
||||||
const options = {
|
const options = {
|
||||||
hostname: option.hostname,
|
hostname: option.hostname,
|
||||||
port: option.port,
|
port: option.port,
|
||||||
path: option.href,
|
path: option.href,
|
||||||
method,
|
method: method,
|
||||||
headers,
|
headers: headers
|
||||||
};
|
};
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
const req = protocol.request(options, (res: any) => {
|
const req = protocol.request(options, (res: any) => {
|
||||||
@ -50,8 +50,12 @@ export class RequestUtil {
|
|||||||
res.on('end', () => {
|
res.on('end', () => {
|
||||||
try {
|
try {
|
||||||
if (res.statusCode && res.statusCode >= 200 && res.statusCode < 300) {
|
if (res.statusCode && res.statusCode >= 200 && res.statusCode < 300) {
|
||||||
const responseJson = JSON.parse(responseBody);
|
if (isJsonRet) {
|
||||||
resolve(responseJson as T);
|
const responseJson = JSON.parse(responseBody);
|
||||||
|
resolve(responseJson as T);
|
||||||
|
} else {
|
||||||
|
resolve(responseBody as T);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
reject(new Error(`Unexpected status code: ${res.statusCode}`));
|
reject(new Error(`Unexpected status code: ${res.statusCode}`));
|
||||||
}
|
}
|
||||||
@ -73,6 +77,7 @@ export class RequestUtil {
|
|||||||
|
|
||||||
// 请求返回都是原始内容
|
// 请求返回都是原始内容
|
||||||
static async HttpGetText(url: string, method: string = 'GET', data?: any, headers: Record<string, string> = {}) {
|
static async HttpGetText(url: string, method: string = 'GET', data?: any, headers: Record<string, string> = {}) {
|
||||||
return this.HttpGetJson<string>(url, method, data, headers);
|
//console.log(url);
|
||||||
|
return this.HttpGetJson<string>(url, method, data, headers, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
2
src/core
2
src/core
@ -1 +1 @@
|
|||||||
Subproject commit c30a351bbb9046c31b471e9a818d7b28f971541a
|
Subproject commit b1351835673f86d445d244fd515560bfcd0b7adb
|
@ -5,13 +5,16 @@ import BaseAction from '../BaseAction';
|
|||||||
import { ActionName } from '../types';
|
import { ActionName } from '../types';
|
||||||
import { NTQQUserApi, WebApi } from '@/core/apis';
|
import { NTQQUserApi, WebApi } from '@/core/apis';
|
||||||
interface Payload {
|
interface Payload {
|
||||||
groud_id: string
|
group_id: number
|
||||||
}
|
}
|
||||||
export class GetGroupHonorInfo extends BaseAction<Payload, Array<any>> {
|
export class GetGroupHonorInfo extends BaseAction<Payload, Array<any>> {
|
||||||
actionName = ActionName.GetGroupHonorInfo;
|
actionName = ActionName.GetGroupHonorInfo;
|
||||||
|
|
||||||
protected async _handle(payload: Payload) {
|
protected async _handle(payload: Payload) {
|
||||||
// console.log(await NTQQUserApi.getRobotUinRange());
|
// console.log(await NTQQUserApi.getRobotUinRange());
|
||||||
return await WebApi.getGroupHonorInfo(payload.groud_id);
|
if(!payload.group_id){
|
||||||
|
throw '缺少参数group_id';
|
||||||
|
}
|
||||||
|
return await WebApi.getGroupHonorInfo(payload.group_id.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user