# Conflicts: # service/src/main/java/com/hfkj/service/order/impl/BsOrderRefundServiceImpl.javadev
commit
90f046bd7f
@ -1,56 +0,0 @@ |
||||
package com.hfkj.common.utils; |
||||
|
||||
import com.alibaba.fastjson.JSONObject; |
||||
import org.apache.http.HttpResponse; |
||||
import org.apache.http.util.EntityUtils; |
||||
|
||||
import java.util.HashMap; |
||||
import java.util.Map; |
||||
|
||||
/** |
||||
* 阿里云业务服务 |
||||
* @className: AliyunService |
||||
* @author: HuRui |
||||
* @date: 2024/4/3 |
||||
**/ |
||||
public class AliyunService { |
||||
|
||||
/** |
||||
* 查询ip地址 |
||||
* @param ip ip地址 |
||||
* @return |
||||
*/ |
||||
public static JSONObject queryAddress(String ip) { |
||||
try { |
||||
String host = "https://ipaddquery.market.alicloudapi.com"; |
||||
String path = "/ip/address-query"; |
||||
String method = "POST"; |
||||
String appcode = "f9ace4c915054ca697a76fb9a4e1e8c0"; |
||||
|
||||
Map<String, String> headers = new HashMap<>(); |
||||
headers.put("Authorization", "APPCODE " + appcode); |
||||
headers.put("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8"); |
||||
|
||||
Map<String, String> bodys = new HashMap<>(); |
||||
bodys.put("ip", ip); |
||||
|
||||
HttpResponse response = HttpUtils.doPost(host, path, method, headers, new HashMap<>(), bodys); |
||||
JSONObject resObj = JSONObject.parseObject(EntityUtils.toString(response.getEntity())); |
||||
if (resObj.getString("code").equals("200")) { |
||||
return resObj.getJSONObject("data"); |
||||
} |
||||
return null; |
||||
|
||||
} catch (Exception e) { |
||||
return null; |
||||
} |
||||
} |
||||
|
||||
public static void main(String[] args) { |
||||
try { |
||||
System.out.println(queryAddress("123.147.76.209")); |
||||
} catch (Exception e) { |
||||
e.printStackTrace(); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,28 @@ |
||||
package com.hfkj.common.utils; |
||||
|
||||
import com.alibaba.fastjson.JSONObject; |
||||
import com.hfkj.common.exception.ErrorCode; |
||||
import com.hfkj.common.exception.ErrorHelp; |
||||
import com.hfkj.common.exception.SysCode; |
||||
|
||||
/** |
||||
* 高德API服务 |
||||
* @className: AmapApiService |
||||
* @author: HuRui |
||||
* @date: 2024/6/28 |
||||
**/ |
||||
public class AmapApiService { |
||||
|
||||
/** |
||||
* 获取ip |
||||
*/ |
||||
public static JSONObject queryIp(String ip) { |
||||
JSONObject obj = HttpsUtils.doGet("https://restapi.amap.com/v3/ip?key=0083a5b1cc5289d7e9691424ee62136e&ip="+ip); |
||||
if (obj.getString("status").equals("1")) { |
||||
return obj; |
||||
} else { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, obj.getString("info")); |
||||
} |
||||
} |
||||
|
||||
} |
@ -0,0 +1,109 @@ |
||||
package com.hfkj.service.pay.huift; |
||||
|
||||
import com.alibaba.fastjson.JSONObject; |
||||
import com.hfkj.common.exception.ErrorCode; |
||||
import com.hfkj.common.exception.ErrorHelp; |
||||
import com.hfkj.common.exception.SysCode; |
||||
import com.hfkj.common.utils.HttpsUtils; |
||||
import com.hfkj.config.CommonSysConst; |
||||
import com.hfkj.entity.BsOrder; |
||||
import com.hfkj.model.order.OrderModel; |
||||
import com.hfkj.service.order.BsOrderService; |
||||
import com.hfkj.service.pay.huift.config.HuiftConfig; |
||||
import com.hfkj.sysenum.order.OrderPayTypeEnum; |
||||
import com.hfkj.sysenum.order.OrderStatusEnum; |
||||
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 BsOrderService orderService; |
||||
|
||||
/** |
||||
* 交易-预下单 |
||||
* @param order |
||||
* @return |
||||
* @throws Exception |
||||
*/ |
||||
public JSONObject thirdPreOrder(OrderModel order) throws Exception { |
||||
Map<String,Object> param = new HashMap<>(); |
||||
param.put("shopCode", HuiftConfig.shopcode); |
||||
param.put("outTradeNo", order.getOrderNo()); |
||||
param.put("transAmt", order.getPayRealPrice().multiply(new BigDecimal("100")).intValue()); |
||||
param.put("mobileNbr", order.getUserPhone()); // 用户标识
|
||||
param.put("callbackUrl", CommonSysConst.getSysConfig().getDomainName() + "/order/payNotify/huiftPay"); |
||||
// param.put("remark", ""); // 备注
|
||||
// param.put("outAppId", "");
|
||||
param.put("outRedirectPath", CommonSysConst.getSysConfig().getDomainName()+"/phg/#/pages/user/order_list/order_list?tbIndex=-1"); |
||||
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 refundOrderNo 退款订单号 |
||||
* @param refundPrice 退款金额 |
||||
* @param orderNo 订单号 |
||||
* @return |
||||
* @throws Exception |
||||
*/ |
||||
public JSONObject thirdPayRefund(String refundOrderNo, BigDecimal refundPrice, String orderNo) throws Exception { |
||||
// 查询订单
|
||||
BsOrder order = orderService.getOrder(orderNo); |
||||
if (order == null) { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未知的的订单"); |
||||
} |
||||
if (!order.getOrderStatus().equals(OrderStatusEnum.status2.getCode()) |
||||
&& !order.getOrderStatus().equals(OrderStatusEnum.status3.getCode())) { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "订单当前状态无法退款"); |
||||
} |
||||
if (!order.getPayType().equals(OrderPayTypeEnum.type3.getCode())) { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "支付方式错误"); |
||||
} |
||||
Map<String,Object> param = new HashMap<>(); |
||||
param.put("shopCode", HuiftConfig.shopcode); |
||||
param.put("preOrderNo", order.getPayChannelOrderNo()); |
||||
param.put("outRefundNo", refundOrderNo); |
||||
param.put("refundAmt", refundPrice.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,59 @@ |
||||
package com.hfkj.service.pay.huift.config; |
||||
|
||||
import com.hfkj.config.CommonSysConst; |
||||
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 = CommonSysConst.getSysConfig().getHuiftReqUrl(); |
||||
public final static String shopcode = CommonSysConst.getSysConfig().getHuiftShopCode(); |
||||
public final static String signSecret = CommonSysConst.getSysConfig().getHuiftSignSecret(); |
||||
|
||||
/** |
||||
* 参数排序 |
||||
* @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