All Projects → Jon-Millent → anger-wechat

Jon-Millent / anger-wechat

Licence: MIT license
👿Angry wechat api 微信支付、小程序、各种接口的封装。

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to anger-wechat

AppPay
💸 AppPay专注于App支付的库,几句代码轻松搞定微信支付、支付宝支付。集成更简单。
Stars: ✭ 33 (+94.12%)
Mutual labels:  weixin-pay, wechat-pay, wechatpay
Payment
Payment是php版本的支付聚合第三方sdk,集成了微信支付、支付宝支付、招商一网通支付。提供统一的调用接口,方便快速接入各种支付、查询、退款、转账能力。服务端接入支付功能,方便、快捷。
Stars: ✭ 2,293 (+13388.24%)
Mutual labels:  weixin-pay, wechat-pay
wechat-pay
Simplest WechatPay(最简单的微信支付)
Stars: ✭ 49 (+188.24%)
Mutual labels:  weixin, wechatpay
wechat-sdk
微信登录支付sdk,支持小程序,APP登录,正在重构。QQ群:879729420
Stars: ✭ 73 (+329.41%)
Mutual labels:  weixin, wechat-pay
wxpay-gitbook
微信支付文档: https://yclimb.gitbook.io/wxpay/
Stars: ✭ 45 (+164.71%)
Mutual labels:  weixin, weixin-pay
Node Tenpay
微信支付 for nodejs
Stars: ✭ 947 (+5470.59%)
Mutual labels:  weixin, wechat-pay
jeewx-boot
JAVA版免费开源的微信管家平台。支持微信公众号、小程序、第三方平台等。平台已经实现了公众号基础管理、群发、系统权限、抽奖活动、小程序官网等功能,便于二次开发,可以快速搭建微信应用!
Stars: ✭ 992 (+5735.29%)
Mutual labels:  weixin
wxMD5
📄基于 blueimp/JavaScript-MD5 的支持小程序的MD5加密库
Stars: ✭ 44 (+158.82%)
Mutual labels:  weixin
go-wechat
💥weixin、wechat、微信公众平台、企业微信 golang/go sdk
Stars: ✭ 18 (+5.88%)
Mutual labels:  weixin
SMmuiscPlay
🎼极简模式JavaScript音乐播放器组件,极简、小巧、无依赖、可定制,适用于手机页面,H5活动页,微信页面等的音乐播放支持
Stars: ✭ 40 (+135.29%)
Mutual labels:  weixin
node-wxpay
微信支付APIv3 for nodejs
Stars: ✭ 93 (+447.06%)
Mutual labels:  wechatpay
openapplus
专为小程序共享而生的小程序容器
Stars: ✭ 51 (+200%)
Mutual labels:  weixin
vux-weixin
基于vue,vux,运行在微信上,增加了 http拦截器, auth权限 , jwt认证 , storage ,目录结构灵感来源于ngx-admin
Stars: ✭ 14 (-17.65%)
Mutual labels:  weixin
wechat-api-examples
wechat-api examples, used java8.
Stars: ✭ 12 (-29.41%)
Mutual labels:  wechat-api
fim
flutter写的IM移动客户端
Stars: ✭ 55 (+223.53%)
Mutual labels:  weixin
mpvue canvas drawer
[mpvue版本]微信小程序上canvas绘制图片助手,一个json就制作分享朋友圈图片
Stars: ✭ 43 (+152.94%)
Mutual labels:  weixin
wechatpay-go
微信支付 APIv3 的 Go Library
Stars: ✭ 553 (+3152.94%)
Mutual labels:  wechatpay
wx-domain-test
微信域名防封系统 实时检测 自动切换域名 消息提醒
Stars: ✭ 71 (+317.65%)
Mutual labels:  weixin
wechat-page-sharing
Wordpress微信分享插件:你可以控制Wordpress页面的微信分享内容,包括Url、标题、图片和内容。
Stars: ✭ 21 (+23.53%)
Mutual labels:  weixin
web wechat api
基于 Itchat&Flask的 Web 微信接口
Stars: ✭ 25 (+47.06%)
Mutual labels:  wechat-api

