调用授权地址 设置
window.location.href = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxbbc27d6e2a2b7be9&redirect_uri="+ urlcode+"&response_type=code&scope=snsapi_userinfo&state=123#wechat_redirect"
urlcode = redirect_uri 授权回调页面 设置参数
带参数 必须使用 encodeURI 加密 (decodeURI) 参数和链接都要加密
let urlcode = encodeURI("http://lm.city.com/callBack.html?item="+encodeURI(JSON.stringify(self.InfoData)))
微信分享 在使用的时候再调用 否则 分享的自定义链接参数将为空
async 异步方法
async wechatShare(){
let self= this
let useUrl = self.useSharData.shardUseId?encodeURI('http://lm.city.com/#/couponShare?item='+encodeURI(JSON.stringify(self.useSharData))+'&type=true'):''
//注释 自定义分享链接 必须 encodeURI 加密 wechatConfig未 分享使用的微信参数 如AppId 等 useUrl 为分享的链接
const data = await wechatConfig();
wx.config({ debug: false, appId: data.data.appId, timestamp: data.data.timestamp, nonceStr: data.data.nonceStr, signature: data.data.signature, jsApiList: [ "onMenuShareTimeline", "onMenuShareAppMessage" ] });
ready 方法为 分享注册成功 回调函数
wx.ready(() => {
//朋友圈
wx.onMenuShareTimeline({
title: '邀请领取',
link: useUrl,
imgUrl:`http://${window.location.host}/static/images/huha_logo.png`,
success: (data) => { if(data.errMsg === 'onMenuShareTimeline:ok') { this.toast('分享成功'); } }, cancel: () => { this.toast('分享失败'); } });
//微信
wx.onMenuShareAppMessage({
title: '邀请领取', // 分享标题
desc: '邀请领取', // 分享描述
link: useUrl, // 分享链接,该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
imgUrl:`http://${window.location.host}/static/images/huha_logo.png`, // 分享图标
type: 'link', // 分享类型,music、video或link,不填默认为link
dataUrl: '', // 如果type是music或video,则要提供数据链接,默认为空
success: (data) => {
if(data.errMsg === 'onMenuShareAppMessage:ok') { this.toast('分享成功'); } },
cancel: () => { this.toast('分享失败'); } }); }) },
注释 手机微信点击分享 无效时肯定是 自定义分享链接错误