微信jsapi支付 退款接口
微信官方退款接口文档地址:https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_4
参数按照文档构造 记录出现错误:System.Net.WebException: The remote server returned an error: (400) Bad Request
这个是由于退款接口需要传证书
证书的话是需要登录商户号进行下载api证书 下载好导入到服务器中 调用支付接口的时候添加证书即可
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | public string PostWebRequest( string postUrl, string paramData) { string ret = string .Empty; try {<br> byte [] byteArray = Encoding.Default.GetBytes(paramData); //转化 HttpWebRequest webReq = (HttpWebRequest)WebRequest.Create( new Uri(postUrl)); webReq.Method = "POST" ; webReq.ContentType = "application/x-www-form-urlencoded" ; webReq.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)" ; //初始化证书 fileName:证书存放的地址 password 证书的密码 X509Certificate2 certificate = new X509Certificate2(fileName,password); //添加证书 webReq.ClientCertificates.Add(certificate); <br><br><br> webReq.ContentLength = byteArray.Length; Stream newStream = webReq.GetRequestStream(); // newStream.Write(byteArray, 0, byteArray.Length); //写入参数 ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Ssl3; HttpWebResponse response = (HttpWebResponse)webReq.GetResponse(); //这里报错 StreamReader sr = new StreamReader(response.GetResponseStream(), Encoding.UTF8); ret = sr.ReadToEnd(); newStream.Close(); sr.Close(); response.Close(); newStream.Close(); } catch (Exception ex) { return ex.Message; } return ret; } |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构