• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

c# 微信分享-原始代码

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

==以下仅供新学习的朋友参考,老鸟就不用看了==

第一步:

  我在后置文件里面创建这么几个参数,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 + "&timestamp="+ 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;
}

 


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C#子窗体调用父窗体的方法发布时间:2022-07-10
下一篇:
C#单例模式的五种写法发布时间:2022-07-10
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap