generated from root/miduo_server
160 lines
7.1 KiB
Java
160 lines
7.1 KiB
Java
package com.jmfy.controller;
|
||
|
||
import com.jmfy.dto.CPayOrder;
|
||
import com.jmfy.dto.CUserDao;
|
||
import com.jmfy.dto.CUserInfo;
|
||
import com.jmfy.paramBean.HaoGameParamBean;
|
||
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.json.JSONObject;
|
||
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 javax.annotation.Resource;
|
||
import javax.servlet.http.HttpServletRequest;
|
||
import java.net.URLDecoder;
|
||
import java.net.URLEncoder;
|
||
import java.text.DateFormat;
|
||
import java.text.SimpleDateFormat;
|
||
import java.util.*;
|
||
|
||
/**
|
||
* KT游戏
|
||
*/
|
||
@RestController
|
||
public class KTGameRechargeController {
|
||
|
||
@Resource
|
||
private CUserDao cuserDao;
|
||
|
||
private static final String PAYKEY = "vNCn3fkgZHt6wxGYl9IQUJo0R4LKPjW2";
|
||
|
||
private static final Logger LOGGER = LoggerFactory.getLogger(KTGameRechargeController.class);
|
||
|
||
@RequestMapping(value = "/ktGameCallback")
|
||
public String ktGameCallback(HttpServletRequest request) throws Exception {
|
||
HashMap<String, String> parameterMap = JsonUtil.getInstence().getParameterMap2(request);
|
||
if (parameterMap.isEmpty()) {
|
||
LOGGER.info("ktGameCallback data is null");
|
||
return "FAIL";
|
||
}
|
||
String orderStatus = request.getParameter("order_status"); //支付状态 0:未支付 1:支付成功 2:支付失败
|
||
if (orderStatus == null || orderStatus.isEmpty() || !"1".equals(orderStatus)) {
|
||
LOGGER.info("ktGameCallback orderStatus={}", orderStatus);
|
||
return "FAIL";
|
||
}
|
||
String gid = request.getParameter("gid"); //gid
|
||
String pid = request.getParameter("pid"); //pid
|
||
String myOrderNo = parameterMap.get("my_order_no"); // 我方平台平台订单号
|
||
String gameOrderNo = parameterMap.get("game_order_no"); // CP订单号,不得超过48个字符
|
||
String openid = parameterMap.get("openid"); // 我方平台用户唯一标识
|
||
String amt = parameterMap.get("amt"); // 充值金额(元) float 小数点后最多两位
|
||
String tm = request.getParameter("tm"); //tm Unix时间戳
|
||
String sign = request.getParameter("sign"); //支付状态 0:未支付 1:支付成功 2:支付失败
|
||
String gameExt = request.getParameter("game_ext"); //透传参数,如CP下单有值提交,则会原样回传,不得超过255个字符
|
||
String serverId = request.getParameter("server_id"); //服务器ID
|
||
String serverName = request.getParameter("server_name"); //服务器名称
|
||
String roleId = request.getParameter("role_id"); //角色ID
|
||
String roleName = request.getParameter("role_name"); //角色名称
|
||
|
||
SortedMap<String, String> params = new TreeMap<>();
|
||
params.put("gid", gid);
|
||
params.put("pid", pid);
|
||
params.put("my_order_no", myOrderNo);
|
||
params.put("game_order_no", gameOrderNo);
|
||
params.put("openid", openid);
|
||
params.put("amt", amt);
|
||
params.put("tm", tm);
|
||
params.put("order_status", orderStatus);
|
||
params.put("game_ext", gameExt);
|
||
params.put("server_id", serverId);
|
||
params.put("server_name", serverName);
|
||
params.put("role_id", roleId);
|
||
params.put("role_name", roleName);
|
||
StringBuilder sbKey = new StringBuilder();
|
||
Set<Map.Entry<String, String>> entries = params.entrySet();
|
||
Iterator<Map.Entry<String, String>> iterator = entries.iterator();
|
||
while (iterator.hasNext()) {
|
||
Map.Entry<String, String> next = iterator.next();
|
||
String key = next.getKey();
|
||
String value = next.getValue();
|
||
if (value == null || "".equals(value)) {
|
||
continue;
|
||
}
|
||
if ("sign".equals(key) || "sign_type".equals(key)) {
|
||
continue;
|
||
}
|
||
sbKey.append(key).append("=").append(value).append("&");
|
||
}
|
||
sbKey.append(PAYKEY);
|
||
String mySign = MD5Util.encrypByMd5(sbKey.toString());
|
||
if (!mySign.equals(sign)) {
|
||
LOGGER.info("callback==>roleUid={},sin derify fail, my sign={} sign={}", openid, mySign, sign);
|
||
return "FAIL";
|
||
}
|
||
|
||
CUserInfo cUserInfo = cuserDao.findUserByOpenIdAndUidInfo(openid, serverId);
|
||
if (cUserInfo == null) {
|
||
LOGGER.info("该用户无此角色 openid={} serverID={}", openid, serverId);
|
||
return "FAIL";
|
||
}
|
||
CPayOrder cPayOrder = cuserDao.getCpayOrderByOrderId(myOrderNo);
|
||
String response = "success";
|
||
if (cPayOrder != null) {
|
||
LOGGER.info("callback==>creditId={},uId={} orderId is exit!!!", cUserInfo.getId(), cUserInfo.getOpenId());
|
||
return response;
|
||
}
|
||
String userAddress = cuserDao.findUserAddress(cUserInfo.getId());
|
||
if (userAddress == null || userAddress.isEmpty()) {
|
||
LOGGER.info("callback==>userAddress={} openId={} uid={}", userAddress, openid, cUserInfo.getId());
|
||
return "FAIL";
|
||
}
|
||
String[] gameExtArr = gameExt.split("_");
|
||
DateFormat dateTimeformat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||
String date = dateTimeformat.format(new Date());
|
||
cPayOrder = new CPayOrder();
|
||
cPayOrder.setOrderId(myOrderNo);
|
||
cPayOrder.setServerId(cUserInfo.getServerid());
|
||
cPayOrder.setDelivery_time(date);
|
||
cPayOrder.setAmount(amt);
|
||
cPayOrder.setGoodsId(gameExtArr[1]);
|
||
cPayOrder.setCc_id(gameExtArr[2]);
|
||
cPayOrder.setPaySdk("KT");
|
||
cPayOrder.setPlatform(gameExtArr[3]);
|
||
cPayOrder.setUserId(roleId);
|
||
Result result = null;
|
||
String[] split = userAddress.split(":");
|
||
String ip = split[0];
|
||
String port = split[1];
|
||
LOGGER.info("RPC address uid={}--> IP : {} PORT : {}", cUserInfo.getId(), ip, port);
|
||
ClientAdapterPo<RPCRequestIFace.Client> rPCClient = null;
|
||
String serviceKey = JsonUtil.getServiceKey(ServiceKey.RPCCore, ip, port);
|
||
try {
|
||
rPCClient = ClientAdapterPo.getClientAdapterPo(serviceKey);
|
||
result = rPCClient.getClient().deliveryRecharge(cUserInfo.getId(), gameExtArr[0], openid, myOrderNo, Long.parseLong(tm) * 1000, Integer.parseInt(amt));
|
||
} catch (Exception e) {
|
||
LOGGER.info("callback=>", e);
|
||
return "FAIL";
|
||
} finally {
|
||
if (rPCClient != null) {
|
||
rPCClient.returnObject(serviceKey);
|
||
} else {
|
||
LOGGER.info("callback=> rPCClient is null ");
|
||
}
|
||
}
|
||
if (result != null && result.getResultCode() == 1) {
|
||
LOGGER.info(" callback==>RPC result : ResultCode : " + result.getResultCode() + "; ResultMsg : " + result.getResultMsg());
|
||
cuserDao.addCpayOrder(cPayOrder);
|
||
return response;
|
||
}
|
||
return "FAIL";
|
||
}
|
||
}
|