时间:2022-08-06 19:06:01 | 来源:网站运营
时间:2022-08-06 19:06:01 来源:网站运营
一、JS-SDK说明文档/*1.获取code的url(访问微信官方服务器获取code) --- 用户操作之后才能有code,如点击页面的授权按钮。*/`https://open.weixin.qq.com/connect/oauth2/authorize?appid=${APPID}&redirect_uri=${url}&response_type=code&scope=snsapi_userinfo&state=STATE&connect_redirect=1#wechat_redirect`/*2.获取网页授权access_token的url(访问微信官方服务器获取)*/`https://api.weixin.qq.com/sns/oauth2/access_token?appid=${APPID}&secret=${SECRET}&code=${CODE}&grant_type=authorization_code`
2)其他微信接口,需要通过基础支持中的“获取access_token”接口来获取到的普通access_token调用。获取此access_token需要给微信服务器接口(https://api.weixin.qq.com/cgi-bin/token)两个参数(appid,appsercet)/*获取js-sdk的jsapi_ticket(临时票据),获取普通access_token的url(访问微信官方服务器获取临时票据)*/`https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=${APPID}&secret=${SECRET}`
三、应用 const url = encodeURIComponent(location.href.split('#')[0]) axios.get(`https://xxxx/api/usersticket?url=${url}`).then((res) => { const {APPID, timestamp, noncestr, signature, url} = res.data wx.config({ debug: false, // 测试时改为true。 appId: APPID, timestamp, nonceStr: noncestr, signature, jsApiList: [ 'onMenuShareAppMessage', 'onMenuShareTimeline' ] }) wx.ready(() => { wx.onMenuShareAppMessage({ title: '自定义', desc: '自定义', link: url, imgUrl: '自定义', success: () => { console.log('分享成功了!') }, cancel: () => { console.log('分享失败了!') } }) wx.onMenuShareTimeline({ title: '自定义', link: url, imgUrl: '自定义', success: () => { console.log('分享成功了!') }, cancel: () => { console.log('分享失败了!') } }) }) wx.error(res => { console.log(res) }) }).catch(err => { console.log(err) })
关键词:公众