【微信公众号H5】vue H5 公众号 授权分享

调用授权地址 设置

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('分享失败'); } }); }) },

注释  手机微信点击分享 无效时肯定是 自定义分享链接错误

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值