npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ts-wxsdk

v1.0.9

Published

> 申请测试好,请移步:https://mp.weixin.qq.com/debug/cgi-bin/sandbox?t=sandbox/login

Downloads

3

Readme

#微信公众号 API 接口

申请测试好,请移步:https://mp.weixin.qq.com/debug/cgi-bin/sandbox?t=sandbox/login

API 文档

proxy

如果你的服务器需要通过代理服务器访问外网,需要在调用任何一个 API 之前设置代理,全局只需要设置一次。 如果服务器是直接连外网,那么忽略。 设置方法:

import {setProxy} from 'ts-wxsdk';

setProxy({
    host: 'your proxy server host',
    port: 'your proxy server port',
});

token

获取全局 accessToken 或 jsapi ticket:

import {accessToken, ticket} from 'ts-wxsdk/token';

// 获取微信全局accesstoken,2小时有效期,建议定时刷新内部保存。
const token = await accessToken(appid, appsecret); // appid和appsecret在微信公众号管理后台获取

// 微信卡券api接口ticket或者jsapi ticket
const jsticket = await ticket(token, 'jsapi');

userinfo

用户登录

import {code2AccessToken, refreshAccessToken, userinfo, code2userinfo, code2Session} from 'ts-wxsdk/user';

// 微信公众号登录,使用code换用户的accessToken和openId
const accessToken = await code2AccessToken(appid, appsecret, code);
const userinfo = await userinfo(appid, openID);

// 小程序登录
const info = await code2Session(appid, appsecret, code);

template

发送模板消息

import {template} from 'ts-wxsdk/template';

template<{
    name: {
        value: string;
        color?: string;
    };
}>(accessToken, {
    touser: 'TO USER OPENID',
    template_id: '3W-7l84S25TMqdzJPN7jaqE5Fj451aGobsc1wMD7NXU',
    url: 'https://www.baidu.com/',
    topcolor: '#00ff00',
    data: {
        name: {
            value: 'name',
            color: '#173177',
        },
    },
});

解析微信事件通知

微信消息通知具体见:https://developers.weixin.qq.com/doc/offiaccount/Message_Management/Receiving_standard_messages.html

此 API 是把通知过来的 XML 内容解析成 JSON 格式。todo: 加密消息解密(当前版本没有处理)

import {parse} from 'ts-wxsdk/message';
const l = parse(wxSendMessage);

回复消息

具体见:https://developers.weixin.qq.com/doc/offiaccount/Message_Management/Passive_user_reply_message.html

这个 API 负责把对应的消息内容组装成 XML 格式。

import {text, image, video, voice, news} from 'ts-wxsdk/message.response';
const r = text({
    ToUserName: 'a',
    FromUserName: 'b',
    Content: 's',
});

const r = image({
    ToUserName: 'a',
    FromUserName: 'b',
    Image: {
        MediaId: 'b',
    },
});

const r = video({
    ToUserName: 'a',
    FromUserName: 'b',
    Video: {
        MediaId: '11',
        Title: 'hello video',
        Description: 'desc',
    },
});

const r = voice({
    ToUserName: 'a',
    FromUserName: 'b',
    Voice: {
        MediaId: 'voiceid',
    },
});

const r = news({
    ToUserName: 'a',
    FromUserName: 'b',
    ArticleCount: 2,
    Articles: {
        item: [
            {
                Title: 't1',
                Description: 'd1',
                PicUrl: 'pu1',
                Url: 'u1',
            },
            {
                Title: 't2',
                Description: 'd2',
                PicUrl: 'pu2',
                Url: 'u2',
            },
        ],
    },
});