Socket
Socket
Sign inDemoInstall

wechat-nodejs-sdk

Package Overview
Dependencies
162
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    wechat-nodejs-sdk

some API related to weixin in nodejs


Version published
Maintainers
1
Created

Readme

Source

Packages用途

提供给Nodejs端开发微信公众号相关的SDK, 目前只支持使用redis作为存储介质。

Usage

  1. 安装: yarn add wechat-nodejs-sdk
  2. 使用:
import WeixinSdk from 'weixin-sdk'
import { logger } from '../helpers/logger'
import redisClient from './redis-client'

module.exports.weixinSdk = new WeixinSdk({ ...config.weixin, client: redisClient, logger: logger })

module.exports.weixinSdk = new WeixinSdk(config.weixin)

Note

config.weixin中可能需要配置的参数

参数说明默认值
noncestr随机数,用于验证消息的确来自微信服务器(可以参考https://mp.weixin.qq.com/wiki)Wm3WZYTPz0wzccnW
appId微信为每个公众号生成的唯一的随机数wx7f70a1cadda24881
appSecret和appId组合使用,也是基于每个公众号5da26c0c6d1b9cf5cef5baf76ee784a8
granType向微信服务器请求的类型,目前只用于获取Token,所以使用默认值client_credential
accessTokenUrl向微信服务器请求Token的Urlhttps://api.weixin.qq.com/cgi-bin/token
ticketUrl向微信请求Tiket的Urlhttps://api.weixin.qq.com/cgi-bin/ticket/getticket
tokenKey缓存到Storage的微信Token名称,根据不同环境下修改成自己的名字BFF:WEIXIN:TOKEN
appToken用于验证消息的确来自微信服务器(可以参考https://mp.weixin.qq.com/wiki)1111111
cacheKey缓存到Memory Cache的微信Ticket字段名称BFF:RIDER:WEIXIN:TICKET

API

init()

初始化微信相关的所有预置条件,比如初始化Redis客户端(因为目前采用redis缓存Token),微信OAuth客户端

getWeixinToken()

用于获取微信基础Token,这个有别于网页Token,每天限制请求次数(1000次)

getWebsiteSignature()

用于微信公众测试号验证服务器有效性。开发者提交信息后,微信服务器将发送GET请求到填写的服务器地址URL上,我们需要按照微信指定的算法去生成一个返回值给微信服务器

getSdkSignature()

用于调用微信SDK而需要针对每个URL生成唯一的签名,当使用wx.config的时候会用到

getWeixinOpenId()

用于根据微信回调code获取用户的openid

getAuthorizeURL()

生成一个微信的认证回调URL

FAQs

Last updated on 27 Apr 2017

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc