import weixin from "../../utils/share";
created() {
weixin({
title: "标题",
desc: "内容",
link: "https://m.bjzmjk.com/yz ", /需要打开的的地址
imgUrl: "https://wosz.oss-cn-beijing.aliyuncs.com/trtjk/face.png"
});
},
//在线跳转top页面
RouterTop() {
window.location.href = "https://m.bjzmjk.com/yz#/top";
},
//首页
import weixin from "../../utils/share";
created() {
weixin({
title: "标题",
desc: "内容",
link: "https://m.bjzmjk.com/yz ", /需要打开的的地址
imgUrl: "https://wosz.oss-cn-beijing.aliyuncs.com/trtjk/face.png"
});
},
//在线跳转top页面
RouterTop() {
window.location.href = "https://m.bjzmjk.com/yz#/top";
},
====
methods: {
//top页面跳转回来
btnre() {
console.log(111, "11");
window.location.href = "https://m.bjzmjk.com/yz";
},
}
//跳转的页面可以这样写
methods: {
//top页面跳转回来
btnre() {
console.log(111, "11");
window.location.href = "https://m.bjzmjk.com/yz";
},
}
//share.js
import { post } from './http.js'
export default function weixin(params, type) { //1 问卷 2 小任务 3 邀请 4 首页 5 提现 6 Banner 7商品, 8:社区文章,9:徽章10徽章墙
var locationUrl = window.location.href;
var reqUrl;
if (locationUrl.indexOf('#') > -1) {
reqUrl = locationUrl.split('#')[0]
}
// post(/wx/jsapi/signaturePost?url=${reqUrl}
)
post(/wx/jsapi/signaturePost
, {
url: reqUrl
})
.then(res => {
console.log('分享接口')
console.log(res)
wx.config({
debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
appId: 'wxc3fcac2c9758f10e', // 必填,公众号的唯一标识
timestamp: res.timestamp, // 必填,生成签名的时间戳
nonceStr: res.nonceStr, // 必填,生成签名的随机串
signature: res.signature, // 必填,签名
jsApiList: [
// 'onMenuShareAppMessage',//分享给好友功能
'hideMenuItems', //隐藏菜单功能
// 'onMenuShareTimeline',
'checkJsApi',
'updateTimelineShareData',
'updateAppMessageShareData'
] // 必填,需要使用的JS接口列表
});
})
// console.log(params.title, params.desc, params.link, params.imgUrl)
wx.ready(function() {
wx.hideMenuItems({
menuList: ["menuItem:share:email", "menuItem:share:qq", "menuItem:share:weiboApp", "menuItem:share:facebook", "menuItem:share:QZone"] // 要隐藏的菜单 测试式环境
});
wx.updateTimelineShareData({
title: params.title,
desc: params.desc,
link: params.link, //"https://wwwtest.taidu8.com/common/share/#/bannershare?bannerId=2019010818095150",//"https://wwwtest.taidu8.com/common/share/#/homeshare", 链接格式
imgUrl: params.imgUrl,
}),
wx.updateAppMessageShareData({
title: params.title,
desc: params.desc,
link: params.link, //"https://wwwtest.taidu8.com/common/share/#/bannershare?bannerId=2019010818095150",//"https://wwwtest.taidu8.com/common/share/#/homeshare", 链接格式
imgUrl: params.imgUrl,
})
wx.checkJsApi({
jsApiList: ['updateTimelineShareData', 'updateAppMessageShareData'], // 需要检测的JS接口列表,所有JS接口列表见附录2,
success: function(res) {
console.log(res)
console.log('ok')
// 以键值对的形式返回,可用的api值true,不可用为false
// 如:{"checkResult":{"chooseImage":true},"errMsg":"checkJsApi:ok"}
}
})
});
}
//share.js
import { post } from './http.js'
export default function weixin(params, type) { //1 问卷 2 小任务 3 邀请 4 首页 5 提现 6 Banner 7商品, 8:社区文章,9:徽章10徽章墙
var locationUrl = window.location.href;
var reqUrl;
if (locationUrl.indexOf('#') > -1) {
reqUrl = locationUrl.split('#')[0]
}
// post(`/wx/jsapi/signaturePost?url=${reqUrl}`)
post(`/wx/jsapi/signaturePost`, {
url: reqUrl
})
.then(res => {
console.log('分享接口')
console.log(res)
wx.config({
debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
appId: 'wxc3fcac2c9758f10e', // 必填,公众号的唯一标识
timestamp: res.timestamp, // 必填,生成签名的时间戳
nonceStr: res.nonceStr, // 必填,生成签名的随机串
signature: res.signature, // 必填,签名
jsApiList: [
// 'onMenuShareAppMessage',//分享给好友功能
'hideMenuItems', //隐藏菜单功能
// 'onMenuShareTimeline',
'checkJsApi',
'updateTimelineShareData',
'updateAppMessageShareData'
] // 必填,需要使用的JS接口列表
});
})
// console.log(params.title, params.desc, params.link, params.imgUrl)
wx.ready(function() {
wx.hideMenuItems({
menuList: ["menuItem:share:email", "menuItem:share:qq", "menuItem:share:weiboApp", "menuItem:share:facebook", "menuItem:share:QZone"] // 要隐藏的菜单 测试式环境
});
wx.updateTimelineShareData({
title: params.title,
desc: params.desc,
link: params.link, //"https://wwwtest.taidu8.com/common/share/#/bannershare?bannerId=2019010818095150",//"https://wwwtest.taidu8.com/common/share/#/homeshare", 链接格式
imgUrl: params.imgUrl,
}),
wx.updateAppMessageShareData({
title: params.title,
desc: params.desc,
link: params.link, //"https://wwwtest.taidu8.com/common/share/#/bannershare?bannerId=2019010818095150",//"https://wwwtest.taidu8.com/common/share/#/homeshare", 链接格式
imgUrl: params.imgUrl,
})
wx.checkJsApi({
jsApiList: ['updateTimelineShareData', 'updateAppMessageShareData'], // 需要检测的JS接口列表,所有JS接口列表见附录2,
success: function(res) {
console.log(res)
console.log('ok')
// 以键值对的形式返回,可用的api值true,不可用为false
// 如:{"checkResult":{"chooseImage":true},"errMsg":"checkJsApi:ok"}
}
})
});
}
网友评论