| | |
| | | package com.panzhihua.applets.unionpay; |
| | | |
| | | import com.panzhihua.common.utlis.DateUtils; |
| | | import org.apache.commons.codec.binary.Base64; |
| | | import org.apache.commons.codec.digest.DigestUtils; |
| | | |
| | |
| | | import java.net.HttpURLConnection; |
| | | import java.net.URL; |
| | | import java.net.URLConnection; |
| | | import java.time.LocalDateTime; |
| | | |
| | | /** |
| | | * @author kkqiao |
| | |
| | | */ |
| | | public class RefundQuery { |
| | | |
| | | static String url = "https://test-api-open.chinaums.com/v1/netpay/refund-query"; |
| | | // static String url = "https://test-api-open.chinaums.com/v1/netpay/refund-query"; |
| | | static String url = "https://api-mop.chinaums.com/v1/netpay/refund-query"; |
| | | |
| | | public static void main(String[] args) throws Exception{ |
| | | /** |
| | | * 退款查询接口 |
| | | * @param args |
| | | * @return |
| | | */ |
| | | public static String refundQuery(String merOrderId) |
| | | { |
| | | //1. 组建请求报文 |
| | | LocalDateTime time= DateUtils.getCurrentDate(); |
| | | RefundQueryBody reqBody = new RefundQueryBody(); |
| | | reqBody.requestTimestamp = "2019-08-09 14:45:55"; |
| | | reqBody.mid = "898460107420248"; |
| | | reqBody.tid = "00000001"; |
| | | reqBody.instMid = "MINIDEFAULT"; |
| | | reqBody.merOrderId = "101771300dc89764b477474"; |
| | | reqBody.requestTimestamp =time.format(DateUtils.format_ymdhms);// "2019-08-09 14:45:55"; |
| | | reqBody.mid = UnionpayContent.MID; |
| | | reqBody.tid = UnionpayContent.TID; |
| | | reqBody.instMid = UnionpayContent.INSTMID; |
| | | reqBody.merOrderId = merOrderId; |
| | | System.out.println("request body:\n"+reqBody); |
| | | |
| | | //2. 获取认证报文,timestamp为当前日期,老旧日期无法请求成功 |
| | | String authorization = getAuthorization(UnionpayContent.APPID,UnionpayContent.APPKEY,"20190809145000","nonce",reqBody.toString()); |
| | | String authorization = null; |
| | | try { |
| | | authorization = getAuthorization(UnionpayContent.APPID,UnionpayContent.APPKEY, |
| | | time.format(DateUtils.format_ymdhms_string),"nonce",reqBody.toString()); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | return "退款查询失败"; |
| | | } |
| | | System.out.println("authorization:\n"+authorization); |
| | | |
| | | //3. 发送http请求,并解析返回信息 |
| | | String response = request(url,authorization,reqBody.toString()); |
| | | System.out.println("response:\n"+response); |
| | | return response; |
| | | } |
| | | |
| | | /** |