generated from root/miduo_server
疯体ios
parent
b4c4de3630
commit
e24e15123c
|
@ -0,0 +1,111 @@
|
|||
package com.jmfy.controller;
|
||||
|
||||
import com.jmfy.paramBean.PaySdkEnum;
|
||||
import com.jmfy.util.JsonUtil;
|
||||
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.*;
|
||||
|
||||
/**
|
||||
* 疯体 ios
|
||||
*/
|
||||
@RestController
|
||||
public class FengTiIosRechargeController {
|
||||
@Resource
|
||||
private PayLogic payLogic;
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(FengTiIosRechargeController.class);
|
||||
private static final String callbackkey = "53780900079388195716762718742907";
|
||||
|
||||
private static final String publicKey = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDmJHw+qP7vzf+QyL2/AC+dItwDMcoClG5csqiUgL6vl4801HogkBGHI9eQZuFqwJKJENoIkPA5apuitGJIor4CaomqiuWHMY+oIywPP+hXelcxzVDf8nx8XWe2f8WVbHlfI9EL40cvcijl5xv2xXGfxqFwvWzbC+64nszfD1HiewIDAQAB";
|
||||
|
||||
@RequestMapping(value = "/FengTiIosCallback")
|
||||
public String FengTiIoCallback(HttpServletRequest request) throws Exception {
|
||||
return process(request,callbackkey);
|
||||
}
|
||||
|
||||
private String process(HttpServletRequest request,String appsecret) throws Exception{
|
||||
HashMap<String, String> parameterMap = JsonUtil.getInstence().getParameterMap2(request);
|
||||
if (parameterMap.isEmpty()) {
|
||||
LOGGER.error("疯体ios,GameCallback data is null");
|
||||
return "FAIL";
|
||||
}
|
||||
LOGGER.info("疯体ios支付回调参数========================》{}", parameterMap);
|
||||
|
||||
// 1、生成待签名字符串
|
||||
String sign = parameterMap.get("sign");
|
||||
parameterMap.remove("sign");
|
||||
TreeMap<String, String> treeMap = new TreeMap<>(parameterMap);
|
||||
|
||||
// 3、验签
|
||||
if (!verifySign(treeMap,sign)){
|
||||
LOGGER.error("疯体ios,GameCallback data is null");
|
||||
return "SIGN_VERIFY_FAIL";
|
||||
}
|
||||
|
||||
return insertOrder(parameterMap);
|
||||
}
|
||||
|
||||
private String insertOrder(Map<String,String> map) {
|
||||
String callbackInfo = map.get("custom_callback_info");
|
||||
String[] callback = callbackInfo.split("_");
|
||||
String orderNo = map.get("external_order_no");
|
||||
String amount = map.get("total_amount");
|
||||
String result = payLogic.initOrder(callbackInfo, orderNo, amount, new Date(), callback[0], PaySdkEnum.FENGTIIOS);
|
||||
if ("ORDER_IS_EXIST".equals(result)) {
|
||||
return "success";
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
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("疯体ios待签名字符串================>publicKey:{},signedData:{},signature:{}",publicKey,substring,sign);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static boolean verify(String pubKeyStr, String signedData, String signature) throws Exception {
|
||||
X509EncodedKeySpec keySpecX509 = new X509EncodedKeySpec(Base64.getDecoder().decode(pubKeyStr));
|
||||
KeyFactory kf = KeyFactory.getInstance("RSA");
|
||||
RSAPublicKey pubKey = (RSAPublicKey) kf.generatePublic(keySpecX509);
|
||||
|
||||
System.out.println("parse key success");
|
||||
try {
|
||||
Signature sig;
|
||||
sig = Signature.getInstance("SHA1withRSA");
|
||||
sig.initVerify(pubKey);
|
||||
System.out.println("initVerify success");
|
||||
// sig.update(signedData.getBytes());
|
||||
sig.update(Base64.getDecoder().decode(Base64.getEncoder().encode(signedData.getBytes())));
|
||||
System.out.println("update success");
|
||||
|
||||
if (!sig.verify(Base64.getDecoder().decode(signature.getBytes()))) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -147,8 +147,6 @@ public class QuickRechargeController3 {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static Map<String,String> getData(String xml){
|
||||
//1.创建Reader对象
|
||||
SAXReader reader = new SAXReader();
|
||||
|
|
|
@ -17,6 +17,7 @@ public enum PaySdkEnum {
|
|||
DUOYOU(7,"DUOYOU"),
|
||||
AIWAN(8,"AIWAN"),
|
||||
HANFAN(9,"HAOFAN"),
|
||||
FENGTIIOS(10,"FENGTIIOS"),
|
||||
;
|
||||
|
||||
private int id;
|
||||
|
|
Loading…
Reference in New Issue