Jim 10 месяцев назад
Родитель
Сommit
6ac38f0d20

+ 5 - 0
build.gradle

@@ -11,6 +11,11 @@ repositories {
     mavenCentral()
     mavenCentral()
 }
 }
 
 
+// 设置 Java 编译编码为 UTF-8
+tasks.withType(JavaCompile) {
+    options.encoding = 'UTF-8'
+}
+
 dependencies {
 dependencies {
     testCompile group: 'junit', name: 'junit', version: '4.11'
     testCompile group: 'junit', name: 'junit', version: '4.11'
     compile("javax.servlet:servlet-api:2.5")
     compile("javax.servlet:servlet-api:2.5")

+ 2 - 1
src/main/java/com/ljsd/controller/GetRechargeController.java

@@ -37,10 +37,11 @@ public class GetRechargeController extends HttpServlet {
         response.setContentType("application/json; charset=utf-8");
         response.setContentType("application/json; charset=utf-8");
         // /getRecharge?&uid=10000026
         // /getRecharge?&uid=10000026
         String uid = request.getParameter("uid");
         String uid = request.getParameter("uid");
+        String serverId = request.getParameter("server_id");
         LOGGER.info("GetRechargeController request = {}", request);
         LOGGER.info("GetRechargeController request = {}", request);
         ResMsg resMsg = new ResMsg();
         ResMsg resMsg = new ResMsg();
         resMsg.setCode(1);
         resMsg.setCode(1);
-        RechargeResult result = ThriftClient.getRecharge(Integer.parseInt(uid));
+        RechargeResult result = ThriftClient.getRecharge(Integer.parseInt(uid), serverId);
         LOGGER.info("GetRechargeController result = {}", result);
         LOGGER.info("GetRechargeController result = {}", result);
 
 
 
 

+ 20 - 20
src/main/java/com/ljsd/controller/GetServerListController.java

@@ -47,11 +47,11 @@ public class GetServerListController extends HttpServlet {
             String openId = request.getParameter("openId");                 //登录账号
             String openId = request.getParameter("openId");                 //登录账号
             String channel = request.getParameter("channel");               //pc
             String channel = request.getParameter("channel");               //pc
             String sub_channel = request.getParameter("sub_channel");       //1
             String sub_channel = request.getParameter("sub_channel");       //1
-            String server_version = String.valueOf(request.getParameter("server_version")); //1
+//            String server_version = String.valueOf(request.getParameter("server_version")); //1
             String plat = request.getParameter("plat");                     //android
             String plat = request.getParameter("plat");                     //android
             //判断非空
             //判断非空
             if (StringUtils.checkIsEmpty(openId) || StringUtils.checkIsEmpty(channel) ||
             if (StringUtils.checkIsEmpty(openId) || StringUtils.checkIsEmpty(channel) ||
-                    StringUtils.checkIsEmpty(sub_channel) || StringUtils.checkIsEmpty(plat) || StringUtils.checkIsEmpty(server_version)) {
+                    StringUtils.checkIsEmpty(sub_channel) || StringUtils.checkIsEmpty(plat)) {
                 response.sendError(400, "parm is wrong");
                 response.sendError(400, "parm is wrong");
                 return;
                 return;
             }
             }
@@ -84,13 +84,13 @@ public class GetServerListController extends HttpServlet {
             SortedSet<String> newServerList = new TreeSet<>();
             SortedSet<String> newServerList = new TreeSet<>();
             String maxNumServerId = "";
             String maxNumServerId = "";
             int maxNum = 0;
             int maxNum = 0;
-            int shenheNum = 0; //记录 审核服数量
-            for (DBObject serverInfo : serverInfoList) {
-                String server_version1 = serverInfo.get("server_version").toString();
-                if(server_version.equals(server_version1)) {
-                    shenheNum += 1;
-                }
-            }
+//            int shenheNum = 0; //记录 审核服数量
+//            for (DBObject serverInfo : serverInfoList) {
+//                String server_version1 = serverInfo.get("server_version").toString();
+//                if(server_version.equals(server_version1)) {
+//                    shenheNum += 1;
+//                }
+//            }
 
 
             for (DBObject serverInfo : serverInfoList) {
             for (DBObject serverInfo : serverInfoList) {
                 int state = Integer.parseInt(serverInfo.get("state").toString());
                 int state = Integer.parseInt(serverInfo.get("state").toString());
@@ -99,7 +99,7 @@ public class GetServerListController extends HttpServlet {
                 //state
                 //state
                 String server_id = serverInfo.get("server_id").toString();
                 String server_id = serverInfo.get("server_id").toString();
                 //server_version
                 //server_version
-                String server_version2 = serverInfo.get("server_version").toString();
+//                String server_version2 = serverInfo.get("server_version").toString();
                 int num = getOnlineNum(server_id);
                 int num = getOnlineNum(server_id);
                 if (whiteList != null && whiteList.size() > 0 && (state == -1 || state == 1 || state == 0)) {
                 if (whiteList != null && whiteList.size() > 0 && (state == -1 || state == 1 || state == 0)) {
                     state = 2;
                     state = 2;
@@ -128,16 +128,16 @@ public class GetServerListController extends HttpServlet {
                 }
                 }
 
 
                 //判断版本号,0=普通服,!=0 审核服
                 //判断版本号,0=普通服,!=0 审核服
-                if(!server_version2.equals("0")){   //审核服
-                    if(!server_version.equals(server_version2)) {
-                        continue;
-                    }
-                }else {
-                    //shenheNum >=1 表示是审核服
-                    if(shenheNum >= 1){
-                        continue;
-                    }
-                }
+//                if(!server_version2.equals("0")){   //审核服
+//                    if(!server_version.equals(server_version2)) {
+//                        continue;
+//                    }
+//                }else {
+//                    //shenheNum >=1 表示是审核服
+//                    if(shenheNum >= 1){
+//                        continue;
+//                    }
+//                }
 
 
                 //new
                 //new
                 int isnew = 0;
                 int isnew = 0;

+ 4 - 17
src/main/java/com/ljsd/controller/PayCallbackController.java

@@ -118,27 +118,14 @@ public class PayCallbackController extends HttpServlet {
             // status 怀疑没有使用,发货成功后,会把handlestatus置为1
             // status 怀疑没有使用,发货成功后,会把handlestatus置为1
             // 放在各sdk实例的saveDB中
             // 放在各sdk实例的saveDB中
 
 
-            // todo 通知发货
-            // todo 各区服分配端口
+            // 通知发货
             LOGGER.info("通知发货, payInfo = {}", payInfo);
             LOGGER.info("通知发货, payInfo = {}", payInfo);
-            Result result = ThriftClient.deliveryRecharge((int) payInfo.get("uid"), (String) payInfo.get("pay_item"), (String) payInfo.get("open_id"),
-                     (String) payInfo.get("billno"), Long.parseLong((String) payInfo.get("creattime")), (int) payInfo.get("money"));
+            Result result = ThriftClient.deliveryRecharge((int) payInfo.get("uid"), (String) payInfo.get("pay_item"),
+                    (String) payInfo.get("open_id"), (String) payInfo.get("billno"), Long.parseLong((String) payInfo.get("creattime")),
+                    (int) payInfo.get("money"), (String) payInfo.get("region"));
 
 
-//            URIBuilder uriBuilder = new URIBuilder("http://127.0.0.1:7915/deliveryRecharge");
-//            uriBuilder.addParameter("uid", (String) payInfo.get("uid"));
-//            uriBuilder.addParameter("goodsId", (String) payInfo.get("pay_item"));
-//            uriBuilder.addParameter("openId", (String) payInfo.get("open_id"));
-//            uriBuilder.addParameter("orderId", (String) payInfo.get("cporderId"));
-//            uriBuilder.addParameter("orderTime", (String) payInfo.get("creattime"));
-//            uriBuilder.addParameter("amount", String.valueOf((int) payInfo.get("money")));
-//
-//            HttpGet httpGet = new HttpGet(uriBuilder.build().toString());
-//            CloseableHttpResponse resp = httpClient.execute(httpGet);
-
-//            String result = EntityUtils.toString(resp.getEntity());
             LOGGER.info("deliveryRecharge result = {}", result);
             LOGGER.info("deliveryRecharge result = {}", result);
 
 
-//            resp.close();
             if (result == null || result.resultCode != 1) {
             if (result == null || result.resultCode != 1) {
                 resMsg.setCode(1);
                 resMsg.setCode(1);
                 resMsg.setMsg("发货失败");
                 resMsg.setMsg("发货失败");

+ 27 - 5
src/main/java/com/ljsd/jieling/thrift/pool/ThriftClient.java

@@ -12,18 +12,19 @@ public class ThriftClient {
 
 
     // 替换为实际的服务 IP 和端口
     // 替换为实际的服务 IP 和端口
     private static final String SERVER_IP = "127.0.0.1";
     private static final String SERVER_IP = "127.0.0.1";
-    private static final int SERVER_PORT = 7915;
+//    private static final int SERVER_PORT = 7915;
     private static final int TIMEOUT_MS = 3000;
     private static final int TIMEOUT_MS = 3000;
 
 
     /**
     /**
      * 调用发货接口 deliveryRecharge
      * 调用发货接口 deliveryRecharge
      */
      */
     public static Result deliveryRecharge(int uid, String goodsId, String openId,
     public static Result deliveryRecharge(int uid, String goodsId, String openId,
-                                          String orderId, long orderTime, int amount) {
+                                          String orderId, long orderTime, int amount, String serverId) {
 
 
         TTransport transport = null;
         TTransport transport = null;
         try {
         try {
-            transport = new TSocket(SERVER_IP, SERVER_PORT, TIMEOUT_MS);
+            int port = getPort(serverId);
+            transport = new TSocket(SERVER_IP, port, TIMEOUT_MS);
             transport.open();
             transport.open();
 
 
             TProtocol protocol = new TBinaryProtocol(transport);
             TProtocol protocol = new TBinaryProtocol(transport);
@@ -45,10 +46,11 @@ public class ThriftClient {
     /**
     /**
      * 调用 getRecharge 查询充值状态
      * 调用 getRecharge 查询充值状态
      */
      */
-    public static RechargeResult getRecharge(int uid) {
+    public static RechargeResult getRecharge(int uid, String serverId) {
         TTransport transport = null;
         TTransport transport = null;
         try {
         try {
-            transport = new TSocket(SERVER_IP, SERVER_PORT, TIMEOUT_MS);
+            int port = getPort(serverId);
+            transport = new TSocket(SERVER_IP, port, TIMEOUT_MS);
             transport.open();
             transport.open();
 
 
             TProtocol protocol = new TBinaryProtocol(transport);
             TProtocol protocol = new TBinaryProtocol(transport);
@@ -66,5 +68,25 @@ public class ThriftClient {
             }
             }
         }
         }
     }
     }
+
+    // serverId:10001
+    public static int getPort(String serverId) {
+        if (serverId == null || serverId.trim().isEmpty()) {
+            throw new IllegalArgumentException("服务器ID不能为空");
+        }
+
+        int id;
+        try {
+            id = Integer.parseInt(serverId.trim())%10000;
+        } catch (NumberFormatException e) {
+            throw new IllegalArgumentException("服务器ID必须为有效整数", e);
+        }
+
+        int port = 19000 + id;
+        if (port < 0 || port > 65535) {
+            throw new IllegalArgumentException("计算后的端口号超出有效范围(0-65535)");
+        }
+        return port;
+    }
 }
 }
 
 

+ 4 - 4
src/main/resources/application.properties

@@ -1,8 +1,8 @@
 #mongodb_url = mongodb://admin:123456@120.92.119.145:27020/?&authSource=admin
 #mongodb_url = mongodb://admin:123456@120.92.119.145:27020/?&authSource=admin
 #mongodb_url = mongodb://ljkji54$^fj5K:dk3$k8G5^a67@10.2.0.3:27020/?&authSource=admin
 #mongodb_url = mongodb://ljkji54$^fj5K:dk3$k8G5^a67@10.2.0.3:27020/?&authSource=admin
 #mongodb_url = mongodb://root:123456@10.255.255.4:27020/?&authSource=admin
 #mongodb_url = mongodb://root:123456@10.255.255.4:27020/?&authSource=admin
-mongodb_url = mongodb://root:f7bd979b98fb334d@127.0.0.1:27017/?&authSource=admin
-mongodb_name = m5_tk_login
+mongodb_url = mongodb://admin:rimZBP82Ia@127.0.0.1:27017/?&authSource=admin
+mongodb_name = x5_tk_login
 #mongodb_name = m5_x1_login
 #mongodb_name = m5_x1_login
 #mongodb_name = x1_cn_test_login
 #mongodb_name = x1_cn_test_login
 
 
@@ -36,7 +36,7 @@ mongodb_socketKeepAlive = true
 #redis_host = 10.255.255.4
 #redis_host = 10.255.255.4
 redis_host = 127.0.0.1
 redis_host = 127.0.0.1
 redis_port=6379
 redis_port=6379
-redis_password=f7bd979b98fb334d
+redis_password=lVzYFQ2i6v
 #redis_password=@emiplay_m5fangzhi_redis
 #redis_password=@emiplay_m5fangzhi_redis
 redis_maxTotal = 10
 redis_maxTotal = 10
 redis_minIdle = 3
 redis_minIdle = 3
@@ -47,4 +47,4 @@ redis_testOnBorrow = false
 isTestLan = 1
 isTestLan = 1
 
 
 # ?????
 # ?????
-openAdultCheck = false
+openAdultCheck = false

+ 50 - 0
src/main/resources/application1.properties

@@ -0,0 +1,50 @@
+#mongodb_url = mongodb://admin:123456@120.92.119.145:27020/?&authSource=admin
+#mongodb_url = mongodb://ljkji54$^fj5K:dk3$k8G5^a67@10.2.0.3:27020/?&authSource=admin
+#mongodb_url = mongodb://root:123456@10.255.255.4:27020/?&authSource=admin
+mongodb_url = mongodb://root:f7bd979b98fb334d@127.0.0.1:27017/?&authSource=admin
+mongodb_name = m5_tk_login
+#mongodb_name = m5_x1_login
+#mongodb_name = x1_cn_test_login
+
+# ????????????????
+mongodb_maximumNumberOfConnections = 100
+
+# ??????????????2???
+mongodb_connectTimeout = 1200000
+
+# ?????????????????????????3??
+mongodb_maxWaitTime = 30000
+
+# ??xx?????????????????5?
+mongodb_threadsAllowedToBlockForConnectionMultiplier = 5
+
+# ???????0??????
+mongodb_maxConnectionIdleTime = 0
+
+# ???????0??????
+mongodb_maxConnectionLifeTime = 0
+
+# ???????0??????
+mongodb_socketTimeout = 0
+
+# ??????????
+mongodb_socketKeepAlive = true
+
+
+# Redis ????
+#redis_host = 120.92.119.145
+#redis_host = 10.255.255.4
+redis_host = 127.0.0.1
+redis_port=6379
+redis_password=f7bd979b98fb334d
+#redis_password=@emiplay_m5fangzhi_redis
+redis_maxTotal = 10
+redis_minIdle = 3
+redis_maxWaitMillis = 20
+redis_maxIdle = 5
+redis_testOnBorrow = false
+
+isTestLan = 1
+
+# ?????
+openAdultCheck = false

+ 50 - 0
src/main/resources/application2.properties

@@ -0,0 +1,50 @@
+#mongodb_url = mongodb://admin:123456@120.92.119.145:27020/?&authSource=admin
+#mongodb_url = mongodb://ljkji54$^fj5K:dk3$k8G5^a67@10.2.0.3:27020/?&authSource=admin
+#mongodb_url = mongodb://root:123456@10.255.255.4:27020/?&authSource=admin
+mongodb_url = mongodb://admin:rimZBP82Ia@127.0.0.1:27017/?&authSource=admin
+mongodb_name = x5_tk_login
+#mongodb_name = m5_x1_login
+#mongodb_name = x1_cn_test_login
+
+# ????????????????
+mongodb_maximumNumberOfConnections = 100
+
+# ??????????????2???
+mongodb_connectTimeout = 1200000
+
+# ?????????????????????????3??
+mongodb_maxWaitTime = 30000
+
+# ??xx?????????????????5?
+mongodb_threadsAllowedToBlockForConnectionMultiplier = 5
+
+# ???????0??????
+mongodb_maxConnectionIdleTime = 0
+
+# ???????0??????
+mongodb_maxConnectionLifeTime = 0
+
+# ???????0??????
+mongodb_socketTimeout = 0
+
+# ??????????
+mongodb_socketKeepAlive = true
+
+
+# Redis ????
+#redis_host = 120.92.119.145
+#redis_host = 10.255.255.4
+redis_host = 127.0.0.1
+redis_port=6379
+redis_password=lVzYFQ2i6v
+#redis_password=@emiplay_m5fangzhi_redis
+redis_maxTotal = 10
+redis_minIdle = 3
+redis_maxWaitMillis = 20
+redis_maxIdle = 5
+redis_testOnBorrow = false
+
+isTestLan = 1
+
+# ?????
+openAdultCheck = false