function array_combine(a,b){ for(item in b){ a[item] = b[item]; } return a; } var wxShare = { config : { appId : '', timestamp : 0, nonceStr : '', signature : '', func: ['shareTimeline','shareAppMessage'], /*--- 分享成功动态调用的方法----*/ timeLineSuccess : 'hidePop', timeLineError : 'hidePop', appMessageSuccess : 'hidePop', appMessageError : 'hidePop', /*--- 分享成功动态调用的方法----*/ timeLine : { title: '', // 分享标题 link: '', // 分享链接 imgUrl: '' // 分享图标 }, appMessage :{ title: '', // 分享标题 desc: '', // 分享描述 link: '', // 分享链接 imgUrl: '', // 分享图标 type: '', // 分享类型,music、video或link,不填默认为link dataUrl: '' // 如果type是music或video,则要提供数据链接,默认为空 }, shareModel :[ 'checkJsApi','onMenuShareTimeline','onMenuShareAppMessage' ] }, init : function(json){ window.onload = function(){ wxShare.config = array_combine(wxShare.config,json); wxShare.configReg(); wx.ready(function () { if(wxShare.config.func.length){ for(var i = 0 ; i < wxShare.config.func.length ; i++){ var mN = wxShare.config.func[i]; wxShare.func[mN](); } } }) } }, configReg : function(){ wx.config({ debug : false, appId: wxShare.config.appId, // 必填,公众号的唯一标识 timestamp: wxShare.config.timestamp, // 必填,生成签名的时间戳 nonceStr: wxShare.config.nonceStr, // 必填,生成签名的随机串 signature: wxShare.config.signature,// 必填,签名,见附录1 jsApiList: wxShare.config.shareModel }); }, func : { shareTimeline :function(){//分享朋友圈 wx.onMenuShareTimeline(array_combine( wxShare.config.timeLine,{success: function(){ eval(wxShare.func[wxShare.config.timeLineSuccess]()); }, cancel: function(){eval(wxShare.func[wxShare.config.timeLineSuccess]());}})); }, shareAppMessage :function(){//分享单个朋友 wx.onMenuShareAppMessage(array_combine( wxShare.config.appMessage,{success: function(){eval(wxShare.func[wxShare.config.appMessageError]()); }, cancel: function(){eval(wxShare.func[wxShare.config.appMessageSuccess]());}})); },hidePop : function(){ hidePopUp() } } }