1000字范文,内容丰富有趣,学习的好帮手!
1000字范文 > C# 微信支付请求分账

C# 微信支付请求分账

时间:2023-10-17 15:03:10

相关推荐

C# 微信支付请求分账

请求单次分账

请求分账返回的参数,有以下这样的直接就是没有问题了,出现FAIL还是有错误

分账到账的效果,我是以百分之二十的比率分配的。

请求单次分账,需要完成了添加分账接收方,参数说明:(商户分账单号 out_order_no )是自己平台的商户订单号;

分账方法代码实例

分配的金额不可以超过总额的百分之三十

交易单号和商户单号,代码中需要的

直接展示个人和公司的分账就没有用循环

public static void profitsharing(){JavaScriptSerializer serializer = new JavaScriptSerializer();List<json2> list = new List<json2>();//for (int i = 0; i < mmm; i++)//{//直接展示个人和公司的分账就没有用循环json2 p = new json2();p.type = "PERSONAL_OPENID";//标识 表示个人p.account = "小程序或者公众号的openid";p.amount = 20;//分配金额p.description = "分到个人";json2 p2 = new json2();p2.type = "PERSONAL_ID";//标识 表示商户号p2.account = "商户号";p2.amount = 10;//分配金额p2.description = "分到公司"; //说明list.Add(p2);list.Add(p);//}var jsonStr = serializer.Serialize(list);var mch_id = "商户号的id";var nonceStr = Guid.NewGuid().ToString("N");var appid = "绑定了商户号的小程序或者公众号的appid";var transaction_id = "交易单号";var out_order_no = "商户单号";var profitsharing = new SortedList<string, object>{{"mch_id", mch_id},{"appid", appid},{"nonce_str", nonceStr},{"transaction_id", transaction_id},{"out_order_no",out_order_no},{"receivers", $"{jsonStr}"},{"sign_type","HMAC-SHA256" }};StringBuilder builder = new StringBuilder();foreach (KeyValuePair<string, object> item in profitsharing){var name = item.Key;var value = item.Value.ToString();if (value != ""){builder.Append(name + "=" + value + "&");}}var MchKey = "0iCjINWd2CXYUnW3yl524K32Yw2Rt85m";var stringSignTemp = builder.ToString().TrimEnd('&') + "&key=" + MchKey;将字符串进行sha256_HMAC加密string singString = Encrypt(stringSignTemp, MchKey).ToUpper();string url = "https://api.mch./secapi/pay/multiprofitsharing";string xml = @"<xml><appid>{0}</appid><mch_id>{1}</mch_id><nonce_str>{2}</nonce_str> <out_order_no>{3}</out_order_no><transaction_id>{4}</transaction_id><sign>{5}</sign><sign_type>HMAC-SHA256</sign_type><receivers>{6}</receivers></xml>";xml = string.Format(xml, appid, mch_id, nonceStr, out_order_no, transaction_id, singString, jsonStr);HttpClientHandler handler = new HttpClientHandler();X509Certificate2 cert = new X509Certificate2(AppDomain.CurrentDomain.BaseDirectory + "cert\\apiclient_cert.p12", mch_id);handler.ClientCertificates.Add(cert);HttpClient client = new HttpClient(handler);var content = new StringContent(xml, Encoding.UTF8, "application/xml");var response = client.PostAsync(url, content).Result;if (response.IsSuccessStatusCode){string msg = response.Content.ReadAsStringAsync().Result;Console.WriteLine(msg);}}

//分账人的信息类public class json2{public string type {get; set; }public string account {get; set; }public int amount {get; set; }public string description {get; set; }}//其他的在类 添加分账接收人中有

其他的在类 添加分账接收人中有

请求多次分账

多次分账和单次分账的参数都是相同的,只要替换请求的api地址就可以了的

多次分账api https://api.mch./secapi/pay/multiprofitsharing

单次分账api https://api.mch./secapi/pay/profitsharing

微信支付多次分账

对于微信多次分账问题的记录

1:微信支付在调用支付接口的时候需要传递一个是否开启分账的标识符(详情请看官方文档)

2:在多次分账及单次分账的时候会有所不同

单次分账:单次分账请求按照传入的分账接收方账号和资金进行分账,同时会将订单剩余的待分账金额解冻给特约商户。故操作成功后,订单不能再进行分账,也不能进行分账完结。

多次分账:在单词分账的基础上又略微的不同,多次分账进行第二次分账的时候,是传递的商户分账单号为第一次进行分账成功返回的微信分账单号,而不是用自己的订单号。

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。