generated from root/miduo_server
安久支付
parent
28249da03d
commit
e263a479b3
|
@ -0,0 +1,89 @@
|
|||
package com.jmfy.controller;
|
||||
|
||||
import com.jmfy.paramBean.PaySdkEnum;
|
||||
import com.jmfy.util.JsonUtil;
|
||||
import com.jmfy.util.MD5Util;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.security.KeyFactory;
|
||||
import java.security.Signature;
|
||||
import java.security.interfaces.RSAPublicKey;
|
||||
import java.security.spec.X509EncodedKeySpec;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* 安久
|
||||
*/
|
||||
@RestController
|
||||
public class AnJiuRechargeController {
|
||||
@Resource
|
||||
private PayLogic payLogic;
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(AnJiuRechargeController.class);
|
||||
public static final String publicKey = "gh3cb7f08zoh1rlk6c09ywgs70rk8ncu";
|
||||
|
||||
@RequestMapping(value = "/AnJiuCallback")
|
||||
public String anJiuCallback(HttpServletRequest request) throws Exception {
|
||||
HashMap<String, String> parameterMap = JsonUtil.getInstence().getParameterMap2(request);
|
||||
if (parameterMap.isEmpty()) {
|
||||
LOGGER.error("安久支付,回调参数为空");
|
||||
return "3";
|
||||
}
|
||||
LOGGER.info("安久支付回调参数========================》{}", parameterMap);
|
||||
|
||||
// 1、生成待签名字符串
|
||||
String sign = parameterMap.get("sign");
|
||||
parameterMap.remove("sign");
|
||||
TreeMap<String, String> treeMap = new TreeMap<>(parameterMap);
|
||||
|
||||
// 3、验签
|
||||
if (!verifySign(treeMap,sign)){
|
||||
LOGGER.error("安久支付,sign验证失败");
|
||||
return "1";
|
||||
}
|
||||
|
||||
return insertOrder(parameterMap);
|
||||
}
|
||||
|
||||
private String insertOrder(Map<String,String> map) {
|
||||
String callbackInfo = map.get("extInfo");
|
||||
String[] callback = callbackInfo.split("_");
|
||||
String orderNo = map.get("orderId");
|
||||
String amount = map.get("amount");
|
||||
String result = payLogic.initOrder(callbackInfo, orderNo, amount, new Date(), callback[0], PaySdkEnum.ANJIU);
|
||||
if ("SUCCESS".equals(result) || "ORDER_IS_EXIST".equals(result)) {
|
||||
return "0";
|
||||
}else {
|
||||
return "2";
|
||||
}
|
||||
}
|
||||
|
||||
private boolean verifySign(Map<String, String> map, String sign) {
|
||||
if (map == null || map.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
StringBuilder builder = new StringBuilder();
|
||||
for (Map.Entry<String, String> entry : map.entrySet()) {
|
||||
builder.append(entry.getKey()).append("=").append(entry.getValue()).append("&");
|
||||
}
|
||||
String substring = builder.substring(0, builder.length() - 1);
|
||||
try {
|
||||
// 2、生成签名
|
||||
return verify(publicKey,substring,sign);
|
||||
} catch (Exception e) {
|
||||
LOGGER.error("安久待签名字符串================>publicKey:{},signedData:{},signature:{}", publicKey,substring,sign);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static boolean verify(String pubKeyStr, String signedData, String signature) {
|
||||
String key = signedData + pubKeyStr;
|
||||
String mySign = MD5Util.encrypByMd5(key);
|
||||
return mySign.equals(signature);
|
||||
}
|
||||
|
||||
}
|
|
@ -18,6 +18,7 @@ public enum PaySdkEnum {
|
|||
AIWAN(8,"AIWAN"),
|
||||
HANFAN(9,"HAOFAN"),
|
||||
FENGTIIOS(10,"FENGTIIOS"),
|
||||
ANJIU(11, "ANJIU"),
|
||||
;
|
||||
|
||||
private int id;
|
||||
|
|
Loading…
Reference in New Issue