在使用商户转帐到零钱时 发起商户转帐 低于2000 不使用 “收款用户姓名 user_name” 可以正常转帐成功,使用 敏感信息加密后出错 400,
用户姓名加密程序如下:
公钥用的是 证书文件中的 apiclient_cert.pem
byte[] publicKey = Encoding.UTF8.GetBytes(证书文件);
public static string RSAEncrypt(string text, byte[] publicKey)
{
using (var x509 = new X509Certificate2(publicKey))
{
using (var rsa = (RSACryptoServiceProvider)x509.PublicKey.Key)
{
var buff = rsa.Encrypt(Encoding.UTF8.GetBytes(text), true);
return Convert.ToBase64String(buff);
}
}
}
API接口请求程序如下:
public static string send(string authorization, string str, string UserAgent)
{
try
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://api.mch.weixin.qq.com/v3/transfer/batches");
request.UserAgent = UserAgent;
request.Method = "POST";
request.Accept = "application/json";
request.ContentType = "application/json";
request.Headers.Add("Authorization", authorization);
request.Headers.Add("Wechatpay-Serial", WxPayConfig.CERTIFICATE);
Stream requestStream = request.GetRequestStream();
StreamWriter streamWriter = new StreamWriter(requestStream);
streamWriter.Write(str);
streamWriter.Flush();
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream responseStream = response.GetResponseStream();
StreamReader streamReader = new StreamReader(responseStream);
str = streamReader.ReadToEnd();
streamWriter.Close();
streamReader.Close();
}
catch (Exception e)
{
Log.Info("出错信息:", e.ToString());
}
return str;
}
具体不知道什么原因,把姓名加入后就不能成功转帐
POST 请求 JSON数据如下:
{
"appid": "wx4c00359c0c0ca000",
"out_batch_no": "DP202209170022066342",
"batch_name": "测试转帐",
"batch_remark": "测试商户转帐到零钱",
"total_amount": 100,
"total_num": 1,
"transfer_detail_list": [
{
"out_detail_no": "UD202209170022066343",
"transfer_amount": 100,
"transfer_remark": "测试转帐",
"openid": "oA_LG610T2AOBSJbOC414141xt_8F4",
"user_name": "jAkxHab9eU2SvrD7udOX//s3l+uXzsfEAaMJwKXDhQyMVzLwth2uj/4mILmSTsonqusfvYEagwUU9zYXHZCTETnH0SudYyaVjKA6/hUCkkuS7uxGm3HpwOwpv6sdIXyLk6aBr4A6XZblSTzUhNZG1WweJHL4F7ztuBx43V2E+ksg3D+TFHSqSNN1CSkVJ23jFHxjvKw4NrIKKywkILbODtpIPa6uW6oenyJCIruHr+3sR5Wrb6nZFxBoplrkwe1mUliikPRu8XIq6Qj0/Y0Yggdam/oh1gyPs3jHItJ2hAXGInct/GTCZamyGbyka/7kCrTEYGI92ADMOwoNM/be3w=="
}
]
}
加密用平台证书给错了,参见: https://pay.weixin.qq.com/wiki/doc/apiv3/apis/wechatpay5_1.shtml
request.Headers.Add("Wechatpay-Serial", WxPayConfig.CERTIFICATE);
请求头里面也用了这个
有没有代码demo 提供下
问题已解决,公钥和平台证书序列号 都要在 https://api.mch.weixin.qq.com/v3/certificates API中获取,证书序列号 在 .NET 中并不需要转为16进制