.net微信服务号发送红包

时间:2021-05-28

本文实例为大家分享了.net微信红包发送代码,供大家参考,具体内容如下

注:需要开通微信支付的服务号!

//跳转微信登录页面public ActionResult Index(){ ViewBag.url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=" + {服务号appid} + "&redirect_uri=http%3A%2F%2F" + {微信重定向域名(填写程序域名,例如:puteHash(inputBye); retStr = System.BitConverter.ToString(outputBye); retStr = retStr.Replace("-", "").ToUpper(); XML += "<sign>" + retStr + "</sign>";//签名 XML += "</xml>"; return XML;}//发送红包请求Post方法public static string PostWebRequests(string postUrl, string menuInfo){ string returnValue = string.Empty; try { Encoding encoding = Encoding.UTF8; byte[] bytes = encoding.GetBytes(menuInfo); string cert = @"E:\cdcert\apiclient_cert.p12";//支付证书路径 string password = "1212121";//支付证书密码 ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult); X509Certificate cer = new X509Certificate(cert, password, X509KeyStorageFlags.MachineKeySet); HttpWebRequest webrequest = (HttpWebRequest)HttpWebRequest.Create(postUrl); webrequest.ClientCertificates.Add(cer); webrequest.Method = "post"; webrequest.ContentLength = bytes.Length; webrequest.GetRequestStream().Write(bytes, 0, bytes.Length); HttpWebResponse webreponse = (HttpWebResponse)webrequest.GetResponse(); Stream stream = webreponse.GetResponseStream(); string resp = string.Empty; using (StreamReader reader = new StreamReader(stream)) { return reader.ReadToEnd(); } } catch (Exception ex) { return ""; }}

以下是微信开发官方相关文档

1. 【微信支付】公众号支付开发者文档
2. 微信开放平台
3.企业号开发者接口文档
4.微信公众平台开发者文档

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。

声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。

相关文章