generated from root/miduo_server
灵动国内先遣服sdk
parent
f0acd97aa9
commit
fd86d6344c
|
@ -0,0 +1,203 @@
|
|||
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.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/3/15
|
||||
* @discribe
|
||||
*/
|
||||
@RestController
|
||||
public class MHTGnWebRechargeController {
|
||||
@Resource
|
||||
private CUserDao cuserDao;
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(MHTHwNetRechargeController.class);
|
||||
private static Gson gson = new Gson();
|
||||
|
||||
|
||||
@RequestMapping(value = "/Web/MHTGnCallback")
|
||||
public String MHTGnCallback(HttpServletRequest request) throws Exception {
|
||||
return process(request,"eb4287c41d8318c140334da7588e4159");
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/Web/MHTGnIosCallback")
|
||||
public String MHTGnIosCallback(HttpServletRequest request) throws Exception {
|
||||
return process(request,"eb4287c41d8318c140334da7588e4159");
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/Web/MHTGnTestCallback")
|
||||
public String MHTGnTestCallback(HttpServletRequest request) throws Exception {
|
||||
return process(request,"eb4287c41d8318c140334da7588e4159");
|
||||
}
|
||||
|
||||
|
||||
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";
|
||||
}
|
||||
|
||||
MHTGnWebRechargeRequestBean data = getData(parameterMap);
|
||||
|
||||
if (data == null) {
|
||||
LOGGER.info("data is null");
|
||||
return "FAIL";
|
||||
}
|
||||
|
||||
String response = "SUCCESS";
|
||||
try {
|
||||
String consumerid = data.getConsumerid();
|
||||
String sign = data.getSign();
|
||||
|
||||
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 MHTGnWebRechargeRequestBean getData(HashMap<String, String> parameterMap) {
|
||||
MHTGnWebRechargeRequestBean rechargeRequestBean = gson.fromJson( new Gson().toJson(parameterMap), MHTGnWebRechargeRequestBean.class);
|
||||
return rechargeRequestBean;
|
||||
}
|
||||
|
||||
|
||||
private String insertOrder(MHTGnWebRechargeRequestBean data) {
|
||||
try {
|
||||
String user_id = data.getConsumerid();
|
||||
|
||||
String consumerName = data.getConsumername();
|
||||
|
||||
String orderNo = data.getOrderNo();
|
||||
|
||||
CUserInfo cUserInfo = cuserDao.findUserInfo(Integer.valueOf(user_id));
|
||||
if (cUserInfo == null) {
|
||||
LOGGER.info("该用户无此角色" + user_id);
|
||||
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());
|
||||
cPayOrder = new CPayOrder();
|
||||
cPayOrder.setOrderId(orderNo);
|
||||
cPayOrder.setServerId(cUserInfo.getServerid());
|
||||
cPayOrder.setDelivery_time(date);
|
||||
cPayOrder.setUserId(user_id);
|
||||
|
||||
|
||||
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.getConsumerid(), 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={} ", user_id);
|
||||
return "FAIL";
|
||||
}
|
||||
if (result != null && result.getResultCode() == 1) {
|
||||
LOGGER.info(" callback==>RPC result : ResultCode : " + result.getResultCode() + "; ResultMsg : " + result.getResultMsg());
|
||||
cuserDao.addCpayOrder(cPayOrder);
|
||||
} else {
|
||||
return "FAIL";
|
||||
}
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
LOGGER.info("callback==>err " + e.toString());
|
||||
return "FAIL";
|
||||
}
|
||||
return "SUCCESS";
|
||||
}
|
||||
|
||||
private static String getMySign(MHTGnWebRechargeRequestBean rechargeRequestBean,String appsecret) throws IllegalAccessException {
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
TreeMap<String, String> tempMap = new TreeMap<>(new Comparator<String>() {
|
||||
@Override
|
||||
public int compare(String o1, String o2) {
|
||||
return o1.compareTo(o2);
|
||||
}
|
||||
});
|
||||
|
||||
Class<? extends MHTGnWebRechargeRequestBean> aClass = rechargeRequestBean.getClass();
|
||||
Field[] fields = aClass.getDeclaredFields();
|
||||
for (Field field : fields) {
|
||||
field.setAccessible(true);
|
||||
if ("sign".equals(field.getName())) {
|
||||
continue;
|
||||
}
|
||||
tempMap.put(field.getName(), field.get(rechargeRequestBean).toString());
|
||||
}
|
||||
for (Map.Entry<String, String> item : tempMap.entrySet()) {
|
||||
String value = item.getValue();
|
||||
if (StringUtils.isEmpty(value)) {
|
||||
continue;
|
||||
}
|
||||
String key = item.getKey();
|
||||
stringBuilder.append(key).append("=").append(value).append("&");
|
||||
}
|
||||
String plain = stringBuilder.substring(0, stringBuilder.length() - 1) +MD5Util.encrypByMd5(appsecret);
|
||||
System.out.println(plain);
|
||||
return MD5Util.encrypByMd5(plain);
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,82 @@
|
|||
package com.jmfy.controller;
|
||||
|
||||
/**
|
||||
* @author lvxinran
|
||||
* @date 2021/3/15
|
||||
* @discribe
|
||||
*/
|
||||
public class MHTGnWebRechargeRequestBean {
|
||||
|
||||
private String consumerid;//游戏用户唯一标识
|
||||
private String consumername;//Cp自定义信息
|
||||
private String orderNo;//平台订单编号
|
||||
private String orderDetail;//订单详情
|
||||
private String mhtOrderAmt;//分
|
||||
private String gameCurrency;//充值游戏币数量
|
||||
private String time;//平台支付时间
|
||||
private String sign;
|
||||
|
||||
public String getConsumerid() {
|
||||
return consumerid;
|
||||
}
|
||||
|
||||
public void setConsumerid(String consumerid) {
|
||||
this.consumerid = consumerid;
|
||||
}
|
||||
|
||||
public String getConsumername() {
|
||||
return consumername;
|
||||
}
|
||||
|
||||
public void setConsumername(String consumername) {
|
||||
this.consumername = consumername;
|
||||
}
|
||||
|
||||
public String getOrderNo() {
|
||||
return orderNo;
|
||||
}
|
||||
|
||||
public void setOrderNo(String orderNo) {
|
||||
this.orderNo = orderNo;
|
||||
}
|
||||
|
||||
public String getOrderDetail() {
|
||||
return orderDetail;
|
||||
}
|
||||
|
||||
public void setOrderDetail(String orderDetail) {
|
||||
this.orderDetail = orderDetail;
|
||||
}
|
||||
|
||||
public String getMhtOrderAmt() {
|
||||
return mhtOrderAmt;
|
||||
}
|
||||
|
||||
public void setMhtOrderAmt(String mhtOrderAmt) {
|
||||
this.mhtOrderAmt = mhtOrderAmt;
|
||||
}
|
||||
|
||||
public String getGameCurrency() {
|
||||
return gameCurrency;
|
||||
}
|
||||
|
||||
public void setGameCurrency(String gameCurrency) {
|
||||
this.gameCurrency = gameCurrency;
|
||||
}
|
||||
|
||||
public String getTime() {
|
||||
return time;
|
||||
}
|
||||
|
||||
public void setTime(String time) {
|
||||
this.time = time;
|
||||
}
|
||||
|
||||
public String getSign() {
|
||||
return sign;
|
||||
}
|
||||
|
||||
public void setSign(String sign) {
|
||||
this.sign = sign;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue