commit
4176f7d6da
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -0,0 +1,96 @@ |
|||||||
|
package com.hai.pay.channel.huift; |
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSONObject; |
||||||
|
import com.hai.common.exception.ErrorCode; |
||||||
|
import com.hai.common.exception.ErrorHelp; |
||||||
|
import com.hai.common.exception.SysCode; |
||||||
|
import com.hai.common.utils.HttpsUtils; |
||||||
|
import com.hai.config.CommonSysConst; |
||||||
|
import com.hai.entity.HighOrder; |
||||||
|
import com.hai.entity.HighOrderRefund; |
||||||
|
import com.hai.pay.channel.huift.config.HuiftConfig; |
||||||
|
import com.hai.service.HighOrderService; |
||||||
|
import org.springframework.stereotype.Component; |
||||||
|
|
||||||
|
import javax.annotation.Resource; |
||||||
|
import java.math.BigDecimal; |
||||||
|
import java.util.HashMap; |
||||||
|
import java.util.Map; |
||||||
|
|
||||||
|
/** |
||||||
|
* @className: TradeService |
||||||
|
* @author: HuRui |
||||||
|
* @date: 2024/4/7 |
||||||
|
**/ |
||||||
|
@Component |
||||||
|
public class TradeService { |
||||||
|
|
||||||
|
@Resource |
||||||
|
private HighOrderService orderService; |
||||||
|
|
||||||
|
/** |
||||||
|
* 交易-预下单 |
||||||
|
* @param order |
||||||
|
* @return |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public JSONObject thirdPreOrder(HighOrder order) throws Exception { |
||||||
|
Map<String,Object> param = new HashMap<>(); |
||||||
|
param.put("shopCode", HuiftConfig.shopcode); |
||||||
|
param.put("outTradeNo", order.getOrderNo()); |
||||||
|
param.put("transAmt", order.getPayablePrice().multiply(new BigDecimal("100")).intValue()); |
||||||
|
param.put("mobileNbr", order.getMemPhone()); // 用户标识
|
||||||
|
param.put("callbackUrl", CommonSysConst.getSysConfig().getHsgDomainName() + "/order/payNotify/huiftPay"); |
||||||
|
// param.put("remark", ""); // 备注
|
||||||
|
// param.put("outAppId", "");
|
||||||
|
// param.put("outRedirectPath", "");
|
||||||
|
param.put("sign", HuiftConfig.md5Encode(HuiftConfig.paramSort(param, HuiftConfig.signSecret).getBytes()).toLowerCase()); |
||||||
|
JSONObject response = HttpsUtils.doPost(HuiftConfig.reqUrl + "/hfq/v1/thirdPay/thirdPreOrder", JSONObject.toJSONString(param)); |
||||||
|
if (response.getString("status").equals("ok")) { |
||||||
|
return response.getJSONObject("data"); |
||||||
|
} |
||||||
|
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR , response.getString("message")); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 查询交易结果 |
||||||
|
* @param preOrderNo |
||||||
|
* @return |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public JSONObject thirdPayResult(String preOrderNo) throws Exception { |
||||||
|
Map<String,Object> param = new HashMap<>(); |
||||||
|
param.put("shopCode", HuiftConfig.shopcode); |
||||||
|
param.put("preOrderNo", preOrderNo); |
||||||
|
param.put("sign", HuiftConfig.md5Encode(HuiftConfig.paramSort(param, HuiftConfig.signSecret).getBytes()).toLowerCase()); |
||||||
|
JSONObject response = HttpsUtils.doPost(HuiftConfig.reqUrl + "/hfq/v1/thirdPay/thirdPayResult", JSONObject.toJSONString(param)); |
||||||
|
if (response.getString("status").equals("ok")) { |
||||||
|
return response.getJSONObject("data"); |
||||||
|
} |
||||||
|
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR , response.getString("message")); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 交易退款 |
||||||
|
* @param orderRefund |
||||||
|
* @return |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public JSONObject thirdPayRefund(HighOrderRefund orderRefund) throws Exception { |
||||||
|
// 查询订单
|
||||||
|
HighOrder order = orderService.getOrderById(orderRefund.getId()); |
||||||
|
|
||||||
|
Map<String,Object> param = new HashMap<>(); |
||||||
|
param.put("shopCode", HuiftConfig.shopcode); |
||||||
|
param.put("preOrderNo", order.getPayChannelOrderNo()); |
||||||
|
param.put("outRefundNo", orderRefund.getRefundOrderNo()); |
||||||
|
param.put("refundAmt", orderRefund.getRefundPrice().multiply(new BigDecimal("100")).intValue()); |
||||||
|
param.put("sign", HuiftConfig.md5Encode(HuiftConfig.paramSort(param, HuiftConfig.signSecret).getBytes()).toLowerCase()); |
||||||
|
JSONObject response = HttpsUtils.doPost(HuiftConfig.reqUrl + "/hfq/v1/thirdPay/thirdPayRefund", JSONObject.toJSONString(param)); |
||||||
|
if (response.getString("status").equals("ok")) { |
||||||
|
return response.getJSONObject("data"); |
||||||
|
} |
||||||
|
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR , response.getString("message")); |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -0,0 +1,58 @@ |
|||||||
|
package com.hai.pay.channel.huift.config; |
||||||
|
|
||||||
|
import org.apache.commons.lang3.StringUtils; |
||||||
|
|
||||||
|
import javax.xml.bind.annotation.adapters.HexBinaryAdapter; |
||||||
|
import java.security.MessageDigest; |
||||||
|
import java.util.Arrays; |
||||||
|
import java.util.Map; |
||||||
|
import java.util.Set; |
||||||
|
|
||||||
|
/** |
||||||
|
* @className: HuiftConfig |
||||||
|
* @author: HuRui |
||||||
|
* @date: 2024/4/7 |
||||||
|
**/ |
||||||
|
public class HuiftConfig { |
||||||
|
|
||||||
|
public final static String reqUrl = "https://linktest.huift.com.cn"; |
||||||
|
public final static String shopcode = "50041b27-f985-dcb0-1cc0-f106b09bf1fe"; |
||||||
|
public final static String signSecret = "DB4D8069A9AC6DDF9D75667EE5CF182A"; |
||||||
|
|
||||||
|
/** |
||||||
|
* 参数排序 |
||||||
|
* @param param |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
public static String paramSort(final Map<String, Object> param, String key) { |
||||||
|
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 (StringUtils.isBlank(sb.toString())) { |
||||||
|
sb.append(k).append("=").append(param.get(k)); |
||||||
|
} else { |
||||||
|
sb.append("&").append(k).append("=").append(param.get(k)); |
||||||
|
} |
||||||
|
} |
||||||
|
sb.append(key); |
||||||
|
return sb.toString(); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* MD5加密 |
||||||
|
* @param data |
||||||
|
* @return |
||||||
|
* @throws Exception |
||||||
|
*/ |
||||||
|
public static String md5Encode(byte[] data) throws Exception { |
||||||
|
// 初始化MessageDigest
|
||||||
|
MessageDigest md = MessageDigest.getInstance("MD5"); |
||||||
|
// 执行摘要信息
|
||||||
|
byte[] digest = md.digest(data); |
||||||
|
// 将摘要信息转换为32位的十六进制字符串
|
||||||
|
return new String(new HexBinaryAdapter().marshal(digest)); |
||||||
|
} |
||||||
|
|
||||||
|
} |
Loading…
Reference in new issue