1.退款須要退款證書。C#都是用p12的證書,雙擊證書導入,密碼是mch_id(商戶號)web
2.調用微信退款接口進行退款操做api
1 string resp=string.Empty 2 string cert = Server.MapPath("apiclient_cert.p12"); 3 string password = mch_id;(商戶號) 4 ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult); 5 6 //這兩句特別注意 7 8 // X509Certificate cer = new X509Certificate(cert, password);//線下發布須要添加的 9 X509Certificate2 cer = new X509Certificate2(cert, password, X509KeyStorageFlags.PersistKeySet | X509KeyStorageFlags.MachineKeySet);//線上發 布須要添加 10 11 HttpWebRequest webrequest = (HttpWebRequest)HttpWebRequest.Create(url); 12 webrequest.ClientCertificates.Add(cer); 13 webrequest.Method = "post"; 14 webrequest.ContentType = "application/x-www-form-urlencoded"; 15 webrequest.ContentLength = xml.Length; 16 HttpWebResponse response = null; 17 try 18 { 19 StreamWriter swRequestWriter = new StreamWriter(webrequest.GetRequestStream()); 20 swRequestWriter.Write(xml); 21 22 if (swRequestWriter != null) 23 swRequestWriter.Close(); 24 25 response = (HttpWebResponse)webrequest.GetResponse(); 26 using (StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.Default)) 27 { 28 resp = reader.ReadToEnd(); 29 } 30 } 31 catch (Exception exp) 32 { 33 throw exp; 34 } 35 finally 36 { 37 if (response != null) 38 response.Close(); 39 }
分享幾個退款時遇到的問題
一、退款提示:訂單號非法
緣由:退款的訂單號錯誤致使的
二、退款時提示:基礎鏈接已關閉,或被意外關閉(驗證證書的問題)
緣由: 首先要經過證書請求退款的接口,其次要把下面的這行語句
// X509Certificate cer = new X509Certificate(cert, password);//線下發布須要添加的 修改爲這樣的才能夠 X509Certificate2 cer = new X509Certificate2(cert, password, X509KeyStorageFlags.PersistKeySet | X509KeyStorageFlags.MachineKeySet);//線上發 布須要添加三、 Miss Parameters 緣由:傳參數時,參數的名字和文檔大小寫不一致四、每次退款,退款的訂單號不能相同,不然沒法退款