以文本方式查看主题 - Foxtable(狐表) (http://foxtable.net/bbs/index.asp) -- 专家坐堂 (http://foxtable.net/bbs/list.asp?boardid=2) ---- 微信支付证书报错 (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=194850) |
-- 作者:lxhmax -- 发布时间:2025/1/21 2:04:00 -- 微信支付证书报错 Dim url As String="https://api.mch.weixin.qq.com/secapi/pay/refund" Dim hc As New HttpClient(url) hc.C \'这里还需要加一个添加证书的方法,新版本才能提供 hc.AddClientCertificate(ProjectPath & "apiclient_cert.p12",Vars("mchid")) hc.Timeout = 6 hc.Content = req.ToXML Dim ret As String = hc.GetData()
报错如下:请问老师这个要怎么处理 |
-- 作者:有点蓝 -- 发布时间:2025/1/21 8:39:00 -- 看V3签名用法:http://www.foxtable.com/bbs/dispbbs.asp?BoardID=2&ID=119409&replyID=&skin=1 [此贴子已经被作者于2025/1/21 8:39:29编辑过]
|
-- 作者:lxhmax -- 发布时间:2025/1/21 9:55:00 -- 老师,我参考了之后,大概弄成下面这样,帮我看下下面的代码要怎么改正,这个是微信退款的接口https://pay.weixin.qq.com/doc/v2/merchant/4011937624 \' 时间戳和随机数 Dim ts As TimeSpan = DirectCast((DateTime.Now - New DateTime(1970, 1, 1, 8, 0, 0, 0)), TimeSpan) Dim timestamp As Long = Convert.ToInt64(ts.TotalSeconds).ToString \'时间戳 Dim nonce_str As String = Guid.NewGuid.ToString.Replace("-", "").ToUpper \'随机数 \' 准备请求体(JSON格式) Dim body As String = "{""refund_id"":""1500000000"", ""out_trade_no"":""2501202258199d238"", ""amount"":{""total"":100, ""refund"":1}, ""notify_url"":""https://system.com/wxxcx""}" \'\' 构建签名字符串 (注意: 对于POST请求,签名字符串中应该包含请求体的哈希值) Dim ss As String = "POST" & Chr(10) & "/secapi/pay/refund" & Chr(10) & timestamp & Chr(10) & nonce_str & Chr(10) & body & Chr(10) Output.Show(0) \' 加载商户私钥证书 Dim pfxFilepath As String = "F:\\apiclient_cert.p12\\wechatpay_376C40BA9077155.pem" \' 证书文件地址 Output.Show(pfxFilepath ) Dim pfxpassword As String = "1500000000" \' 商户号 Dim privateCert As New Security.Cryptography.X509Certificates.X509Certificate2(pfxFilepath, pfxpassword, Security.Cryptography.X509Certificates.X509KeyStorageFlags.Exportable) Output.Show(1) \' 获取RSA私钥对象并签名数据 Dim privateKey As Security.Cryptography.RSACryptoServiceProvider = privateCert.PrivateKey Dim privateKey1 As New Security.Cryptography.RSACryptoServiceProvider() privateKey1.ImportParameters(privateKey.ExportParameters(True)) \'这一步报错了\' Output.Show(2) Dim data() As Byte = Encoding.UTF8.GetBytes(ss) Dim signature() As Byte = privateKey1.SignData(data, "SHA256") Dim sign As String = Convert.ToBase64String(signature) Output.Show(sign) \' 构建授权头 Dim serialNo As String = privateCert.SerialNumber \' 获取证书序列号 Dim authorizationHeader As String = "WECHATPAY2-SHA256-RSA2048 mchid=""" & pfxpassword & """,n & nonce_str & """,signature=""" & sign & """,timestamp=""" & timestamp & """,serial_no=""" & serialNo & """" \' 发送请求 Dim htc As New HttpClient("https://api.mch.weixin.qq.com/secapi/pay/refund") htc.C htc.Accept = "application/json" \' 必须 htc.UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36" \' 必须 htc.Headers.Add("Authorization", authorizationHeader) Dim ret As String = htc.GetData() Output.Show(ret) [此贴子已经被作者于2025/1/21 9:55:33编辑过]
|
-- 作者:有点蓝 -- 发布时间:2025/1/21 9:59:00 -- 提示什么错误? |
-- 作者:lxhmax -- 发布时间:2025/1/21 10:01:00 -- |
-- 作者:有点蓝 -- 发布时间:2025/1/21 10:07:00 -- 您发的链接是V2的签名用法,不是V3,。V2看例子里的全局代码,注意证书要下载和使用p12格式的,不是pem格式的 |