全栈小学生 0e47055ccb v1.0.0-beta.1
2023-04-15 17:12:49 +08:00

47 lines
1.3 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import wx from 'weixin-js-sdk'
import { getWechatSkdConfig } from '@/api/system'
class Wechat {
constructor() {
this.init()
}
private init() {
getWechatSkdConfig({
url: uni.getSystemInfoSync().platform == 'ios' ? uni.getStorageSync('initUrl') : location.href
}).then((res : responseResult) => {
const { data } = res
wx.config({
debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来若要查看传入的参数可以在pc端打开参数信息会通过log打出仅在pc端时才会打印。
appId: data.appId, // 必填,公众号的唯一标识
timestamp: data.timestamp, // 必填,生成签名的时间戳
nonceStr: data.nonceStr, // 必填,生成签名的随机串
signature: data.signature,// 必填,签名
jsApiList: ['chooseWXPay', 'updateAppMessageShareData', 'updateTimelineShareData'] // 必填需要使用的JS接口列表
});
})
}
/**
* 发起支付
*/
public pay(options : WeixinJsSdk.ChooseWXPayOptions) {
wx.ready(() => {
wx.chooseWXPay(options)
})
}
/**
* 分享设置
*/
public share(options : WeixinJsSdk.OnMenuShareAppMessageOptions) {
wx.ready(() => {
// 分享给朋友
wx.updateAppMessageShareData(options)
// 分享到朋友圈
wx.updateTimelineShareData(options)
})
}
}
export default new Wechat()