公众号设置
将网站域名添加到这里,并且将MP_verify_xxxxxxxxxxxx.txt文件放到网站更目录
Controller中的代码
WechatPublic wxshare = new WechatPublic();
string jstocken = wxshare.GetWxConfig(Request.Url.AbsoluteUri);
ViewData["jstocken"] = jstocken;
页面上:
@{
var jstocken = Html.Raw(ViewData["jstocken"]);
}
<script src="~/Content/Mobile/js/jweixin-1.2.0.js"></script>
<script>
wx_onMenuShareTimeline_config(@jstocken, false, '江阴市梵音寺清明追思法会线上登记', '@Request.Url.AbsoluteUri','https://s1.ax1x.com/2020/03/16/8JPf78.jpg', '同沾法喜,共沐佛恩!');
function wx_onMenuShareTimeline_config(date, debug, title, link, imgUrl, desc) {
if (typeof (debug) == "undefined" || debug == "") {
debug = false;
}
//var da1 = $.parseJSON(date);
var da1 = date;
wx.config({
debug: debug, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
appId: da1.appId, // 必填,公众号的唯一标识
timestamp: da1.timeStamp, // 必填,生成签名的时间戳
nonceStr: da1.nonceStr, // 必填,生成签名的随机串
signature: da1.signature,// 必填,签名,见附录1
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'] // 必填,需要使用的JS接口列表,所有JS接口列表见附录2
});
wx.ready(function () {
//获取“分享到朋友圈”按钮点击状态及自定义分享内容接口
wx.onMenuShareTimeline({
title: title, // 分享标题
link: link, // 分享链接,该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
imgUrl: imgUrl, // 分享图标
success: function () {
alert("分享成功!");
// 用户确认分享后执行的回调函数
},
cancel: function () {
alert("您取消了分享");
// 用户取消分享后执行的回调函数
}
});
//获取“分享到QQ空间”按钮点击状态及自定义分享内容接口
wx.onMenuShareQZone({
title: title, // 分享标题
desc: desc, // 分享描述
link: link, // 分享链接
imgUrl: imgUrl, // 分享图标
success: function () {
alert("分享成功!");
// 用户确认分享后执行的回调函数
},
cancel: function () {
alert("您取消了分享");
// 用户取消分享后执行的回调函数
}
});
//获取“分享给朋友”按钮点击状态及自定义分享内容接口
wx.onMenuShareAppMessage({
title: title, // 分享标题
desc: desc, // 分享描述
link: link, // 分享链接,该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
imgUrl: imgUrl, // 分享图标
type: '', // 分享类型,music、video或link,不填默认为link
dataUrl: '', // 如果type是music或video,则要提供数据链接,默认为空
success: function () {
alert("分享成功!");
// 用户确认分享后执行的回调函数
},
cancel: function () {
alert("您取消了分享");
// 用户取消分享后执行的回调函数
}
});
});
wx.error(function (res) {
alert("wx.config failed.");
alert(res);
// config信息验证失败会执行error函数,如签名过期导致验证失败,具体错误信息可以打开config的debug模式查看,
// 也可以在返回的res参数中查看,对于SPA可以在这里更新签名。
});
}
</script>











网友评论