环境:微信开发者工具、真实手机、iPhone 7, 7Plus, 11Pro Max, Android 华为 M6 Jweixin版本:1.6.0 (其实我也试过1.4.0,一样有问题)
时间:2020/04/04 19:34:21 - 19:36:59 (China Standard Time)
AppId: wxaf95f18b86178aa1
问题:在微信网页里面使用API : updateTimelineShareData无法分享。wx.config 成功,wx.updateTimelineShareData 控制台里面显示调用成功。但始终没有弹出分享控件来分享。
我微信的日志上传了,微信号:cxyxe1986
$(function () {
if (document.location.href.indexOf('details') > 0) {
$.ajax({
url: _configUrl,
type: "GET",
error: function (res) {
console.log(JSON.stringify(res));
//alert(JSON.stringify(res));
$.toast.prototype.defaults.duration = 900;
$.toast('分享失败,请稍后再试。', 'text');
},
success: function (data) {
console.log(data);
wx.config({
debug: false,
appId: data.appId,
timestamp: data.timestamp,
nonceStr: data.nonce,
signature: data.signature,
jsApiList: ['checkJsApi', 'onMenuShareTimeline', 'onMenuShareAppMessage', 'updateTimelineShareData', 'updateAppMessageShareData'
, 'getLocation', 'scanQRCode', 'uploadImage', 'downloadImage', 'showAllNonBaseMenuItem', 'hideAllNonBaseMenuItem']
});
wx.checkJsApi({
jsApiList: ['checkJsApi',
'updateAppMessageShareData',
'updateTimelineShareData',
'onMenuShareAppMessage',
'onMenuShareTimeline',
'getLocation', 'scanQRCode', 'uploadImage', 'downloadImage',
'showAllNonBaseMenuItem', 'hideAllNonBaseMenuItem'
],
success: function (res) {
console.log(res)
// 以键值对的形式返回,可用的api值true,不可用为false
// 如:{"checkResult":{"chooseImage":true},"errMsg":"checkJsApi:ok"}
}
});
wx.error(function (res) {
alert("error00:" + JSON.stringify(res));
});
}
});
}
$('.ea-share').on('click', function () {
//shareProject(shareData);
wx.ready(function () {
console.log('enter wx.ready3')
wx.updateTimelineShareData({
title: shareData.title,
link: shareData.link,
imgUrl: shareData.imgUrl,
success: function (res) {
console.log('shared success');
console.log(res);
$.ajax({
type: 'POST',
url: _baseUrl + '/customer/shared/project/' + shareData.projectId,
success: function (res) {
//console.log(res)
$.toast('分享成功', 'text')
},
error: function (xhr, code, error) {
console.log(xhr.responseText);
}
});
},
cancel: function (res) {
console.log(res);
$.toast('cancel', 'text')
}
});
wx.error(function (res) {
alert("errorMSG2:" + res);
});
});
wx.error(function (res) {
alert("errorMSG3:" + res);
});
});
});
function tryShare(type) {
wx.ready(function () {
console.log('enter menuShare')
if (type == 1)
wx.onMenuShareTimeline(_configShare);
else if (type == 2)
wx.onMenuShareAppMessage(_configShare);
else if (type == 3)
wx.updateTimelineShareData(_configShare);
else
wx.updateAppMessageShareData(_configShare);
wx.error(function (res) {
alert("errorMSG:" + res);
});
});
}
不能自定义按钮点击分享的,而且判断不出是分享成功还是失败。是点击右上角菜单的那个分享按钮,你搞错了。
看来是不支持自定义的按钮来做分享,对应的API是用来设置分享内容的(微信官方文档不过准确细致)
我也以为可以自定义分享按钮,没想到是触发微信浏览器的分享,自定义分享内容