$.ajax({
type:'GET',
url: url,
dataType: 'jsonp'
})
.then((data)=> {
wx.config({
debug: true, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
appId: '', // 必填,公众号的唯一标识
timestamp: , // 必填,生成签名的时间戳
nonceStr: '', // 必填,生成签名的随机串
signature: '',// 必填,签名,见附录1
jsApiList: [] // 必填,需要使用的JS接口列表,所有JS接口列表见附录2
});
})
wx.ready (()=> {
// alert('ready');
//$('#onMenuShareAppMessage').on('click', ()=> {
// 分享给朋友
wx.onMenuShareAppMessage({
title: '',
desc: '',
link: shareUrl,
imgUrl: '',
trigger: function (res) {
// alert('用户点击发送给朋友');
},
success: function (res) {
alert('已分享');
},
cancel: function (res) {
alert('已取消');
},
fail: function (res) {
alert(JSON.stringify(res));
}
});
//});
//分享到朋友圈
wx.onMenuShareTimeline({
title: '', // 分享标题
link: shareUrl, // 分享链接
imgUrl: '', // 分享图标
success: function () {
alert('已分享');
// alert($('.no-num').html());
},
cancel: function () {
alert('已取消');
// 用户取消分享后执行的回调函数
// alert('取消');
}
});
});
wx.error((res)=> {
alert(res.errMsg);
})
wx.onMenuShareTimeline({
title: '', // 分享标题
link: '', // 分享链接
imgUrl: '', // 分享图标
success: function () {
// 用户确认分享后执行的回调函数
},
cancel: function () {
// 用户取消分享后执行的回调函数
}
});
wx.onMenuShareAppMessage({
title: '', // 分享标题
desc: '', // 分享描述
link: '', // 分享链接
imgUrl: '', // 分享图标
type: '', // 分享类型,music、video或link,不填默认为link
dataUrl: '', // 如果type是music或video,则要提供数据链接,默认为空
success: function () {
// 用户确认分享后执行的回调函数
},
cancel: function () {
// 用户取消分享后执行的回调函数
}
});
'use strict';
let wxDefaultOptions = {
debug: true,
appId: '',
timestamp: 0,
nonceStr: '',
signature: '',
jsApiList: [
'checkJsApi',
'onMenuShareTimeline',
'onMenuShareAppMessage',
'onMenuShareQQ',
'onMenuShareWeibo',
'hideMenuItems',
'showMenuItems',
'hideAllNonBaseMenuItem',
'showAllNonBaseMenuItem',
'translateVoice',
'startRecord',
'stopRecord',
'onRecordEnd',
'playVoice',
'pauseVoice',
'stopVoice',
'uploadVoice',
'downloadVoice',
'chooseImage',
'previewImage',
'uploadImage',
'downloadImage',
'getNetworkType',
'openLocation',
'getLocation',
'hideOptionMenu',
'showOptionMenu',
'closeWindow',
'scanQRCode',
'chooseWXPay',
'openProductSpecificView',
'addCard',
'chooseCard',
'openCard'
]
};
//let shareUrl = 'http://xxx' + location.pathname;
let getWxParam = (url, wxOptions) => {
let url = location.href.split('#')[0];
url = encodeURIComponent(url);
let promise = new Promise((resolve, reject)=> {
$.ajax({
type:'GET',
url: 'http://xxx/xxx?param='+url,
dataType: 'jsonp'
})
.then((data)=> {
let wxParam = data;
console.log(wxParam);
wxOptions.appId = 'wxeb5c3f4a03b880f0';
wxOptions.timestamp = wxParam.timestamp;
wxOptions.nonceStr = wxParam.nonceStr;
wxOptions.signature = wxParam.signature;
wx.config(wxOptions);
wx.error((res)=> {
alert(res.errMsg);
})
resolve();
}, (error)=> {
console.log(error);
})
});
return promise;
}
//分享到朋友圈
let shareSocial = (param)=> {
wx.onMenuShareTimeline({
title: param.title, // 分享标题
link: param.link, // 分享链接
imgUrl: param.imgUrl, // 分享图标
success: function () {
// 用户确认分享后执行的回调函数
param.suCallback();
},
cancel: function () {
// 用户取消分享后执行的回调函数
param.failCalback();
}
});
}
//分享给好友
let shareToFriends = (param) => {
wx.onMenuShareAppMessage({
title: param.title,
desc: param.desc,
link: param.link,
imgUrl: param.imgUrl,
trigger: function (res) {
},
success: function (res) {
param.suCallback();
},
cancel: function (res) {
},
fail: function (res) {
param.failCalback();
console.alert(JSON.stringify(res));
}
});
}
//title,desc,link,imgUrl,suCallback, failCalback
let jssdk = (param) => {
wx.ready(()=> {
//分享到朋友圈
shareSocial(param);
shareToFriends(param);
})
}
function callWx(param, wxoptions) {
getWxParam(param.url, wxOptions).then(()=> {
jssdk(param);
})
}
//param = {url: '', title:'',desc:'',link:'',imgUrl:'',suCallback:func, failCalback: func}
module.exports = {
wxDefaultOptions,//更改配置
callWx, //默认配置,进行config配置 和ready后定制微信分享内容,
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有