==以下仅供新学习的朋友参考,老鸟就不用看了==
第一步:
我在后置文件里面创建这么几个参数,WxPayApi是引用的微信官方demo里面的WxPayApi,
demo地址:https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=11_1
public string AppId = "---------------------------";
public string AppSecret = "------------------------------------";
public string timestamp = WxPayApi.GenerateTimeStamp();
public string nonceStr = WxPayApi.GenerateNonceStr();
public string signature = "";
public string link = "";
public string imgUrl = "";
public string desc = "";
第二步:写分享代码 这个建议放在读取页面内容的后面
//分享代码
link = Request.Url.ToString(); //获取当前URL
imgUrl = "http://m.fdc0737.com/images/fdc0737Logo.jpg"; //分享的小图片
desc = Content; //分享的描述
string oneUrl = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid="+ AppId + "&secret="+ AppSecret; //第一次请求文件换access_token
string result1 = HttpService.Get(oneUrl);
JsonData jd = JsonMapper.ToObject(result1);
string access_token = (string)jd["access_token"];
string twoUrl = "https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token="+ access_token + "&type=jsapi"; //第二次请求微信换ticket
string result2 = HttpService.Get(twoUrl);
JsonData jd2 = JsonMapper.ToObject(result2);
string ticket = (string)jd2["ticket"];
//string expires_in = (string)jd2["expires_in"];
string String1 = "jsapi_ticket="+ ticket + "&noncestr="+ nonceStr + "×tamp="+ timestamp + "&url="+ link; //拼接字符串准备生成签名
signature = SHA1(String1, Encoding.UTF8); //微信签名
//加密代码
public static string SHA1(string content, Encoding encode)
{
SHA1 sha1 = new SHA1CryptoServiceProvider();
byte[] bytes_in = encode.GetBytes(content);
byte[] bytes_out = sha1.ComputeHash(bytes_in);
sha1.Dispose();
string result = BitConverter.ToString(bytes_out);
result = result.Replace("-", "");
return result;
}