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'
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()
},
})
wechat.startAuth(state, url, appId, componentAppId)
wechat.getAuthQuery(url, checkRule)
wechat.endAuth(state)
分享
参考微信网页开发 JS-SDK 说明文档:
https://developers.weixin.qq.com/doc/offiaccount/OA_Web_Apps/JS-SDK.html
wechat
.share((wx, signature, jsApiList, shareInfo, debug)
.then(() => {})
.catch(() => {})
支付
参考微信支付文档:
https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=7_7
wechat.pay(params)
.then(() => {})
.catch(() => {})