如果微信H5页面转发分享后标题及内容、链接不是自己自定义的内容,及logo https兼容性问题如下解决方法
1 function wxShare(shareData){
2 // 分课改变分享内容标题
3 if(shareData == null || shareData == undefined || shareData == ''){
4 var title = '报名入口';
5 var shareTit = title;
6 var desc = '为每个孩子定制个性化学习套餐,价格灵活,现在报名还能得到送课机会哦!';
7 var shareDesc = desc;
8 shareData = {
9 title: shareTit,
10 imgUrl: location.origin + '/' +'https://baidu.com/nviews/mobile/images/amlogo.jpg',
11 desc: shareDesc,
12 link: location.origin + '/' +'https://baidu.com/nviews/mobile/html/appoint.html'
13 }
14 }
15 // console.log(shareData);
16 $.ajax({
17 url:'/rest/getJssdkTicket?url='+encodeURIComponent(window.location.href.split('#')[0]),
18 dataType: 'json',
19 type: 'GET',
20 success: function(res){
21 wxconfig(res.data);
22 // console.log("wxconfig data:",res.data)
23 }
24 });
25
26 // 微信setting
27 function wxconfig(data) {
28 wx.config({
29 appId: data.appId, // 必填,公众号的唯一标识
30 timestamp: data.timestamp, // 必填,生成签名的时间戳
31 nonceStr: data.nonceStr, // 必填,生成签名的随机串
32 signature: data.signature,// 必填,签名,见附录1
33 jsApiList: [
34 'onMenuShareTimeline',
35 'onMenuShareAppMessage'
36 ] // 必填,需要使用的JS接口列表,所有JS接口列表见附录2
37 });
38
39 wx.ready(function () {
40 wx.onMenuShareTimeline({
41 title: shareData.title, // 分享标题
42 desc: shareData.desc, // 分享描述
43 link: shareData.link, // 分享链接,该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
44 imgUrl: shareData.imgUrl, // 分享图标
45 success: function () {
46 // 用户确认分享后执行的回调函数
47 },
48 cancel: function () {
49 // 用户取消分享后执行的回调函数
50 }
51 });
52
53 wx.onMenuShareAppMessage({
54 title: shareData.title, // 分享标题
55 desc: shareData.desc, // 分享描述
56 link: shareData.link, // 分享链接,该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
57 imgUrl: shareData.imgUrl, // 分享图标
58 success: function () {
59 // 用户确认分享后执行的回调函数
60 },
61 cancel: function () {
62 // 用户取消分享后执行的回调函数
63 }
64 });
65 });
66 }
67 };
68
69 exports = {
70 wxShare:wxShare
71 }
1 var shareData = {
2 title: "我孩子正在你家孩子来试试!",
3 imgUrl: 'https://baidu.com/nviews/mobile/images/wx_logo.jpg',
// imgUrl: window.location.protocol + '//' + window.location.host + '/nviews/mobile/images/amlogo.jpg',(解决https logo不显示问题)
4 desc: "全国已超过3000多万孩子在学。",
5 link:'https://' + window.location.host + '/mkt/bbm40.html'
6 }
7
8 // console.log(shareData);
9 wxShare(shareData);
注意:
1、页面引入:,然后定义相应的标题及内容、链接如上代码
d
2、假如转发后标题及内容、链接不是自己自定义的,问题出现在红色代码部分,以上红色部分代码已解决!