payermax-兼容无targetOrg的情况
This commit is contained in:
@@ -34,7 +34,7 @@ public class PayermaxService {
|
||||
String[] paymentMethodType = params.getPaymentMethodType().split(SPILT_PREFIX);
|
||||
TradeOrderRequest.PaymentDetail paymentDetail = new TradeOrderRequest.PaymentDetail();
|
||||
paymentDetail.setPaymentMethodType(paymentMethodType[0]);
|
||||
paymentDetail.setTargetOrg(paymentMethodType[1]);
|
||||
paymentDetail.setTargetOrg(paymentMethodType.length > 1 ? paymentMethodType[1]: null);
|
||||
|
||||
request.setPaymentDetail(paymentDetail);
|
||||
request.setFrontCallbackUrl(params.getFrontCallBackUrl());
|
||||
|
@@ -34,6 +34,7 @@ public class PayerMaxStrategy extends AbstractPayStrategy {
|
||||
public Object pay(PayContext context) throws Exception {
|
||||
//渠道黑名單
|
||||
chargeUserLimitService.chargeLimitCheck(UidContextHolder.get(), ChargeUserLimitConstant.LIMIT_TYPE_OF_H5);
|
||||
|
||||
ChargeRecord chargeRecord = context.getChargeRecord();
|
||||
ChargeProd chargeProd = context.getChargeProd();
|
||||
CreateOrderParams params = new CreateOrderParams();
|
||||
|
@@ -2,38 +2,13 @@ package com.accompany.payment.utils;
|
||||
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.security.MessageDigest;
|
||||
import java.util.*;
|
||||
|
||||
public class PayermaxUtils {
|
||||
|
||||
public static void main(String[] args) {
|
||||
//演示实例
|
||||
String merchantMD5Key = "123456789";
|
||||
Map<String, Object> params = new HashMap<>(16);
|
||||
|
||||
Map<String, Object> aa = new HashMap<>(16);
|
||||
aa.put("bizType", "test");
|
||||
Map<String, Object> bb = new HashMap<>(16);
|
||||
bb.put("version", "test");
|
||||
List<Map<String, Object>> a = Arrays.asList(aa, bb);
|
||||
|
||||
params.put("bizType", "test");
|
||||
params.put("version", "2.0");
|
||||
params.put("merchantId", "SP4189603");
|
||||
params.put("orderId", "1535433516149");
|
||||
params.put("amount", "13.6");
|
||||
params.put("currency", "INR");
|
||||
params.put("countryCode", a);
|
||||
|
||||
String sign = signForMD5(params, merchantMD5Key);
|
||||
params.put("sign", sign);
|
||||
System.out.println("this is your request params with sign: " + params);
|
||||
boolean flag = verifyForMD5(params, sign, merchantMD5Key);
|
||||
System.out.println("verify sign result is: " + flag);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据请求参数生成签名:请求参数排序并后面补充key值,最后进行MD5加密,返回大写结果
|
||||
*
|
||||
@@ -133,7 +108,7 @@ public class PayermaxUtils {
|
||||
if (val instanceof JSONObject || val instanceof HashMap) {
|
||||
buf.append(key + "=" + formatMapToSignStr((Map) val));
|
||||
buf.append("&");
|
||||
} else if (val instanceof JSONArray) {
|
||||
} else if(val instanceof JSONArray){
|
||||
for (int i = 0; i < ((JSONArray) val).size(); i++) {
|
||||
buf.append(key + "=" + formatMapToSignStr(((JSONArray) val).getJSONObject(i)));
|
||||
buf.append("&");
|
||||
@@ -151,4 +126,110 @@ public class PayermaxUtils {
|
||||
return buff;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取链接的参数
|
||||
* @param url 链接
|
||||
* @return
|
||||
*/
|
||||
public static LinkedHashMap<String, String> getParamsMap(String url){
|
||||
if(StringUtils.isBlank(url)){
|
||||
return null;
|
||||
}
|
||||
|
||||
url = url.trim();
|
||||
int length = url.length();
|
||||
int index = url.indexOf("?");
|
||||
|
||||
if(index > -1){//url说明有问号
|
||||
if((length - 1) == index){//url最后一个符号为?,如:http://wwww.baidu.com?
|
||||
return null;
|
||||
|
||||
}else{
|
||||
//情况为:http://wwww.baidu.com?aa=11或http://wwww.baidu.com?aa=或http://wwww.baidu.com?aa
|
||||
String baseUrl = url.substring(0, index);
|
||||
String paramsString = url.substring(index + 1);
|
||||
|
||||
if(!StringUtils.isBlank(paramsString)){
|
||||
LinkedHashMap<String, String> paramsMap = new LinkedHashMap<String, String>();
|
||||
String[] params = paramsString.split("&");
|
||||
|
||||
for (String param : params) {
|
||||
if(!StringUtils.isBlank(param)){
|
||||
String[] oneParam = param.split("=");
|
||||
String paramName = oneParam[0];
|
||||
|
||||
if(!StringUtils.isBlank(paramName)){
|
||||
if(oneParam.length > 1){
|
||||
paramsMap.put(paramName.trim(), oneParam[1]);//键可以去空格,值不能去空格
|
||||
|
||||
}else{
|
||||
paramsMap.put(paramName.trim(), "");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
return paramsMap;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 保留url链接的多个参数
|
||||
* @param url String 链接地址
|
||||
* @param paramNames String... 参数
|
||||
* @return
|
||||
*/
|
||||
public static String retainParams(String url, String... paramNames){
|
||||
if(StringUtils.isBlank(url)){
|
||||
return "";
|
||||
|
||||
}else if(paramNames == null || paramNames.length < 1){
|
||||
return url.trim();
|
||||
|
||||
}else{
|
||||
url = url.trim();
|
||||
int length = url.length();
|
||||
int index = url.indexOf("?");
|
||||
|
||||
|
||||
if(index > -1){//url有问号
|
||||
if((length - 1) == index){//url最后一个符号为?,如:http://wwww.baidu.com?
|
||||
return url;
|
||||
}else{
|
||||
String baseUrl = url.substring(0, index);
|
||||
LinkedHashMap<String, String> paramsMap = new LinkedHashMap<>();
|
||||
|
||||
LinkedHashMap<String, String> oldParamsMap = getParamsMap(url);
|
||||
|
||||
//删除参数
|
||||
if(oldParamsMap != null && oldParamsMap.size() > 0){
|
||||
for (String paramName : paramNames) {
|
||||
if(!StringUtils.isBlank(paramName)){
|
||||
paramsMap.put(paramName, oldParamsMap.get(paramName));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//重新拼接链接
|
||||
if(paramsMap.size() > 0){
|
||||
StringBuilder paramBuffer = new StringBuilder(baseUrl);
|
||||
paramBuffer.append("?");
|
||||
Set<String> set = paramsMap.keySet();
|
||||
for (String paramName : set) {
|
||||
paramBuffer.append(paramName).append("=").append(paramsMap.get(paramName)).append("&");
|
||||
}
|
||||
paramBuffer.deleteCharAt(paramBuffer.length() - 1);
|
||||
return paramBuffer.toString();
|
||||
}
|
||||
return baseUrl;
|
||||
}
|
||||
}
|
||||
return url;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -5,14 +5,12 @@ import com.accompany.common.constant.Constant;
|
||||
import com.accompany.common.redis.RedisKey;
|
||||
import com.accompany.common.result.BusiResult;
|
||||
import com.accompany.common.status.BusiStatus;
|
||||
import com.accompany.common.utils.DateTimeUtil;
|
||||
import com.accompany.core.exception.ServiceException;
|
||||
import com.accompany.payment.constant.PayConstant;
|
||||
import com.accompany.payment.model.ChargeRecord;
|
||||
import com.accompany.payment.payermax.params.PayCallbackReqVo;
|
||||
import com.accompany.payment.service.ChargeRecordService;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.payermax.sdk.client.DefaultPayermaxClient;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
@@ -21,10 +19,7 @@ import org.redisson.api.RedissonClient;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.Date;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@@ -47,9 +42,7 @@ public class PayermaxPayController {
|
||||
private RedissonClient redissonClient;
|
||||
|
||||
@PostMapping("/callback")
|
||||
public BusiResult<Void> callback(HttpServletRequest request,
|
||||
@RequestBody String paramsString) {
|
||||
String sign = request.getHeader("sign");
|
||||
public BusiResult<Void> callback(@RequestHeader("sign") String sign, @RequestBody String paramsString) {
|
||||
log.info("[payermax] 接受回调参数为:{}",paramsString);
|
||||
|
||||
if (!DefaultPayermaxClient.getInstance().verifyNotification(paramsString, sign)) {
|
||||
@@ -73,7 +66,7 @@ public class PayermaxPayController {
|
||||
isLocked = lock.tryLock(5L, TimeUnit.SECONDS);
|
||||
if (!isLocked){
|
||||
log.error("[payermax] 支付回调 加锁失败 chargeRecordId: {}", chargeRecordId);
|
||||
throw new ServiceException(BusiStatus.SERVER_BUSY);
|
||||
throw new ServiceException(BusiStatus.SERVERBUSY);
|
||||
}
|
||||
|
||||
ChargeRecord chargeRecord = chargeRecordService.getChargeRecordById(chargeRecordId);
|
||||
@@ -104,8 +97,7 @@ public class PayermaxPayController {
|
||||
|
||||
return BusiResult.success();
|
||||
} catch (Exception e) {
|
||||
//todo log
|
||||
log.error("{}", e);
|
||||
log.error("[payermax] 回调异常", e);
|
||||
return BusiResult.fail(BusiStatus.SERVERERROR);
|
||||
} finally {
|
||||
if (isLocked || lock.isLocked()){
|
||||
|
@@ -717,7 +717,7 @@
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>peko-public</id>
|
||||
<url>http://nexus.molistar.xyz/repository/maven-public/</url>
|
||||
<url>https://nexus.molistar.xyz/repository/maven-public/</url>
|
||||
<releases>
|
||||
<enabled>true</enabled>
|
||||
</releases>
|
||||
|
Reference in New Issue
Block a user