基于微信公众平台的jssdk的自定义分享整理,.net语言的,当前用的已认证的微信订阅号。
首先登陆微信公众平台进行相关配置:
第一步:在最底部有个开发>基本配置>获取到AppID和AppSercret备用,配置到web.config文件中
第二步:设置>公众号设置>功能设置>设置业务域名和JS安全域名,注意不带http://,根据提示下载相关.txt文件放至业务域名根目录中
第三步:设置>安全中心>IP白名单设置,多个ip用回车间隔
第四步:在要分享的页面添加http://res.wx.qq.com/open/js/jweixin-1.0.0.js引用
<script type="text/javascript">
wx.config({
debug: false,
appId: '<%=entity.AppId%>',
timestamp: '<%=entity.Timestamp%>',
nonceStr: '<%=entity.NonceStr%>',
signature: '<%=entity.Signature%>',
jsApiList: [
'checkJsApi',
'onMenuShareTimeline',
'onMenuShareAppMessage',
'onMenuShareQQ',
'onMenuShareWeibo'
]
});
wx.ready(function () {
var shareData = {
title: '“民生幸福账单”线上有奖竞答', // 分享标题
desc: '话费送不停!请关注“崂山民政”公众号,“民生幸福账单”等您来参与!', // 分享描述
link: "http://test.eaaa.cn/index.aspx", //分享的链接地址
imgUrl: "http://test.eaaa.cn/images/header.jpg", // 分享图标
type: 'link', // 分享类型,music、video或link,不填默认为link
dataUrl: '', // 如果type是music或video,则要提供数据链接,默认为空
success: function () {
},
cancel: function () {
}
}
wx.onMenuShareAppMessage(shareData);
wx.onMenuShareTimeline(shareData);
wx.onMenuShareQQ(shareData);
wx.onMenuShareWeibo(shareData);
});
wx.error(function (res) {
alert(res.errMsg);
});
</script>
第五步:项目中添加JSSDK类库引用,引用Newtonsoft.Json类库
类库下载地址https://download.csdn.net/download/qq_27165657/10895741
Newtonsoft.Json.dll下载:https://github.com/JamesNK/Newtonsoft.Json/releases
最后在.cs文件中添加调用就可以自定义分享了
public XDJ_WXShareEntity entity = null;
protected void Page_Load(object sender, EventArgs e)
{
entity = XDJ_JSDKHelper.GetWXEntity(ConfigurationManager.AppSettings[“appid”].ToString(), ConfigurationManager.AppSettings[“secret”].ToString(), Request.Url.ToString(), “FBAEB76D56A84DBF”);
entity.Url = Request.Url.Host.ToString();
}
调用这里有个加密的时间,这个是设置的过期时间如果时间到期了会导致sdk调用失败
可以使用加密工具检测设置的日期是否到期工具下载地址:
https://download.csdn.net/download/qq_27165657/10895900
检测方式