| | |
| | | package com.ruoyi.account.util.payment; |
| | | |
| | | import cn.hutool.http.Header; |
| | | import cn.hutool.http.HttpRequest; |
| | | import cn.hutool.http.HttpResponse; |
| | | import cn.hutool.http.HttpUtil; |
| | | import com.alibaba.fastjson2.JSON; |
| | | import com.alibaba.fastjson2.JSONObject; |
| | | import com.ruoyi.account.util.payment.model.*; |
| | | import com.ruoyi.common.core.utils.StringUtils; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | |
| | | import java.util.*; |
| | |
| | | */ |
| | | private static final String merchantNo = "888122600004175"; |
| | | /** |
| | | * 平台-报备商户号 |
| | | */ |
| | | private static final String sysTradeMerchantNo = "777168500885852"; |
| | | /** |
| | | * 支付回调地址 |
| | | */ |
| | | private static final String callbackUrl = "http://221.182.45.100:9000"; |
| | | private static final String callbackUrl = "https://www.qijisheng.top"; |
| | | |
| | | |
| | | /** |
| | |
| | | public static UniPayResult uniPay(String orderNo, Double amount, String productName, String productDesc, String mp, String notifyUrl, String openId, String tradeMerchantNo){ |
| | | String url = "https://trade.joinpay.com/tradeRt/uniPay"; |
| | | HttpRequest post = HttpUtil.createPost(url); |
| | | post.header(Header.CONTENT_TYPE, "application/x-www-form-urlencoded"); |
| | | JSONObject body = new JSONObject(); |
| | | //版本号 |
| | | body.put("p0_Version", "2.5"); |
| | |
| | | //APPID |
| | | body.put("q7_AppId", appId); |
| | | //报备商户号 |
| | | body.put("qa_TradeMerchantNo", tradeMerchantNo); |
| | | body.put("qa_TradeMerchantNo", StringUtils.isNotEmpty(tradeMerchantNo) ? tradeMerchantNo : sysTradeMerchantNo); |
| | | String sign = null; |
| | | try { |
| | | sign = sign(body); |
| | |
| | | throw new RuntimeException(e); |
| | | } |
| | | body.put("hmac", sign); |
| | | post.body(body.toString()); |
| | | post.form(body); |
| | | log.info("支付接口请求参数:" + body); |
| | | HttpResponse execute = post.execute(); |
| | | log.info("支付接口请求响应:" + execute.body()); |
| | |
| | | public static QueryOrderResult queryOrder(String orderNo){ |
| | | String url = "https://trade.joinpay.com/tradeRt/queryOrder"; |
| | | HttpRequest post = HttpUtil.createPost(url); |
| | | post.header(Header.CONTENT_TYPE, "application/x-www-form-urlencoded"); |
| | | JSONObject body = new JSONObject(); |
| | | //版本号 |
| | | body.put("p0_Version", "2.5"); |
| | |
| | | throw new RuntimeException(e); |
| | | } |
| | | body.put("hmac", sign); |
| | | post.body(body.toString()); |
| | | post.form(body); |
| | | log.info("查询支付接口请求参数:" + body); |
| | | HttpResponse execute = post.execute(); |
| | | log.info("查询支付接口请求响应:" + execute.body()); |
| | |
| | | public static RefundResult refund(String orderNo, String refundOrderNo, Double refundAmount, String notifyUrl){ |
| | | String url = "https://trade.joinpay.com/tradeRt/refund"; |
| | | HttpRequest post = HttpUtil.createPost(url); |
| | | post.header(Header.CONTENT_TYPE, "application/x-www-form-urlencoded"); |
| | | JSONObject body = new JSONObject(); |
| | | //版本号 |
| | | body.put("p0_Version", "2.3"); |
| | |
| | | throw new RuntimeException(e); |
| | | } |
| | | body.put("hmac", sign); |
| | | post.body(body.toString()); |
| | | post.form(body); |
| | | log.info("退款接口请求参数:" + body); |
| | | HttpResponse execute = post.execute(); |
| | | log.info("退款接口请求响应:" + execute.body()); |
| | |
| | | public static QueryRefundResult queryRefund(String refundOrderNo){ |
| | | String url = "https://trade.joinpay.com/tradeRt/refund"; |
| | | HttpRequest post = HttpUtil.createPost(url); |
| | | post.header(Header.CONTENT_TYPE, "application/x-www-form-urlencoded"); |
| | | JSONObject body = new JSONObject(); |
| | | //版本号 |
| | | body.put("p0_Version", "2.3"); |
| | |
| | | throw new RuntimeException(e); |
| | | } |
| | | body.put("hmac", sign); |
| | | post.body(body.toString()); |
| | | post.form(body); |
| | | log.info("退款接口请求参数:" + body); |
| | | HttpResponse execute = post.execute(); |
| | | log.info("退款接口请求响应:" + execute.body()); |
| | |
| | | public static CloseOrderResult closeOrder(String orderNo){ |
| | | String url = "https://www.joinpay.com/trade/closeOrder.action"; |
| | | HttpRequest post = HttpUtil.createPost(url); |
| | | post.header(Header.CONTENT_TYPE, "application/x-www-form-urlencoded"); |
| | | JSONObject body = new JSONObject(); |
| | | //商户编号 |
| | | body.put("p1_MerchantNo", merchantNo); |
| | |
| | | throw new RuntimeException(e); |
| | | } |
| | | body.put("hmac", sign); |
| | | post.body(body.toString()); |
| | | post.form(body); |
| | | log.info("关闭订单接口请求参数:" + body); |
| | | HttpResponse execute = post.execute(); |
| | | log.info("关闭订单接口请求响应:" + execute.body()); |
| | |
| | | |
| | | |
| | | |
| | | public static String sign(JSONObject body) throws Exception{ |
| | | public static String sign(JSONObject body) { |
| | | Set<Map.Entry<String, Object>> entries = body.entrySet(); |
| | | List<Map.Entry<String, Object>> infoIds = new ArrayList<Map.Entry<String, Object>>(entries); |
| | | // 对所有传入参数按照字段名的 ASCII 码从小到大排序(字典序) |
| | | Collections.sort(infoIds, new Comparator<Map.Entry<String, Object>>() { |
| | | public int compare(Map.Entry<String, Object> o1, Map.Entry<String, Object> o2) { |
| | | return (o1.getKey()).toString().compareTo(o2.getKey()); |
| | | return (o1.getKey()).compareTo(o2.getKey()); |
| | | } |
| | | }); |
| | | // 构造签名键值对的格式 |
| | |
| | | } |
| | | } |
| | | sb.append(key); |
| | | log.info("待签名串:{}", sb.toString()); |
| | | return MD5AndKL.MD5(sb.toString()); |
| | | } |
| | | |
| | | |
| | | public static void main(String[] args) { |
| | | UniPayResult uniPayResult = PaymentUtil.uniPay("123456", 0.01D, "测试商品", "这是用于对接支付测试的商品描述", "", "", "", ""); |
| | | System.err.println(JSON.toJSONString(uniPayResult)); |
| | | // UniPayResult uniPayResult = PaymentUtil.uniPay("852963742", 0.01D, "测试商品", "这是用于对接支付测试的商品描述", |
| | | // "", "/order/shopping-cart/shoppingCartPaymentCallback", "ooOrs64zHLuInkZ_GF0LpIN9_Rxc", "777168500885852"); |
| | | // PaymentUtil.queryOrder("852963742"); |
| | | // PaymentUtil.closeOrder("852963742"); |
| | | |
| | | } |
| | | } |