微信支付05

接上次 退款接口、现在开始做退款查询接口、该接口主要用于在查询单笔订单退款信息查询、商户月末清算等。废话不多说、、、

看文档:


 

                         
  退款查询API

                                 提交退款申请后, 通过调用该接口查询退款状态。 退款有一定延时, 请在 3 个工作日后重新查询退款状态。

                       请求参数列表

                                 请求url:https://pay.swiftpass.cn/pay/gateway

                                 POST XML 内容体进行请求

字段名变量名必填类型说明
接口类型serviceString(32)接口类型:unified.trade.refundquery
版本号versionString(8)版本号,version默认值是1.0。
字符集charsetString(8)可选值 UTF-8 ,默认为 UTF-8。
签名方式sign_typeString(8)签名类型,取值:MD5默认:MD5
商户号mch_idString(32)商户号,由平台分配
商户订单号out_trade_noString(32)商户系统内部的订单号, out_trade_no和transaction_id至少一个必填,同时存在时transaction_id优先
平台订单号transaction_idString(32)平台单号, out_trade_no和transaction_id至少一个必填,同时存在时transaction_id优先
商户退款单号out_refund_noString(32)商户退款单号,32个字符内、可包含字母,确保在商户系统唯一。
平台退款单号refund_idString(32)平台退款单号refund_id、out_refund_no、out_trade_no 、transaction_id 四个参数必填一个, 如果同事存在优先级为:refund_id>out_refund_no>transaction_id>out_trade_no
随机字符串nonce_strString(32)随机字符串,不长于 32 位
签名signString(32)MD5签名结果,详见“安全规范”

 

                                      返回结果

                                      数据按XML的格式实时返回

字段名变量名必填类型说明
版本号versionString(8)版本号,version默认值是2.0。
字符集charsetString(8)可选值 UTF-8 ,默认为 UTF-8。
签名方式sign_typeString(8)签名类型,取值:MD5默认:MD5
返回状态码statusString(16)0表示成功,非0表示失败此字段是通信标识,非交易标识,交易是否成功需要查看 result_code 来判断
返回信息messageString(128)异常或错误时返回信息,具体描述请看文档最后返回信息列表
以下字段在 status 为 0的时候有返回
业务结果result_codeString(16)0表示成功,非0表示失败
商户号mch_idString(32)商户号,由平台分配
设备号device_infoString(32)平台分配的终端设备号
随机字符串nonce_strString(32)随机字符串,不长于 32 位
错误代码err_codeString(32)具体错误码请看文档最后错误码列表
签名signString(32)MD5签名结果,详见“安全规范”
以下字段在 status 和 result_code 都为 0的时候有返回
平台订单号transaction_idString(32)平台订单号。
商户订单号out_trade_noString(32)商户系统内部的订单号
退款笔数refund_countInt退款记录数
商户退款单号out_refund_no_$nString(32)商户退款单号
平台退款单号refund_id_$nString(32)平台退款单号
退款渠道refund_channel_$nString(16)ORIGINAL—原路退款,默认
退款金额refund_fee_$nInt退款总金额,单位为分,可以做部分退款
现金券退款金额coupon_refund_fee_$nInt现金券退款金额 <= 退款金额, 退款金额-现金券退款金额为现金
退款时间refund_time_$nString(14)yyyyMMddHHmmss
退款状态refund_status_$nString(16)SUCCESS—退款成功
FAIL—退款失败
PROCESSING—退款处理中
NOTSURE—未确定, 需要商户原退款单号重新发起
CHANGE—转入代发,退款到银行发现用户的卡作废或者冻结了,导致原路退款银行卡失败,资金回流到商户的现金帐号,需要商户人工干预,通过线下或者平台转账的方式进行退款。
$n 表示记录的序号,取值为 0~($ refund_count -1),例如 refund_count 指示返回的退款记录有 2 条。第一条序号为“0”,第二条序号为“1”。

 

微信支付05

根据文档我们看到该接口的请求参数和订单查询的请求参数基本相同、除了那个交易类型不同之外。所以(可以考虑公用订单查询接口、这样开发工作量就小了)、当然最好有个单独的接口。、、、、、、

下面看demo:


 

 1 protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { 2 req.setCharacterEncoding("utf-8"); 3 resp.setCharacterEncoding("utf-8"); 4  5 SortedMap<String,String> map = XmlUtils.getParameterMap(req); 6  System.out.println(XmlUtils.toXml(map)); 7 String key = SwiftpassConfig.key; 8 String res = null; 9 String reqUrl = SwiftpassConfig.req_url;10 map.put("mch_id", SwiftpassConfig.mch_id);11 map.put("nonce_str", String.valueOf(new Date().getTime()));12 13 Map<String,String> params = SignUtils.paraFilter(map);14 StringBuilder buf = new StringBuilder((params.size() +1) * 10);15 SignUtils.buildPayParams(buf,params,false);16 String preStr = buf.toString();17 String sign = MD5.sign(preStr, "&key=" + key, "utf-8");18 map.put("sign", sign);19 20 System.out.println("reqUrl:" + reqUrl);21 22 CloseableHttpResponse response = null;23 CloseableHttpClient client = null;24 try {25 HttpPost httpPost = new HttpPost(reqUrl);26 StringEntity entityParams = new StringEntity(XmlUtils.parseXML(map),"utf-8");27  httpPost.setEntity(entityParams);28 httpPost.setHeader("Content-Type", "text/xml;charset=ISO-8859-1");29 client = HttpClients.createDefault();30 response = client.execute(httpPost);31 if(response != null && response.getEntity() != null){32 Map<String,String> resultMap = XmlUtils.toMap(EntityUtils.toByteArray(response.getEntity()), "utf-8");33 res = XmlUtils.toXml(resultMap);34 System.out.println("请求结果:" + res);35 36 if(resultMap.containsKey("sign") && !SignUtils.checkParam(resultMap, key)){37 res = "验证签名不通过";38  }39 }else{40 res = "操作失败!";41  }42 } catch (Exception e) {43  e.printStackTrace();44 res = "操作失败";45 } finally {46 if(response != null){47  response.close();48  }49 if(client != null){50  client.close();51  }52  }53 if(res.startsWith("<")){54 resp.setHeader("Content-type", "text/xml;charset=UTF-8");55 }else{56 resp.setHeader("Content-type", "text/html;charset=UTF-8");57  }58  resp.getWriter().write(res);59 }

 

根据demo、、、、、、   (注意事项和之前的一样、这也就是个查询操作)

我们把只需要把订单查询接口的传入参数中的service(交易类型)改变成上面文档中的即可。

、、、 基本现在就差一个  ---- 结算的接口了、想想办法。

 

相关文章