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

nestjs-wechat

v0.1.0

Published

nestjs module for wechat server-side api.

Downloads

3

Readme

nest-wechat

微信公众号、微信程序开、微信小游戏、微信支付以及企业微信等服务端API nestjs 模块封装。也可以直接当工具类使用。

快速开始

安装

npm i --save nest-wechat

nestjs 模块引入

  • register方法注册
import { Module } from '@nestjs/common';

import { WeChatModule } from 'nest-wechat';

@Module({
  imports: [WeChatModule.register({appId: 'your app id', secret: 'your secret'})],
})
export class AppModule {
}
  • forRoot配置注册
import { Module } from '@nestjs/common';
import { ConfigModule, ConfigService } from '@nestjs/config';

import { WeChatModule } from 'nest-wechat';

@Module({
  imports: [ConfigModule.forRoot({
    envFilePath: '.env.test.local',
  })],
  inject: [ConfigService],
  useFactory: (configService: ConfigService) => ({
    appId: configService.get('TEST_APPID') || '',
    secret: configService.get('TEST_SECRET') || '',
  }),
  })],
})
export class AppModule {
}

工具类引入

import { WeChatService } from 'nest-wechat';
const service = new WeChatService({ appId: 'your app id', secret: 'your secret'});

微信公众号API

网页授权

getAccessTokenByCode

  • 参数:
    • {string} code 微信客户端打开授权页跳转后获取到的code
  • 返回值
    • Promise<AccessTokenResult> 调用后返回Promise

正确时返回

{
  "access_token":"ACCESS_TOKEN",
  "expires_in":7200,
  "refresh_token":"REFRESH_TOKEN",
  "openid":"OPENID",
  "scope":"SCOPE" 
}

错误时返回

{
    "errcode": 40029,
    "errmsg": "invalid code"
}

参考文档

获取Access token

getAccountAccessToken

  • 返回值
    • Promise<AccountAccessTokenResult> 调用后返回Promise

正确时返回

{
  "access_token": "52_s0Mcl3E3DBKs12rthjxG8_DOvsIC4puV9A34WQR6Bhb_30TW9W9BjhUxDRkyph-hY9Ab2QS03Q8wZBe5UkA1k0q0hc17eUDZ7vAWItl4iahnhq_57dCoKc1dQ3AfiHUKGCCMJ2NcQ0BmbBRIKBEgAAAPGJ",
  "expires_in": 7200
}

错误时返回

{
  "errcode": 40013,
  "errmsg": "invalid appid"
}

参考文档

获取jsapi_ticket

getJSApiTicket

  • 返回值
    • Promise<TicketResult> 调用后返回Promise

返回数据

{
  "errcode": 0,
  "errmsg": "ok",
  "ticket": "bxLdikRXVbTPdHSM05e5u5sUoXNKd8-41ZO3MhKoyN5OfkWITDGgnr2fwJ0m9E8NYzWKVZvdVtaUgWvsdshFKA",
  "expires_in": 7200
}

参考文档

JS-SDK使用权限签名

jssdkSignature

  • 参数:
    • {string} url 参与签名计算的url
  • 返回值
    • Promise<SignatureResult> 调用后返回Promise

参考文档

发送模板消息

sendTemplateMessage

  • 参数:
    • {TemplateMessage} message 模板消息参数类型
  • 返回值
    • Promise<DefaultRequestResult & { msgid: string }> 调用后返回Promise

参考文档

Run Test

Create .env.test.local file, and save your test appid and secret in the file.

TEST_APPID=your/test/appid
TEST_SECRET=your/test/secret
TEST_JSSDK_URL=your/test/url

Run test.

npm run test