generated from root/miduo_server
乾游支付
parent
1c903ab9fe
commit
0c0747811e
|
@ -0,0 +1,155 @@
|
||||||
|
package com.jmfy.controller;
|
||||||
|
|
||||||
|
import com.jmfy.dto.CPayOrder;
|
||||||
|
import com.jmfy.dto.CUserDao;
|
||||||
|
import com.jmfy.dto.CUserInfo;
|
||||||
|
import com.jmfy.paramBean.QYParam;
|
||||||
|
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.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 乾游支付回调
|
||||||
|
*/
|
||||||
|
@RestController
|
||||||
|
public class QYGameRechargeController {
|
||||||
|
|
||||||
|
|
||||||
|
// 3 SUCCESS 充值成功
|
||||||
|
//3001 OTHER_ERROR 其它错误
|
||||||
|
//3002 PARAMETER_NOT_LEGAL 其它参数不合法
|
||||||
|
//3003 SIGN_NOT_MATCH 数据签名不匹配
|
||||||
|
//3004 USER_NOT_EXIST 无法找到用户
|
||||||
|
//3005 FAILURE 无法找到订单
|
||||||
|
//3006 REPEAT_ORDER 订单重复提交
|
||||||
|
//3007 AMOUNT_DIFFER 订单金额不匹配
|
||||||
|
// 7)返回数据示例(JSON):{"code": "3","message": "SUCCESS"}
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private CUserDao cuserDao;
|
||||||
|
|
||||||
|
private static final String PAYKEY = "huangjiayl&qypay";
|
||||||
|
|
||||||
|
private static final Logger LOGGER = LoggerFactory.getLogger(QYGameRechargeController.class);
|
||||||
|
|
||||||
|
@RequestMapping(value = "/Web/qyGameCallback")
|
||||||
|
public String qyGameCallback(HttpServletRequest request) throws Exception {
|
||||||
|
QYParam qyParam = new QYParam();
|
||||||
|
HashMap<String, String> parameterMap = JsonUtil.getInstence().getParameterMap2(request);
|
||||||
|
if (parameterMap.isEmpty()) {
|
||||||
|
LOGGER.info("qyGameCallback data is null");
|
||||||
|
return qyParam.getJsonStr(3002, "PARAMETER_NOT_LEGAL");
|
||||||
|
}
|
||||||
|
String orderId = request.getParameter("orderId");// 2Y9Y订单号
|
||||||
|
String money = request.getParameter("money"); // 金额,单位元(厂商发放虚币请务必根据money*兑换比例 来发)
|
||||||
|
String timestamp = parameterMap.get("timestamp"); // 储值时间
|
||||||
|
String openid = parameterMap.get("userId"); // 2Y9Y用户名
|
||||||
|
String platformId = parameterMap.get("platformId"); // 渠道ID
|
||||||
|
String roleId = parameterMap.get("roleId"); // 角色ID
|
||||||
|
String serverId = request.getParameter("serverId"); // 区服ID
|
||||||
|
String sign = request.getParameter("sign"); //支付状态 0:未支付 1:支付成功 2:支付失败
|
||||||
|
String gameExt = request.getParameter("callbackStr"); //透传参数,如CP下单有值提交,则会原样回传,不得超过255个字符
|
||||||
|
String gold = request.getParameter("gold"); // 虚币数量(不作为发放元宝数依据)
|
||||||
|
String pvc = request.getParameter("pvc"); // 通讯协议版本号,是保留参数,只有一个值1
|
||||||
|
|
||||||
|
SortedMap<String, String> params = new TreeMap<>();
|
||||||
|
params.put("orderId", orderId);
|
||||||
|
params.put("money", money);
|
||||||
|
params.put("timestamp", timestamp);
|
||||||
|
params.put("userId", openid);
|
||||||
|
params.put("platformId", platformId);
|
||||||
|
params.put("roleId", roleId);
|
||||||
|
params.put("serverId", serverId);
|
||||||
|
params.put("game_ext", gameExt);
|
||||||
|
params.put("callbackStr", gameExt);
|
||||||
|
params.put("gold", gold);
|
||||||
|
params.put("pvc", pvc);
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
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 qyParam.getJsonStr(3003, "SIGN_NOT_MATCH");
|
||||||
|
}
|
||||||
|
|
||||||
|
CUserInfo cUserInfo = cuserDao.findUserByOpenIdAndUidInfo(openid, serverId);
|
||||||
|
if (cUserInfo == null) {
|
||||||
|
LOGGER.info("该用户无此角色 openid={} serverID={}", openid, serverId);
|
||||||
|
return qyParam.getJsonStr(3004,"USER_NOT_EXIST");
|
||||||
|
}
|
||||||
|
CPayOrder cPayOrder = cuserDao.getCpayOrderByOrderId(orderId);
|
||||||
|
if (cPayOrder != null) {
|
||||||
|
LOGGER.info("qyGameCallback==>creditId={},uId={} orderId is exit!!!", cUserInfo.getId(), cUserInfo.getOpenId());
|
||||||
|
return qyParam.getJsonStr(3006, "REPEAT_ORDER");
|
||||||
|
}
|
||||||
|
String userAddress = cuserDao.findUserAddress(cUserInfo.getId());
|
||||||
|
if (userAddress == null || userAddress.isEmpty()) {
|
||||||
|
LOGGER.info("qyGameCallback==>userAddress={} openId={} uid={}", userAddress, openid, cUserInfo.getId());
|
||||||
|
return qyParam.getJsonStr(3004, "USER_NOT_EXIST");
|
||||||
|
}
|
||||||
|
// 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(orderId);
|
||||||
|
cPayOrder.setServerId(cUserInfo.getServerid());
|
||||||
|
cPayOrder.setDelivery_time(date);
|
||||||
|
cPayOrder.setAmount(money);
|
||||||
|
cPayOrder.setGoodsId(gameExtArr[1]);
|
||||||
|
cPayOrder.setCc_id(gameExtArr[2]);
|
||||||
|
cPayOrder.setPaySdk("qy");
|
||||||
|
cPayOrder.setPlatform(gameExtArr[3]);
|
||||||
|
cPayOrder.setUserId(roleId);
|
||||||
|
Result result = null;
|
||||||
|
String[] split = userAddress.split(":");
|
||||||
|
String ip = split[0];
|
||||||
|
String port = split[1];
|
||||||
|
LOGGER.info("qyGameCallback 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], openid, orderId, Long.parseLong(timestamp) * 1000, (int) (Float.parseFloat(money) * 100));
|
||||||
|
} catch (Exception e) {
|
||||||
|
LOGGER.info("qyGameCallback callback=>", e);
|
||||||
|
return qyParam.getJsonStr(3001, "OTHER_ERROR");
|
||||||
|
} finally {
|
||||||
|
if (rPCClient != null) {
|
||||||
|
rPCClient.returnObject(serviceKey);
|
||||||
|
} else {
|
||||||
|
LOGGER.info("qyGameCallback=> rPCClient is null ");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (result != null && result.getResultCode() == 1) {
|
||||||
|
LOGGER.info(" qyGameCallback==>RPC result : ResultCode : " + result.getResultCode() + "; ResultMsg : " + result.getResultMsg());
|
||||||
|
cuserDao.addCpayOrder(cPayOrder);
|
||||||
|
return qyParam.getJsonStr(3, "SUCCESS");
|
||||||
|
}
|
||||||
|
return qyParam.getJsonStr(3001, "OTHER_ERROR");
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,17 @@
|
||||||
|
package com.jmfy.paramBean;
|
||||||
|
|
||||||
|
import com.jmfy.util.RedisUtil;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 乾游response参数
|
||||||
|
*/
|
||||||
|
public class QYParam {
|
||||||
|
private int code;
|
||||||
|
private String message;
|
||||||
|
|
||||||
|
public String getJsonStr(int code, String message){
|
||||||
|
this.code = code;
|
||||||
|
this.message = message;
|
||||||
|
return RedisUtil.getInstence().gson.toJson(this);
|
||||||
|
}
|
||||||
|
}
|
|
@ -38,7 +38,7 @@ public class RedisUtil {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static RedisUtil redisUtil;
|
private static RedisUtil redisUtil;
|
||||||
private Gson gson = new Gson();
|
public Gson gson = new Gson();
|
||||||
public static RedisUtil getInstence() {
|
public static RedisUtil getInstence() {
|
||||||
if (redisUtil == null) {
|
if (redisUtil == null) {
|
||||||
redisUtil = InnerClass.SINGLETON;
|
redisUtil = InnerClass.SINGLETON;
|
||||||
|
|
Loading…
Reference in New Issue