wxAuth v0.1.0
用于微信授权和微信签名
Installation
Using npm:
$ npm i wxAuth -S
In project:
import wxAuth from "wxAuth";
const WxInstance = WxAuth.getInstance();
const authHttp = () => {
const searchParams = locationSearch(window.location.search);
return WxInstance.wxAuth(loginApi.wxGetJsapiSignature, loginApi.wxGetAuth, {
auth: {
code: searchParams.code,
type: "parent",
clientKey: searchParams.clientKey || "",
},
signature: {
clientKey: searchParams.clientKey || "",
url: window.location.href.split("#")[0],
},
});
};
xport function routerBeforeEachFunc(to, from, next) {
authHttp()
.then((res) => {
if (res.status === 'authed') {
} else if (res.status === 'failed') {
this.$toast.fail(res.message)
}
next()
})
.catch(() => {
if (process.env.NODE_ENV === 'production') {
WxInstance.wxAuthRedirect()
} else {
next()
}
})
}