generated from root/miduo_server
116 lines
5.6 KiB
Java
116 lines
5.6 KiB
Java
package com.jmfy.controller;
|
|
|
|
import com.jmfy.dto.*;
|
|
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 com.jmfy.util.YsjConstant;
|
|
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.text.DateFormat;
|
|
import java.text.SimpleDateFormat;
|
|
import java.util.Date;
|
|
import java.util.HashMap;
|
|
@RestController
|
|
public class RechargeController {
|
|
@Resource
|
|
private CUserDao cuserDao;
|
|
private static final Logger LOGGER = LoggerFactory.getLogger(RechargeController.class);
|
|
@RequestMapping(value = "/callback")
|
|
public String deliveryGoods(HttpServletRequest request) throws Exception {
|
|
HashMap<String, String> parameterMap = JsonUtil.getInstence().getParameterMap(request);
|
|
String pOrderId = parameterMap.get("pOrderId");
|
|
String userId = parameterMap.get("userId");
|
|
String creditId = parameterMap.get("creditId");
|
|
String currency = parameterMap.get("currency");
|
|
String amount = parameterMap.get("amount");
|
|
String rCurrency = parameterMap.get("RCurrency");
|
|
String rAmount = parameterMap.get("RAmount");
|
|
String gameCode = parameterMap.get("gameCode");
|
|
String serverCode = parameterMap.get("serverCode");
|
|
String stone = parameterMap.get("stone");
|
|
String stoneType = parameterMap.get("stoneType");
|
|
String activityExtra = parameterMap.get("activityExtra");
|
|
String sign = parameterMap.get("sign");
|
|
String time = parameterMap.get("time");
|
|
String remark = parameterMap.get("remark");
|
|
String productId = parameterMap.get("productId");
|
|
String payType = parameterMap.get("payType");
|
|
String sig = MD5Util.encrypByMd5(pOrderId+serverCode+creditId+userId+amount+stone+time+YsjConstant.TW_GameKey);
|
|
if (!sig.equals(sign)){
|
|
FindPlayerResult findPlayerResult = new FindPlayerResult("1010","sign derify failed",null);
|
|
return JsonUtil.getInstence().getGson().toJson(findPlayerResult);
|
|
}
|
|
String plat = "android";
|
|
if (gameCode.equals(YsjConstant.TW_IOS_GameCode)){
|
|
plat = "ios";
|
|
}
|
|
CUserInfo cUserInfo = cuserDao.getUserInfobyNameAndServerId(userId, Integer.parseInt(serverCode),plat);
|
|
if (Integer.parseInt(creditId) != cUserInfo.getUserId()){
|
|
LOGGER.info("deliveryGoods==>creditId={},uId={}",creditId,cUserInfo.getUserId());
|
|
ResultVo resultVo = new ResultVo("1038", "该用户无此角色");
|
|
return JsonUtil.getInstence().getGson().toJson(resultVo);
|
|
}
|
|
int itemNum = Integer.parseInt(activityExtra)+Integer.parseInt(stone);
|
|
String payitem = "1002#"+ itemNum+"#1";
|
|
CPayOrder cPayOrder = cuserDao.getCpayOrderByOrderId(pOrderId);
|
|
ResultVo resultVo;
|
|
if (cPayOrder != null) {
|
|
LOGGER.info("deliveryGoods==>creditId={},uId={} pOrderId is exit!!!",creditId,cUserInfo.getUserId());
|
|
resultVo = new ResultVo("0000", "send reward success !!!!");
|
|
} else {
|
|
DateFormat dateTimeformat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
|
|
String date = dateTimeformat.format(new Date());
|
|
cPayOrder = new CPayOrder();
|
|
cPayOrder.setOrderId(pOrderId);
|
|
cPayOrder.setServerId(serverCode);
|
|
cPayOrder.setDelivery_time(date);
|
|
cPayOrder.setUserId(userId);
|
|
cPayOrder.setCpOrderId(remark);
|
|
cPayOrder.setCurrency(currency);
|
|
cPayOrder.setAmount(amount);
|
|
cPayOrder.setGameCurrency(stone);
|
|
cPayOrder.setPayType(payType);
|
|
cPayOrder.setCreditId(creditId);
|
|
Result result = null;
|
|
String userAddress = cuserDao.findUserInfo(Integer.parseInt(serverCode), Integer.parseInt(creditId));
|
|
LOGGER.info("userAddress={},payitem={} ",userAddress,payitem);
|
|
if (userAddress != null) {
|
|
String[] split = userAddress.split(":");
|
|
String ip = split[0];
|
|
String port = split[1];
|
|
LOGGER.info("RPC address --> IP : " + ip + "; PORT : " + port);
|
|
ClientAdapterPo<RPCRequestIFace.Client> rPCClient;
|
|
String serviceKey = JsonUtil.getServiceKey(ServiceKey.RPCCore, ip, port);
|
|
LOGGER.info("serviceKey : " + serviceKey);
|
|
try {
|
|
rPCClient = ClientAdapterPo.getClientAdapterPo(serviceKey);
|
|
result = rPCClient.getClient().deliveryRecharge(Integer.parseInt(creditId), payitem,productId, Double.parseDouble(amount));
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
LOGGER.info("RPC result : ResultCode : " + result.getResultCode() + "; ResultMsg : " + result.getResultMsg());
|
|
if (result.getResultCode() == 0) {
|
|
cuserDao.addCpayOrder(cPayOrder);
|
|
resultVo = new ResultVo("0000", "send reward success !!!!");
|
|
} else {
|
|
resultVo = new ResultVo("0010", "send reward fail !!!!");
|
|
}
|
|
}
|
|
return JsonUtil.getInstence().getGson().toJson(resultVo);
|
|
}
|
|
public static void main (String [] args){
|
|
String s = MD5Util.encrypByMd5("test1323456789"+10074+10005686+"111112"+0.99+60+1550828074000L+YsjConstant.TW_GameKey);
|
|
System.out.println(s);
|
|
}
|
|
}
|