C#微信环境分享页面给好友
作者:互联网
1.js引用
<script src="http://res.wx.qq.com/open/js/jweixin-1.2.0.js"></script>
2.代码示例
string appid ="微信公众号appId";
string showimg = "图片地址";
string msg = "描述";
string imgurl = "";
#region 设置分享
StringBuilder share = new StringBuilder();
string shareurl = Request.Url.ToString();
string jumpurl = "分享页可带参数" ;
string timespan = DateTime.Now.ToString("hhmmssffff");
//获取token
string acctoken =GetToken();
string ticken =GetJsTiket(acctoken);
//组织分享操作
share.Append("wx.config({");
share.Append(" debug:false,");//true 成功失败提示信息
share.Append(" appId: '" + appid + "',");
share.Append(" timestamp: '" + timespan + "',");
share.Append(" nonceStr: '" + timespan + "',");
string zzurl = "jsapi_ticket=" + ticken +
"&noncestr=" + timespan + "×tamp=" + timespan + "&url=" + shareurl.Trim();
string sign = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(zzurl, "SHA1").ToLower();
share.Append(" signature: '" + sign + "',");
share.Append(" jsApiList: ['onMenuShareTimeline','onMenuShareAppMessage']");
share.Append(" });");
//分享到好友
share.Append(" wx.onMenuShareAppMessage({");
share.Append(" title: '标题',");
share.Append(" desc:'" + msg + "',");
share.Append(" link: '" + jumpurl + "', ");
share.Append(" imgUrl: '" + showimg + "', ");
share.Append(" success: function () { },");
share.Append(" cancel: function () {}");
share.Append(" });");
Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), "initkey", share.ToString(), true);
#endregion
标签:string,timespan,C#,微信,share,ToString,分享,Append,页面 来源: https://www.cnblogs.com/dsjbk/p/14705294.html