H5卡片分享
常用卡片分享配置(微信、钉钉、QQ等)
常规
1 |
|
微信分享转发
- 服务端鉴权接口获取鉴权信息
- 配置微信分享参数
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76# 提前引入sdk <script src="https://res.wx.qq.com/open/js/jweixin-1.3.2.js"></script>
function initWxShare() {
const appId = '*'
const pms = {
title: '标题',
link: `https://*`,
desc: '简介',
imgUrl: 'https://*',
success: function () {
alert("分享成功!")
},
cancel: function () {
alert("分享失败!")
}
}
const xhr = new XMLHttpRequest()
xhr.onload = () => {
const r = JSON.parse(xhr.responseText)
if (r.code != 1) return
const { timestamp, nonceStr, signature } = r.result
wx.error(function (r) {
console.error(r)
})
wx.config({
appId,
timestamp,
nonceStr,
signature,
debug: false,
jsApiList: [
'checkJsApi',
'onMenuShareTimeline',
'onMenuShareAppMessage',
'onMenuShareQQ',
'onMenuShareWeibo',
'onMenuShareQZone',
'chooseImage',
'previewImage',
'uploadImage',
'getNetworkType',
"startRecord",
"stopRecord",
"onVoiceRecordEnd",
"playVoice",
"pauseVoice",
"stopVoice",
"onVoicePlayEnd",
"uploadVoice",
"downloadVoice"
]
})
wx.ready(() => {
wx.onMenuShareTimeline(pms)
wx.onMenuShareQQ(pms)
wx.onMenuShareWeibo(pms)
wx.onMenuShareQZone(pms)
wx.onMenuShareAppMessage({
...pms,
type: '', // 分享类型,music、video或link,不填默认为link
dataUrl: '' // 如果type是music或video,则要提供数据链接,默认为空
})
})
}
xhr.open('POST', '//鉴权接口地址/getWxMpJsConfig')
xhr.setRequestHeader('Content-Type', 'application/json;charset=utf-8')
xhr.send(JSON.stringify({
appId,
url: location.href.split('#')[0]
}))
}
服务端获取鉴权
待补充
H5卡片分享
http://example.com/20220429-H5卡片分享/