generated from root/miduo_server
178 lines
6.4 KiB
Java
178 lines
6.4 KiB
Java
package com.jmfy.controller;
|
||
|
||
import com.jmfy.paramBean.PaySdkEnum;
|
||
import com.jmfy.util.JsonUtil;
|
||
import com.jmfy.util.MD5Util;
|
||
import org.dom4j.Document;
|
||
import org.dom4j.DocumentException;
|
||
import org.dom4j.Element;
|
||
import org.dom4j.io.SAXReader;
|
||
import org.slf4j.Logger;
|
||
import org.slf4j.LoggerFactory;
|
||
import org.springframework.web.bind.annotation.RequestMapping;
|
||
import org.springframework.web.bind.annotation.RestController;
|
||
import org.xml.sax.InputSource;
|
||
|
||
import javax.annotation.Resource;
|
||
import javax.servlet.http.HttpServletRequest;
|
||
import java.io.StringReader;
|
||
import java.util.*;
|
||
import java.util.regex.Matcher;
|
||
import java.util.regex.Pattern;
|
||
@Deprecated
|
||
@RestController
|
||
public class QuickRechargeController2 {
|
||
@Resource
|
||
private PayLogic payLogic;
|
||
private static final Logger LOGGER = LoggerFactory.getLogger(QuickRechargeController2.class);
|
||
private static final String callbackkey = "69382864976094208404596003308975";
|
||
private static final String md5key = "q6k5xzvtkcwhgbiudluckacqzwutqgpg";
|
||
|
||
@RequestMapping(value = "/QUICKCallback2")
|
||
public String QuickGnCallback(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.info("data is null");
|
||
return "FAILED";
|
||
}
|
||
String ntdata0 = parameterMap.get("nt_data");
|
||
|
||
String ntdata = decode(ntdata0,callbackkey);
|
||
Map<String,String> map = getData(ntdata);
|
||
LOGGER.info("MapInfo: is_test:{},channel:{},channel_uid:{},game_order:{},order_no:{},pay_time:{}," +
|
||
"amount:{},atatus:{}",map.get("is_test"),map.get("channel"),map.get("channel_uid"),
|
||
map.get("game_order"),map.get("order_no"),map.get("pay_time"));
|
||
if (map.size() == 0) {
|
||
LOGGER.info("data is null");
|
||
return "FAILED";
|
||
}
|
||
|
||
|
||
String response = "SUCCESS";
|
||
try {
|
||
String consumerid = map.get("channel_uid");
|
||
String sign = parameterMap.get("sign");
|
||
String md5Sign = parameterMap.get("md5Sign");
|
||
if(!sign(ntdata0,sign,md5Sign)){
|
||
LOGGER.info("callback==>roleUid={},sin derify fail ", consumerid);
|
||
return "FAILED";
|
||
}
|
||
if(map.get("status").equals("1")){
|
||
LOGGER.info("callback==>status:FAILED ");
|
||
return "FAILED";
|
||
}
|
||
response = insertOrder(map);
|
||
|
||
} catch (Exception e) {
|
||
e.printStackTrace();
|
||
LOGGER.info("callback==>err " + e.toString());
|
||
response = "FAILED";
|
||
}
|
||
|
||
return response;
|
||
}
|
||
|
||
private String insertOrder(Map<String,String> map) {
|
||
String callbackInfo = map.get("extras_params");
|
||
String[] callback = callbackInfo.split("_");
|
||
String orderNo = map.get("order_no");
|
||
String amount = map.get("amount");
|
||
//quick的是元 要处理一下
|
||
String amountForward = String.valueOf((int)Double.parseDouble(amount) * 100);
|
||
String s = payLogic.initOrder(callbackInfo, orderNo, amountForward, new Date(System.currentTimeMillis()), callback[0], PaySdkEnum.QUICK);
|
||
if ("ORDER_IS_EXIST".equals(s)) {
|
||
return "SUCCESS";
|
||
}
|
||
return s;
|
||
}
|
||
|
||
public boolean sign(String ntdata0,String sign0,String md5Sign){
|
||
String paramStr = ntdata0+sign0+md5key;
|
||
String sign = MD5Util.encrypByMd5(paramStr);
|
||
// LOGGER.info("加密前字符串:{}",paramStr);
|
||
LOGGER.info("加密后得:{}",sign);
|
||
if(sign.equals(md5Sign)){
|
||
return true;
|
||
}else{
|
||
LOGGER.info("sign:{} md5Sign:{}",sign,md5Sign);
|
||
return false;
|
||
}
|
||
}
|
||
|
||
public String encode(String src,String key) {
|
||
byte[] data = src.getBytes();
|
||
byte[] keys = key.getBytes();
|
||
StringBuilder sb = new StringBuilder();
|
||
for (int i = 0; i < data.length; i++) {
|
||
int n = (0xff & data[i]) + (0xff & keys[i % keys.length]);
|
||
sb.append("@" + n);
|
||
}
|
||
return sb.toString();
|
||
}
|
||
|
||
public String decode(String src,String key) {
|
||
if(src == null || src.length() == 0){
|
||
return src;
|
||
}
|
||
Pattern pattern = Pattern.compile("@([^@]*)");
|
||
Matcher m = pattern.matcher(src);
|
||
List<Integer> list = new ArrayList();
|
||
while (m.find()) {
|
||
try {
|
||
String group = m.group(1);
|
||
if(group.equals(""))
|
||
continue;
|
||
list.add(Integer.valueOf(group));
|
||
} catch (Exception e) {
|
||
e.printStackTrace();
|
||
return src;
|
||
}
|
||
}
|
||
if (list.size() > 0) {
|
||
byte[] data = new byte[list.size()];
|
||
byte[] keys = key.getBytes();
|
||
for (int i = 0; i < data.length; i++) {
|
||
data[i] = (byte) (list.get(i) - (0xff & keys[i % keys.length]));
|
||
}
|
||
return new String(data);
|
||
} else {
|
||
return src;
|
||
}
|
||
}
|
||
|
||
|
||
|
||
public static Map<String,String> getData(String xml){
|
||
//1.创建Reader对象
|
||
SAXReader reader = new SAXReader();
|
||
StringReader sr = new StringReader(xml);
|
||
InputSource is = new InputSource(sr);
|
||
Map<String,String> map = new HashMap<>();
|
||
//2.加载xml
|
||
try {
|
||
Document document = reader.read(is);
|
||
//3.获取根节点
|
||
Element rootElement = document.getRootElement();
|
||
Iterator iterator = rootElement.elementIterator();
|
||
while (iterator.hasNext()){
|
||
Element stu = (Element) iterator.next();
|
||
LOGGER.info("======遍历子节点======");
|
||
Iterator iterator1 = stu.elementIterator();
|
||
while (iterator1.hasNext()){
|
||
Element stuChild = (Element) iterator1.next();
|
||
map.put(stuChild.getName(),stuChild.getStringValue());
|
||
LOGGER.info("节点名:"+stuChild.getName()+"---节点值:"+stuChild.getStringValue());
|
||
}
|
||
}
|
||
}catch (DocumentException e) {
|
||
// TODO Auto-generated catch block
|
||
e.printStackTrace();
|
||
}
|
||
return map;
|
||
}
|
||
}
|