update at 2026-04-21 17:55:41

This commit is contained in:
douboer
2026-04-21 17:55:41 +08:00
parent dda7eaeec1
commit 6199ec79d4
37 changed files with 1106 additions and 174 deletions

27
server/src/wechat.ts Normal file
View File

@@ -0,0 +1,27 @@
import type { IncomingMessage } from "http";
import * as https from "https";
export interface WechatTokenResponse {
access_token?: string;
expires_in?: number;
errcode?: number;
errmsg?: string;
}
export function httpsGetJson(url: string): Promise<WechatTokenResponse> {
return new Promise((resolve, reject) => {
https.get(url, (res: IncomingMessage) => {
let data = "";
res.on("data", (chunk: Buffer) => {
data += chunk;
});
res.on("end", () => {
try {
resolve(JSON.parse(data) as WechatTokenResponse);
} catch (_error) {
reject(new Error("Invalid JSON from WeChat API"));
}
});
}).on("error", reject);
});
}