private RedpackResponse SendLuckMoney(string payKey, Redpack redpack) { //证书下载 地址 https://kf.qq.com/faq/180824JvUZ3i180824YvMNJj.html //证书下载 地址 https://kf.qq.com/faq/161222NneAJf161222U7fARv.html var url = "https://api.mch.weixin.qq.com/mmpaymkttransfers/sendredpack"; var sign = string.Concat(redpack.PrepareSign(), $"&key={payKey}").MakeSign(WxPayData.SIGN_TYPE_MD5, payKey); redpack.SetSign(sign); var xml = redpack.SerializeToXml(); return(url.GetUriContentDirectly((http) => { http.Method = "POST"; http.ContentType = "text/xml"; var store = new X509Store(StoreName.My, StoreLocation.LocalMachine); store.Open(OpenFlags.ReadOnly | OpenFlags.OpenExistingOnly | OpenFlags.MaxAllowed); var cert = store.Certificates.Find(X509FindType.FindByIssuerName, "MmpaymchCA", false); http.ClientCertificates.Add(cert[0]); using (var stream = http.GetRequestStream()) { var body = redpack.SerializeToXml(); var buffers = UTF8Encoding.UTF8.GetBytes(body); stream.Write(buffers, 0, buffers.Length); stream.Flush(); } return http; }).DeserializeFromXml <RedpackResponse>()); }
public RedpackResponse SendRedpack(IWxApp official, string payKey, Redpack redpack) { var url = "https://api.mch.weixin.qq.com/mmpaymkttransfers/sendredpack"; var sign = string.Concat(redpack.PrepareSign(), $"&key={payKey}").MakeSign(WxPayData.SIGN_TYPE_MD5, payKey); redpack.SetSign(sign); return(url.GetUriContentDirectly((http) => { http.Method = "POST"; http.ContentType = "text/xml"; var store = new X509Store(StoreName.Root, StoreLocation.LocalMachine); store.Open(OpenFlags.ReadOnly | OpenFlags.OpenExistingOnly | OpenFlags.MaxAllowed); var path = Path.Combine(Environment.CurrentDirectory, @"cert\apiclient_cert.p12"); var cert = new X509Certificate2(path, "1520961881"); //var cert = store.Certificates.Find(X509FindType.FindBySerialNumber, "7d4daceb0866305aed424a175e86c005e6b80ee3", false); http.ClientCertificates.Add(cert); using (var stream = http.GetRequestStream()) { var body = redpack.SerializeToXml(); var buffers = UTF8Encoding.UTF8.GetBytes(body); stream.Write(buffers, 0, buffers.Length); stream.Flush(); } return http; }).DeserializeFromXml <RedpackResponse>()); }