@use-services/wechatlite
Version:
```ts import * as WechatLite from "@use-services/wechatlite";
130 lines (129 loc) • 3.73 kB
TypeScript
/// <reference types="node" />
import { ServiceOption, InitOption } from "use-services";
export declare type Option<S extends Service> = ServiceOption<Args, S>;
export interface Args {
appId: string;
secret: string;
token?: string;
encodingAESKey?: string;
timeout?: number;
}
export declare class Service {
args: Args;
constructor(option: InitOption<Args, Service>);
wxBizDataDecrypt(sessionKeyRaw: string, encryptedDataRaw: string, ivRaw: string): any;
code2Session(code: string): Promise<any>;
getWXACodeUnlimit(accessToken: string, page: string, scene: string): Promise<any>;
getAccessToken(): Promise<any>;
sendCustomerMessage(accessToken: string, msg: CustomerMessage): Promise<any>;
sendTemplateMessage(accessToken: string, msg: TemplateMessage): Promise<any>;
uploadTempMedia(accessToken: string, img: Buffer, imgfile: string, imgtype: string): Promise<void>;
checkSignature(signature: string, timestamp: string, nonce: string): boolean;
decryptWXContact(wechatData: string): ContactMessage;
private checkError;
}
export declare const init: (option: InitOption<unknown, Service>) => Promise<Service>;
export declare class WechatLiteRequestError extends Error {
}
export declare class WechatLiteArgError extends Error {
}
export declare class WechatLiteBusinessError extends Error {
readonly errcode: string;
readonly errmsg: string;
constructor(msg: string, errcode: string, errmsg: string);
}
export interface Session {
openid: string;
session_key: string;
unionid?: string;
}
export interface AccessToken {
access_token: string;
expires_in: number;
}
export declare type CustomerMessage = CustomerMessageText | CustomerMessageImage | CustomerMessageLink | CustomerMessageMiniprogrampage;
export interface CustomerMessageText {
touser: string;
msgtype: "text";
text: {
content: string;
};
}
export interface CustomerMessageImage {
touser: string;
msgtype: "image";
image: {
media_id: string;
};
}
export interface CustomerMessageLink {
touser: string;
msgtype: "link";
link: {
title: string;
description: string;
url: string;
thumb_url: string;
};
}
export interface CustomerMessageMiniprogrampage {
touser: string;
msgtype: "miniprogrampage";
miniprogrampage: {
title: string;
pagepath: string;
thumb_media_id: string;
};
}
export declare type ContactMessage = ContactMessageText | ContactMessageImage | ContactMessageMiniprogrampage | ContactMessageEvent;
export interface ContactMessageText {
FromUserName: string;
CreateTime: number;
MsgType: "text";
Content: string;
MsgId: number;
}
export interface ContactMessageImage {
FromUserName: string;
CreateTime: number;
MsgType: "image";
PicUrl: string;
MediaId: string;
MsgId: number;
}
export interface ContactMessageMiniprogrampage {
FromUserName: string;
CreateTime: number;
MsgType: "miniprogrampage";
MsgId: number;
Title: string;
AppId: string;
PagePath: string;
ThumbUrl: string;
ThumbMediaId: string;
}
export interface ContactMessageEvent {
FromUserName: string;
CreateTime: number;
MsgType: "event";
Event: string;
SessionFrom: string;
}
export interface TemplateMessage {
touser: string;
template_id: string;
page: string;
form_id: string;
data?: {
[k: string]: {
value: string;
};
};
emphasis_keyword?: string;
}
export interface UploadTempMediaRes {
type: string;
media_id: string;
created_at: string;
}
export declare function sha1(data: string): string;