微信支付 申请退款 报(400) 错误的请求 ?
var url = "https://api.mch.weixin.qq.com/secapi/pay/refund";
string strA = "appid=" + appid + "&mch_id=" + mch_id + "&nonce_str=" + nonce_str + "&out_trade_no=" + out_trade_no
+ "&total_fee=" + total_fee + "&out_refund_no=" + out_refund_no + "&refund_fee=" + refund_fee;
string strk = strA + "&key=" + _keyGroup; //key为商户平台设置的密钥key(假)
string strMD5 = MD5(strk).ToUpper();//MD5签名
var formData = "<xml>";
formData += "<appid>" + appid + "</appid>";//appid
formData += "<mch_id>" + mch_id + "</mch_id>";//商户号
formData += "<nonce_str>" + nonce_str + "</nonce_str>";//随机字符串,不长于32位。
formData += "<out_refund_no>" + out_refund_no + "</out_refund_no>";//商户退款单号
formData += "<out_trade_no>" + out_trade_no + "</out_trade_no>";//商户订单号 --待
formData += "<refund_fee>" + refund_fee + "</refund_fee>";//退款金额
formData += "<total_fee>" + total_fee + "</total_fee>";//支付金额单位为(分)
formData += "<sign>" + strMD5 + "</sign>"; //签名
formData += "</xml>";
//请求数据
var getdata = sendPost(url, formData);
/// <summary>
/// wx统一下单请求数据
/// </summary>
/// <param name="URL">请求地址</param>
/// <param name="urlArgs">参数</param>
/// <returns></returns>
private static string sendPost(string URL, string urlArgs)
{
//context.Request["args"]
System.Net.WebClient wCient = new System.Net.WebClient();
wCient.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
byte[] postData = System.Text.Encoding.UTF8.GetBytes("body=" + urlArgs);
byte[] responseData = wCient.UploadData(URL, "POST", postData);
string returnStr = System.Text.Encoding.UTF8.GetString(responseData);//返回接受的数据
return returnStr;
}
V2退款接口请求需要携带商户证书
string strA = "appid=" + appid + "&mch_id=" + mch_id + "&nonce_str=" + nonce_str + "&out_trade_no=" + out_trade_no
+ "&total_fee=" + total_fee + "&out_refund_no=" + out_refund_no + "&refund_fee=" + refund_fee;
string strk = strA + "&key=" + _keyGroup; //key为商户平台设置的密钥key(假)
string strMD5 = MD5(strk).ToUpper();//MD5签名
var formData = "<xml>";
formData += "<appid>" + appid + "</appid>";//appid
formData += "<mch_id>" + mch_id + "</mch_id>";//商户号
formData += "<nonce_str>" + nonce_str + "</nonce_str>";//随机字符串,不长于32位。
formData += "<out_refund_no>" + out_refund_no + "</out_refund_no>";//商户退款单号
formData += "<out_trade_no>" + out_trade_no + "</out_trade_no>";//商户订单号 --待
formData += "<refund_fee>" + refund_fee + "</refund_fee>";//退款金额
formData += "<total_fee>" + total_fee + "</total_fee>";//支付金额单位为(分)
formData += "<sign>" + strMD5 + "</sign>"; //签名
formData += "</xml>";