先引入该文件
请注意,如果你的页面启用了https,务必引入 该js文件 ,否则将无法在iOS9.0以上系统中成功使用JSSDK
<script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
<script>
var wx = window.wx;
var timestamp=Date.parse(new Date()); //时间戳
var url = window.encodeURIComponent(location.href.split('#')[0]);//可把字符串作为URI 组件进行编码
var wxconfig = function() {
//将参数url放在utl中传递 data=JSON.stringify({url:url})
$.ajax({
type:'get',
url:'http://api.m-internal.s-ant.cn/m/?api=mtop.app.getJSSDKConfigInfo&v=1.0&sign=sign&ttid=home@wireless&ts='+timestamp+'&data='+JSON.stringify({url:url}),
success:function(data) {
wx.config({
debug: false,
appId: data.result.data.appId,
timestamp:data.result.data.timestamp,
nonceStr: data.result.data.nonceStr,
signature: data.result.data.signature,
jsApiList: [
'onMenuShareTimeline',
'onMenuShareAppMessage'
],
});
}
})
}
wxconfig();
wx.ready(function(){
//分享到朋友圈
wx.onMenuShareTimeline({
title: '杭州微蚁科技有限公司', // 分享标题
link: 'http://www.microants.cn', // 分享链接
imgUrl: 'http://public-read-bkt-oss.oss-cn-hangzhou.aliyuncs.com/app/icon/logo_zj.png', // 分享图标
success: function () {
// 用户确认分享后执行的回调函数
},
cancel: function () {
// 用户取消分享后执行的回调函数
}
});
//分享给朋友
wx.onMenuShareAppMessage({
title: '杭州微蚁科技有限公司', // 分享标题
desc: '专业的实体批发采购平台', // 分享描述
link: 'http://www.microants.cn', // 分享链接
imgUrl: 'http://public-read-bkt-oss.oss-cn-hangzhou.aliyuncs.com/app/icon/logo_zj.png', // 分享图标
type: '', // 分享类型,music、video或link,不填默认为link
dataUrl: '', // 如果type是music或video,则要提供数据链接,默认为空
success: function () {
// 用户确认分享后执行的回调函数
},
cancel: function () {}
});
});
</script>