anger-wechat

封装微信常用api

Install

npm i anger-wechat

Use

var AngerWechat = require('anger-wechat')
var weixinApi = new AngerWechat({
    appId: '[your appId]', // appId 必传
    appSecret: '[your appSecret]', // appSecret 必传
    authUrl: 'http://www.test.cc/get-weixin-code.html'
})

如果需要支付的话

var AngerWechat = require('anger-wechat')
var weixinApi = new AngerWechat({
    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.join(__dirname, 'apiclient_cert.p12'), //【可选】证书路径,不传大多接口掉不了
        notifyUrl: '' // 【可选】微信支付接受到结果'
    }
})

API

getGlobalAccessToken

建议access_token保存在数据库
获取 access_token 戳我查看官方文档 access_token是公众号的全局唯一接口调用凭据,公众号调用各接口时都需使用access_token。开发者需要进行妥善保存。access_token的存储至少要保留512个字符空间。access_token的有效期目前为2个小时,需定时刷新,重复获取将导致上次获取的access_token失效。

@params

weixinApi.getGlobalAccessToken()

  • 无参数

@return

返回 access_token

{ 
	"code": 200,
	"msg": "请求成功",
	"data": { 
		"access_token": "11_oTBrYVsT9wqa_-q3WDNEBOtfz1XKdM7YKIcNBEiu29Wfh5yTnlqaj5W0hMuxZ7C9FlY7CxD0RjR35V1ik1M3Nyi5QENcgFKhh0gYoBnAXEQ2oV93sVtO7IRqhh1kd9QLG8fwyA3vFRdifpJCOVLgAGAVCS",
		"expires_in": 7200 
	} 
}

@example

let access_token = await weixinApi.getGlobalAccessToken()

isWechat

判断是否是微信环境

@params

weixinApi.isWechat([@userAgent: String])

  • @userAgent : 浏览器useragent

@return

返回 true | false

@example

let ua = request.headers["user-agent"]
let isWeixin = weixinApi.isWechat(ua)

getJsTicket

建议getJsTicket保存在数据库
获取 js api_ticket 戳我查看官方文档 api_ticket 是用于调用微信卡券JS API的临时票据,有效期为7200 秒,通过access_token 来获取。

@params

weixinApi.Web.getJsTicket([@config: Object])

  • @config :传入从上一步获取到的access_token 获取 js api_ticket
    {
      access_token: '11_oTBrYVsT9wqa_-q3W...' // 以上一步获取到的access_token 获取 js api_ticket
    }

@return

返回 ticket

{
	"code": 200,
	"msg": "ok",
	"data": {
		"errcode": 0,
		"errmsg": "ok",
		"ticket": "HoagFKDcsGMVCIY2vOjf9oKOmI5MR...",
		"expires_in": 7200
	}
}

@example

let jsTrickt = await weixinApi.Web.getJsTicket({
    access_token: '11_oTBrYVsT9wqa_-V1LgAGAVCS...'
})

getAuthUrl

获取 Auth地址,重定向之后用来获取code

@params

weixinApi.Web.getAuthUrl([@config: Object])

  • @config : 配置
    {
      edirect_uri: 'http://www.baidu.com',
      scope: 'snsapi_userinfo' // snsapi_base:静默授权,snsapi_userinfo:提示授权(可以后续获取用户信息)
    }

@return

返回解析后的重定向url

@example

let authURl = weixinApi.Web.getAuthUrl({
	redirect_uri: 'http://www.baidu.com',
	scope: 'snsapi_userinfo' // snsapi_base:静默授权,snsapi_userinfo:提示授权(可以后续获取用户信息)
})
console.log(authURl)
// http://www.toolos.cc/get-weixin-code.html?appid=wxf638c1f64239e786&redirect_uri=http://www.baidu.com&scope=snsapi_userinfo&state=STATE

