parent
406b262178
commit
abbdd56d40
File diff suppressed because one or more lines are too long
@ -0,0 +1,103 @@ |
||||
package com.hai.config; |
||||
|
||||
import com.alibaba.fastjson.JSONObject; |
||||
import com.wechat.pay.contrib.apache.httpclient.util.PemUtil; |
||||
import org.apache.commons.codec.binary.Base64; |
||||
import com.hai.common.pay.util.sdk.WXPayConstants; |
||||
import com.hai.common.utils.HttpsUtils; |
||||
import org.apache.commons.lang3.StringUtils; |
||||
|
||||
import java.io.*; |
||||
import java.math.BigDecimal; |
||||
import java.nio.file.Files; |
||||
import java.nio.file.Path; |
||||
import java.nio.file.Paths; |
||||
import java.security.*; |
||||
import java.security.spec.PKCS8EncodedKeySpec; |
||||
import java.util.*; |
||||
|
||||
/** |
||||
* 银联分期 |
||||
* @author hurui |
||||
*/ |
||||
public class UnionStagingPayConfig { |
||||
|
||||
/** |
||||
* 银联分期支付,H5预下单-标准 |
||||
* 文档地址: https://doc.eycard.cn/web/#/42?page_id=1516
|
||||
* @param orderNo 订单号 |
||||
* @param orgTrace 订单号 |
||||
* @param openId 支付宝、微信、云闪付用户授权唯一标识(如果没有,送:-) |
||||
* @param payPrice 支付金额 【单位:分】 |
||||
* @return 响应信息 |
||||
* @throws Exception |
||||
*/ |
||||
public static JSONObject advancePay(String orderNo, String orgTrace, BigDecimal payPrice, String openId, String notifyUrl) throws Exception { |
||||
Map<String,Object> paramMap = new HashMap<>(); |
||||
paramMap.put("orgId", CommonSysConst.getSysConfig().getUnionStagingPayOrgId()); |
||||
paramMap.put("orgMerCode", CommonSysConst.getSysConfig().getUnionStagingPayOrgMerCode()); |
||||
paramMap.put("orgTermNo", CommonSysConst.getSysConfig().getUnionStagingPayOrgTermNo()); |
||||
paramMap.put("prodTrace", orderNo); |
||||
paramMap.put("orgTrace", orgTrace); |
||||
paramMap.put("prodCode", "ISYH"); |
||||
paramMap.put("signType", "RSA"); |
||||
|
||||
Map<String, Object> bizDataMap = new HashMap<>(); |
||||
bizDataMap.put("transAmt", payPrice.multiply(new BigDecimal("100")).intValue()); |
||||
bizDataMap.put("openId", openId); |
||||
bizDataMap.put("notifyUrl", notifyUrl); |
||||
paramMap.put("bizData", bizDataMap); |
||||
paramMap.put("sign", generateSign(bizDataMap)); |
||||
|
||||
JSONObject responseParam = HttpsUtils.doPost(CommonSysConst.getSysConfig().getUnionStagingPayUrl()+"cashier/apply/advancePay", paramMap, new HashMap<>()); |
||||
return responseParam; |
||||
} |
||||
|
||||
/** |
||||
* 参数排序 |
||||
* @param param |
||||
* @return |
||||
*/ |
||||
private static String paramSort(final Map<String, Object> param) { |
||||
Set<String> keySet = param.keySet(); |
||||
String[] keyArray = keySet.toArray(new String[keySet.size()]); |
||||
Arrays.sort(keyArray); |
||||
StringBuilder sb = new StringBuilder(); |
||||
for (String k : keyArray) { |
||||
if (k.equals(WXPayConstants.FIELD_SIGN)) { |
||||
continue; |
||||
} |
||||
if (StringUtils.isBlank(sb.toString())) { |
||||
sb.append(k).append("=").append(param.get(k)); |
||||
} else { |
||||
sb.append("&").append(k).append("=").append(param.get(k)); |
||||
} |
||||
} |
||||
return sb.toString(); |
||||
} |
||||
|
||||
/** |
||||
* 生成签名 |
||||
* @param data |
||||
* @return |
||||
* @throws Exception |
||||
*/ |
||||
private static String generateSign(final Map<String, Object> data) throws IOException { |
||||
String paramSort = paramSort(data); |
||||
PrivateKey privateKey = PemUtil.loadPrivateKey(new FileInputStream("/home/project/wx_cert/BZ0001toORG000000000001.key")); |
||||
String signStr = null; |
||||
try { |
||||
Signature sign = Signature.getInstance("SHA256withRSA"); |
||||
sign.initSign(privateKey); |
||||
sign.update(paramSort.getBytes("utf-8")); |
||||
signStr = java.util.Base64.getEncoder().encodeToString(sign.sign()); |
||||
} catch (SignatureException e) { |
||||
e.printStackTrace(); |
||||
} catch (NoSuchAlgorithmException e) { |
||||
e.printStackTrace(); |
||||
} catch (InvalidKeyException e) { |
||||
e.printStackTrace(); |
||||
} |
||||
return signStr; |
||||
} |
||||
} |
Loading…
Reference in new issue