From d42f32d6c6ff2cbaab2fbdabbeefb2367e72d446 Mon Sep 17 00:00:00 2001
From: puzhibing <393733352@qq.com>
Date: 星期一, 25 三月 2024 17:08:31 +0800
Subject: [PATCH] 新增加功能
---
cloud-server-competition/src/main/java/com/dsh/competition/util/PayMoneyUtil.java | 340 ++++++++++++++++++++++++++++++++++---------------------
1 files changed, 209 insertions(+), 131 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 785d7c1..fc97d88 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
@@ -6,7 +6,7 @@
import com.alipay.api.AlipayClient;
import com.alipay.api.CertAlipayRequest;
import com.alipay.api.DefaultAlipayClient;
-import com.alipay.api.domain.AlipayTradeAppPayModel;
+import com.alipay.api.domain.*;
import com.alipay.api.request.*;
import com.alipay.api.response.*;
import com.dsh.competition.util.httpClinet.HttpClientUtil;
@@ -49,15 +49,15 @@
private String alipay_public_key = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAmu8n/4yTHWbn7VOrNc9OsLtDL1bEQ8gC1dHkj8Wy5z0mkaOsjJRIG/28ze12M0V8jdCKuuDr5Z1OPKiqf+XO3ypguEh+mYUVMBM/cZodDFQfTY1TKLWjvQCuaqlA+QUTCK6f7T7stsgyQ1o9Jj0rXZDz6PM4QHSTzjrLIBaeqM5WIBvH+fy/X+QG5Utd+/UT0kc0JyvuKhZ65yVUd/C9VcwJJAPliRsAQNrqYterwAJ9zvw9tF11wj9W0XgJ8Ccu4x3gR1vrlLRJJo/OA97RmxPQ+5hSacWQZCUd1dwiBq+YCrKVHGTj14izRHXrLc0yBlRXo7tBOIqcy3IsvKVthQIDAQAB";//支付宝支付公钥
- private String appid = "";//微信appid
+ private String appid = "wx41d32f362ba0f911";//微信appid
- private String appletsAppid = "";//微信小程序appid
+ private String appSecret = "cf0ebf950f5926a69041a0e2bbe20f3e";
- private String mchId = "";//微信商户号
+ private String mchId = "1501481761";//微信商户号
- private String key = "";//微信商户号
+ private String key = "6f5e0c2dcabfa9c27b5da5836a362fef";//微信商户号
- private String callbackPath = "";//支付回调网关地址
+ private String callbackPath = "http://221.182.45.100:56666/competition";//支付回调网关地址
private String app_cert_path = "C:/cert/alipay/user/app_cert_path.crt";//应用公钥证书路径
@@ -65,14 +65,13 @@
private String alipay_root_cert_path = "C:/cert/alipay/user/alipay_root_cert_path.crt";//支付宝CA根证书文件路径
- private String certPath = "C:\\cert\\1523106371_20211206_cert\\apiclient_cert.p12";//微信证书
-
+ private String certPath = "C:\\Users\\Admin\\Desktop\\weixin_cert\\apiclient_cert.p12";//微信证书
/**
* 支付宝支付
*/
- public ResultUtil alipay(String body, String subject, String passbackParams, String outTradeNo, String amount, String notifyUrl){
+ public ResultUtil alipay(String smid,String body, String subject, String passbackParams, String outTradeNo, String amount, String notifyUrl) {
// //构造client
// CertAlipayRequest certAlipayRequest = new CertAlipayRequest ();
// //设置网关地址
@@ -132,14 +131,30 @@
//SDK已经封装掉了公共参数,这里只需要传入业务参数。以下方法为sdk的model入参方式(model和biz_content同时存在的情况下取biz_content)。
AlipayTradeAppPayModel model = new AlipayTradeAppPayModel();
model.setBody(body);//对一笔交易的具体描述信息。如果是多种商品,请将商品描述字符串累加传给body。
- model.setSubject(subject);//商品的标题/交易标题/订单标题/订单关键字等。
+ model.setSubject("报名赛事");//商品的标题/交易标题/订单标题/订单关键字等。
model.setOutTradeNo(outTradeNo);//商户网站唯一订单号
model.setTimeoutExpress("30m");
model.setTotalAmount(amount);//付款金额
model.setProductCode("QUICK_MSECURITY_PAY");
model.setPassbackParams(passbackParams);//自定义参数
+ SettleInfo settleInfo = new SettleInfo();
+ settleInfo.setSettlePeriodTime("3d");
+ SettleDetailInfo settleDetailInfo = new SettleDetailInfo();
+ settleDetailInfo.setTransInType("defaultSettle");
+ settleDetailInfo.setAmount(amount);
+ List<SettleDetailInfo> settleDetailInfos = new ArrayList<>();
+ settleDetailInfos.add(settleDetailInfo);
+ settleInfo.setSettleDetailInfos(settleDetailInfos);
+ model.setSettleInfo(settleInfo);
+ SubMerchant subMerchant = new SubMerchant();
+ subMerchant.setMerchantId(smid);
+ model.setSubMerchant(subMerchant);
+ ExtendParams extendParams = new ExtendParams();
+ extendParams.setRoyaltyFreeze("true");// 冻结资金 用于后续分账处理
+ model.setExtendParams(extendParams);
request.setBizModel(model);
request.setNotifyUrl(callbackPath + notifyUrl);
+
try {
//这里和普通的接口调用不同,使用的是sdkExecute
AlipayTradeAppPayResponse response = alipayClient.sdkExecute(request);
@@ -156,6 +171,7 @@
/**
* 支付宝扫码支付下单
+ *
* @param body
* @param subject
* @param outTradeNo
@@ -163,7 +179,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 +205,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,38 +268,88 @@
/**
* 支付宝查询订单支付状态
+ *
* @param out_trade_no
* @return
* @throws Exception
*/
- public ResultUtil 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 ResultUtil.success(tradeStatus);
+ return response;
} else {
- return ResultUtil.error(response.getMsg());
+ return response;
}
}
-
+ /**
+ * 统一确认结算接口
+ * @param smid
+ * @param code
+ * @param outTradeNo
+ * @param amount
+ * @return
+ */
+ public ResultUtil confirm(String smid,String code, String outTradeNo, String amount) {
+ AlipayClient alipayClient = new DefaultAlipayClient("https://openapi.alipay.com/gateway.do",
+ aliAppid,
+ appPrivateKey,
+ "json",
+ "GBK",
+ alipay_public_key,
+ "RSA2");
+ AlipayTradeSettleConfirmRequest request = new AlipayTradeSettleConfirmRequest();
+ request.setBizContent("{" +
+ " \"out_request_no\":\""+code+"\"," +
+ " \"trade_no\":\""+outTradeNo+"\"," +
+ " \"settle_info\":{" +
+ " \"settle_detail_infos\":[" +
+ " {" +
+ " \"trans_in_type\":\"defaultSettle\"," +
+ " \"settle_entity_id\":\""+smid+"\"," +
+ " \"settle_entity_type\":\"SecondMerchant\"," +
+ " \"amount\":"+amount+"," +
+ " }" +
+ " ]" +
+ " }," +
+ " \"extend_params\":{" +
+ " \"royalty_freeze\":\"false\"" +
+ " }" +
+ "}");
+ AlipayTradeSettleConfirmResponse response = null;
+ try {
+ response = alipayClient.execute(request);
+ } catch (AlipayApiException e) {
+ e.printStackTrace();
+ }
+ if(response.isSuccess()){
+ System.out.println("调用成功");
+ return ResultUtil.success();
+ } else {
+ System.out.println("调用失败");
+ return ResultUtil.error("出现问题啦");
+ }
+ }
/**
* 微信统一下单
- * @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 {
@@ -292,7 +359,7 @@
}
String nonce_str = UUIDUtil.getRandomCode(16);
Map<String, Object> map = new HashMap<>();
- map.put("appid", "APP".equals(tradeType) ? appid : appletsAppid);
+ map.put("appid", appid);
map.put("mch_id", mchId);
map.put("nonce_str", nonce_str);
map.put("body", body);
@@ -302,7 +369,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);
@@ -318,7 +385,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>");
@@ -326,7 +393,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");
@@ -336,12 +403,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<>();
@@ -376,34 +443,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
@@ -413,10 +478,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) {
@@ -430,15 +495,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 {
@@ -476,7 +542,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>");
@@ -489,7 +555,7 @@
e.printStackTrace();
}
//将结果xml解析成map
- body1 = body1.replaceAll("<!\\[CDATA\\[","");
+ body1 = body1.replaceAll("<!\\[CDATA\\[", "");
body1 = body1.replaceAll("]]>", "");
try {
map1 = this.xmlToMap(body1, "UTF-8");
@@ -499,11 +565,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":
@@ -527,11 +593,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());
}
@@ -540,24 +606,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();
@@ -583,7 +651,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>");
@@ -597,7 +665,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");
@@ -608,19 +676,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;
@@ -630,20 +698,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<>();
@@ -652,7 +721,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) {
@@ -678,13 +747,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);
@@ -692,7 +762,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
@@ -709,10 +779,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<>();
@@ -733,7 +804,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>");
@@ -741,7 +812,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");
@@ -751,35 +822,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<>();
@@ -804,7 +875,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>");
@@ -812,7 +883,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");
@@ -823,20 +894,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;
@@ -846,16 +917,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<>();
@@ -880,7 +952,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>");
@@ -888,7 +960,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");
@@ -899,20 +971,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;
@@ -921,15 +993,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);
}
}
@@ -937,19 +1010,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
@@ -977,13 +1050,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());
}
@@ -997,6 +1070,7 @@
/**
* 获取请求内容
+ *
* @param request
* @return
* @throws IOException
@@ -1019,10 +1093,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);
@@ -1055,10 +1130,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);
@@ -1091,6 +1167,7 @@
/**
* 微信退款成功后的解密
+ *
* @param req_info
* @return
*/
@@ -1098,7 +1175,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");
@@ -1124,6 +1201,7 @@
/**
* xml转map
+ *
* @param xml
* @param charset
* @return
@@ -1141,7 +1219,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