getAuthAccessTokenByCode

根据code获取 openid

@params

weixinApi.Web.getAuthAccessTokenByCode([@config: Object])

  • @config : 配置
    {
      code: '061729xv1BtSAa09g8yv1hr0xv1729xB'
    }

@return

返回openid

{
	"code": 200,
	"msg": "请求成功",
	"data": {
		"access_token": "11_Vc7D8AoYURWoECzJgD6Q1ccUOOHypO...",
		"expires_in": 7200,
		"refresh_token": "11_ii3uONcMPA-04RjuLlckMMiwaDGF2MjW2SB5...",
		"openid": "oI-Aa04T6FrpFFpTfyAaXR4SKacU",
		"scope": "snsapi_userinfo"
	}
}

@example

let codeInfo = await weixinApi.Web.getAuthAccessTokenByCode({
    code: '061729xv1BtSAa09g8yv1hr0xv1729xB'
})

getUserInfo

根据 getAuthAccessTokenByCode 获取的 access_tokenopenid 获取用户信息,注意这里的获取回调url方法 getAuthUrlscope 需要传 snsapi_userinfo

@params

weixinApi.Web.getUserInfo([@config: Object])

  • config: 配置
    {
      access_token: access_token, // 根据 `getAuthAccessTokenByCode` 获取的 `access_token`
      openid: openid // 根据 `getAuthAccessTokenByCode` 获取的 `openid`
    }

@return

{
	"code": 200,
	"msg": "请求成功",
	"data": {
		"openid": "oI-Aa04T6FrpFFpTfyAaXR4SKacU",
		"nickname": "吃鱼的帆",
		"sex": 1,
		"language": "zh_CN",
		"city": "**",
		"province": "**",
		"country": "中国",
		"headimgurl": "http://thirdwx.qlogo.cn/mmopen/vi_32/Q0j4TwGTfT...",
		"privilege": []
	}
}

@example

let userInfo = await weixinApi.Web.getUserInfo({
	access_token: codeInfo.data.access_token,
	openid: codeInfo.data.openid
})

getJsSdkConfig

获取js sdk config配置 微信 JS 接口签名校验工具

@params

weixinApi.Web.getJsSdkConfig([config: Object])

  • config: 配置
    {
      ticket: 'HoagFKDcsGMVCIY2vOjf9oKOmI5MRTBgKJJwCD...', // 从 getJsTicket 方法获取的ticket
      url: 'http://www.toolos.cc' // 调用js sdk 页面地址
    }

@return

{
	"appId": "wxf638c1f64239e786",
	"signature": "2c18eb8d6adaa5e02a9df517e776f5eef40ed402",
	"noncestr": "04b21a6a-caea-4878-9fdb-8b2c1ff699b0",
	"timestamp": 1530636997,
	"jsapi_ticket": "HoagFKDcsGMVCIY2vOjf9oKOmI5MRTBgK...."
}

@example

let jsTricktConfig = await weixinApi.Web.getJsSdkConfig({
  ticket: 'HoagFKDcsGMVCIY2vOjf9oKOmI5MRTBgKJJwCDQ2Bnx34...',
  url: 'http://www.toolos.cc'
})

getOpenidByCode

根据小程序传来的code获取openid等信息 临时登录凭证code 获取 session_key 和 openid 等。

@params

  • config: 配置
    {
      code: 'xxxxxxxxxxxxxx'
    }

@return

{
    "openid" : "oynY34-0Err_YssQIFsK-Ht1eGs",
    "session_key" : "sPxOFsssssCP54n6cCfshw=="
}

@example

let info = await weixinApi.Mini.getOpenidByCode({
    code: 'xxxxxxxxxxxxxx'
})

支付

戳我查看文档地址

附录

关于 authUrl 参数

参考 GetWeixinCode

校验工具

官方文档目录(真心想吐槽,找个文档真难)

请我喝杯咖啡,支持更多开源

1024.png

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].