helper.js
1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
export async function wechatShareSetting(axios, store, shareConfig = {
title: `借条100`, // 分享标题
link: `https://www.51liuliang.cc/netiou`,
imgUrl: 'https://www.51liuliang.cc/netiou/logo1.png',
desc: '',
success: function () {},
cancel: function () {}
}) {
const u = navigator.userAgent
const isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/);
let {data} = await axios.post(`/wechatTicket`, {
userId: store.state.user.id,
href: isiOS ? store.state.firstUrl : window.location.href
})
if (data.success) {
window.wx.config({
debug: false,
appId: data.config.appId, // 必填,公众号的唯一标识
timestamp: data.config.timestamp, // 必填,生成签名的时间戳
nonceStr: data.config.nonceStr, // 必填,生成签名的随机串
signature: data.config.signature,// 必填,签名
jsApiList: ['onMenuShareTimeline', 'onMenuShareAppMessage'] // 必填,需要使用的JS接口列表
})
window.wx.ready(() => {
window.wx.onMenuShareTimeline(shareConfig)
window.wx.onMenuShareAppMessage(shareConfig)
})
window.wx.error(function(res){
console.log(res)
})
}
}
export function testIOSVersion() {
const u = navigator.userAgent.toLowerCase()
const ver = u.match(/cpu iphone os (.*?) like mac os/)
if (!ver) {
return true
} else {
return (parseFloat(ver[1].replace(/_/g,".")) < 10 ? false : true)
}
}