From f0753e3b608ba47deaaf4619924bb8765003fd1d Mon Sep 17 00:00:00 2001
From: puzhibing <393733352@qq.com>
Date: 星期五, 08 十二月 2023 17:25:12 +0800
Subject: [PATCH] Merge branch 'master' of http://120.76.84.145:10101/gitblit/r/java/PlayPai
---
cloud-server-account/src/main/java/com/dsh/account/util/PayMoneyUtil.java | 259 +++++++++++++++++++++++++++------------------------
1 files changed, 136 insertions(+), 123 deletions(-)
diff --git a/cloud-server-account/src/main/java/com/dsh/account/util/PayMoneyUtil.java b/cloud-server-account/src/main/java/com/dsh/account/util/PayMoneyUtil.java
index ef7e699..0f8df47 100644
--- a/cloud-server-account/src/main/java/com/dsh/account/util/PayMoneyUtil.java
+++ b/cloud-server-account/src/main/java/com/dsh/account/util/PayMoneyUtil.java
@@ -76,7 +76,7 @@
private String key = "";//微信商户号
- private String callbackPath = "8.137.22.229:56666/account";//支付回调网关地址
+ private String callbackPath = "http://8.137.22.229:56666/account";//支付回调网关地址
private String app_cert_path = "C:/cert/alipay/user/app_cert_path.crt";//应用公钥证书路径
@@ -87,11 +87,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 ();
// //设置网关地址
@@ -204,7 +203,7 @@
AlipayTradeAppPayResponse response = alipayClient.sdkExecute(request);
Map<String, String> map = new HashMap<>();
map.put("orderString", response.getBody());
- map.put("returnId",passbackParams);
+ map.put("returnId", passbackParams);
System.out.println(map);//就是orderString 可以直接给客户端请求,无需再做处理。
return ResultUtil.success(map);
} catch (AlipayApiException e) {
@@ -216,6 +215,7 @@
/**
* 支付宝扫码支付下单
+ *
* @param body
* @param subject
* @param outTradeNo
@@ -223,7 +223,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("{" +
@@ -249,13 +249,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 = "";
@@ -311,12 +312,13 @@
/**
* 支付宝查询订单支付状态
+ *
* @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 + "\"" +
@@ -332,18 +334,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 {
@@ -363,7 +365,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);
@@ -379,7 +381,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>");
@@ -387,7 +389,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");
@@ -397,16 +399,14 @@
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<>();
@@ -441,11 +441,11 @@
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());
}
@@ -458,18 +458,19 @@
/**
* 微信支付成功后的回调处理
+ *
* @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
@@ -480,12 +481,11 @@
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) {
@@ -498,8 +498,8 @@
return null;
}
-@Resource
-private CoursePackageClient coursePackageClient;
+ @Resource
+ private CoursePackageClient coursePackageClient;
@Resource
private DeductionCompetitionsClient competitionsClient;
@@ -609,15 +609,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 {
@@ -655,7 +656,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>");
@@ -668,7 +669,7 @@
e.printStackTrace();
}
//将结果xml解析成map
- body1 = body1.replaceAll("<!\\[CDATA\\[","");
+ body1 = body1.replaceAll("<!\\[CDATA\\[", "");
body1 = body1.replaceAll("]]>", "");
try {
map1 = this.xmlToMap(body1, "UTF-8");
@@ -678,11 +679,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":
@@ -706,11 +707,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());
}
@@ -719,24 +720,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();
@@ -762,7 +765,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>");
@@ -776,7 +779,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");
@@ -787,19 +790,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;
@@ -809,20 +812,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<>();
@@ -831,7 +835,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) {
@@ -857,13 +861,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);
@@ -871,7 +876,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
@@ -888,10 +893,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<>();
@@ -912,7 +918,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>");
@@ -920,7 +926,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");
@@ -930,35 +936,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<>();
@@ -983,7 +989,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>");
@@ -991,7 +997,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");
@@ -1002,20 +1008,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;
@@ -1025,16 +1031,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<>();
@@ -1059,7 +1066,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>");
@@ -1067,7 +1074,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");
@@ -1078,20 +1085,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;
@@ -1100,15 +1107,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);
}
}
@@ -1116,19 +1124,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
@@ -1156,13 +1164,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());
}
@@ -1176,6 +1184,7 @@
/**
* 获取请求内容
+ *
* @param request
* @return
* @throws IOException
@@ -1198,10 +1207,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);
@@ -1234,10 +1244,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);
@@ -1270,6 +1281,7 @@
/**
* 微信退款成功后的解密
+ *
* @param req_info
* @return
*/
@@ -1277,7 +1289,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");
@@ -1303,6 +1315,7 @@
/**
* xml转map
+ *
* @param xml
* @param charset
* @return
@@ -1320,7 +1333,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