微信网页开发JS-SDK
微信网页开发JS-SDK说明文档:https://developers.weixin.qq.com/doc/offiaccount/OA_Web_Apps/JS-SDK.html。参照说明文档,可以进行使用。
网页分享
function wechatShare(detail: shareData) {
const { code, data } = await getWechatSign(detail.link, getAppId({ env:ENV.APP_ENV,type:"wx" }));
if (code === 0) {
// 微信分享配置
wx.config({
debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
appId: getAppId({ env:ENV.APP_ENV,type:"wx" }), // 必填,公众号的唯一标识
timestamp: data.timestamp, // 必填,生成签名的时间戳
nonceStr: data.nonceStr, // 必填,生成签名的随机串
signature: data.signature, // 必填,签名
jsApiList // 必填,需要使用的JS接口列表
});
wx.ready(() => {
wx.checkJsApi({
jsApiList, // 需要检测的JS接口列表,所有JS接口列表见附录2,
success() {
// 以键值对的形式返回,可用的api值true,不可用为false
// 如:{"checkResult":{"chooseImage":true},"errMsg":"checkJsApi:ok"}
}
});
if(wx.updateTimelineShareData){
wx.updateTimelineShareData({
title: detail.title || document.title, // 分享标题
link: detail.link || getLink(),// 分享链接,该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
imgUrl: detail.imgUrl,// 分享图标
success() {
}
});
}
if(wx.updateAppMessageShareData){
wx.updateAppMessageShareData({
title: detail.title || document.title, // 分享标题
desc: detail.desc, // 分享描述
link: detail.link || getLink(), // 分享链接,该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
imgUrl: detail.imgUrl, // 分享图标
success () {
}
});
}
});
};
};
隐藏右上角菜单接口
const jsApiList = ["hideOptionMenu"];
if(wx.hideOptionMenu) {
wx.hideOptionMenu();
}
显示右上角菜单接口
const jsApiList = ["showOptionMenu"];
if(wx.showOptionMenu) {
wx.showOptionMenu();
}