增加F5礼包接口,增加F5G官网登录,校验,支付接口

main
grimm 2025-09-02 17:55:49 +08:00
parent 7a4dac0d53
commit e0d963160a
5 changed files with 507 additions and 1 deletions

View File

@ -2101,4 +2101,460 @@ public class PayController {
return json.toString();
}
@RequestMapping(value = "/pay/f5Gift", method = {RequestMethod.POST,RequestMethod.GET})
public String f5Gift(String appId,
String giftId,
String transactionId,
long userId,
String serverId,
String gameUserId,
String osign) {
JSONObject json = new JSONObject();
try {
LOGGER.info("f5Gift--01, appId={}giftId={}transactionId={}userId={}serverId={}," +
"gameUserId={}osign={}", appId,giftId,transactionId
,userId,serverId,gameUserId,osign);
if(appId == null){
LOGGER.error("appId null");
json.put("code", 400);
json.put("msg", "appId null");
return json.toString();
}
if(giftId == null){
LOGGER.error("giftId null");
json.put("code", 400);
json.put("msg", "giftId null");
return json.toString();
}
if(transactionId == null){
LOGGER.error("transactionId null");
json.put("code", 400);
json.put("msg", "transactionId null");
return json.toString();
}
if(serverId == null){
LOGGER.error("serverId null");
json.put("code", 400);
json.put("msg", "serverId null");
return json.toString();
}
if(gameUserId == null){
LOGGER.error("gameUserId null");
json.put("code", 400);
json.put("msg", "gameUserId null");
return json.toString();
}
if(userId <= 0){
LOGGER.error("userId error");
json.put("code", 400);
json.put("msg", "userId error");
return json.toString();
}
String signStr = appId + giftId + transactionId + userId + serverId + gameUserId+ Constant.F5_SECURE_KEY;
String mySign=MD5Util.encrypByMd5(signStr);
if(!mySign.equals(osign)){
LOGGER.error("错误信息:签名不一致 mySign={}osign={}", mySign,osign);
json.put("code", 400);
json.put("msg", "签名不一致");
return json.toString();
}
int uid = Integer.parseInt(gameUserId);
String key = serverId + RedisUserKey.Delimiter_colon + gameUserId;
Map<String, String> map = RedisUtil.getInstence().getStringMapValues(key);
if(map!=null) {
if (map.containsKey(transactionId)) {
json.put("code", 200);
json.put("msg", "SUCCESS");
return json.toString();
}
}
String rpcString = RedisUtil.getInstence().getObject(RedisUserKey.LOGIC_SERVER_INFO, serverId, String.class, -1);
System.out.println("rpcString " + rpcString);
if (null == rpcString) {
LOGGER.error("serverAddress not exist");
json.put("code", 400);
json.put("msg", "serverAddress not exist");
return json.toString();
}
String thriftIp = rpcString.split(":")[0];
String thriftPort = rpcString.split(":")[3];
if (thriftIp == null || thriftIp.isEmpty() || null == thriftPort || thriftPort.isEmpty()) {
LOGGER.error("serverAddress not exist");
json.put("code", 400);
json.put("msg", "serverAddress not exist");
return json.toString();
} else {
Result result = RPCClient.deliveryRecharge(thriftIp, thriftPort, uid, giftId, String.valueOf(userId), transactionId, System.currentTimeMillis(), 0, "f5");
if (result.getResultCode() != 1) {
LOGGER.error(result.getResultMsg());
json.put("code", 400);
json.put("msg", result.getResultMsg());
return json.toString();
} else {
json.put("code", 200);
json.put("msg", "SUCCESS");
return json.toString();
}
}
} catch (Exception ex) {
ex.printStackTrace();
json.put("code", 400);
json.put("msg", ex.toString());
return json.toString();
}
}
@RequestMapping(value = "/pay/f5GwGift", method = {RequestMethod.POST,RequestMethod.GET})
public String f5GwGift(String appId,
String giftId,
String transactionId,
long userId,
String serverId,
String gameUserId,
String osign) {
JSONObject json = new JSONObject();
try {
LOGGER.info("f5GwGift--01, appId={}giftId={}transactionId={}userId={}serverId={}," +
"gameUserId={}osign={}", appId,giftId,transactionId
,userId,serverId,gameUserId,osign);
if(appId == null){
LOGGER.error("appId null");
json.put("code", 400);
json.put("msg", "appId null");
return json.toString();
}
if(giftId == null){
LOGGER.error("giftId null");
json.put("code", 400);
json.put("msg", "giftId null");
return json.toString();
}
if(transactionId == null){
LOGGER.error("transactionId null");
json.put("code", 400);
json.put("msg", "transactionId null");
return json.toString();
}
if(serverId == null){
LOGGER.error("serverId null");
json.put("code", 400);
json.put("msg", "serverId null");
return json.toString();
}
if(gameUserId == null){
LOGGER.error("gameUserId null");
json.put("code", 400);
json.put("msg", "gameUserId null");
return json.toString();
}
if(userId <= 0){
LOGGER.error("userId error");
json.put("code", 400);
json.put("msg", "userId error");
return json.toString();
}
String signStr = appId + giftId + transactionId + userId + serverId + gameUserId+ Constant.F5_GW_SECURE_KEY;
String mySign=MD5Util.encrypByMd5(signStr);
if(!mySign.equals(osign)){
LOGGER.error("错误信息:签名不一致 mySign={}osign={}", mySign,osign);
json.put("code", 400);
json.put("msg", "签名不一致");
return json.toString();
}
int uid = Integer.parseInt(gameUserId);
String key = serverId + RedisUserKey.Delimiter_colon + gameUserId;
Map<String, String> map = RedisUtil.getInstence().getStringMapValues(key);
if(map!=null) {
if (map.containsKey(transactionId)) {
json.put("code", 200);
json.put("msg", "SUCCESS");
return json.toString();
}
}
String rpcString = RedisUtil.getInstence().getObject(RedisUserKey.LOGIC_SERVER_INFO, serverId, String.class, -1);
System.out.println("rpcString " + rpcString);
if (null == rpcString) {
LOGGER.error("serverAddress not exist");
json.put("code", 400);
json.put("msg", "serverAddress not exist");
return json.toString();
}
String thriftIp = rpcString.split(":")[0];
String thriftPort = rpcString.split(":")[3];
if (thriftIp == null || thriftIp.isEmpty() || null == thriftPort || thriftPort.isEmpty()) {
LOGGER.error("serverAddress not exist");
json.put("code", 400);
json.put("msg", "serverAddress not exist");
return json.toString();
} else {
Result result = RPCClient.deliveryRecharge(thriftIp, thriftPort, uid, giftId, String.valueOf(userId), transactionId, System.currentTimeMillis(), 0, "f5");
if (result.getResultCode() != 1) {
LOGGER.error(result.getResultMsg());
json.put("code", 400);
json.put("msg", result.getResultMsg());
return json.toString();
} else {
json.put("code", 200);
json.put("msg", "SUCCESS");
return json.toString();
}
}
} catch (Exception ex) {
ex.printStackTrace();
json.put("code", 400);
json.put("msg", ex.toString());
return json.toString();
}
}
/**
* F5
* @param appId
* @param orderId
* @param defaultAmount
* @param defaultCurrency
* @param gameAmount
* @param gameCurrency
* @param productId
* @param payChannel
* @param userId
* @param serverId
* @param orderStatus
* @param statusMsg
* @param ots
* @param payDoneTime
* @param extInfo
* @param osign
* @return
*/
@RequestMapping(value = "/pay/f5GwNotify", method = {RequestMethod.POST,RequestMethod.GET})
public String f5GwNotify(String appId,
String orderId,
double defaultAmount,
String defaultCurrency,
int gameAmount,
String gameCurrency,
String productId,
String payChannel,
long userId,
String serverId,
int orderStatus,
String statusMsg,
Integer ots,
String payDoneTime,
String extInfo,
String osign) {
JSONObject json = new JSONObject();
json.put("appId", Constant.F5_GW_APPID);
json.put("userId", userId);
try {
LOGGER.info("f5Notify--01, appId={}orderId={}defaultAmount={}defaultCurrency={}gameAmount={}," +
"gameCurrency={}productId={}payChannel={}userId={}serverId={}," +
"orderStatus={}statusMsg={}ots={}payDoneTime={}extInfo={},osign={}", appId,orderId,defaultAmount
,defaultCurrency,gameAmount,gameCurrency,productId,payChannel,userId,serverId,orderStatus,statusMsg,ots,payDoneTime,extInfo,osign);
if(productId == null){
productId = "";
}
//为预注册奖励,不走发货逻辑
if("ms_590001".equals(productId)){
String key = RedisUserKey.F5_PRE_REWARD + RedisUserKey.Delimiter_colon + userId;
Map<String, Integer> map = RedisUtil.getInstence().getMapValues(key);
//已经发过直接返回
if(map !=null){
if(map.containsKey(productId)){
json.put("code", 200);
json.put("msg", "SUCCESS");
json.put("deliverStatus", 1);
return json.toString();
}else{
map.put(productId, 0);
RedisUtil.getInstence().putMap(key, "",map,-1);
json.put("code", 200);
json.put("msg", "SUCCESS");
json.put("deliverStatus", 1);
return json.toString();
}
}else{
Map<String, Integer> map1 = new HashMap<>();
map1.put(productId, 0);
RedisUtil.getInstence().putMap(key, "",map1,-1);
json.put("code", 200);
json.put("msg", "SUCCESS");
json.put("deliverStatus", 1);
return json.toString();
}
}
if(payDoneTime == null){
payDoneTime = "";
}
if(extInfo == null){
extInfo = "";
}
if(ots == null){
LOGGER.error("ots null");
json.put("code", -1);
json.put("msg", "ots null");
json.put("deliverStatus", 2);
return json.toString();
}
if(statusMsg == null){
statusMsg = "";
}
String signStr = appId + orderId + defaultAmount + defaultCurrency + gameAmount + gameCurrency + productId +
userId + serverId + orderStatus + ots + payDoneTime + extInfo + Constant.F5_GW_PAY_KEY;
String mySign=MD5Util.encrypByMd5(signStr);
if(!mySign.equals(osign)){
LOGGER.error("错误信息:签名不一致 mySign={}osign={}", mySign,osign);
json.put("code", -1);
json.put("msg", "签名不一致");
json.put("deliverStatus", 2);
return json.toString();
}
//渠道订单号不能为空
if(StringUtils.isEmpty(orderId)){
LOGGER.error("错误信息orderId empty");
json.put("code", -2);
json.put("msg", "orderId empty");
json.put("deliverStatus", 2);
return json.toString();
}
// 统一发货接口
int payres = 0;
Double amountDouble = defaultAmount * 100;
//充值中心充值,订单号需要现生成
if(payChannel.equals("WINGA")){
payres = payHandler.processOrderWithoutOrderId(String.valueOf(userId), Integer.parseInt(serverId),orderId, productId,amountDouble.intValue(),defaultCurrency,payChannel); //充值中心充值,订单号需要现生成
}else{
//extInfo为游戏订单号
if(StringUtils.isEmpty(extInfo)){
LOGGER.error("错误信息extInfo empty");
json.put("code", -2);
json.put("msg", "extInfo empty");
json.put("deliverStatus", 2);
return json.toString();
}
payres = payHandler.processOrderNew(extInfo, orderId,amountDouble.intValue());
}
// 成功
if (payres == 1) {
json.put("code", 200);
json.put("msg", "SUCCESS");
json.put("deliverStatus", 1);
return json.toString();
} else if (payres == -1) {
LOGGER.error("pay:gameNoticeInterface, {} 订单不存在,", orderId);
json.put("msg", "订单不存在");
} else if (payres == -2) {
LOGGER.error("pay:gameNoticeInterface, {} 订单参数错误,", orderId);
json.put("msg", "订单参数错误");
} else if (payres == -3) {
LOGGER.error("pay:gameNoticeInterface, {} 服务器配置错误,", orderId);
json.put("msg", "服务器配置错误");
} else if (payres == -4) {
LOGGER.error("pay:gameNoticeInterface, {} 充值失败,", orderId);
json.put("msg", "充值失败");
} else {
LOGGER.error("pay:gameNoticeInterface, {} 返回错误,payres = {}", orderId,payres);
json.put("msg", "game exception");
}
} catch (Exception ex) {
ex.printStackTrace();
}
json.put("code", -3);
json.put("deliverStatus", 2);
return json.toString();
}
@RequestMapping(value = "/pay/f5GwGetRole", method = {RequestMethod.POST,RequestMethod.GET})
public String f5GwGetRole(@RequestParam("appId") String appId,
@RequestParam("userId") long userId,
@RequestParam("osign") String osign) throws Exception {
JSONObject json = new JSONObject();
json.put("appId", Constant.F5_GW_APPID);
json.put("userId", userId);
String currentServerId = "0";
String currentRoleId = "0";
JSONArray serverList = new JSONArray();
LOGGER.info("f5GetRole--01, appId={}userId={}osign={}", appId,userId,osign);
if(!appId.equals(Constant.F5_GW_APPID)){
LOGGER.error("错误信息:参数不正确 appId={}userId={}", appId,userId);
json.put("code", 4010);
json.put("msg", "appId error");
json.put("currentServerId", currentServerId);
json.put("currentRoleId", currentRoleId);
json.put("serverList", serverList);
return json.toString();
}
String signStr = Constant.F5_GW_APPID + userId + Constant.F5_GW_SECURE_KEY;
String mySign = MD5Util.encrypByMd5(signStr);
if(!mySign.equals(osign)){
LOGGER.error("错误信息:签名不一致 mySign={}osign={}", mySign,osign);
json.put("code", 4011);
json.put("msg", "sign error");
json.put("currentServerId", currentServerId);
json.put("currentRoleId", currentRoleId);
json.put("serverList", serverList);
return json.toString();
}
MongoTemplate mongoTemplate = mongoConnectDao.getConnect().getMongoTemplete(Application.coreDb);
//查询mongo:客户端传的serverId找到合服后的对应的真实的serverId
BasicQuery query = new BasicQuery(new BasicDBObject("openId", String.valueOf(userId)));
List<CoreUserInfo> list = mongoTemplate.find(query, CoreUserInfo.class);
if(list == null || list.isEmpty()){
json.put("code", 404);
json.put("msg", "user not exist");
json.put("currentServerId", currentServerId);
json.put("currentRoleId", currentRoleId);
json.put("serverList", serverList);
return json.toString();
}
long loginTime = 0;
for(CoreUserInfo user : list){
String serverId = String.valueOf(user.getServerid());
BasicQuery serverQuery = new BasicQuery(new BasicDBObject("server_id", serverId));
ServerInfo serverInfo = mongoTemplate.findOne(serverQuery, ServerInfo.class, "server_info");
String uid = String.valueOf(user.getUid());
if(serverInfo == null){
LOGGER.info("f5GetRole--02, user serverInfo not exist uid={}",uid);
continue;
}
PlayerInfoCache cache = RedisUtil.getInstence().getMapValue(RedisUserKey.PLAYER_INFO_CACHE + RedisUserKey.Delimiter_colon, "",uid, PlayerInfoCache.class,-1);
if(cache == null){
LOGGER.info("f5GetRole--03, user cache not exist uid={}",uid);
continue;
}
JSONObject serverObj = new JSONObject();
serverObj.put("serverId", serverInfo.getRealServerId());
serverObj.put("serverName", serverInfo.getName());
JSONArray roleList = new JSONArray();
JSONObject roleObj = new JSONObject();
roleObj.put("roleId", uid);
roleObj.put("roleName", cache.getName());
roleList.add(roleObj);
serverObj.put("roleList", roleList);
serverList.add(serverObj);
long lastLoginTime = cache.getOffLineTime();
//取最近登录时间的角色信息
if(lastLoginTime >= loginTime){
loginTime = lastLoginTime;
currentServerId = String.valueOf(serverInfo.getRealServerId());
currentRoleId = uid;
}
}
if(serverList.size() > 0){
json.put("code", 200);
json.put("msg", "SUCCESS");
}else{
json.put("code", 404);
json.put("msg", "user role not exist");
}
json.put("currentServerId", currentServerId);
json.put("currentRoleId", currentRoleId);
json.put("serverList", serverList);
return json.toString();
}
}

