From 64f7ccb9ef8b5a0618e65cddc14b981c1f108ba3 Mon Sep 17 00:00:00 2001 From: 无关风月 <443237572@qq.com> Date: 星期一, 04 十一月 2024 09:01:59 +0800 Subject: [PATCH] 代码提交 --- xinquan-modules/xinquan-order/src/main/java/com/xinquan/order/utils/JuHeFuUtil.java | 201 +++++++++++++++++++++++++++++++++++++++++-------- 1 files changed, 167 insertions(+), 34 deletions(-) diff --git a/xinquan-modules/xinquan-order/src/main/java/com/xinquan/order/utils/JuHeFuUtil.java b/xinquan-modules/xinquan-order/src/main/java/com/xinquan/order/utils/JuHeFuUtil.java index 7132651..bce3919 100644 --- a/xinquan-modules/xinquan-order/src/main/java/com/xinquan/order/utils/JuHeFuUtil.java +++ b/xinquan-modules/xinquan-order/src/main/java/com/xinquan/order/utils/JuHeFuUtil.java @@ -45,8 +45,11 @@ private static final String AES_KEY = "cb0a181ac97395c6942be19315fc0727"; // 创建用户接口 private static final String CREATE_USER_INTERFACE = "/api/member/create_user_a"; + private static final String BALANCE_PAY = "/api/account/balance_pay"; // 创建支付订单 private static final String CREATE_PAYMENT_INTERFACE = "/api/payment/create_payment"; + private static final String CREATE_PAYMENT_INTERFACE_CODE = "/api/payment/create_payment_qrcode"; + private static final String CREATE_PAYMENT_INTERFACE_THIRD = "/api/payment/create_payment_third"; // 退款接口 private static final String PAYMENT_REFUND_INTERFACE = "/api/payment/payment_refund"; private static final String MERCHANT_PAY_INTERFACE = "/api/account/merchant_pay"; @@ -56,6 +59,7 @@ private static final String PAY_CHANNEL_ALIPAY = "alipay_qr"; // 微信支付渠道 private static final String PAY_CHANNEL_WECHAT = "wx_lite"; + private static final String PAY_CHANNEL_WECHAT_THiRD = "wx"; // 微信小程序id TODO private static final String WX_APP_ID = ""; @@ -67,41 +71,70 @@ * @return boolean * @throws Exception */ - public static boolean createUser(String memberId, Map<String, Object> memberP) + public static boolean createUser(String memberId) throws Exception { + JSONObject memberP = new JSONObject(); + memberP.put("user_name","周帅"); + memberP.put("cert_type","00"); + memberP.put("cert_id","513902200006257079"); + memberP.put("tel_no","19983174515"); + memberP.put("card_id","6228480469852935177"); JSONObject data = new JSONObject(); data.put("app_id", APP_ID); data.put("member_id", memberId); data.put("member_type", "01"); - data.put("member_p", memberP); + String jsonString = JSON.toJSONString(JSONObject.parseObject(data.toString(), TreeMap.class)); + data.put("member_p", jsonString); + System.err.println(data); JSONObject body = new JSONObject(); body.put("merId", MER_ID); body.put("sign", sign(JSONObject.toJSONString(data))); body.put("reqCipher", EncryptUtils.aes256ECBPkcs7PaddingEncrypt(JSONObject.toJSONString(data), AES_KEY)); - body.put("reqTime", DateUtils.dateTimeNow("yyyyMMddHHmmssfff")); - // 发送Post请求 - logger.info("桔禾付创建用户请求体====================>{}", body.toJSONString()); + body.put("reqTime", DateUtils.dateTimeNow("yyyyMMddHHmmsssss")); + System.err.println(body); String result = sendPost(BASE_URL + CREATE_USER_INTERFACE, body); - logger.info("桔禾付创建用户请求结果====================>{}", result); - if (StringUtils.isBlank(result)) { - throw new ServiceException("请求第三方支付平台异常"); - } JSONObject resJsonObject = JSONObject.parseObject(result); - if (resJsonObject.getString("status").equals("succeeded")) { - return true; - } else if (resJsonObject.getString("status").equals("failed")) { - throw new ServiceException(resJsonObject.getString("error_msg")); - } + System.err.println(resJsonObject); return false; } public static void main(String[] args) throws Exception { - createPayment("MX123aaa9999911",1, "0.01", - "测试商品", "测试商品描述", - "221.182.45.100", "oG50n6Vf0JNid5DOg0brcAnZ0T4s", "https://v7ro848ar5jx.ngrok.xiaomiqiu123.top/order/client/order/order/testCallback"); + createPaymentCode("CZ19281833123", 1, "0.01", + "充值", "充值", + "127.0.0.1", "openId", + "https://v7ro848ar5jx.ngrok.xiaomiqiu123.top/order/client/order/order/base/callback"); +// String orderNo = OrderUtil.getOrderNoForPrefix("User"); +// createUser("usera12937812893718297391"); +//// balancePay("12345678912", "0.01", "http://www.baidu.com"); } + + public static JSONObject balancePay(String orderNo, String payAmt, String notifyUrl) throws Exception { + JSONObject data = new JSONObject(); + + data.put("order_no", orderNo); + data.put("app_id", APP_ID); + data.put("pay_amt", payAmt); + data.put("member_id", "21233333"); + data.put("notify_url", notifyUrl); + JSONObject body = new JSONObject(); + body.put("merId", MER_ID); + body.put("sign", sign(JSONObject.toJSONString(data))); + body.put("reqCipher", + EncryptUtils.aes256ECBPkcs7PaddingEncrypt(JSONObject.toJSONString(data), AES_KEY)); + body.put("reqTime", DateUtils.dateTimeNow("yyyyMMddHHmmsssss")); + String result = sendPost(BASE_URL + BALANCE_PAY, body); + JSONObject resJsonObject = JSONObject.parseObject(result); + System.err.println(resJsonObject); + String string = resJsonObject.getString("resCipher"); + String decrypt = decrypt(string); + System.err.println(decrypt); + JSONObject jsonObject = JSONObject.parseObject(decrypt); + System.err.println(jsonObject); + return null; + } + /** * 创建支付订单 * @@ -124,12 +157,14 @@ data.put("order_no", orderNo); data.put("app_id", APP_ID); if (payChannel == 1) { - data.put("pay_channel", PAY_CHANNEL_ALIPAY); - } else { data.put("pay_channel", PAY_CHANNEL_WECHAT); expand.put("open_id", openId); expand.put("wx_app_id", WX_APP_ID); data.put("expand", expand); + } else { + + data.put("pay_channel", PAY_CHANNEL_ALIPAY); + } data.put("pay_amt", payAmt); data.put("goods_title", goodsTitle); @@ -158,7 +193,103 @@ // if (resJsonObject.getString("status").equals("succeeded")) { // return resJsonObject.getJSONObject("expand"); // } + return jsonObject; + } + public static JSONObject createPaymentCode(String orderNo, Integer payChannel, String payAmt, + String goodsTitle, String goodsDesc, String deviceIp, String openId, + String notifyUrl) throws Exception { + JSONObject data = new JSONObject(); + JSONObject expand = new JSONObject(); + data.put("order_no", orderNo); + data.put("app_id", APP_ID); + if (payChannel == 1) { + data.put("pay_channel", PAY_CHANNEL_ALIPAY); + } else { + data.put("pay_channel", PAY_CHANNEL_WECHAT); + expand.put("open_id", openId); + expand.put("wx_app_id", WX_APP_ID); + data.put("expand", expand); + } + data.put("pay_amt", payAmt); + data.put("goods_title", goodsTitle); + data.put("goods_desc", goodsDesc); + data.put("time_expire", "20241031000000"); + Map<String, Object> deviceInfo = new HashMap<>(); + deviceInfo.put("device_ip", deviceIp); + data.put("device_info", deviceInfo); + data.put("notify_url", notifyUrl); + JSONObject body = new JSONObject(); + body.put("merId", MER_ID); + body.put("sign", sign(JSONObject.toJSONString(data))); + body.put("reqCipher", + EncryptUtils.aes256ECBPkcs7PaddingEncrypt(JSONObject.toJSONString(data), AES_KEY)); + body.put("reqTime", DateUtils.dateTimeNow("yyyyMMddHHmmsssss")); + String result = sendPost(BASE_URL + CREATE_PAYMENT_INTERFACE_CODE, body); + JSONObject resJsonObject = JSONObject.parseObject(result); + System.err.println(resJsonObject); + String string = resJsonObject.getString("resCipher"); + String decrypt = decrypt(string); + System.err.println(decrypt); + JSONObject jsonObject = JSONObject.parseObject(decrypt); + +// if (resJsonObject.getString("status").equals("failed")) { +// throw new ServiceException(resJsonObject.getString("error_msg")); +// } +// if (resJsonObject.getString("status").equals("succeeded")) { +// return resJsonObject.getJSONObject("expand"); +// } return jsonObject.getJSONObject("expand"); + } + /** + * 创建支付订单 微信托管支付 + * + * @param orderNo 订单号 + * @param payChannel 支付渠道 1:支付宝 2:微信 + * @param payAmt 支付金额 + * @param goodsTitle 商品标题 + * @param goodsDesc 商品描述信息,微信小程序和微信公众号该字段 最大长度 42 个字符 + * @param deviceIp 设备支付公网ip + * @param openId 微信openId + * @param notifyUrl 回调地址 + * @return JSONObject + * @throws Exception + */ + public static JSONObject createPayment1(String orderNo, Integer payChannel, String payAmt, + String goodsTitle, String goodsDesc, String deviceIp, String openId, + String notifyUrl) throws Exception { + JSONObject data = new JSONObject(); + JSONObject expand = new JSONObject(); + data.put("order_no", orderNo); + data.put("app_id", APP_ID); + data.put("pay_channel", PAY_CHANNEL_WECHAT_THiRD); + data.put("pay_amt", payAmt); + data.put("goods_title", goodsTitle); + data.put("goods_desc", goodsDesc); + Map<String, Object> deviceInfo = new HashMap<>(); + deviceInfo.put("device_ip", deviceIp); + data.put("device_info", deviceInfo); + data.put("notify_url", notifyUrl); + JSONObject body = new JSONObject(); + body.put("merId", MER_ID); + body.put("sign", sign(JSONObject.toJSONString(data))); + body.put("reqCipher", + EncryptUtils.aes256ECBPkcs7PaddingEncrypt(JSONObject.toJSONString(data), AES_KEY)); + body.put("reqTime", DateUtils.dateTimeNow("yyyyMMddHHmmsssss")); + String result = sendPost(BASE_URL + CREATE_PAYMENT_INTERFACE_THIRD, body); + JSONObject resJsonObject = JSONObject.parseObject(result); + System.err.println(resJsonObject); + String string = resJsonObject.getString("resCipher"); + String decrypt = decrypt(string); + System.err.println("解密后"+decrypt); + JSONObject jsonObject = JSONObject.parseObject(decrypt); + +// if (resJsonObject.getString("status").equals("failed")) { +// throw new ServiceException(resJsonObject.getString("error_msg")); +// } +// if (resJsonObject.getString("status").equals("succeeded")) { +// return resJsonObject.getJSONObject("expand"); +// } + return jsonObject; } /** @@ -168,7 +299,7 @@ * @param orderNo 订单号 * @return */ - public static boolean refund(String paymentId, String orderNo) throws Exception { + public static String refund(String paymentId, String orderNo) throws Exception { JSONObject data = new JSONObject(); data.put("payment_id", paymentId); data.put("order_no", orderNo); @@ -177,15 +308,15 @@ body.put("sign", sign(JSONObject.toJSONString(data))); body.put("reqCipher", EncryptUtils.aes256ECBPkcs7PaddingEncrypt(JSONObject.toJSONString(data), AES_KEY)); - body.put("reqTime", DateUtils.dateTimeNow("yyyyMMddHHmmssfff")); + body.put("reqTime", DateUtils.dateTimeNow("yyyyMMddHHmmsssss")); String result = sendPost(BASE_URL + PAYMENT_REFUND_INTERFACE, body); JSONObject resJsonObject = JSONObject.parseObject(result); - if (resJsonObject.getString("status").equals("succeeded")) { - return true; - } else if (resJsonObject.getString("status").equals("failed")) { - throw new ServiceException(resJsonObject.getString("error_msg")); - } - return false; +// if (resJsonObject.getString("status").equals("succeeded")) { +// return "ok"; +// } else if (resJsonObject.getString("status").equals("failed")) { +// throw new ServiceException(resJsonObject.getString("error_msg")); +// } + return "ok"; } /** @@ -200,14 +331,16 @@ * @return * @throws Exception */ - public static boolean merchantPay(String orderNo, String payAmt, String cardName, String cardId, + public static JSONObject merchantPay(String orderNo, String payAmt, String cardName, String cardId, String cardType) throws Exception { JSONObject data = new JSONObject(); data.put("order_no", orderNo); + data.put("app_id", APP_ID); data.put("pay_amt", payAmt); data.put("card_name", cardName); data.put("card_id", cardId); + data.put("card_type", cardType); JSONObject body = new JSONObject(); body.put("merId", MER_ID); body.put("sign", sign(JSONObject.toJSONString(data))); @@ -216,12 +349,12 @@ body.put("reqTime", DateUtils.dateTimeNow("yyyyMMddHHmmss")); String result = sendPost(BASE_URL + MERCHANT_PAY_INTERFACE, body); JSONObject resJsonObject = JSONObject.parseObject(result); - if (resJsonObject.getString("status").equals("succeeded")) { - return true; - } else if (resJsonObject.getString("status").equals("failed")) { - throw new ServiceException(resJsonObject.getString("error_msg")); - } - return false; + System.err.println(resJsonObject); + String string = resJsonObject.getString("resCipher"); + String decrypt = decrypt(string); + System.err.println("解密后"+decrypt); + JSONObject jsonObject = JSONObject.parseObject(decrypt); + return jsonObject; } /** -- Gitblit v1.7.1