Wechat
Easy to use Wechat SDK for Node(Under dev)
Implements
Usage
公众平台
实例化 sdk 客户端
import Wechat from "wechat-one";
const wx = new Wechat.OfficialAccount({
appid: WX_APPID,
secret: WX_APPSECRET,
token: WX_TOKEN,
aesKey: WX_AESKEY,
server: "koa",
cacher
});
cacher: {
getter: (key: string) => string;
setter: (key: string, data: string) => void;
}
import * as Koa from "koa";
const app = new Koa();
const wx = ...
const mpServer = wx.getService("server");
mpServer.handle(async function handler(msg) {
switch (msg.type) {
case "text":
return "received: " + msg.content;
return new Wechat.Core.ImageReply("MediaId")
...
default:
return ""
}
});
mpServer.connect(app);
mpServer.connect(app, path);
const mediaService = wx.getService("media");
mediaService.uploadImage("image file path");
mediaService.uploadVoice("voice file path");
mediaService.uploadVideo("video file path");
mediaService.uploadThumb("thumb image file path");
const menuService = wx.getService("menu");
menuService.list();
menuService.current();
menuService.create([
{
type: "click",
name: "name",
key: "",
sub_button: [],
url: "",
media_id: "",
appid: "",
pagepath: ""
}
]);
menuService.delete();
menuService.createConditional([
{
button: buttons,
matchrule: {}
}
]);
menuService.deleteConditional(menuId);
menuService.tryMatch(userId);
const qrcodeService = wx.getService("qrcode");
qrcodeService.forever("your scene");
qrcodeService.temporary("your scene", 3600 );
qrcodeService.url("ticket");
const templatemessageService = wx.getService("templatemessage");
templatemessageService.setIndustry(primaryIndustry, secondaryIndustry);
templatemessageService.getIndustry();
templatemessageService.addTemplate(shortId);
templatemessageService.getPrivateTemplates();
templatemessageService.deletePrivateTemplate(templateId);
templatemessageService.send(data);
templatemessageService.sendSubscription(data);
const urlService = wx.getService("url");
urlService.shorten("your long url");
const userService = wx.getService("user");
userService.createTag("tag name");
userService.getTags();
userService.updateTag(123 , "tag name");
userService.deleteTag(123 );
userService.getTagUserList(123 , "next openid");
userService.tagUsers(123 , ["openid1", "openid2"]);
userService.untagUsers(123 , ["openid1", "openid2"]);
userService.getUserTags("openid");
userService.setRemark("openid", "remark");
userService.getInfo("openid", "zh_CN");
userService.batchGetInfo([
{ openid: "openid1", lang: "zh_CN" },
{ openid: "openid2", lang: "zh_CN" }
]);
userService.list("next openid");
userService.blacklist("next openid");
userService.drop(["openid1", "openid2"]);
userService.recover(["openid1", "openid2"]);
const commentService = wx.getService("comment");
commentService.open(msgId, index);
commentService.close(msgId, index);
commentService.list(msgId, index, begin, count, type);
commentService.markElect(msgId, index, commentId);
commentService.unmarkElect(msgId, index, commentId);
commentService.delete(msgId, index, commentId);
commentService.reply(msgId, index, commentId, content);
commentService.deleteReply(msgId, index, commentId);
const autoreplyService = wx.getService("autoreply");
autoreplyService.current();
const poiService = wx.getService("poi");
poiService.getPOI(id);
poiService.list(offset, limit);
poiService.create(poi);
poiService.update(id, poi);
poiService.delete(id);
poiService.categories();
const deviceService = wx.getService("device");
deviceService.message(deviceId, openId, content);
deviceService.statMessage(deviceId, openId, type, status);
deviceService.openId(deviceId);
deviceService.qrCode(deviceIds);
deviceService.verifyQrCode(ticket);
deviceService.createId(productId);
deviceService.authorize(devices, productId, opType);
deviceService.update(devices);
deviceService.stat(deviceId);
deviceService.bind(openId, deviceId, ticket);
deviceService.unbind(openId, deviceId, ticket);
deviceService.forceBind(openId, deviceId);
deviceService.forceUnbind(openId, deviceId);
deviceService.getBindDevice(openId);
const semanticService = wx.getService("semantic");
semanticService.query(keyword, categories, optional?);
const datacubeService = wx.getService("datacube");
datacubeService.userSummary(from, to);
datacubeService.userCumulate(from, to);
datacubeService.articleSummary(from, to);
datacubeService.articleTotal(from, to);
datacubeService.userReadSummary(from, to);
datacubeService.userReadHourly(from, to);
datacubeService.userShareSummary(from, to);
datacubeService.userShareHourly(from, to);
datacubeService.upstreamMessageSummary(from, to);
datacubeService.upstreamMessageHourly(from, to);
datacubeService.upstreamMessageWeekly(from, to);
datacubeService.upstreamMessageMonthly(from, to);
datacubeService.upstreamMessageDistSummary(from, to);
datacubeService.upstreamMessageDistWeekly(from, to);
datacubeService.upstreamMessageDistMonthly(from, to);
datacubeService.interfaceSummary(from, to);
datacubeService.interfaceSummaryHourly(from, to);
datacubeService.cardSummary(from, to, condSource);
datacubeService.freeCardSummary(from, to, condSource, cardId);
datacubeService.memberCardSummary(from, to, condSource);
datacubeService.memberCardDetail(from, to, cardId);
const baseService = wx.getService("base");
baseService.getValidIps();
baseService.clearQuota();