recharge change

master
wangyuan 2019-09-05 10:00:02 +08:00
parent ec3df8af3e
commit 14a2a9fc0c
2 changed files with 33 additions and 12 deletions

View File

@ -15,18 +15,12 @@ import com.jmfy.util.MD5Util;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.context.support.HttpRequestHandlerServlet;
import javax.annotation.Resource;
import javax.servlet.ServletInputStream;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.Reader;
import java.lang.reflect.Field;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
@ -37,15 +31,15 @@ public class RechargeController {
@Resource
private CUserDao cuserDao;
private static final Logger LOGGER = LoggerFactory.getLogger(RechargeController.class);
private static Gson gson = new Gson();
@RequestMapping(value = "/callback")
public String callback( HttpServletRequest request) throws Exception {
HashMap<String, String> parameterMap = JsonUtil.getInstence().getParameterMap(request);
if(parameterMap.isEmpty()){
if(parameterMap.isEmpty()) {
ResultVo resultVo = new ResultVo(8, "data is null");
return JsonUtil.getInstence().getGson().toJson(resultVo);
}
Gson gson = new Gson();
String source = parameterMap.keySet().iterator().next();
LOGGER.info(source);
RechargeRequestBean rechargeRequestBean = gson.fromJson(source, RechargeRequestBean.class);
@ -64,7 +58,7 @@ public class RechargeController {
String sig = getMySign(rechargeRequestBean);
if (!sig.equals(sign)){
LOGGER.info("callback==>roleUid={},sin derify fail ",userId);
LOGGER.info("callback==>roleUid={},sin derify fail,mine sign={} ",userId,sig);
ResultVo resultVo = new ResultVo(9, "sign fail");
return JsonUtil.getInstence().getGson().toJson(resultVo);
}

View File

@ -7,6 +7,8 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.servlet.http.HttpServletRequest;
import java.io.BufferedReader;
import java.io.IOException;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.text.ParseException;
@ -38,19 +40,44 @@ public class JsonUtil {
return gson;
}
public HashMap<String, String> getParameterMap(HttpServletRequest request) {
public HashMap<String, String> getParameterMap(HttpServletRequest request) throws IOException {
HashMap<String, String> map = new HashMap();
Enumeration paramNames = request.getParameterNames();
while (paramNames.hasMoreElements()) {
String paramName = (String) paramNames.nextElement();
String[] paramValues = request.getParameterValues(paramName);
String paramValue = paramValues[0];
map.put(paramName, paramValue);
if(!StringUtils.checkIsEmpty(paramName)){
map.put(paramName+"="+paramValue, paramValue);
}else{
map.put(paramName, paramValue);
}
LOGGER.info("parameter : " + paramName + "=" + paramValue);
}
return map;
}
public static byte[] getRequestPostBytes(HttpServletRequest request)
throws IOException {
int contentLength = request.getContentLength();
if (contentLength < 0) {
return null;
}
byte buffer[] = new byte[contentLength];
for (int i = 0; i < contentLength; ) {
int readlen = request.getInputStream().read(buffer, i,
contentLength - i);
if (readlen == -1) {
break;
}
i += readlen;
}
return buffer;
}
public static String getServiceKey(String serviceName, String host, String port) {
StringBuilder sb = new StringBuilder();
return sb.append(serviceName).append("|")