generated from root/miduo_server
增加gamota网页支付获取服务器列表接口
parent
7f40dd5856
commit
dea80889b2
|
|
@ -0,0 +1,207 @@
|
|||
package com.ljsd.controller;
|
||||
|
||||
import com.ljsd.pojo.UserRecentLoginInfo;
|
||||
import com.ljsd.redis.RedisKey;
|
||||
import com.ljsd.util.BaseGlobal;
|
||||
import com.ljsd.util.GamotaConstats;
|
||||
import com.ljsd.util.MD5Util;
|
||||
import com.ljsd.util.StringUtils;
|
||||
import com.mongodb.BasicDBObject;
|
||||
import com.mongodb.DBObject;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServlet;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* gamota网页支付获取服务器列表接口
|
||||
*/
|
||||
public class GamotaGetServerListController extends HttpServlet {
|
||||
private final static String _COLLECTION_NAME = "server_info";
|
||||
private final static String _WHITE_LIST = "white_list";
|
||||
private static ConcurrentHashMap<String, DBObject> serverInfosCache = new ConcurrentHashMap<>();
|
||||
private static volatile DBObject whiteListCache = new BasicDBObject();
|
||||
private static volatile String recommend = "";//推荐列表
|
||||
private static volatile long lastRefreshTime = 0;
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(GetServerListController.class);
|
||||
|
||||
public GamotaGetServerListController() {
|
||||
super();
|
||||
}
|
||||
|
||||
public void destroy() {
|
||||
super.destroy();
|
||||
}
|
||||
|
||||
// 服务器状态 0:不可见 -1 准备状态 1:维护 2:流畅 3拥挤 4爆满 5状态根据在线人数改变
|
||||
public void doGet(HttpServletRequest request, HttpServletResponse response)
|
||||
throws ServletException, IOException {
|
||||
response.setCharacterEncoding("UTF-8");
|
||||
response.setContentType("application/json; charset=utf-8");
|
||||
PrintWriter out = response.getWriter();
|
||||
String regEx="[^0-9]";
|
||||
try {
|
||||
String appota_user_id = request.getParameter("appota_user_id");
|
||||
String channel = request.getParameter("channel");
|
||||
String sub_channel = request.getParameter("sub_channel");
|
||||
String api_key = request.getParameter("api_key");
|
||||
String signature = request.getParameter("signature");
|
||||
LOGGER.info("channel0={}",channel);
|
||||
DBObject resp = new BasicDBObject();
|
||||
List<DBObject> serverList = new ArrayList<>();
|
||||
if (StringUtils.checkIsEmpty(appota_user_id)) {
|
||||
resp.put("message", "appota_user_id null");
|
||||
resp.put("error_code", 1);
|
||||
resp.put("data", serverList);
|
||||
out.print(resp.toString());
|
||||
return;
|
||||
}
|
||||
if (StringUtils.checkIsEmpty(channel)) {
|
||||
resp.put("message", "channel null");
|
||||
resp.put("error_code", 1);
|
||||
resp.put("data", serverList);
|
||||
out.print(resp.toString());
|
||||
return;
|
||||
}
|
||||
if (StringUtils.checkIsEmpty(sub_channel)) {
|
||||
resp.put("message", "sub_channel null");
|
||||
resp.put("error_code", 1);
|
||||
resp.put("data", serverList);
|
||||
out.print(resp.toString());
|
||||
return;
|
||||
}
|
||||
if (StringUtils.checkIsEmpty(api_key)) {
|
||||
resp.put("message", "api_key null");
|
||||
resp.put("error_code", 1);
|
||||
resp.put("data", serverList);
|
||||
out.print(resp.toString());
|
||||
return;
|
||||
}
|
||||
if (StringUtils.checkIsEmpty(signature)) {
|
||||
resp.put("message", "signature null");
|
||||
resp.put("error_code", 1);
|
||||
resp.put("data", serverList);
|
||||
out.print(resp.toString());
|
||||
return;
|
||||
}
|
||||
if(!api_key.equals(GamotaConstats.apikey)){
|
||||
resp.put("message", "api_key error");
|
||||
resp.put("error_code", 1);
|
||||
resp.put("data", serverList);
|
||||
out.print(resp.toString());
|
||||
return;
|
||||
}
|
||||
String signStr = api_key + appota_user_id;
|
||||
String sign = MD5Util.encrypByMd5(signStr);
|
||||
if(!sign.equals(signature)){
|
||||
LOGGER.info("sign=" + sign + " --- signature="+signature);
|
||||
resp.put("message", "signature error");
|
||||
resp.put("error_code", 1);
|
||||
resp.put("data", serverList);
|
||||
out.print(resp.toString());
|
||||
return;
|
||||
}
|
||||
DBObject req = new BasicDBObject();
|
||||
serverInfosCache.clear();
|
||||
List<DBObject> serverInfoList = BaseGlobal.getInstance().mongoDBPool.find(_COLLECTION_NAME, req);
|
||||
String maxNumServerId= "";
|
||||
int maxNum = 0;
|
||||
for (DBObject serverInfo : serverInfoList) {
|
||||
int state = Integer.parseInt(serverInfo.get("state").toString());
|
||||
if ( state == -1) {
|
||||
continue;
|
||||
}
|
||||
//opentime
|
||||
long time = Long.parseLong(serverInfo.get("open_time").toString());
|
||||
if (System.currentTimeMillis() < time) {
|
||||
continue;
|
||||
}
|
||||
|
||||
//state
|
||||
String server_id=serverInfo.get("server_id").toString();
|
||||
int num = getOnlineNum(server_id);
|
||||
if (state == 5) {
|
||||
state = getState(server_id,num);
|
||||
}
|
||||
if(state==0){
|
||||
continue;
|
||||
}
|
||||
if(state==2&&maxNum<num){
|
||||
maxNum = num;
|
||||
maxNumServerId = server_id;
|
||||
}
|
||||
|
||||
DBObject res = new BasicDBObject();
|
||||
res.put("server_id",server_id);
|
||||
res.put("server_name", serverInfo.get("name"));
|
||||
String a = (String) serverInfo.get("name");
|
||||
Pattern p = Pattern.compile(regEx);
|
||||
Matcher m = p.matcher(a);
|
||||
String result = m.replaceAll("").trim();
|
||||
if (result.isEmpty()) {
|
||||
res.put("sort", 9999);
|
||||
} else {
|
||||
res.put("sort", Integer.parseInt(result));
|
||||
}
|
||||
serverList.add(res);
|
||||
serverInfosCache.put(serverInfo.get("server_id").toString(), res);
|
||||
}
|
||||
serverList.sort(Comparator.comparingInt(dbObject -> (int) dbObject.get("sort")));
|
||||
resp.put("message", "success");
|
||||
resp.put("error_code", 0);
|
||||
resp.put("data", serverList);
|
||||
out.print(resp.toString());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
out.flush();
|
||||
out.close();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private DBObject getDBObject(String serverId, UserRecentLoginInfo userRecentLoginInfo) {
|
||||
DBObject res = new BasicDBObject();
|
||||
res.put("serverid", serverId);
|
||||
res.put("name", userRecentLoginInfo.getName());
|
||||
res.put("level", userRecentLoginInfo.getLevel());
|
||||
return res;
|
||||
}
|
||||
|
||||
public void doPost(HttpServletRequest request, HttpServletResponse response)
|
||||
throws ServletException, IOException {
|
||||
this.doGet(request, response);
|
||||
}
|
||||
|
||||
private int getState(String server_id,int num) throws Exception {
|
||||
int state = 2;
|
||||
Map<String, String> globalCfgMap = BaseGlobal.getInstance().redisApp.hgetAll(RedisKey.GLOBAL_SYS_PRO, "", String.class, -1, false);
|
||||
int crowdnum = Integer.valueOf(globalCfgMap.getOrDefault("crowdnum", "0"));
|
||||
int highnum = Integer.valueOf(globalCfgMap.getOrDefault("highnum", "0"));
|
||||
if (crowdnum != 0 && highnum != 0) {
|
||||
if (num >= crowdnum) {
|
||||
state = 3;
|
||||
if (num >= highnum)
|
||||
state = 4;
|
||||
}
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
private int getOnlineNum(String server_id) throws Exception {
|
||||
Integer num = BaseGlobal.getInstance().redisApp.get("ONLINE_NUM", server_id, Integer.class, -1);
|
||||
if (num == null) {
|
||||
num = 0;
|
||||
}
|
||||
return num;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
package com.ljsd.util;
|
||||
|
||||
/**
|
||||
* Gamota渠道参数常量
|
||||
*/
|
||||
public class GamotaConstats {
|
||||
|
||||
public final static String apikey = "GMA202401-4B0C8B6C-C3B7290DEC0B";
|
||||
|
||||
public final static String secretKey = "XAhRvf9ycmv6BJGTUJci";
|
||||
}
|
||||
|
|
@ -162,18 +162,6 @@
|
|||
<url-pattern>/getServerVersion</url-pattern>
|
||||
</servlet-mapping>
|
||||
|
||||
|
||||
<servlet>
|
||||
<servlet-name>getHaoGameUserInfo</servlet-name>
|
||||
<servlet-class>com.ljsd.controller.HaoGameGetUserController</servlet-class>
|
||||
</servlet>
|
||||
|
||||
<servlet-mapping>
|
||||
<servlet-name>getHaoGameUserInfo</servlet-name>
|
||||
<url-pattern>/getHaoGameUserInfo</url-pattern>
|
||||
</servlet-mapping>
|
||||
|
||||
|
||||
<servlet>
|
||||
<servlet-name>getKTGameUserInfo</servlet-name>
|
||||
<servlet-class>com.ljsd.controller.KTGetUserOpenIdController</servlet-class>
|
||||
|
|
@ -184,6 +172,16 @@
|
|||
<url-pattern>/getKTGameUserInfo</url-pattern>
|
||||
</servlet-mapping>
|
||||
|
||||
<servlet>
|
||||
<servlet-name>gamotaGetServerList</servlet-name>
|
||||
<servlet-class>com.ljsd.controller.GamotaGetServerListController</servlet-class>
|
||||
</servlet>
|
||||
|
||||
<servlet-mapping>
|
||||
<servlet-name>gamotaGetServerList</servlet-name>
|
||||
<url-pattern>/gamotaGetServerList</url-pattern>
|
||||
</servlet-mapping>
|
||||
|
||||
|
||||
<listener>
|
||||
<listener-class>com.ljsd.listener.WebContextListener</listener-class>
|
||||
|
|
|
|||
Loading…
Reference in New Issue