From 75a2623173bcc4a235aa1f99f7ef28519186160b Mon Sep 17 00:00:00 2001 From: yanghb <yanghb> Date: 星期五, 21 四月 2023 11:24:25 +0800 Subject: [PATCH] 代码调整 --- UserTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/util/PayMoneyUtil.java | 471 +++++++++------------------------------------------------- 1 files changed, 78 insertions(+), 393 deletions(-) diff --git a/UserTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/util/PayMoneyUtil.java b/UserTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/util/PayMoneyUtil.java index 8687432..d34abcd 100644 --- a/UserTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/util/PayMoneyUtil.java +++ b/UserTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/util/PayMoneyUtil.java @@ -4,12 +4,18 @@ import com.alibaba.fastjson.JSONObject; import com.alipay.api.AlipayApiException; 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.internal.util.AlipaySignature; -import com.alipay.api.request.*; -import com.alipay.api.response.*; +import com.alipay.api.request.AlipayTradeAppPayRequest; +import com.alipay.api.request.AlipayTradePrecreateRequest; +import com.alipay.api.request.AlipayTradeQueryRequest; +import com.alipay.api.request.AlipayTradeRefundRequest; +import com.alipay.api.response.AlipayTradeAppPayResponse; +import com.alipay.api.response.AlipayTradePrecreateResponse; +import com.alipay.api.response.AlipayTradeQueryResponse; +import com.alipay.api.response.AlipayTradeRefundResponse; +import com.stylefeng.guns.modular.system.util.httpClinet.HttpClientUtil; import org.apache.commons.collections.map.HashedMap; import org.bouncycastle.jce.provider.BouncyCastleProvider; import org.dom4j.Document; @@ -60,7 +66,10 @@ private String appid;//微信appid @Value("${wx.appletsAppid}") - private String appletsAppid;//微信小程序appid + private String appletsAppid; + + @Value("${wx.appletsAppSecret}") + private String appletsAppSecret; @Value("${wx.mchId}") private String mchId;//微信商户号 @@ -68,102 +77,41 @@ @Value("${wx.key}") private String key;//微信商户号 - @Value("${callbackPath}") - private String callbackPath;//支付回调网关地址 - - private String app_cert_path = "C:/cert/alipay/user/app_cert_path.crt";//应用公钥证书路径 - - private String alipay_cert_path = "C:/cert/alipay/user/alipay_cert_path.crt";//支付宝公钥证书文件路径 - - private String alipay_root_cert_path = "C:/cert/alipay/user/alipay_root_cert_path.crt";//支付宝CA根证书文件路径 + @Value("${wx.certPath}") + String certPath; @Autowired private HttpClientUtil httpClientUtil; - - private Map<String, JSONObject> order = new HashMap<>();//存储支付订单用于主动查询支付结果 /** * 支付宝支付 */ - public ResultUtil alipay(String body, String subject, String passbackParams, String outTradeNo, String amount, String notifyUrl){ - //构造client - CertAlipayRequest certAlipayRequest = new CertAlipayRequest (); - //设置网关地址 - certAlipayRequest.setServerUrl("https://openapi.alipay.com/gateway.do"); - //设置应用Id - certAlipayRequest.setAppId(aliAppid); - //设置应用私钥 - certAlipayRequest.setPrivateKey(appPrivateKey); - //设置请求格式,固定值json - certAlipayRequest.setFormat("json"); - //设置字符集 - certAlipayRequest.setCharset("UTF-8"); - //设置签名类型 - certAlipayRequest.setSignType("RSA2"); - //设置应用公钥证书路径 - certAlipayRequest.setCertPath(app_cert_path); - //设置支付宝公钥证书路径 - certAlipayRequest.setAlipayPublicCertPath(alipay_cert_path); - //设置支付宝根证书路径 - certAlipayRequest.setRootCertPath(alipay_root_cert_path); - //构造client - AlipayClient alipayClient = null; - try { - alipayClient = new DefaultAlipayClient(certAlipayRequest); - } catch (AlipayApiException e) { - e.printStackTrace(); - } + public ResultUtil alipay(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", alipayPublicKey, "RSA2"); //实例化具体API对应的request类,类名称和接口名称对应,当前调用接口名称:alipay.trade.app.pay - AlipayTradeAppPayRequest request = new AlipayTradeAppPayRequest (); + AlipayTradeAppPayRequest request = new AlipayTradeAppPayRequest(); //SDK已经封装掉了公共参数,这里只需要传入业务参数。以下方法为sdk的model入参方式(model和biz_content同时存在的情况下取biz_content)。 - AlipayTradeAppPayModel model = new AlipayTradeAppPayModel (); - model.setBody(body); - model.setSubject (subject); - model.setOutTradeNo (outTradeNo); - model.setTimeoutExpress ("30m" ); - model.setTotalAmount (amount); - model.setProductCode ( "QUICK_MSECURITY_PAY" ); - model.setPassbackParams(passbackParams);//自定义参数 - request.setBizModel ( model ); - request.setNotifyUrl (callbackPath + notifyUrl); - try { + AlipayTradeAppPayModel model = new AlipayTradeAppPayModel(); + model.setBody(body);//对一笔交易的具体描述信息。如果是多种商品,请将商品描述字符串累加传给body。 + model.setSubject(subject);//商品的标题/交易标题/订单标题/订单关键字等。 + model.setOutTradeNo(outTradeNo);//商户网站唯一订单号 + model.setTimeoutExpress("30m"); + model.setTotalAmount(amount);//付款金额 + model.setProductCode("QUICK_MSECURITY_PAY"); + request.setBizModel(model); + request.setNotifyUrl(notifyUrl); + try { //这里和普通的接口调用不同,使用的是sdkExecute AlipayTradeAppPayResponse response = alipayClient.sdkExecute(request); Map<String, String> map = new HashMap<>(); map.put("orderString", response.getBody()); System.out.println(map);//就是orderString 可以直接给客户端请求,无需再做处理。 return ResultUtil.success(map); - } catch (AlipayApiException e ) { + } catch (AlipayApiException e) { e.printStackTrace(); } - - -// //实例化客户端 -// AlipayClient alipayClient = new DefaultAlipayClient("https://openapi.alipay.com/gateway.do", aliAppid, appPrivateKey, "json", "UTF-8", alipay_public_key, "RSA2"); -// //实例化具体API对应的request类,类名称和接口名称对应,当前调用接口名称:alipay.trade.app.pay -// AlipayTradeAppPayRequest request = new AlipayTradeAppPayRequest(); -// //SDK已经封装掉了公共参数,这里只需要传入业务参数。以下方法为sdk的model入参方式(model和biz_content同时存在的情况下取biz_content)。 -// AlipayTradeAppPayModel model = new AlipayTradeAppPayModel(); -// model.setBody(body);//对一笔交易的具体描述信息。如果是多种商品,请将商品描述字符串累加传给body。 -// model.setSubject(subject);//商品的标题/交易标题/订单标题/订单关键字等。 -// model.setOutTradeNo(outTradeNo);//商户网站唯一订单号 -// model.setTimeoutExpress("30m"); -// model.setTotalAmount(amount);//付款金额 -// model.setProductCode("QUICK_MSECURITY_PAY"); -// model.setPassbackParams(passbackParams);//自定义参数 -// request.setBizModel(model); -// request.setNotifyUrl(callbackPath + notifyUrl); -// try { -// //这里和普通的接口调用不同,使用的是sdkExecute -// AlipayTradeAppPayResponse response = alipayClient.sdkExecute(request); -// Map<String, String> map = new HashMap<>(); -// map.put("orderString", response.getBody()); -// System.out.println(map);//就是orderString 可以直接给客户端请求,无需再做处理。 -// return ResultUtil.success(map); -// } catch (AlipayApiException e) { -// e.printStackTrace(); -// } return null; } @@ -184,7 +132,7 @@ " \"out_trade_no\":\"" + outTradeNo + "\"," +//商户订单号 " \"total_amount\":\"" + 1 + "\"," + " \"subject\":\"" + subject + "\"," + - " \"notify_url\":\"" + callbackPath + notifyUrl + "\"," + + " \"notify_url\":\"" + notifyUrl + "\"," + " \"body\":\"" + body + "\"," + " \"store_id\":\"NJ_001\"," + " \"timeout_express\":\"90m\"}");//订单允许的最晚付款时间 @@ -215,51 +163,47 @@ String valueStr = ""; for (int i = 0; i < values.length; i++) { valueStr = (i == values.length - 1) ? valueStr + values[i] - : valueStr + values[i] + "_"; + : valueStr + values[i] + ","; } //乱码解决,这段代码在出现乱码时使用。 //valueStr = new String(valueStr.getBytes("ISO-8859-1"), "utf-8"); params.put(name, valueStr); } - //切记alipaypublickey是支付宝的公钥,请去open.alipay.com对应应用下查看。 - //boolean AlipaySignature.rsaCheckV1(Map<String, String> params, String publicKey, String charset, String sign_type) -// try { -// boolean flag = AlipaySignature.rsaCheckV1(params, alipay_public_key, "UTF-8","RSA2"); -// if(flag){ -// Map<String, String> map = new HashMap<>(); -// String out_trade_no = params.get("out_trade_no"); -// String subject = params.get("subject"); -// String total_amount = params.get("total_amount"); -// String trade_no = params.get("trade_no"); -// String passback_params = params.get("passback_params"); -// map.put("out_trade_no", out_trade_no);//商家订单号 -// map.put("subject", subject); -// map.put("total_amount", total_amount); -// map.put("trade_no", trade_no);//支付宝交易号 -// map.put("passback_params", passback_params);//回传参数 -// return map; -// }else{ -// System.err.println("验签失败"); -// } -// -// } catch (AlipayApiException e) { -// e.printStackTrace(); -// } -// return null; - Map<String, String> map = new HashMap<>(); String out_trade_no = params.get("out_trade_no"); String subject = params.get("subject"); String total_amount = params.get("total_amount"); String trade_no = params.get("trade_no"); - String passback_params = params.get("passback_params"); map.put("out_trade_no", out_trade_no);//商家订单号 map.put("subject", subject); map.put("total_amount", total_amount); map.put("trade_no", trade_no);//支付宝交易号 - map.put("passback_params", passback_params);//回传参数 return map; + + + + //切记alipaypublickey是支付宝的公钥,请去open.alipay.com对应应用下查看。 + //boolean AlipaySignature.rsaCheckV1(Map<String, String> params, String publicKey, String charset, String sign_type) +// try { +// boolean flag = AlipaySignature.rsaCheckV1(params, alipayPublicKey, "UTF-8","RSA2"); +// if(flag){ +// Map<String, String> map = new HashMap<>(); +// String out_trade_no = params.get("out_trade_no"); +// String subject = params.get("subject"); +// String total_amount = params.get("total_amount"); +// String trade_no = params.get("trade_no"); +// map.put("out_trade_no", out_trade_no);//商家订单号 +// map.put("subject", subject); +// map.put("total_amount", total_amount); +// map.put("trade_no", trade_no);//支付宝交易号 +// return map; +// } +// +// } catch (AlipayApiException e) { +// e.printStackTrace(); +// } +// return null; } @@ -296,7 +240,7 @@ * @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 { @@ -306,7 +250,7 @@ } String nonce_str = UUIDUtil.getRandomCode(16); Map<String, Object> map = new HashMap<>(); - map.put("appid", "APP".equals(tradeType) ? appid : appletsAppid); + map.put("appid", "JSAPI".equals(tradeType) ? appletsAppid : appid); map.put("mch_id", mchId); map.put("nonce_str", nonce_str); map.put("body", body); @@ -314,11 +258,9 @@ map.put("out_trade_no", out_trade_no);//存储的订单code map.put("total_fee", i); map.put("spbill_create_ip", hostAddress); - map.put("notify_url", callbackPath + notify_url); + map.put("notify_url", notify_url); map.put("trade_type", tradeType); - if("JSAPI".equals(tradeType)){ - map.put("openid", openId); - } + map.put("openid", openid); String s = this.weixinSignature(map); map.put("sign", s); @@ -338,7 +280,7 @@ xmlString.append("</xml>"); Map<String, String> map1 = null; - String body1 = httpClientUtil.pushHttpRequsetXml(url, xmlString.toString(), new HashMap<>()); + String body1 = httpClientUtil.pushHttpRequsetXml(url, xmlString.toString(), new HashMap<>()).getData(); //将结果xml解析成map body1 = body1.replaceAll("<!\\[CDATA\\[",""); body1 = body1.replaceAll("]]>", ""); @@ -357,7 +299,6 @@ String prepay_id = map1.get("prepay_id"); switch (type){ case "JSAPI": - //重新进行签名后返回给前端 Map<String, Object> map2 = new HashMap<>(); map2.put("appId", map1.get("appid")); map2.put("nonceStr", map1.get("nonce_str")); @@ -373,8 +314,10 @@ map2.put("sign", s2); return ResultUtil.success(map2); case "NATIVE": + Map<String, Object> map4 = new HashMap<>(); String code_url = map1.get("code_url"); - return ResultUtil.success(code_url); + map4.put("code_url", code_url); + return ResultUtil.success(map4); case "APP": //重新进行签名后返回给前端 Map<String, Object> map3 = new HashMap<>(); @@ -384,8 +327,8 @@ map3.put("partnerid", mchId); map3.put("prepayid", prepay_id); map3.put("timestamp", new Date().getTime() / 1000); - String s1 = this.weixinSignature(map3); - map3.put("sign", s1); + String s3 = this.weixinSignature(map3); + map3.put("sign", s3); System.err.println(map3); return ResultUtil.success(map3); } @@ -496,7 +439,12 @@ xmlString.append("</xml>"); Map<String, String> map1 = null; - String body1 = httpClientUtil.pushHttpRequsetXml(url, xmlString.toString(), new HashMap<>()); + String body1 = null; + try { + body1 = httpClientUtil.pushHttpRequsetXml(url, xmlString.toString(), new HashMap<>()).getData(); + } catch (Exception e) { + e.printStackTrace(); + } //将结果xml解析成map body1 = body1.replaceAll("<!\\[CDATA\\[",""); body1 = body1.replaceAll("]]>", ""); @@ -571,15 +519,15 @@ int rf = new BigDecimal(refund_fee).multiply(new BigDecimal("100")).intValue(); String nonce_str = UUIDUtil.getRandomCode(); Map<String, Object> map = new HashMap<>(); - map.put("appid", appid); + map.put("appid", appletsAppid); map.put("mch_id", mchId); map.put("nonce_str", nonce_str); map.put("transaction_id", transaction_id); map.put("out_refund_no", out_refund_no); map.put("total_fee", tf); map.put("refund_fee", rf); - map.put("notify_url", callbackPath + notify_url); - String s = this.weixinSignature(map, key); + map.put("notify_url", notify_url); + String s = this.weixinSignature(map); map.put("sign", s); String url = "https://api.mch.weixin.qq.com/secapi/pay/refund"; @@ -600,8 +548,7 @@ Map<String, String> map1 = null; String body1 = null; try { - String certPath = "C:\\cert\\1523106371_20211206_cert\\apiclient_cert.p12"; - body1 = httpClientUtil.pushHttpsRequsetXml(url, xmlString.toString(), new HashMap<>(), "1523106371", certPath, "PKCS12"); + body1 = httpClientUtil.pushHttpsRequsetXml(url, xmlString.toString(), new HashMap<>(), mchId, certPath, "PKCS12"); } catch (Exception e) { e.printStackTrace(); } @@ -663,7 +610,7 @@ map1.put("result", result); return map1; }else{ -// System.err.println(map.get("return_msg")); + System.err.println(map.get("return_msg")); } } catch (IOException e) { e.printStackTrace(); @@ -748,7 +695,7 @@ xmlString.append("</xml>"); Map<String, String> map1 = null; - String body1 = httpClientUtil.pushHttpRequsetXml(url, xmlString.toString(), new HashMap<>()); + String body1 = httpClientUtil.pushHttpRequsetXml(url, xmlString.toString(), new HashMap<>()).getData(); //将结果xml解析成map body1 = body1.replaceAll("<!\\[CDATA\\[",""); body1 = body1.replaceAll("]]>", ""); @@ -789,232 +736,6 @@ } } - - - /** - * 微信转账功能(企业付款到零钱) - * @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{ - int amount = new BigDecimal(total_fee).multiply(new BigDecimal("100")).intValue(); - String nonce_str = UUIDUtil.getRandomCode(); - Map<String, Object> map = new HashMap<>(); - map.put("mch_appid", appid);//申请商户号的appid或商户号绑定的appid - map.put("mchid", mchId);//微信支付分配的商户号 - map.put("nonce_str", nonce_str);//随机字符串,不长于32位 - map.put("partner_trade_no", partner_trade_no);//商户订单号,需保持唯一性 - map.put("openid", openid);//商户appid下,某用户的openid - map.put("check_name", "NO_CHECK");//NO_CHECK:不校验真实姓名 FORCE_CHECK:强校验真实姓名 - map.put("amount", amount);//企业付款金额,单位为分 - map.put("desc", desc);//企业付款备注,必填。 - String s = this.weixinSignature(map, key); - map.put("sign", s); - - String url = "https://api.mch.weixin.qq.com/mmpaymkttransfers/promotion/transfers"; - //设置请求头 - HttpHeaders headers = new HttpHeaders(); - headers.setContentType(MediaType.APPLICATION_XML); - StringBuffer xmlString = new StringBuffer(); - Set<String> strings = map.keySet(); - String[] keys = {}; - keys = strings.toArray(keys); - Arrays.sort(keys); - xmlString.append("<xml>"); - for(int l = 0; l < keys.length; l++){ - xmlString.append("<" + keys[l] + ">" + map.get(keys[l]) + "</" + keys[l] + ">"); - } - xmlString.append("</xml>"); - - Map<String, String> map1 = null; - String certPath = "C:\\cert\\1523106371_20211206_cert\\apiclient_cert.p12";//证书地址 - String body1 = httpClientUtil.pushHttpsRequsetXml(url, xmlString.toString(), new HashMap<>(), "1523106371", certPath, "PKCS12"); - //将结果xml解析成map - body1 = body1.replaceAll("<!\\[CDATA\\[",""); - body1 = body1.replaceAll("]]>", ""); - try { - map1 = this.xmlToMap(body1, "UTF-8"); - } catch (UnsupportedEncodingException e) { - e.printStackTrace(); - } catch (DocumentException e) { - e.printStackTrace(); - } - String return_code = map1.get("return_code"); - Map<String, String> map2 = new HashMap<>(); - if("SUCCESS".equals(return_code)){ - String result_code = map1.get("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{ - 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{ - map2.put("return_code", return_code); - map2.put("return_msg", map1.get("return_msg")); - return map2; - } - } - - - /** - * 微信转账功能(企业付款到银行卡) - * @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{ - int amount = new BigDecimal(total_fee).multiply(new BigDecimal("100")).intValue(); - String nonce_str = UUIDUtil.getRandomCode(); - Map<String, Object> map = new HashMap<>(); - map.put("mch_id", mchId);//微信支付分配的商户号 - map.put("nonce_str", nonce_str);//随机字符串,不长于32位 - map.put("partner_trade_no", partner_trade_no);//商户订单号,需保持唯一性 - map.put("enc_bank_no", enc_bank_no);//收款方银行卡号(采用标准RSA算法,公钥由微信侧提供) - map.put("enc_true_name", enc_true_name);//收款方用户名(采用标准RSA算法,公钥由微信侧提供) - map.put("bank_code", findBankCode(bankName));// - map.put("amount", amount);//企业付款金额,单位为分 - map.put("desc", desc);//企业付款备注,必填。 - String s = this.weixinSignature(map, key); - map.put("sign", s); - - String url = "https://api.mch.weixin.qq.com/mmpaysptrans/pay_bank"; - //设置请求头 - HttpHeaders headers = new HttpHeaders(); - headers.setContentType(MediaType.APPLICATION_XML); - StringBuffer xmlString = new StringBuffer(); - Set<String> strings = map.keySet(); - String[] keys = {}; - keys = strings.toArray(keys); - Arrays.sort(keys); - xmlString.append("<xml>"); - for(int l = 0; l < keys.length; l++){ - xmlString.append("<" + keys[l] + ">" + map.get(keys[l]) + "</" + keys[l] + ">"); - } - xmlString.append("</xml>"); - - Map<String, String> map1 = null; - String certPath = "C:\\cert\\1523106371_20211206_cert\\apiclient_cert.p12";//证书地址 - String body1 = httpClientUtil.pushHttpsRequsetXml(url, xmlString.toString(), new HashMap<>(), "1523106371", certPath, "PKCS12"); - //将结果xml解析成map - body1 = body1.replaceAll("<!\\[CDATA\\[",""); - body1 = body1.replaceAll("]]>", ""); - try { - map1 = this.xmlToMap(body1, "UTF-8"); - } catch (UnsupportedEncodingException e) { - e.printStackTrace(); - } catch (DocumentException e) { - e.printStackTrace(); - } - String return_code = map1.get("return_code"); - Map<String, String> map2 = new HashMap<>(); - if("SUCCESS".equals(return_code)){ - String result_code = map1.get("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{ - 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{ - map2.put("return_code", return_code); - map2.put("return_msg", map1.get("return_msg")); - return map2; - } - } - - /** - * 微信转账到银行卡不编号 - * @param bankName - * @return - */ - 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){ - return jsonObject.getString(key); - } - } - return ""; - } - - - - /** - * 支付宝转账 - * @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{ - CertAlipayRequest certAlipayRequest = new CertAlipayRequest(); - certAlipayRequest.setServerUrl("https://openapi.alipay.com/gateway.do"); //gateway:支付宝网关(固定)https://openapi.alipay.com/gateway.do - certAlipayRequest.setAppId(aliAppid); //APPID 即创建应用后生成,详情见创建应用并获取 APPID - certAlipayRequest.setPrivateKey(appPrivateKey); //开发者应用私钥,由开发者自己生成 - certAlipayRequest.setFormat("json"); //参数返回格式,只支持 json 格式 - certAlipayRequest.setCharset("UTF-8"); //请求和签名使用的字符编码格式,支持 GBK和 UTF-8 - certAlipayRequest.setSignType("RSA2"); //商户生成签名字符串所使用的签名算法类型,目前支持 RSA2 和 RSA,推荐商家使用 RSA2。 - certAlipayRequest.setCertPath(app_cert_path); //应用公钥证书路径(app_cert_path 文件绝对路径) - certAlipayRequest.setAlipayPublicCertPath(alipay_cert_path); //支付宝公钥证书文件路径(alipay_cert_path 文件绝对路径) - certAlipayRequest.setRootCertPath(alipay_root_cert_path); //支付宝CA根证书文件路径(alipay_root_cert_path 文件绝对路径) - AlipayClient alipayClient = new DefaultAlipayClient(certAlipayRequest); - AlipayFundTransUniTransferRequest request = new AlipayFundTransUniTransferRequest(); - request.setBizContent("{" + - "\"out_biz_no\":\"" + out_biz_no + "\"," + - "\"trans_amount\":" + trans_amount + "," + - "\"product_code\":\"TRANS_ACCOUNT_NO_PWD\"," + - "\"biz_scene\":\"DIRECT_TRANSFER\"," + - "\"order_title\":\"" + order_title + "\"," + - "\"payee_info\":{" + - "\"identity\":\"" + identity + "\"," + - "\"identity_type\":\"ALIPAY_USER_ID\"," + - "\"name\":\"" + name + "\"," + - "}," + - "\"remark\":\"" + remark + "\"" + - "}"); - AlipayFundTransUniTransferResponse response = alipayClient.certificateExecute(request); - Map<String, Object> map = new HashMap<>(); - if(response.isSuccess()){ - String status = response.getStatus(); - if(status.equals("SUCCESS")){//成功 - map.put("code", response.getCode()); - map.put("order_id", response.getOrderId());//支付宝订单号 - map.put("pay_fund_order_id", response.getPayFundOrderId());//支付宝流水号 - }else{ - map.put("code", response.getCode()); - map.put("sub_msg", response.getSubMsg()); - } - } else { - map.put("code", response.getSubCode()); - map.put("sub_msg", response.getSubMsg()); - } - return map; - } /** @@ -1066,42 +787,6 @@ } } sb.append("key=" + key); - String sign = MD5AndKL.MD5Encode(sb.toString(), "UTF-8").toUpperCase(); //注:MD5签名方式 - return sign; - } catch (Exception e) { - e.printStackTrace(); - } - return null; - } - - - /** - * 微信下单的签名算法 - * @param map - * @return - */ - 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); - // 对所有传入参数按照字段名的 ASCII 码从小到大排序(字典序) - Collections.sort(infoIds, new Comparator<Map.Entry<String, Object>>() { - public int compare(Map.Entry<String, Object> o1, Map.Entry<String, Object> o2) { - return (o1.getKey()).toString().compareTo(o2.getKey()); - } - }); - // 构造签名键值对的格式 - StringBuilder sb = new StringBuilder(); - for (Map.Entry<String, Object> item : infoIds) { - if (item.getKey() != null || item.getKey() != "") { - String key = item.getKey(); - Object val = item.getValue(); - if (!(val == "" || val == null)) { - sb.append(key + "=" + val + "&"); - } - } - } - sb.append("key=" + key_); String sign = MD5AndKL.MD5Encode(sb.toString(), "UTF-8").toUpperCase(); //注:MD5签名方式 return sign; } catch (Exception e) { -- Gitblit v1.7.1