anger-wechat
封装微信常用api
Directory
-
Global
全局方法 -
Web
适用于网页公众号开发 -
Mini
适用于小程序开发 -
angerPay
适用于支付
Getting started
npm install anger-wechat --save
Use
var AngerWechat = var weixinApi = appId: '[your appId]' // appId 必传 appSecret: '[your appSecret]' // appSecret 必传 authUrl: 'http://www.test.cc/get-weixin-code.html'
如果需要支付的话
var AngerWechat = var weixinApi = appId: '[your appId]' // appId 必传 appSecret: '[your appSecret]' // appSecret 必传 authUrl: 'http://www.test.cc/get-weixin-code.html' // 可选 微信auth2.0授权公共页面 payment: // 可选 如果需要支付模块的话 mchId: '123456' partnerKey: '456789' pfx: path //【可选】证书路径,不传大多接口掉不了 notifyUrl: '' // 【可选】微信支付接受到结果'
Global
getGlobalAccessToken
全局使用,建议保存在数据库
获取 access_token 戳我查看官方文档
access_token是公众号的全局唯一接口调用凭据,公众号调用各接口时都需使用access_token。开发者需要进行妥善保存。access_token的存储至少要保留512个字符空间。access_token的有效期目前为2个小时,需定时刷新,重复获取将导致上次获取的access_token失效。
let access_token = await weixinApi
isWechat
判断是否是微信环境
let ua = requestheaders"user-agent"let isWeixin = weixinApi // 传入 `UserAgent` 字符串,返回 true | false
Web
[AngerWechat.Web]
getJsTicket
全局使用,建议保存在数据库
获取 js api_ticket 戳我查看官方文档
api_ticket 是用于调用微信卡券JS API的临时票据,有效期为7200 秒,通过access_token 来获取。
let jsTrickt = await weixinApiWeb
getAuthUrl
获取 Auth地址,重定向之后用来获取code
let authURl = weixinApiWebconsole// http://www.toolos.cc/get-weixin-code.html?appid=wxf638c1f64239e786&redirect_uri=http://www.baidu.com&scope=snsapi_userinfo&state=STATE
getAuthAccessTokenByCode
根据code获取 openid
let codeInfo = await weixinApiWeb
getUserInfo
根据 getAuthAccessTokenByCode
获取的 access_token
和 openid
获取用户信息,注意这里的获取回调url方法 getAuthUrl
的 scope
需要传 snsapi_userinfo
let userInfo = await weixinApiWeb
getJsSdkConfig
获取js sdk config配置 微信 JS 接口签名校验工具
let jsTricktConfig = await weixinApiWeb
Mini
[AngerWechat.Mini]
getOpenidByCode
根据小程序传来的code获取openid等信息 临时登录凭证code 获取 session_key 和 openid 等。
let info = await weixinApiMini