web 移动端 微信分享(nativeShare)

1、引入nativeShare.js
2、
config -> 后端请求得到微信参数
info -> 后端请求到分享的内容
mycommand -> “wechatFriend” (分享微信好友)“wechatTimeline”(朋友圈) “qqFriend”(qq分享)“qZone”(qq空间)“weibo” (微博)

function h5Share(config, info, mycommand) {
var nativeShare = new NativeShare();
// 你也可以在setConfig方法中设置配置参数
nativeShare.setConfig({
wechatConfig: {
appId: config.appid,
timestamp: config.timestamp,
nonceStr: config.nonceStr,
signature: config.signature,
}
})
var shareData = {
title: info.title,
desc: info.desc,
link: info.link,
icon: info.imgUrl,
// 不要过于依赖以下两个回调,很多浏览器是不支持的
success: function() {
console.log(“success”)
},
fail: function() {
console.log(“fail”)
}
}
nativeShare.setShareData(shareData);
call(mycommand);

function call(command) {
	try {
		nativeShare.call(command)
	} catch(err) {
		// 如果不支持,你可以在这里做降级处理
		alert(err.message)
		// console.log("err.message")
	}
}

}

发布了44 篇原创文章 · 获赞 24 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/qq_43634982/article/details/89478373