Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@yorkjs/wechat

Package Overview
Dependencies
Maintainers
2
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@yorkjs/wechat

process wechat auth/pay/share tool

  • 2.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
18
Maintainers
2
Weekly downloads
 
Created
Source

wechat

整合微信常用的授权、支付、分享方法。

安装

CDN

<script src="https://unpkg.com/@yorkjs/wechat"></script>

NPM

npm install @yorkjs/wechat

YARN

yarn add @yorkjs/wechat

微信授权

参考微信授权文档:

https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/2.0/api/Before_Develop/Official_Accounts/official_account_website_authorization.html

import wechat from '@yorkjs/wechat'

// 初始化需要的对象
// storage 存储对象,包含 get/set/remove 方法
// getTimestamp 获取当前时间的方法(毫秒)
wechat.init({
  storage: {
    get(key) {
      return localStorage.getItem(key)
    },
    set(key, value) {
      localStorage.setItem(key, value)
    },
    remove(key) {
      localStorage.removeItem(key)
    }
  },
  getTimestamp() {
    return Date.now()
  },
})

// 发起微信授权 componentAppId 可选(第三方授权账号使用)
wechat.startAuth(state, url, appId, componentAppId)

// 解析授权返回的 state 和 code
// checkRule 校验规则,可选
// {
//   expireSeconds: 10, // 过期秒数
//   once: true, // 是否只读一次
// }
wechat.getAuthQuery(url, checkRule)

// 成功后,结束授权,清理内部相关信息
wechat.endAuth(state)

分享

参考微信网页开发 JS-SDK 说明文档:

https://developers.weixin.qq.com/doc/offiaccount/OA_Web_Apps/JS-SDK.html

// wx: 微信网页内的 wx 对象
// signatrue: 签名
// jsApiList: js 接口列表
// shareInfo: 分享的内容
// debug: 是否开启调试
wechat
  .share((wx, signature, jsApiList, shareInfo, debug)
  .then(() => {})
  .catch(() => {})

支付

参考微信支付文档:

https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=7_7

// params 参数,参考微信支付文档的 getBrandWCPayRequest 参数定义
wechat.pay(params)
  .then(() => {})
  .catch(() => {})

Keywords

FAQs

Package last updated on 27 Jun 2022

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc