From 53e7558400dcacecdce70e39ebfe1727740f9296 Mon Sep 17 00:00:00 2001
From: puzhibing <393733352@qq.com>
Date: 星期六, 25 十一月 2023 17:20:06 +0800
Subject: [PATCH] 重写课包支付和排课逻辑
---
cloud-server-competition/src/main/java/com/dsh/competition/util/PayMoneyUtil.java | 253 ++++++++++++++++++++++++++------------------------
1 files changed, 133 insertions(+), 120 deletions(-)
diff --git a/cloud-server-competition/src/main/java/com/dsh/competition/util/PayMoneyUtil.java b/cloud-server-competition/src/main/java/com/dsh/competition/util/PayMoneyUtil.java
index 5996da1..e85dd04 100644
--- a/cloud-server-competition/src/main/java/com/dsh/competition/util/PayMoneyUtil.java
+++ b/cloud-server-competition/src/main/java/com/dsh/competition/util/PayMoneyUtil.java
@@ -68,11 +68,10 @@
private String certPath = "C:\\cert\\1523106371_20211206_cert\\apiclient_cert.p12";//微信证书
-
/**
* 支付宝支付
*/
- public ResultUtil alipay(String body, String subject, String passbackParams, String outTradeNo, String amount, String notifyUrl){
+ public ResultUtil alipay(String body, String subject, String passbackParams, String outTradeNo, String amount, String notifyUrl) {
// //构造client
// CertAlipayRequest certAlipayRequest = new CertAlipayRequest ();
// //设置网关地址
@@ -156,6 +155,7 @@
/**
* 支付宝扫码支付下单
+ *
* @param body
* @param subject
* @param outTradeNo
@@ -163,7 +163,7 @@
* @param notifyUrl
* @return
*/
- public ResultUtil aliScanCodePay(String body, String subject, String outTradeNo, String amount, String notifyUrl){
+ public ResultUtil aliScanCodePay(String body, String subject, String outTradeNo, String amount, String notifyUrl) {
AlipayClient alipayClient = new DefaultAlipayClient("https://openapi.alipay.com/gateway.do", aliAppid, appPrivateKey, "json", "UTF-8", alipay_public_key, "RSA2"); //获得初始化的AlipayClient
AlipayTradePrecreateRequest request = new AlipayTradePrecreateRequest();//创建API对应的request类
request.setBizContent("{" +
@@ -189,13 +189,14 @@
/**
* 支付成功后的回调处理逻辑
+ *
* @param request
*/
- public Map<String, String> alipayCallback(HttpServletRequest request){
+ public Map<String, String> alipayCallback(HttpServletRequest request) {
//获取支付宝POST过来反馈信息
- Map<String,String> params = new HashMap<String,String>();
+ Map<String, String> params = new HashMap<String, String>();
Map requestParams = request.getParameterMap();
- for (Iterator iter = requestParams.keySet().iterator(); iter.hasNext();) {
+ for (Iterator iter = requestParams.keySet().iterator(); iter.hasNext(); ) {
String name = (String) iter.next();
String[] values = (String[]) requestParams.get(name);
String valueStr = "";
@@ -251,18 +252,19 @@
/**
* 支付宝查询订单支付状态
+ *
* @param out_trade_no
* @return
* @throws Exception
*/
- public AlipayTradeQueryResponse queryALIOrder(String out_trade_no) throws Exception{
- AlipayClient alipayClient = new DefaultAlipayClient("https://openapi.alipay.com/gateway.do",aliAppid, appPrivateKey,"json","UTF-8",alipay_public_key,"RSA2");
+ public AlipayTradeQueryResponse queryALIOrder(String out_trade_no) throws Exception {
+ AlipayClient alipayClient = new DefaultAlipayClient("https://openapi.alipay.com/gateway.do", aliAppid, appPrivateKey, "json", "UTF-8", alipay_public_key, "RSA2");
AlipayTradeQueryRequest request = new AlipayTradeQueryRequest();
request.setBizContent("{" +
" \"out_trade_no\":\"" + out_trade_no + "\"" +
"}");
AlipayTradeQueryResponse response = alipayClient.execute(request);
- if(response.isSuccess()){
+ if (response.isSuccess()) {
String tradeStatus = response.getTradeStatus();//交易状态:WAIT_BUYER_PAY(交易创建,等待买家付款)、TRADE_CLOSED(未付款交易超时关闭,或支付完成后全额退款)、TRADE_SUCCESS(交易支付成功)、TRADE_FINISHED(交易结束,不可退款)
// return ResultUtil.success(tradeStatus);
return response;
@@ -272,18 +274,18 @@
}
-
/**
* 微信统一下单
- * @param body 商品描述
- * @param attach 附加数据
- * @param out_trade_no 商户订单号
- * @param total_fee 标价金额
- * @param notify_url 通知地址
- * @param tradeType 交易类型
+ *
+ * @param body 商品描述
+ * @param attach 附加数据
+ * @param out_trade_no 商户订单号
+ * @param total_fee 标价金额
+ * @param notify_url 通知地址
+ * @param tradeType 交易类型
* @return
*/
- public ResultUtil weixinpay(String body, String attach, String out_trade_no, String total_fee, String notify_url, String tradeType, String openId) throws Exception{
+ public ResultUtil weixinpay(String body, String attach, String out_trade_no, String total_fee, String notify_url, String tradeType, String openId) throws Exception {
int i = new BigDecimal(total_fee).multiply(new BigDecimal("100")).intValue();
String hostAddress = null;
try {
@@ -303,7 +305,7 @@
map.put("spbill_create_ip", hostAddress);
map.put("notify_url", callbackPath + notify_url);
map.put("trade_type", tradeType);
- if("JSAPI".equals(tradeType)){
+ if ("JSAPI".equals(tradeType)) {
map.put("openid", openId);
}
String s = this.weixinSignature(map);
@@ -319,7 +321,7 @@
keys = strings.toArray(keys);
Arrays.sort(keys);
xmlString.append("<xml>");
- for(int l = 0; l < keys.length; l++){
+ for (int l = 0; l < keys.length; l++) {
xmlString.append("<" + keys[l] + ">" + map.get(keys[l]) + "</" + keys[l] + ">");
}
xmlString.append("</xml>");
@@ -327,7 +329,7 @@
Map<String, String> map1 = null;
String body1 = HttpClientUtil.pushHttpRequsetXml(url, xmlString.toString(), new HashMap<>()).getData();
//将结果xml解析成map
- body1 = body1.replaceAll("<!\\[CDATA\\[","");
+ body1 = body1.replaceAll("<!\\[CDATA\\[", "");
body1 = body1.replaceAll("]]>", "");
try {
map1 = this.xmlToMap(body1, "UTF-8");
@@ -337,12 +339,12 @@
e.printStackTrace();
}
String return_code = map1.get("return_code");
- if("SUCCESS".equals(return_code)){
+ if ("SUCCESS".equals(return_code)) {
String result_code = map1.get("result_code");
- if("SUCCESS".equals(result_code)){
+ if ("SUCCESS".equals(result_code)) {
String type = map1.get("trade_type");
String prepay_id = map1.get("prepay_id");
- switch (type){
+ switch (type) {
case "JSAPI":
//重新进行签名后返回给前端
Map<String, Object> map2 = new HashMap<>();
@@ -377,34 +379,32 @@
return ResultUtil.success(map3);
}
return null;
- }else{
+ } else {
System.err.println(map1.get("err_code_des"));
return ResultUtil.error(map1.get("err_code_des"));
}
- }else{
+ } else {
System.err.println(map1.get("return_msg") + appid + "----" + mchId);
return ResultUtil.error(map1.get("return_msg"), new JSONObject());
}
}
-
-
-
/**
* 微信支付成功后的回调处理
+ *
* @param request
*/
- public Map<String, String> weixinpayCallback(HttpServletRequest request){
+ public Map<String, String> weixinpayCallback(HttpServletRequest request) {
try {
String param = this.getParam(request);
- param = param.replaceAll("<!\\[CDATA\\[","");
+ param = param.replaceAll("<!\\[CDATA\\[", "");
param = param.replaceAll("]]>", "");
Map<String, String> map = this.xmlToMap(param, "UTF-8");
String return_code = map.get("return_code");
- if("SUCCESS".equals(return_code)){
+ if ("SUCCESS".equals(return_code)) {
String result_code = map.get("result_code");
- if("SUCCESS".equals(result_code)){
+ if ("SUCCESS".equals(result_code)) {
Map<String, String> map1 = new HashedMap();
map1.put("nonce_str", map.get("nonce_str"));
map1.put("out_trade_no", map.get("out_trade_no"));//存储的订单code
@@ -414,10 +414,10 @@
String result = "<xml><return_code><![CDATA[SUCCESS]]></return_code><return_msg><![CDATA[OK]]></return_msg></xml>";
map1.put("result", result);
return map1;
- }else{
+ } else {
System.err.println(map.get("err_code_des"));
}
- }else{
+ } else {
System.err.println(map.get("return_msg"));
}
} catch (IOException e) {
@@ -431,15 +431,16 @@
/**
* 微信扫码收款
- * @param body 商品描述
- * @param attach 附加数据
- * @param nonce_str 随机字符串
- * @param out_trade_no 商户订单号
- * @param total_fee 订单金额
- * @param auth_code 授权码 扫码支付授权码,设备读取用户微信中的条码或者二维码信息(注:用户付款码条形码规则:18位纯数字,以10、11、12、13、14、15开头)
+ *
+ * @param body 商品描述
+ * @param attach 附加数据
+ * @param nonce_str 随机字符串
+ * @param out_trade_no 商户订单号
+ * @param total_fee 订单金额
+ * @param auth_code 授权码 扫码支付授权码,设备读取用户微信中的条码或者二维码信息(注:用户付款码条形码规则:18位纯数字,以10、11、12、13、14、15开头)
* @return
*/
- public ResultUtil wxScanQRCodePay(String body, String attach, String nonce_str, String out_trade_no, String total_fee, String auth_code){
+ public ResultUtil wxScanQRCodePay(String body, String attach, String nonce_str, String out_trade_no, String total_fee, String auth_code) {
int i = new BigDecimal(total_fee).multiply(new BigDecimal("100")).intValue();
String hostAddress = null;
try {
@@ -477,7 +478,7 @@
keys = strings.toArray(keys);
Arrays.sort(keys);
xmlString.append("<xml>");
- for(int l = 0; l < keys.length; l++){
+ for (int l = 0; l < keys.length; l++) {
xmlString.append("<" + keys[l] + ">" + map.get(keys[l]) + "</" + keys[l] + ">");
}
xmlString.append("</xml>");
@@ -490,7 +491,7 @@
e.printStackTrace();
}
//将结果xml解析成map
- body1 = body1.replaceAll("<!\\[CDATA\\[","");
+ body1 = body1.replaceAll("<!\\[CDATA\\[", "");
body1 = body1.replaceAll("]]>", "");
try {
map1 = this.xmlToMap(body1, "UTF-8");
@@ -500,11 +501,11 @@
e.printStackTrace();
}
String return_code = map1.get("return_code");
- if("SUCCESS".equals(return_code)){
+ if ("SUCCESS".equals(return_code)) {
String result_code = map1.get("result_code");
- if("SUCCESS".equals(result_code)){
+ if ("SUCCESS".equals(result_code)) {
String type = map1.get("trade_type");
- switch (type){
+ switch (type) {
case "JSAPI":
break;
case "NATIVE":
@@ -528,11 +529,11 @@
return ResultUtil.success(map2);
}
return null;
- }else{
+ } else {
// System.err.println(map1.get("err_code_des"));
return ResultUtil.error(map1.get("err_code_des"));
}
- }else{
+ } else {
// System.err.println(map1.get("return_msg") + appid + "----" + mchId);
return ResultUtil.error(map1.get("return_msg"), new JSONObject());
}
@@ -541,24 +542,26 @@
/**
* 支付宝扫码收款
+ *
* @param data
* @return
*/
- public Object aliScanQRCodePay(String data){
+ public Object aliScanQRCodePay(String data) {
return null;
}
/**
* 微信退款申请
- * @param transaction_id 微信订单号。微信生成的订单号,在支付通知中有返回
- * @param out_refund_no 商户退款单号。商户系统内部的退款单号,商户系统内部唯一,只能是数字、大小写字母_-|*@ ,同一退款单号多次请求只退一笔。
- * @param total_fee 订单金额。订单总金额,单位为分,只能为整数
- * @param refund_fee 退款金额。退款总金额,订单总金额,单位为分,只能为整数
- * @param notify_url 退款结果通知url。异步接收微信支付退款结果通知的回调地址,通知URL必须为外网可访问的url,不允许带参数 如果参数中传了notify_url,则商户平台上配置的回调地址将不会生效。
+ *
+ * @param transaction_id 微信订单号。微信生成的订单号,在支付通知中有返回
+ * @param out_refund_no 商户退款单号。商户系统内部的退款单号,商户系统内部唯一,只能是数字、大小写字母_-|*@ ,同一退款单号多次请求只退一笔。
+ * @param total_fee 订单金额。订单总金额,单位为分,只能为整数
+ * @param refund_fee 退款金额。退款总金额,订单总金额,单位为分,只能为整数
+ * @param notify_url 退款结果通知url。异步接收微信支付退款结果通知的回调地址,通知URL必须为外网可访问的url,不允许带参数 如果参数中传了notify_url,则商户平台上配置的回调地址将不会生效。
* @return
*/
- public Map<String, String> wxRefund(String transaction_id, String out_refund_no, String total_fee, String refund_fee, String notify_url){
+ public Map<String, String> wxRefund(String transaction_id, String out_refund_no, String total_fee, String refund_fee, String notify_url) {
int tf = new BigDecimal(total_fee).multiply(new BigDecimal("100")).intValue();
int rf = new BigDecimal(refund_fee).multiply(new BigDecimal("100")).intValue();
String nonce_str = UUIDUtil.getRandomCode();
@@ -584,7 +587,7 @@
keys = strings.toArray(keys);
Arrays.sort(keys);
xmlString.append("<xml>");
- for(int l = 0; l < keys.length; l++){
+ for (int l = 0; l < keys.length; l++) {
xmlString.append("<" + keys[l] + ">" + map.get(keys[l]) + "</" + keys[l] + ">");
}
xmlString.append("</xml>");
@@ -598,7 +601,7 @@
}
System.err.println(body1);
//将结果xml解析成map
- body1 = body1.replaceAll("<!\\[CDATA\\[","");
+ body1 = body1.replaceAll("<!\\[CDATA\\[", "");
body1 = body1.replaceAll("]]>", "");
try {
map1 = this.xmlToMap(body1, "UTF-8");
@@ -609,19 +612,19 @@
}
String return_code = map1.get("return_code");
Map<String, String> map2 = new HashMap<>();
- if("SUCCESS".equals(return_code)){
+ if ("SUCCESS".equals(return_code)) {
String result_code = map1.get("result_code");
- if("SUCCESS".equals(result_code)){
+ if ("SUCCESS".equals(result_code)) {
map2.put("return_code", result_code);
map2.put("refund_id", String.valueOf(map1.get("refund_id")));//微信退款订单号
map2.put("refund_fee", String.valueOf(map1.get("refund_fee")));//退款金额
return map2;
- }else{
+ } else {
map2.put("return_code", result_code);
map2.put("return_msg", map1.get("err_code_des"));
return map2;
}
- }else{
+ } else {
map2.put("return_code", return_code);
map2.put("return_msg", map1.get("return_msg"));
return map2;
@@ -631,20 +634,21 @@
/**
* 微信退款成功后的回调处理
+ *
* @param request
* @return
*/
- public Map<String, String> wxRefundCallback(HttpServletRequest request){
+ public Map<String, String> wxRefundCallback(HttpServletRequest request) {
try {
String param = this.getParam(request);
- param = param.replaceAll("<!\\[CDATA\\[","");
+ param = param.replaceAll("<!\\[CDATA\\[", "");
param = param.replaceAll("]]>", "");
Map<String, String> map = this.xmlToMap(param, "UTF-8");
String return_code = map.get("return_code");
- if("SUCCESS".equals(return_code)){
+ if ("SUCCESS".equals(return_code)) {
String req_info = map.get("req_info");//加密信息请用商户秘钥进行解密
String s = this.wxDecrypt(req_info);
- s = s.replaceAll("<!\\[CDATA\\[","");
+ s = s.replaceAll("<!\\[CDATA\\[", "");
s = s.replaceAll("]]>", "");
map = this.xmlToMap(s, "UTF-8");
Map<String, String> map1 = new HashMap<>();
@@ -653,7 +657,7 @@
String result = "<xml><return_code><![CDATA[SUCCESS]]></return_code><return_msg><![CDATA[OK]]></return_msg></xml>";
map1.put("result", result);
return map1;
- }else{
+ } else {
// System.err.println(map.get("return_msg"));
}
} catch (IOException e) {
@@ -679,13 +683,14 @@
/**
* 支付宝退款
- * @param trade_no 支付宝交易号
- * @param refund_amount 退款金额
+ *
+ * @param trade_no 支付宝交易号
+ * @param refund_amount 退款金额
* @return
* @throws AlipayApiException
*/
public Map<String, String> aliRefund(String trade_no, String refund_amount) throws AlipayApiException {
- AlipayClient alipayClient = new DefaultAlipayClient("https://openapi.alipay.com/gateway.do", aliAppid, appPrivateKey,"json","UTF-8", alipay_public_key,"RSA2");
+ AlipayClient alipayClient = new DefaultAlipayClient("https://openapi.alipay.com/gateway.do", aliAppid, appPrivateKey, "json", "UTF-8", alipay_public_key, "RSA2");
AlipayTradeRefundRequest request = new AlipayTradeRefundRequest();
JSONObject jsonObject = new JSONObject();
jsonObject.put("trade_no", trade_no);
@@ -693,7 +698,7 @@
request.setBizContent(jsonObject.toJSONString());
AlipayTradeRefundResponse response = alipayClient.execute(request);
Map<String, String> map = new HashMap<>();
- if(response.isSuccess()){
+ if (response.isSuccess()) {
System.out.println("调用成功");
String outTradeNo = response.getOutTradeNo();
map.put("code", response.getCode());//10000
@@ -710,10 +715,11 @@
/**
* 查询微信支付订单
+ *
* @return
* @throws Exception
*/
- public ResultUtil<Map<String, String>> queryWXOrder(String out_trade_no, String transaction_id) throws Exception{
+ public ResultUtil<Map<String, String>> queryWXOrder(String out_trade_no, String transaction_id) throws Exception {
String url = "https://api.mch.weixin.qq.com/pay/orderquery";
String nonce_str = UUIDUtil.getRandomCode(16);
Map<String, Object> map = new HashMap<>();
@@ -734,7 +740,7 @@
keys = strings.toArray(keys);
Arrays.sort(keys);
xmlString.append("<xml>");
- for(int l = 0; l < keys.length; l++){
+ for (int l = 0; l < keys.length; l++) {
xmlString.append("<" + keys[l] + ">" + map.get(keys[l]) + "</" + keys[l] + ">");
}
xmlString.append("</xml>");
@@ -742,7 +748,7 @@
Map<String, String> map1 = null;
String body1 = HttpClientUtil.pushHttpRequsetXml(url, xmlString.toString(), new HashMap<>()).getData();
//将结果xml解析成map
- body1 = body1.replaceAll("<!\\[CDATA\\[","");
+ body1 = body1.replaceAll("<!\\[CDATA\\[", "");
body1 = body1.replaceAll("]]>", "");
try {
map1 = this.xmlToMap(body1, "UTF-8");
@@ -752,35 +758,35 @@
e.printStackTrace();
}
String return_code = map1.get("return_code");
- if("SUCCESS".equals(return_code)){
+ if ("SUCCESS".equals(return_code)) {
String result_code = map1.get("result_code");
- if("SUCCESS".equals(result_code)){
+ if ("SUCCESS".equals(result_code)) {
Map<String, String> map2 = new HashMap<>();
map2.put("trade_type", map1.get("trade_type"));
map2.put("trade_state", map1.get("trade_state"));//订单状态SUCCESS—支付成功,REFUND—转入退款,NOTPAY—未支付,CLOSED—已关闭,REVOKED—已撤销(刷卡支付),USERPAYING--用户支付中,PAYERROR--支付失败(其他原因,如银行返回失败)
map2.put("transaction_id", map1.get("transaction_id"));
return ResultUtil.success(map2);
- }else{
+ } else {
System.err.println(map1.get("err_code_des"));
return ResultUtil.error(map1.get("err_code_des"));
}
- }else{
+ } else {
System.err.println(map1.get("return_msg") + appid + "----" + mchId);
return ResultUtil.error(map1.get("return_msg"));
}
}
-
/**
* 微信转账功能(企业付款到零钱)
- * @param openid 商户appid下,某用户的openid
- * @param desc 企业付款备注,必填。
- * @param total_fee 企业付款金额
- * @param partner_trade_no 商户订单号,需保持唯一性
+ *
+ * @param openid 商户appid下,某用户的openid
+ * @param desc 企业付款备注,必填。
+ * @param total_fee 企业付款金额
+ * @param partner_trade_no 商户订单号,需保持唯一性
* @return
*/
- public Map<String, String> wxTransfers(String openid, String desc, String total_fee, String partner_trade_no) throws Exception{
+ public Map<String, String> wxTransfers(String openid, String desc, String total_fee, String partner_trade_no) throws Exception {
int amount = new BigDecimal(total_fee).multiply(new BigDecimal("100")).intValue();
String nonce_str = UUIDUtil.getRandomCode();
Map<String, Object> map = new HashMap<>();
@@ -805,7 +811,7 @@
keys = strings.toArray(keys);
Arrays.sort(keys);
xmlString.append("<xml>");
- for(int l = 0; l < keys.length; l++){
+ for (int l = 0; l < keys.length; l++) {
xmlString.append("<" + keys[l] + ">" + map.get(keys[l]) + "</" + keys[l] + ">");
}
xmlString.append("</xml>");
@@ -813,7 +819,7 @@
Map<String, String> map1 = null;
String body1 = HttpClientUtil.pushHttpsRequsetXml(url, xmlString.toString(), new HashMap<>(), mchId, certPath, "PKCS12");
//将结果xml解析成map
- body1 = body1.replaceAll("<!\\[CDATA\\[","");
+ body1 = body1.replaceAll("<!\\[CDATA\\[", "");
body1 = body1.replaceAll("]]>", "");
try {
map1 = this.xmlToMap(body1, "UTF-8");
@@ -824,20 +830,20 @@
}
String return_code = map1.get("return_code");
Map<String, String> map2 = new HashMap<>();
- if("SUCCESS".equals(return_code)){
+ if ("SUCCESS".equals(return_code)) {
String result_code = map1.get("result_code");
- if("SUCCESS".equals(result_code)){
+ if ("SUCCESS".equals(result_code)) {
map2.put("return_code", result_code);
map2.put("payment_no", String.valueOf(map1.get("payment_no")));//付款订单号
map2.put("payment_time", String.valueOf(map1.get("payment_time")));//付款时间
return map2;
- }else{
+ } else {
map2.put("return_code", result_code);
map2.put("err_code", map1.get("err_code"));
map2.put("err_code_des", map1.get("err_code_des"));
return map2;
}
- }else{
+ } else {
map2.put("return_code", return_code);
map2.put("return_msg", map1.get("return_msg"));
return map2;
@@ -847,16 +853,17 @@
/**
* 微信转账功能(企业付款到银行卡)
- * @param desc 备注信息
- * @param total_fee 转账金额
- * @param partner_trade_no 订单号
- * @param enc_bank_no 银行卡号
- * @param enc_true_name 收款方用户名
- * @param bankName 银行名称
+ *
+ * @param desc 备注信息
+ * @param total_fee 转账金额
+ * @param partner_trade_no 订单号
+ * @param enc_bank_no 银行卡号
+ * @param enc_true_name 收款方用户名
+ * @param bankName 银行名称
* @return
* @throws Exception
*/
- public Map<String, String> wxPayBank(String desc, String total_fee, String partner_trade_no, String enc_bank_no, String enc_true_name, String bankName) throws Exception{
+ public Map<String, String> wxPayBank(String desc, String total_fee, String partner_trade_no, String enc_bank_no, String enc_true_name, String bankName) throws Exception {
int amount = new BigDecimal(total_fee).multiply(new BigDecimal("100")).intValue();
String nonce_str = UUIDUtil.getRandomCode();
Map<String, Object> map = new HashMap<>();
@@ -881,7 +888,7 @@
keys = strings.toArray(keys);
Arrays.sort(keys);
xmlString.append("<xml>");
- for(int l = 0; l < keys.length; l++){
+ for (int l = 0; l < keys.length; l++) {
xmlString.append("<" + keys[l] + ">" + map.get(keys[l]) + "</" + keys[l] + ">");
}
xmlString.append("</xml>");
@@ -889,7 +896,7 @@
Map<String, String> map1 = null;
String body1 = HttpClientUtil.pushHttpsRequsetXml(url, xmlString.toString(), new HashMap<>(), mchId, certPath, "PKCS12");
//将结果xml解析成map
- body1 = body1.replaceAll("<!\\[CDATA\\[","");
+ body1 = body1.replaceAll("<!\\[CDATA\\[", "");
body1 = body1.replaceAll("]]>", "");
try {
map1 = this.xmlToMap(body1, "UTF-8");
@@ -900,20 +907,20 @@
}
String return_code = map1.get("return_code");
Map<String, String> map2 = new HashMap<>();
- if("SUCCESS".equals(return_code)){
+ if ("SUCCESS".equals(return_code)) {
String result_code = map1.get("result_code");
- if("SUCCESS".equals(result_code)){
+ if ("SUCCESS".equals(result_code)) {
map2.put("return_code", result_code);
map2.put("payment_no", String.valueOf(map1.get("payment_no")));//付款订单号
map2.put("cmms_amt", String.valueOf(map1.get("cmms_amt")));//手续费金额 RMB:分
return map2;
- }else{
+ } else {
map2.put("return_code", result_code);
map2.put("err_code", map1.get("err_code"));
map2.put("err_code_des", map1.get("err_code_des"));
return map2;
}
- }else{
+ } else {
map2.put("return_code", return_code);
map2.put("return_msg", map1.get("return_msg"));
return map2;
@@ -922,15 +929,16 @@
/**
* 微信转账到银行卡不编号
+ *
* @param bankName
* @return
*/
- public String findBankCode(String bankName){
+ public String findBankCode(String bankName) {
String json = "{\"工商银行 \":1002,\"农业银行\":1005,\"建设银行\":1003,\"中国银行\":1026,\"交通银行 \":1020,\"招商银行 \":1001,\"邮储银行\":1066,\"民生银行 \":1006,\"平安银行 \":1010,\"中信银行\":1021,\"浦发银行 \":1004,\"兴业银行 \":1009,\"光大银行 \":1022,\"广发银行\":1027,\"华夏银行\":1025,\"宁波银行\":1056,\"北京银行\":4836,\"上海银行\":1024,\"南京银行\":1054,\"长子县融汇村镇银行\":4755,\"长沙银行\":4216,\"浙江泰隆商业银行\":4051,\"中原银行 \":4753,\"企业银行(中国)\":4761,\"顺德农商银行 \":4036,\"衡水银行\":4752,\"长治银行\":4756,\"大同银行\":4767,\"河南省农村信用社\":4115,\"宁夏黄河农村商业银行\":4150,\"山西省农村信用社\":4156,\"安徽省农村信用社\":4166,\"甘肃省农村信用社\":4157,\"天津农村商业银行\":4153,\"广西壮族自治区农村信用社\":4113,\"陕西省农村信用社\":4108,\"深圳农村商业银行\":4076,\"宁波鄞州农村商业银行\":4052,\"浙江省农村信用社联合社\":4764,\"江苏省农村信用社联合社\":4217,\"江苏紫金农村商业银行股份有限公司 \":4072,\"北京中关村银行股份有限公司 \":4769,\"星展银行( 中国) 有限公司 \":4778,\"枣庄银行股份有限公司 \":4766,\"海口联合农村商业银行股份有限公司 \":4758,\"南洋商业银行( 中国) 有限公司 \":4763}";
JSONObject jsonObject = JSON.parseObject(json);
Set<String> strings = jsonObject.keySet();
- for(String key : strings){
- if(key.indexOf(bankName) >= 0){
+ for (String key : strings) {
+ if (key.indexOf(bankName) >= 0) {
return jsonObject.getString(key);
}
}
@@ -938,19 +946,19 @@
}
-
/**
* 支付宝转账
- * @param out_biz_no 商家侧唯一订单号,由商家自定义。对于不同转账请求,商家需保证该订单号在自身系统唯一。
- * @param trans_amount 订单总金额,单位为元,精确到小数点后两位
- * @param order_title 转账业务的标题,用于在支付宝用户的账单里显示
- * @param identity 参与方的唯一标识(收款方支付宝账号)
- * @param name 参与方真实姓名,如果非空,将校验收款支付宝账号姓名一致性。
- * @param remark 业务备注
+ *
+ * @param out_biz_no 商家侧唯一订单号,由商家自定义。对于不同转账请求,商家需保证该订单号在自身系统唯一。
+ * @param trans_amount 订单总金额,单位为元,精确到小数点后两位
+ * @param order_title 转账业务的标题,用于在支付宝用户的账单里显示
+ * @param identity 参与方的唯一标识(收款方支付宝账号)
+ * @param name 参与方真实姓名,如果非空,将校验收款支付宝账号姓名一致性。
+ * @param remark 业务备注
* @return
* @throws Exception
*/
- public Map<String, Object> aliTransfer(String out_biz_no, Double trans_amount, String order_title, String identity, String name, String remark) throws Exception{
+ public Map<String, Object> aliTransfer(String out_biz_no, Double trans_amount, String order_title, String identity, String name, String remark) throws Exception {
CertAlipayRequest certAlipayRequest = new CertAlipayRequest();
certAlipayRequest.setServerUrl("https://openapi.alipay.com/gateway.do"); //gateway:支付宝网关(固定)https://openapi.alipay.com/gateway.do
certAlipayRequest.setAppId(aliAppid); //APPID 即创建应用后生成,详情见创建应用并获取 APPID
@@ -978,13 +986,13 @@
"}");
AlipayFundTransUniTransferResponse response = alipayClient.certificateExecute(request);
Map<String, Object> map = new HashMap<>();
- if(response.isSuccess()){
+ if (response.isSuccess()) {
String status = response.getStatus();
- if(status.equals("SUCCESS")){//成功
+ if (status.equals("SUCCESS")) {//成功
map.put("code", response.getCode());
map.put("order_id", response.getOrderId());//支付宝订单号
map.put("pay_fund_order_id", response.getPayFundOrderId());//支付宝流水号
- }else{
+ } else {
map.put("code", response.getCode());
map.put("sub_msg", response.getSubMsg());
}
@@ -998,6 +1006,7 @@
/**
* 获取请求内容
+ *
* @param request
* @return
* @throws IOException
@@ -1020,10 +1029,11 @@
/**
* 微信下单的签名算法
+ *
* @param map
* @return
*/
- private String weixinSignature(Map<String, Object> map){
+ private String weixinSignature(Map<String, Object> map) {
try {
Set<Map.Entry<String, Object>> entries = map.entrySet();
List<Map.Entry<String, Object>> infoIds = new ArrayList<Map.Entry<String, Object>>(entries);
@@ -1056,10 +1066,11 @@
/**
* 微信下单的签名算法
+ *
* @param map
* @return
*/
- private String weixinSignature(Map<String, Object> map, String key_){
+ private String weixinSignature(Map<String, Object> map, String key_) {
try {
Set<Map.Entry<String, Object>> entries = map.entrySet();
List<Map.Entry<String, Object>> infoIds = new ArrayList<Map.Entry<String, Object>>(entries);
@@ -1092,6 +1103,7 @@
/**
* 微信退款成功后的解密
+ *
* @param req_info
* @return
*/
@@ -1099,7 +1111,7 @@
InvalidKeyException, BadPaddingException, IllegalBlockSizeException {
byte[] decode = Base64.getDecoder().decode(req_info);
String sign = MD5AndKL.MD5Encode(key, "UTF-8").toLowerCase();
- if (Security.getProvider("BC") == null){
+ if (Security.getProvider("BC") == null) {
Security.addProvider(new BouncyCastleProvider());
}
Cipher cipher = Cipher.getInstance("AES/ECB/PKCS7Padding", "BC");
@@ -1125,6 +1137,7 @@
/**
* xml转map
+ *
* @param xml
* @param charset
* @return
@@ -1142,7 +1155,7 @@
return respMap;
}
- public static Map<String, String> xmlToMap(Element tmpElement, Map<String, String> respMap){
+ public static Map<String, String> xmlToMap(Element tmpElement, Map<String, String> respMap) {
if (tmpElement.isTextOnly()) {
respMap.put(tmpElement.getName(), tmpElement.getText());
return respMap;
--
Gitblit v1.7.1