123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161 |
- import weixin from "@/js_sdk/jweixin-module";
- import {
- isAndroid
- } from "./tools"
- import {
- getJsconfig,
- getCodeUrl,
- wechatLogin,
- wechatBindLogin
- } from '@/api/app'
- import store from '../store'
- import Cache from './cache'
- class Wechath5 {
-
- signLink() {
- if (typeof window.entryUrl === 'undefined' || window.entryUrl === '') {
- window.entryUrl = location.href.split('#')[0]
- }
- return isAndroid() ? location.href.split('#')[0] : window.entryUrl;
- }
-
- config() {
- return new Promise((resolve) => {
- getJsconfig().then(res => {
- if (res.code == 1) {
- let config = res.data.config
- weixin.config({
- debug: false,
- appId: config.appId,
- timestamp: config.timestamp,
- nonceStr: config.nonceStr,
- signature: config.signature,
- jsApiList: config.jsApiList
- });
- resolve()
- }
- })
- })
- }
-
- getWxUrl() {
- getCodeUrl().then(res => {
- if (res.code == 1) {
- location.href = res.data.url
- }
- })
- }
-
- authLogin(code) {
- return new Promise((resolve, reject) => {
- wechatLogin({
- code
- })
- .then(res => {
- if(res.code == 1) {
- store.commit("login", {
- token: res.data.token
- });
- resolve(res.data);
- }
- })
- });
- }
-
- authLoginWx(code) {
- return new Promise((resolve, reject) => {
- wechatBindLogin({
- code
- })
- .then(res => {
- if(res.code == 1) {
- store.commit("login", {
- token: res.data.token
- });
- resolve(res.data);
- }
- })
- });
- }
-
- share(option) {
- weixin.ready(() => {
- const {
- shareTitle,
- shareLink,
- shareImage,
- shareDesc
- } = option
- weixin.updateTimelineShareData({
- title: shareTitle,
- link: shareLink,
- imgUrl: shareImage,
- success: function(res) {
-
- }
- });
-
- weixin.updateAppMessageShareData({
- title: shareTitle,
- link: shareLink,
- imgUrl: shareImage,
- desc: shareDesc,
- success: function(res) {
-
- }
- });
-
- weixin.onMenuShareWeibo({
- title: shareTitle,
- link: shareLink,
- imgUrl: shareImage,
- desc: shareDesc,
- success: function(res) {
-
- }
- })
- })
- }
- wxPay(opt) {
- return new Promise((reslove, reject) => {
- weixin.ready(() => {
- weixin.chooseWXPay({
- timestamp: opt.timeStamp,
- nonceStr: opt.nonceStr,
- package: opt.package,
- signType: opt.signType,
- paySign: opt.paySign,
- success: (res) => {
- reslove()
- },
- cancel: (res) => {
- reject()
- },
- fail: (res) => {
- reject()
- },
- });
- });
- })
-
- }
-
- getWxAddress() {
- return new Promise((reslove, reject) => {
- weixin.ready(() => {
- weixin.openAddress({
- success: (res) => {
- reslove(res)
- },
- })
- })
- })
- }
- }
- export default new Wechath5()
|