generated from root/miduo_server
xp发货
parent
b6463a9e25
commit
11bd641263
|
@ -4,6 +4,7 @@ import com.google.gson.Gson;
|
||||||
import com.jmfy.dto.CPayOrder;
|
import com.jmfy.dto.CPayOrder;
|
||||||
import com.jmfy.dto.CUserDao;
|
import com.jmfy.dto.CUserDao;
|
||||||
import com.jmfy.dto.CUserInfo;
|
import com.jmfy.dto.CUserInfo;
|
||||||
|
import com.jmfy.paramBean.MHTGnWebRechargeRequestBean;
|
||||||
import com.jmfy.thrift.idl.RPCRequestIFace;
|
import com.jmfy.thrift.idl.RPCRequestIFace;
|
||||||
import com.jmfy.thrift.idl.Result;
|
import com.jmfy.thrift.idl.Result;
|
||||||
import com.jmfy.thrift.pool.ClientAdapterPo;
|
import com.jmfy.thrift.pool.ClientAdapterPo;
|
||||||
|
|
|
@ -4,6 +4,7 @@ import com.google.gson.Gson;
|
||||||
import com.jmfy.dto.CPayOrder;
|
import com.jmfy.dto.CPayOrder;
|
||||||
import com.jmfy.dto.CUserDao;
|
import com.jmfy.dto.CUserDao;
|
||||||
import com.jmfy.dto.CUserInfo;
|
import com.jmfy.dto.CUserInfo;
|
||||||
|
import com.jmfy.paramBean.MHTNetRechargeRequestBean;
|
||||||
import com.jmfy.thrift.idl.RPCRequestIFace;
|
import com.jmfy.thrift.idl.RPCRequestIFace;
|
||||||
import com.jmfy.thrift.idl.Result;
|
import com.jmfy.thrift.idl.Result;
|
||||||
import com.jmfy.thrift.pool.ClientAdapterPo;
|
import com.jmfy.thrift.pool.ClientAdapterPo;
|
||||||
|
|
|
@ -5,15 +5,13 @@ import com.jmfy.dto.CPOrder;
|
||||||
import com.jmfy.dto.CPayOrder;
|
import com.jmfy.dto.CPayOrder;
|
||||||
import com.jmfy.dto.CUserDao;
|
import com.jmfy.dto.CUserDao;
|
||||||
import com.jmfy.dto.CUserInfo;
|
import com.jmfy.dto.CUserInfo;
|
||||||
|
import com.jmfy.paramBean.MHTRechargeRequestBean;
|
||||||
import com.jmfy.thrift.idl.RPCRequestIFace;
|
import com.jmfy.thrift.idl.RPCRequestIFace;
|
||||||
import com.jmfy.thrift.idl.Result;
|
import com.jmfy.thrift.idl.Result;
|
||||||
import com.jmfy.thrift.pool.ClientAdapterPo;
|
import com.jmfy.thrift.pool.ClientAdapterPo;
|
||||||
import com.jmfy.thrift.pool.ServiceKey;
|
import com.jmfy.thrift.pool.ServiceKey;
|
||||||
import com.jmfy.util.JsonUtil;
|
import com.jmfy.util.JsonUtil;
|
||||||
import com.jmfy.util.KTSDKConstans;
|
|
||||||
import com.jmfy.util.MD5Util;
|
import com.jmfy.util.MD5Util;
|
||||||
import com.jmfy.util.MHTSDKConstans;
|
|
||||||
import net.sf.json.JSON;
|
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
@ -22,7 +20,6 @@ import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import java.io.UnsupportedEncodingException;
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.text.DateFormat;
|
import java.text.DateFormat;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
|
|
|
@ -1,15 +1,14 @@
|
||||||
package com.jmfy.controller;
|
package com.jmfy.controller;
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
|
||||||
import com.jmfy.dto.CPayOrder;
|
import com.jmfy.dto.CPayOrder;
|
||||||
import com.jmfy.dto.CUserDao;
|
import com.jmfy.dto.CUserDao;
|
||||||
import com.jmfy.dto.CUserInfo;
|
import com.jmfy.dto.CUserInfo;
|
||||||
|
import com.jmfy.paramBean.MHTRechargeRequestBean;
|
||||||
import com.jmfy.thrift.idl.RPCRequestIFace;
|
import com.jmfy.thrift.idl.RPCRequestIFace;
|
||||||
import com.jmfy.thrift.idl.Result;
|
import com.jmfy.thrift.idl.Result;
|
||||||
import com.jmfy.thrift.pool.ClientAdapterPo;
|
import com.jmfy.thrift.pool.ClientAdapterPo;
|
||||||
import com.jmfy.thrift.pool.ServiceKey;
|
import com.jmfy.thrift.pool.ServiceKey;
|
||||||
import com.jmfy.util.JsonUtil;
|
import com.jmfy.util.JsonUtil;
|
||||||
import com.jmfy.util.KTSDKConstans;
|
|
||||||
import com.jmfy.util.MD5Util;
|
import com.jmfy.util.MD5Util;
|
||||||
import com.jmfy.util.MHTSDKConstans;
|
import com.jmfy.util.MHTSDKConstans;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
|
@ -22,9 +21,6 @@ import javax.annotation.Resource;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.net.URLDecoder;
|
|
||||||
import java.net.URLEncoder;
|
|
||||||
import java.nio.charset.StandardCharsets;
|
|
||||||
import java.text.DateFormat;
|
import java.text.DateFormat;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
|
@ -2,6 +2,7 @@ package com.jmfy.controller;
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import com.jmfy.dto.*;
|
import com.jmfy.dto.*;
|
||||||
|
import com.jmfy.paramBean.RechargeRequestBean;
|
||||||
import com.jmfy.thrift.idl.RPCRequestIFace;
|
import com.jmfy.thrift.idl.RPCRequestIFace;
|
||||||
import com.jmfy.thrift.idl.Result;
|
import com.jmfy.thrift.idl.Result;
|
||||||
import com.jmfy.thrift.pool.ClientAdapterPo;
|
import com.jmfy.thrift.pool.ClientAdapterPo;
|
||||||
|
@ -12,7 +13,6 @@ import com.jmfy.util.MD5Util;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.web.bind.annotation.RequestBody;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,195 @@
|
||||||
|
package com.jmfy.controller;
|
||||||
|
|
||||||
|
import com.google.gson.Gson;
|
||||||
|
import com.jmfy.dto.CPayOrder;
|
||||||
|
import com.jmfy.dto.CUserDao;
|
||||||
|
import com.jmfy.dto.CUserInfo;
|
||||||
|
import com.jmfy.paramBean.MHTGnWebRechargeRequestBean;
|
||||||
|
import com.jmfy.paramBean.XPParamBean;
|
||||||
|
import com.jmfy.thrift.idl.RPCRequestIFace;
|
||||||
|
import com.jmfy.thrift.idl.Result;
|
||||||
|
import com.jmfy.thrift.pool.ClientAdapterPo;
|
||||||
|
import com.jmfy.thrift.pool.ServiceKey;
|
||||||
|
import com.jmfy.util.JsonUtil;
|
||||||
|
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.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.text.DateFormat;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author lvxinran
|
||||||
|
* @date 2021/6/9
|
||||||
|
* @discribe
|
||||||
|
*/
|
||||||
|
@RestController
|
||||||
|
public class XPRechargeController {
|
||||||
|
@Resource
|
||||||
|
private CUserDao cuserDao;
|
||||||
|
private static final Logger LOGGER = LoggerFactory.getLogger(XPRechargeController.class);
|
||||||
|
private static Gson gson = new Gson();
|
||||||
|
|
||||||
|
|
||||||
|
@RequestMapping(value = "/XPCallback")
|
||||||
|
public String MHTGnCallback(HttpServletRequest request) throws Exception {
|
||||||
|
return process(request,"bdbda1c460fb2273f061d9123ee39dae");
|
||||||
|
}
|
||||||
|
|
||||||
|
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 "FAIL";
|
||||||
|
}
|
||||||
|
|
||||||
|
XPParamBean data = getData(parameterMap);
|
||||||
|
|
||||||
|
if (data == null) {
|
||||||
|
LOGGER.info("data is null");
|
||||||
|
return "FAIL";
|
||||||
|
}
|
||||||
|
|
||||||
|
String response = "SUCCESS";
|
||||||
|
try {
|
||||||
|
String consumerid = data.getOpenId();
|
||||||
|
String sign = parameterMap.get("newsign");
|
||||||
|
|
||||||
|
String sig = getMySign(data, appsecret);
|
||||||
|
|
||||||
|
if (!sig.equals(sign)) {
|
||||||
|
LOGGER.info("callback==>roleUid={},sin derify fail,mine sign={} ", consumerid, sig);
|
||||||
|
return "sign fail";
|
||||||
|
}
|
||||||
|
|
||||||
|
response = insertOrder(data);
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
LOGGER.info("callback==>err " + e.toString());
|
||||||
|
response = "FAIL";
|
||||||
|
}
|
||||||
|
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
|
||||||
|
private XPParamBean getData(HashMap<String, String> parameterMap) {
|
||||||
|
XPParamBean paramBean = new XPParamBean();
|
||||||
|
paramBean.setAppId(parameterMap.getOrDefault("appId",""));
|
||||||
|
paramBean.setOrderId(parameterMap.getOrDefault("orderId",""));
|
||||||
|
paramBean.setOpenId(parameterMap.getOrDefault("openId",""));
|
||||||
|
paramBean.setServerId(parameterMap.getOrDefault("serverId",""));
|
||||||
|
paramBean.setRoleId(parameterMap.getOrDefault("roleId",""));
|
||||||
|
paramBean.setMoney(parameterMap.getOrDefault("money",""));
|
||||||
|
paramBean.setAmount(parameterMap.getOrDefault("amount",""));
|
||||||
|
paramBean.setCallbackInfo(parameterMap.getOrDefault("callbackInfo",""));
|
||||||
|
return paramBean;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private String insertOrder(XPParamBean data) {
|
||||||
|
try {
|
||||||
|
|
||||||
|
String consumerName = data.getCallbackInfo();
|
||||||
|
|
||||||
|
String orderNo = data.getOrderId();
|
||||||
|
String amount = data.getAmount();
|
||||||
|
String uid =data.getRoleId();
|
||||||
|
CUserInfo cUserInfo = cuserDao.findUserInfo(Integer.valueOf(uid));
|
||||||
|
if (cUserInfo == null) {
|
||||||
|
LOGGER.info("该用户无此角色" + uid);
|
||||||
|
return "FAIL";
|
||||||
|
}
|
||||||
|
|
||||||
|
CPayOrder cPayOrder = cuserDao.getCpayOrderByOrderId(orderNo);
|
||||||
|
|
||||||
|
if (cPayOrder != null) {
|
||||||
|
LOGGER.info("callback==>creditId={},uId={} orderId is exit!!!", cUserInfo.getId(), cUserInfo.getOpenId());
|
||||||
|
return "FAIL";
|
||||||
|
} else {
|
||||||
|
DateFormat dateTimeformat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||||
|
String date = dateTimeformat.format(new Date(System.currentTimeMillis()));
|
||||||
|
cPayOrder = new CPayOrder();
|
||||||
|
cPayOrder.setOrderId(orderNo);
|
||||||
|
cPayOrder.setServerId(cUserInfo.getServerid());
|
||||||
|
cPayOrder.setDelivery_time(date);
|
||||||
|
cPayOrder.setUserId(uid);
|
||||||
|
cPayOrder.setAmount(amount);
|
||||||
|
cPayOrder.setGoodsId(consumerName);
|
||||||
|
// cPayOrder.setRecharge_type();
|
||||||
|
|
||||||
|
Result result = null;
|
||||||
|
String userAddress = cuserDao.findUserAddress(cUserInfo.getId());
|
||||||
|
if (userAddress != null) {
|
||||||
|
LOGGER.info("callback==>userAddress={} ", userAddress);
|
||||||
|
String[] split = userAddress.split(":");
|
||||||
|
String ip = split[0];
|
||||||
|
String port = split[1];
|
||||||
|
LOGGER.info("RPC address --> IP : " + ip + "; PORT : " + port);
|
||||||
|
ClientAdapterPo<RPCRequestIFace.Client> rPCClient = null;
|
||||||
|
String serviceKey = JsonUtil.getServiceKey(ServiceKey.RPCCore, ip, port);
|
||||||
|
LOGGER.info("serviceKey : " + serviceKey);
|
||||||
|
try {
|
||||||
|
rPCClient = ClientAdapterPo.getClientAdapterPo(serviceKey);
|
||||||
|
result = rPCClient.getClient().deliveryRecharge(cUserInfo.getId(), consumerName, data.getOpenId(), orderNo, 0, 0);
|
||||||
|
} catch (Exception e) {
|
||||||
|
LOGGER.info("callback=>", e);
|
||||||
|
} finally {
|
||||||
|
if (rPCClient != null) {
|
||||||
|
rPCClient.returnObject(serviceKey);
|
||||||
|
} else {
|
||||||
|
LOGGER.info("callback=> rPCClient is null ");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
LOGGER.info("not get the user url,the openID={} ", uid);
|
||||||
|
return "FAIL";
|
||||||
|
}
|
||||||
|
if (result != null && result.getResultCode() == 1) {
|
||||||
|
LOGGER.info(" callback==>RPC result : ResultCode : " + result.getResultCode() + "; ResultMsg : " + result.getResultMsg());
|
||||||
|
cuserDao.addCpayOrder(cPayOrder);
|
||||||
|
} else {
|
||||||
|
System.out.println("测试代码");
|
||||||
|
return "FAIL";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
LOGGER.info("callback==>err " + e.toString());
|
||||||
|
return "FAIL";
|
||||||
|
}
|
||||||
|
return "SUCCESS";
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String getMySign(XPParamBean paramBean,String appsecret) throws IllegalAccessException {
|
||||||
|
StringBuilder stringBuilder = new StringBuilder();
|
||||||
|
TreeMap<String, String> tempMap = new TreeMap<>(String::compareTo);
|
||||||
|
|
||||||
|
Class<? extends XPParamBean> aClass = paramBean.getClass();
|
||||||
|
Field[] fields = aClass.getDeclaredFields();
|
||||||
|
for (Field field : fields) {
|
||||||
|
field.setAccessible(true);
|
||||||
|
tempMap.put(field.getName(), field.get(paramBean).toString());
|
||||||
|
}
|
||||||
|
for (Map.Entry<String, String> item : tempMap.entrySet()) {
|
||||||
|
String value = item.getValue();
|
||||||
|
if (StringUtils.isEmpty(value)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
stringBuilder.append(value);
|
||||||
|
}
|
||||||
|
String blankSign = stringBuilder.append(appsecret).toString();
|
||||||
|
String sign = MD5Util.encrypByMd5(blankSign);
|
||||||
|
LOGGER.info("加密前字符串:{}",blankSign);
|
||||||
|
LOGGER.info("加密后得:{}",sign);
|
||||||
|
return sign;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
package com.jmfy.controller;
|
package com.jmfy.paramBean;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author lvxinran
|
* @author lvxinran
|
|
@ -1,4 +1,4 @@
|
||||||
package com.jmfy.controller;
|
package com.jmfy.paramBean;
|
||||||
|
|
||||||
public class MHTNetRechargeRequestBean {
|
public class MHTNetRechargeRequestBean {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package com.jmfy.controller;
|
package com.jmfy.paramBean;
|
||||||
|
|
||||||
public class MHTRechargeRequestBean {
|
public class MHTRechargeRequestBean {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package com.jmfy.controller;
|
package com.jmfy.paramBean;
|
||||||
|
|
||||||
public class RechargeRequestBean {
|
public class RechargeRequestBean {
|
||||||
|
|
|
@ -0,0 +1,81 @@
|
||||||
|
package com.jmfy.paramBean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author lvxinran
|
||||||
|
* @date 2021/6/9
|
||||||
|
* @discribe
|
||||||
|
*/
|
||||||
|
public class XPParamBean {
|
||||||
|
private String appId;//游戏ID
|
||||||
|
private String orderId;// 平台订单号
|
||||||
|
private String openId;// 平台账号 ID
|
||||||
|
private String serverId;//游戏服务器ID
|
||||||
|
private String roleId;//角色ID
|
||||||
|
private String money; //人民币(分单位)
|
||||||
|
private String amount;// 游戏币
|
||||||
|
private String callbackInfo;//CP透传参数
|
||||||
|
|
||||||
|
public void setAppId(String appId) {
|
||||||
|
this.appId = appId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOrderId(String orderId) {
|
||||||
|
this.orderId = orderId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOpenId(String openId) {
|
||||||
|
this.openId = openId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setServerId(String serverId) {
|
||||||
|
this.serverId = serverId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRoleId(String roleId) {
|
||||||
|
this.roleId = roleId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMoney(String money) {
|
||||||
|
this.money = money;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAmount(String amount) {
|
||||||
|
this.amount = amount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCallbackInfo(String callbackInfo) {
|
||||||
|
this.callbackInfo = callbackInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getAppId() {
|
||||||
|
return appId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getOrderId() {
|
||||||
|
return orderId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getOpenId() {
|
||||||
|
return openId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getServerId() {
|
||||||
|
return serverId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getRoleId() {
|
||||||
|
return roleId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getMoney() {
|
||||||
|
return money;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getAmount() {
|
||||||
|
return amount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCallbackInfo() {
|
||||||
|
return callbackInfo;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue