微信支付之退款查询
应用场景
提交退款申请后,通过调用该接口查询退款状态。退款有一定延时,用零钱支付的退款20分钟内到账,银行卡支付的退款3个工作日后重新查询退款状态。
官方文档: http://pay.weixin.qq.com/wiki/doc/api/index.php?chapter=9_5
参考代码:
package com.wingo.action.config;
import java.util.Map;
import java.util.SortedMap;
import java.util.TreeMap;
import com.wingo.util.CommonUtil;
import com.wingo.util.ConfigUtil;
import com.wingo.util.PayCommonUtil;
import com.wingo.util.XMLUtil;
/**
*
* @author李欣桦
* @date 2015-1-15下午2:00:49
* 退款查询
*/
publicclassCheckRefundAction {
publicstaticvoid main(String[] args) throws Exception {
SortedMap<Object,Object> parameters = newTreeMap<Object,Object>();
parameters.put("appid", ConfigUtil.APPID);
parameters.put("mch_id", ConfigUtil.MCH_ID);
//parameters.put("device_info","");//微信支付分配的终端设备号
parameters.put("nonce_str", PayCommonUtil.CreateNoncestr());
//下列四个单号同时存在优先级refund_id>out_refund_no>transaction_id>out_trade_no
parameters.put("transaction_id", "1008010446201412030006459614");//微信交易单号
parameters.put("out_trade_no", "1340297960");//商户交易单号
parameters.put("out_refund_no", "");//商户退款单号
parameters.put("refund_id", "");//微信退款单号
String sign = PayCommonUtil.createSign("utf-8",parameters);
parameters.put("sign", sign);
String reuqestXml = PayCommonUtil.getRequestXml(parameters);
String result =CommonUtil.httpsRequest(ConfigUtil.CHECK_REFUND_URL,"POST",reuqestXml);
System.out.println(result);
Map<String, String> map = XMLUtil.doXMLParse(result);
String returnCode = map.get("return_code");
String resultCode = map.get("result_code");
if(returnCode.equalsIgnoreCase("SUCCESS")&&resultCode.equalsIgnoreCase("SUCCESS")){
String refundCount = map.get("refund_count");
Integer count = new Integer(refundCount);
for (inti = 0; i < count; i++) {
StringrefundStatus = (String) map.get("refund_status_"+i);
//refudnStatus有如下状态:
//SUCCES—退款成功,FAIL—退款失败,PROCESSING—退款处理中NOTSURE—未确定,需要商户原退款单号重新发起
//CHANGE—转入代发,退款到银行发现用户的卡作废或者冻结了,导致原路退款银行卡失败,资金回流到商户的现金帐号,需要商户人工干
//预,通过线下或者财付通转账的方式进行退款。
if(refundStatus.equalsIgnoreCase("SUCCESS")){
//TODO退款成功操作
System.out.println("退款状态为已成功退款");
}
}
}
}
}
上述代码中相关工具类的下载地址如下:
http://download.csdn.net/detail/u011160656/8354883