View File

@ -155,9 +155,12 @@ public class SDKController {
case "QKZB02"://quick直播2
uid = SdkVerfy.quickGameVerfy2(userId, sdksign, sdktoken);
break;
case "F5"://quick直播2
case "F5"://F5渠道
uid = SdkVerfy.f5Verify(userId, sdktoken);
break;
case "F5_GW"://F5渠道
uid = SdkVerfy.f5GwVerify(userId, sdktoken);
break;
default:
uid = "-1";
}

View File

@ -641,6 +641,35 @@ public class SdkVerfy {
return "-1";
}
/**
*
* @param userId
* @param sdktoken
* @return
*/
public static String f5GwVerify(String userId, String sdktoken) {
try {
// 请求参数
Map<String, String> params = new HashMap<String, String>();
params.put("token", sdktoken);
params.put("appId", Constant.F5_GW_APPID);
String osign = MD5Util.encrypByMd5(Constant.F5_GW_APPID + sdktoken + Constant.F5_GW_SECURE_KEY);
params.put("osign", osign);
// String jsonStr = JSON.toJSONString(params);
String resurl = HttpUtil.postForm(Constant.F5_GW_VERIFY_URL, params);
JSONObject jsonObject = JSONObject.fromObject(resurl);
LOGGER.info("res:{}", jsonObject.toString());
// code状态为200时 登陆成功 其他为失败
if (jsonObject.getInt("code") == 200) {
return userId;
}
return jsonObject.getString("msg");
} catch (Exception e) {
e.printStackTrace();
}
return "-1";
}
public static void main(String[] args) throws IOException {
Map<String, String> params = new HashMap<String, String>();
params.put("token", "1_o1ioab9ktedQF3Lj5SkinbGOt9GexZX1");

View File

@ -151,4 +151,11 @@ public class Constant {
public static final String F5_SECURE_KEY = "Dw4bOiwgtHwjxCZ6dr68CwjcuVepTQu5";
public static final String F5_PAY_KEY = "mAspdbkb2gGBYKyCdfJnZ392om38npHF";
public static final String F5_VERIFY_URL = "https://api.wingsdk.com/cpapi/v2/user/authorize.do";
//F5官网包
public static final String F5_GW_APPID = "51bf1b027da511f0b5e002c85f0429f5";
public static final String F5_GW_APP_KEY = "wCUo3QLEHozLeJenkxVjHzRHpR9apNvT";
public static final String F5_GW_SECURE_KEY = "sgDNFbfuVz2BmJvtIfikl5oAupmbxwym";
public static final String F5_GW_PAY_KEY = "rHBzPzP3xGb2UvufRPIDiR6jJXKxgVDU";
public static final String F5_GW_VERIFY_URL = "https://api.wingsdk.com/cpapi/v2/user/authorize.do";
}

View File

@ -347,4 +347,15 @@ public class RedisUtil {
}
return result;
}
public Map<String,String> getStringMapValues(String key){
Map<String,String> result = new HashMap<String,String>();
Map<Object, Object> entries = redisObjectTemplate.opsForHash().entries(key);
for(Map.Entry<Object,Object> item : entries.entrySet()){
Object key1 = item.getKey();
Object value = item.getValue();
result.put(gson.fromJson(gson.toJson(key1),String.class),gson.fromJson(value.toString(),String.class));
}
return result;
}
}