generated from root/miduo_server
悠谷支付
parent
7bc32b132d
commit
1379e628be
|
@ -0,0 +1,122 @@
|
||||||
|
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.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;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* KT游戏
|
||||||
|
*/
|
||||||
|
@RestController
|
||||||
|
public class YouGuRechargeController {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private CUserDao cuserDao;
|
||||||
|
|
||||||
|
private static final String PAYKEY = "fda6e5e13e75285dd0c8e8636a85704b";
|
||||||
|
|
||||||
|
private static final Logger LOGGER = LoggerFactory.getLogger(YouGuRechargeController.class);
|
||||||
|
|
||||||
|
@RequestMapping(value = "/Web/youguCallback")
|
||||||
|
public String youguCallback(HttpServletRequest request) throws Exception {
|
||||||
|
HashMap<String, String> parameterMap = JsonUtil.getInstence().getParameterMap2(request);
|
||||||
|
if (parameterMap.isEmpty()) {
|
||||||
|
LOGGER.info("ktGameCallback data is null");
|
||||||
|
return "FAIL";
|
||||||
|
}
|
||||||
|
String status = request.getParameter("status"); // 状态(1 成功,2 失败)(目前支付失败不通知)
|
||||||
|
if (status == null || status.isEmpty() || !"1".equals(status)) {
|
||||||
|
LOGGER.info("youguCallback orderStatus={}", status);
|
||||||
|
return "FAIL";
|
||||||
|
}
|
||||||
|
String sid = request.getParameter("sid"); //游戏区服标识
|
||||||
|
String uid = request.getParameter("uid"); //51sfsy 用户 ID
|
||||||
|
String orderno = parameterMap.get("orderno"); // 51sfsy 支付订单号(唯一
|
||||||
|
String amount = parameterMap.get("amount"); // 充值金额(单位:元)
|
||||||
|
String gameExt = request.getParameter("extinfo"); //透传参数,如CP下单有值提交,则会原样回传,不得超过255个字符
|
||||||
|
String nonce = request.getParameter("nonce"); //签名时间戳(由 51sfsy 服务端获取当前时间戳,用于生成签名)
|
||||||
|
String token = request.getParameter("token"); //签名(规则见下
|
||||||
|
|
||||||
|
StringBuilder sbKey = new StringBuilder();
|
||||||
|
sbKey.append(sid).append(uid).append(orderno).append(amount).append(gameExt).append(nonce).append(PAYKEY);
|
||||||
|
String mySign = MD5Util.encrypByMd5(sbKey.toString());
|
||||||
|
if (!mySign.equals(token)) {
|
||||||
|
LOGGER.info("callback==>roleUid={},sin derify fail, my sign={} sign={}", gameExt, mySign, token);
|
||||||
|
return "FAIL";
|
||||||
|
}
|
||||||
|
// gameExtArr: userid_goodsid_ccid_platform
|
||||||
|
CUserInfo cUserInfo = cuserDao.findUserByOpenIdAndUidInfo(uid, sid);
|
||||||
|
if (cUserInfo == null) {
|
||||||
|
LOGGER.info("该用户无此角色 openid={} serverID={}", uid, sid);
|
||||||
|
return "FAIL";
|
||||||
|
}
|
||||||
|
CPayOrder cPayOrder = cuserDao.getCpayOrderByOrderId(orderno);
|
||||||
|
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, uid, cUserInfo.getId());
|
||||||
|
return "FAIL";
|
||||||
|
}
|
||||||
|
// gameExtArr: userid_goodsid_ccid_platform
|
||||||
|
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(orderno);
|
||||||
|
cPayOrder.setServerId(cUserInfo.getServerid());
|
||||||
|
cPayOrder.setDelivery_time(date);
|
||||||
|
cPayOrder.setAmount(amount);
|
||||||
|
cPayOrder.setGoodsId(gameExtArr[1]);
|
||||||
|
cPayOrder.setCc_id(gameExtArr[2]);
|
||||||
|
cPayOrder.setPaySdk("YG");
|
||||||
|
cPayOrder.setPlatform(gameExtArr[3]);
|
||||||
|
cPayOrder.setUserId(Integer.toString(cUserInfo.getId()));
|
||||||
|
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[1], cUserInfo.getOpenId(), orderno, Long.parseLong(nonce) * 1000, (int) (Float.parseFloat(amount) * 100));
|
||||||
|
} 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";
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue