公众号的H5 分享朋友圈 不显示图片标题?一会可以一会不可以
const share = () => {
const hostWithPort = window.location.host;
const protocol = window.location.protocol;
let shareMsage = {
title: state.article.articleInfo.articleTitle,
link: window.location.href,
desc: state.article.articleInfo.articleRemark ? state.article.articleInfo.articleRemark : state.article.articleInfo.articleTitle,
type: 'link',
img: protocol + "//" + hostWithPort + `/img/mylogo.860ef6a8.png`
}
getJSSDK(shareMsage)
}
import wx from 'weixin-js-sdk'
import { getShareConfig } from '@/api/shares'
const jsApiList = ['updateAppMessageShareData', 'updateTimelineShareData', 'onMenuShareTimeline', 'onMenuShareAppMessage', 'onMenuShareQQ', 'onMenuShareWeibo', 'onMenuShareQZone']
export const getJSSDK = (shareMsage) => {
const protocol = window.location.protocol
const hostWithPort = window.location.host
let url = encodeURIComponent(shareMsage.link)
getShareConfig(url).then((res) => {
const shareConfig = res
wx.config({
debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
appId: shareConfig.appId, // 必填,公众号的唯一标识
timestamp: shareConfig.timestamp, // 必填,生成签名的时间戳
nonceStr: shareConfig.nonceStr, // 必填,生成签名的随机串
signature: shareConfig.signature, // 必填,签名
jsApiList: jsApiList, // 必填,需要使用的JS接口列表
})
wx.ready(() => {
let shareData = {
title: shareMsage.title,
desc: shareMsage.desc,
link: shareMsage.link,
imgUrl: shareMsage.img ? shareMsage.img : protocol + "//" + hostWithPort + `/img/mylogo.860ef6a8.png`,
trigger: (res) => {
console.log('用户点击分享按钮', res)
},
success: (res) => {
console.log('已分享', res)
},
cancel: (res) => {
console.log('已取消', res)
},
fail: (res) => {
console.log('分享失败', res)
},
}
wx.onMenuShareTimeline(shareData)
wx.updateAppMessageShareData(shareData)
wx.updateTimelineShareData(shareData)
wx.onMenuShareAppMessage(shareData)
wx.onMenuShareQQ(shareData)
wx.onMenuShareWeibo(shareData)
wx.onMenuShareQZone(shareData)
})
wx.error((res) => {
console.log('微信验证失败', res)
})
})
}
export default {
getJSSDK,
}