- 微信支付商家 转帐 user_name能用微信支付平台证书证书模式加密敏感信息需要加密?
name属于敏感信息需要加密的。【微信支付公钥】和【平台证书】的功能一模一样,是二选一的。平台证书有效期是5年,去年9月,微信支付加了个“微信支付公钥”的验签方式。在不降低安全性的同时,公钥不会过期,方便商户维护。 现在没有开启微信支付公钥,想使用 现在证书模式进行加密。 微信平台证书是用java -jar CertificateDownloader.jar -k ${apiV3key} -m ${mchId} -f ${mchPrivateKeyFilePath} -s ${mchSerialNo} -o ${outputFilePath}下载的,文件名为wechatpay.pem。 开发语言是asp.net4.5.
07-05 - 微信支付商家 转帐 user_name是 属于敏感信息需要加密的,能使用证书模式加密吗?
商家转帐{\"appid\":\"wx48e923d9886gh\",\"out_bill_no\":\"preub15\",\"transfer_scene_id\":\"1000\",\"transfer_remark\":\"0\",\"openid\":\"oyQFh*******jBsdiwys6jt6tu4\",\"transfer_amount\":\"120\",\"user_name\":\"**堂\",\"user_recv_perception\":\"现金奖励\",\"transfer_scene_report_infos\":[{\"info_type\":\"佣金报酬\",\"info_content\":\"佣金提现报酬\"}]}"; user_name是 属于敏感信息需要加密的,能使用证书模式加密吗?现在使用的的是证书模式,没有开通微信支付公钥。 微信推荐 http请求增加一个Wechatpay-Serial请求头,Wechatpay-Serial 对应是微信支付平台证书序列号,使用微信支付公钥加密。但现在使用的是证书模式,能使用证书模式加密吗?aps.net 4.5。
07-03 - 微信支付切换成微信支付公钥模式后,原有的支付方式是不是作废了?
现在使用的是商户号+ 证书 + APIv2密钥方式。现在因为 开发商家转帐功能,需要开启微信支付公钥模式。看说明开启后,原有的支付方式就不能用了,需要针对 微信支付公钥模式 重新开发代码,是这样吗?
07-03 - 微信支付 商家转帐微信支付 商家转帐 请确认待处理的消息是否为加密后的密文?
生成的head: Authorization:WECHATPAY2-SHA256-RSA2048 mchid="171***12",nonce_str="9d2640bee3dc439e877cbe0181e0b569",signature="jFKNe+YM/UmNkwRpXnodrJuqbHZl74DKPhUgkRuowSitPH6k91SVkWP4YeQ8PP9kfzgzLFlbOn8K0XQ2AQIqzsvGVDAvneTuqg/oAuXdUSFyvNLzRlyftoqILFx0lwSEhWWST62RUS7OK+y8CXdJ7OdnKsol66UgrvKEArZ+u9l/Nk7sz5ti1cmpMYiEHsr55Iri7yw3JnA8esy1CM2eHmG3XaYduVDHQMeHwALJb+gVyNK6ZjT/6dKgY08YYMnlooKbK22qfQ4w2pJw5aI+LfTkLDjyHUI7jxL2Z4HD/CuYgK/rWEE3s6hO3s4oW2k9np8cweSkdWqdH9P9Gq8SFg==",timestamp="1751437716",serial_no="5D1E3AA427034E38F36A7D75B81F4EDE420E65B9";Wechatpay-Serial:5D1E3AA***5B9;Accept:application/json;User-Agent:Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;);Content-Type:application/json; 调试过过程中,httpWebResponse = (HttpWebResponse)httpRequest.GetResponse(); 返回 :微信支付 商家转帐 请确认待处理的消息是否为加密后的密文 responseText = {"code":"PARAM_ERROR","message":"请确认待处理的消息是否为加密后的密文"} 请问哪里需要 加密。aasp.net4.5 使用什么方法 进行加密? 代码参考:https://developers.weixin.qq.com/community/develop/article/doc/00082cf0934a106b420a678d45b013 { string requestBody =" {\"appid\":\"wx48e923d9886gh\",\"out_bill_no\":\"preub15\",\"transfer_scene_id\":\"1000\",\"transfer_remark\":\"0\",\"openid\":\"oyQFh*******jBsdiwys6jt6tu4\",\"transfer_amount\":\"120\",\"total_num\":\"1\",\"user_name\":\"**堂\",\"user_recv_perception\":\"现金奖励\",\"transfer_scene_report_infos\":[{\"info_type\":\"佣金报酬\",\"info_content\":\"佣金提现报酬\"}]}"; string physicalApplicationPath = HttpContext.Current.Request.PhysicalApplicationPath; string pemPath = physicalApplicationPath + "config/apiclient_key.pem"; var pemContent = File.ReadAllText(pemPath) .Replace("-----BEGIN PRIVATE KEY-----", "") .Replace("-----END PRIVATE KEY-----", "") .Replace("\n", ""); string method = "POST"; string timestamp = Convert.ToInt64((DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0)).TotalSeconds).ToString(); string nonce = Guid.NewGuid().ToString("N"); string url = "/v3/fund-app/mch-transfer/transfer-bills"; string message = $"{method}\n{url}\n{timestamp}\n{nonce}\n{requestBody}\n"; string signature = Sign( message, pemContent); string CertSerialNo = "5D1E3AA**********81F0E65B9"; string token = $"WECHATPAY2-SHA256-RSA2048 " + $"mchid=\"{this.mchid}\"," + $"nonce_str=\"{nonce}\"," + $"signature=\"{signature}\"," + $"timestamp=\"{timestamp}\"," + $"serial_no=\"{CertSerialNo}\""; string Gateway = "https://api.mch.weixin.qq.com/v3/fund-app/mch-transfer/transfer-bills"; // 3. 发送请求 HttpWebRequest httpRequest = (HttpWebRequest)WebRequest.Create(Gateway); httpRequest.Method = "POST"; httpRequest.Headers.Add("Authorization", token); httpRequest.Headers.Add("Wechatpay-Serial", CertSerialNo); httpRequest.Accept = "application/json"; httpRequest.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)"; httpRequest.ContentType = "application/json"; HttpWebResponse httpWebResponse = null; // 写入请求体 Stream stream = null; byte[] data = Encoding.UTF8.GetBytes(requestBody); stream = httpRequest.GetRequestStream(); stream.Write(data, 0, data.Length); stream.Close(); // 4. 获取响应 httpWebResponse = (HttpWebResponse)httpRequest.GetResponse(); StreamReader streamReader = new StreamReader(httpWebResponse.GetResponseStream(), Encoding.UTF8); string text = streamReader.ReadToEnd().Trim(); streamReader.Close(); } protected string Sign(string message, string privateKey) { // SHA256withRSA //根据需要加签时的哈希算法转化成对应的hash字符节 //byte[] bt = Encoding.GetEncoding("utf-8").GetBytes(str); byte[] bt =Encoding.UTF8.GetBytes(message); var sha256 = new SHA256CryptoServiceProvider(); byte[] rgbHash = sha256.ComputeHash(bt); RSACryptoServiceProvider key = new RSACryptoServiceProvider(); var _privateKey = RSAKeyConvert.RSAPrivateKeyJava2DotNet(privateKey); key.FromXmlString(_privateKey); RSAPKCS1SignatureFormatter formatter = new RSAPKCS1SignatureFormatter(key); formatter.SetHashAlgorithm("SHA256");//此处是你需要加签的hash算法,需要和上边你计算的hash值的算法一致,不然会报错。 byte[] inArray = formatter.CreateSignature(rgbHash); return Convert.ToBase64String(inArray); } protected string RSAPrivateKeyJava2DotNet(string privateKey) { RsaPrivateCrtKeyParameters privateKeyParam = (RsaPrivateCrtKeyParameters)PrivateKeyFactory.CreateKey(Convert.FromBase64String(privateKey)); return string.Format("<RSAKeyValue><Modulus>{0}</Modulus><Exponent>{1}</Exponent><P>{2}</P><Q>{3}</Q><DP>{4}</DP><DQ>{5}</DQ><InverseQ>{6}</InverseQ><D>{7}</D></RSAKeyValue>", Convert.ToBase64String(privateKeyParam.Modulus.ToByteArrayUnsigned()), Convert.ToBase64String(privateKeyParam.PublicExponent.ToByteArrayUnsigned()), Convert.ToBase64String(privateKeyParam.P.ToByteArrayUnsigned()), Convert.ToBase64String(privateKeyParam.Q.ToByteArrayUnsigned()), Convert.ToBase64String(privateKeyParam.DP.ToByteArrayUnsigned()), Convert.ToBase64String(privateKeyParam.DQ.ToByteArrayUnsigned()), Convert.ToBase64String(privateKeyParam.QInv.ToByteArrayUnsigned()), Convert.ToBase64String(privateKeyParam.Exponent.ToByteArrayUnsigned())); }
07-02 - asp.net 4.5开发 微信支付 商家转帐功能问题: 返回:远程服务器返回错误: (401) ?
asp.net 4.5开发 微信支付 商家转帐功能问题: 返回:远程服务器返回错误: (401) 未经授权,不知道是什么原因。 注:微信支付支付功能运行正常。 代码如下: 代码参考:https://developers.weixin.qq.com/community/develop/article/doc/00082cf0934a106b420a678d45b013 { string requestBody =" {\"appid\":\"wx48e923d9886gh\",\"out_bill_no\":\"preub15\",\"transfer_scene_id\":\"1000\",\"transfer_remark\":\"0\",\"openid\":\"oyQFh*******jBsdiwys6jt6tu4\",\"transfer_amount\":\"120\",\"total_num\":\"1\",\"user_name\":\"**堂\",\"user_recv_perception\":\"现金奖励\",\"transfer_scene_report_infos\":[{\"info_type\":\"佣金报酬\",\"info_content\":\"佣金提现报酬\"}]}"; string physicalApplicationPath = HttpContext.Current.Request.PhysicalApplicationPath; string pemPath = physicalApplicationPath + "config/apiclient_key.pem"; var pemContent = File.ReadAllText(pemPath) .Replace("-----BEGIN PRIVATE KEY-----", "") .Replace("-----END PRIVATE KEY-----", "") .Replace("\n", ""); string method = "POST"; string timestamp = Convert.ToInt64((DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0)).TotalSeconds).ToString(); string nonce = Guid.NewGuid().ToString("N"); string url = "/v3/fund-app/mch-transfer/transfer-bills"; string message = $"{method}\n{url}\n{timestamp}\n{nonce}\n{requestBody}\n"; string signature = Sign( message, pemContent); string CertSerialNo = "5D1E3AA**********81F0E65B9"; string token = $"WECHATPAY2-SHA256-RSA2048 " + $"mchid=\"{this.mchid}\"," + $"nonce_str=\"{nonce}\"," + $"signature=\"{signature}\"," + $"timestamp=\"{timestamp}\"," + $"serial_no=\"{CertSerialNo}\""; string Gateway = "https://api.mch.weixin.qq.com//v3/fund-app/mch-transfer/transfer-bills"; // 3. 发送请求 HttpWebRequest httpRequest = (HttpWebRequest)WebRequest.Create(Gateway); httpRequest.Method = "POST"; httpRequest.Headers.Add("Authorization", token); httpRequest.Headers.Add("Wechatpay-Serial", CertSerialNo); httpRequest.Accept = "application/json"; httpRequest.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)"; httpRequest.ContentType = "application/json"; HttpWebResponse httpWebResponse = null; // 写入请求体 Stream stream = null; byte[] data = Encoding.UTF8.GetBytes(requestBody); stream = httpRequest.GetRequestStream(); stream.Write(data, 0, data.Length); stream.Close(); // 4. 获取响应 httpWebResponse = (HttpWebResponse)httpRequest.GetResponse(); StreamReader streamReader = new StreamReader(httpWebResponse.GetResponseStream(), Encoding.UTF8); string text = streamReader.ReadToEnd().Trim(); streamReader.Close(); } protected string Sign(string message, string privateKey) { // SHA256withRSA //根据需要加签时的哈希算法转化成对应的hash字符节 //byte[] bt = Encoding.GetEncoding("utf-8").GetBytes(str); byte[] bt =Encoding.UTF8.GetBytes(message); var sha256 = new SHA256CryptoServiceProvider(); byte[] rgbHash = sha256.ComputeHash(bt); RSACryptoServiceProvider key = new RSACryptoServiceProvider(); var _privateKey = RSAKeyConvert.RSAPrivateKeyJava2DotNet(privateKey); key.FromXmlString(_privateKey); RSAPKCS1SignatureFormatter formatter = new RSAPKCS1SignatureFormatter(key); formatter.SetHashAlgorithm("SHA256");//此处是你需要加签的hash算法,需要和上边你计算的hash值的算法一致,不然会报错。 byte[] inArray = formatter.CreateSignature(rgbHash); return Convert.ToBase64String(inArray); } protected string RSAPrivateKeyJava2DotNet(string privateKey) { RsaPrivateCrtKeyParameters privateKeyParam = (RsaPrivateCrtKeyParameters)PrivateKeyFactory.CreateKey(Convert.FromBase64String(privateKey)); return string.Format("<RSAKeyValue><Modulus>{0}</Modulus><Exponent>{1}</Exponent><P>{2}</P><Q>{3}</Q><DP>{4}</DP><DQ>{5}</DQ><InverseQ>{6}</InverseQ><D>{7}</D></RSAKeyValue>", Convert.ToBase64String(privateKeyParam.Modulus.ToByteArrayUnsigned()), Convert.ToBase64String(privateKeyParam.PublicExponent.ToByteArrayUnsigned()), Convert.ToBase64String(privateKeyParam.P.ToByteArrayUnsigned()), Convert.ToBase64String(privateKeyParam.Q.ToByteArrayUnsigned()), Convert.ToBase64String(privateKeyParam.DP.ToByteArrayUnsigned()), Convert.ToBase64String(privateKeyParam.DQ.ToByteArrayUnsigned()), Convert.ToBase64String(privateKeyParam.QInv.ToByteArrayUnsigned()), Convert.ToBase64String(privateKeyParam.Exponent.ToByteArrayUnsigned())); }
07-02