增加好游戏(游心)支付回调

master
jiahuiwen 2021-10-26 13:42:04 +08:00
parent 6ce2c87cc2
commit aac6bee5fc
1 changed files with 147 additions and 0 deletions

View File

@ -0,0 +1,147 @@
package com.jmfy.controller;
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.json.JSONObject;
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.*;
/**
*
*/
@RestController
public class HaoGameRechargeController {
@Resource
private CUserDao cuserDao;
private static final String PAYKEY = "77cb6d6666424ade9783f1830d8fc243";
private static final Logger LOGGER = LoggerFactory.getLogger(HaoGameRechargeController.class);
@RequestMapping(value = "/haoGameCallback")
public String haoGameCallback(HttpServletRequest request) throws Exception {
HashMap<String, String> parameterMap = JsonUtil.getInstence().getParameterMap(request);
if (parameterMap.isEmpty()) {
LOGGER.info("data is null");
return "data is null";
}
String outtradeno = request.getParameter("outtradeno");
String orderId = request.getParameter("tradeno");
String status = request.getParameter("status");
if (status == null || status.isEmpty() || "fail".equals(status)) {
LOGGER.info("status is null {} ", status);
return "failure";
}
String timeend = request.getParameter("timeend");
String amount = request.getParameter("amount");
String openid = request.getParameter("openid");
String extra = request.getParameter("extra");
String sign = request.getParameter("sign");
if (extra == null || extra.isEmpty()) {
LOGGER.info("extra is null");
return "failure";
}
SortedMap<String, Object> parameters = new TreeMap<>();
parameters.put("outtradeno", outtradeno);
parameters.put("tradeno", orderId);
parameters.put("status", status);
parameters.put("timeend", timeend);
parameters.put("amount", amount);
parameters.put("openid", openid);
parameters.put("extra", extra);
StringBuilder sbKey = new StringBuilder();
Set<Map.Entry<String, Object>> entries = parameters.entrySet();
Iterator<Map.Entry<String, Object>> iterator = entries.iterator();
while (iterator.hasNext()) {
Map.Entry<String, Object> next = iterator.next();
String key = next.getKey();
Object value = next.getValue();
if (value == null || "".equals(value)) {
continue;
}
sbKey.append(key).append("=").append(value).append("&");
}
sbKey.append("secret=").append(PAYKEY);
String mySign = MD5Util.encrypByMd5(sbKey.toString()).toUpperCase();
if (!mySign.equals(sign)) {
LOGGER.info("callback==>roleUid={},sin derify fail, my sign={} sign={}", openid, mySign, sign);
return "failure";
}
JSONObject data = new JSONObject(extra);
String serverID = data.getString("districtid");// 区服id
String productID = data.getString("productId");
String ccId = data.getString("ccId");
String platform = data.getString("platform");
CUserInfo cUserInfo = cuserDao.findUserByOpenIdAndUidInfo(openid, serverID);
if (cUserInfo == null) {
LOGGER.info("该用户无此角色 openid={} serverID={}", openid, serverID);
return "failure";
}
CPayOrder cPayOrder = cuserDao.getCpayOrderByOrderId(orderId);
String response = "success";
if (cPayOrder != null) {
LOGGER.info("callback==>creditId={},uId={} orderId is exit!!!", cUserInfo.getId(), cUserInfo.getOpenId());
return response;
}
DateFormat dateTimeformat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String date = dateTimeformat.format(new Date());
cPayOrder = new CPayOrder();
cPayOrder.setOrderId(orderId);
cPayOrder.setServerId(cUserInfo.getServerid());
cPayOrder.setDelivery_time(date);
cPayOrder.setAmount(amount);
cPayOrder.setGoodsId(productID);
cPayOrder.setCc_id(ccId);
cPayOrder.setPaySdk("haoyouxi");
cPayOrder.setPlatform(platform);
cPayOrder.setUserId(Integer.toString(cUserInfo.getId()));
Result result = null;
String userAddress = cuserDao.findUserAddress(cUserInfo.getId());
if (userAddress == null || userAddress.isEmpty()) {
LOGGER.info("callback==>userAddress={} openId={} uid={}", userAddress, openid, cUserInfo.getId());
return "failure";
}
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(), productID, openid, orderId, Long.parseLong(timeend), Integer.parseInt(amount));
} catch (Exception e) {
LOGGER.info("callback=>", e);
return "failure";
} 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 "failure";
}
}