lt hace 5 meses
padre
commit
5f45db2856

+ 45 - 34
src/main/java/com/ljsd/channel/MsySDK.java

@@ -1,6 +1,7 @@
 package com.ljsd.channel;
 
 import java.math.BigDecimal;
+import java.net.URISyntaxException;
 import java.net.URLEncoder;
 import java.nio.charset.StandardCharsets;
 import java.security.MessageDigest;
@@ -17,6 +18,8 @@ import com.mongodb.BasicDBObject;
 import com.mongodb.DBObject;
 import org.apache.http.client.methods.CloseableHttpResponse;
 import org.apache.http.client.methods.HttpGet;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.entity.StringEntity;
 import org.apache.http.impl.client.CloseableHttpClient;
 import org.apache.http.impl.client.HttpClients;
 import org.apache.http.util.EntityUtils;
@@ -41,26 +44,31 @@ public class MsySDK {
     public static boolean verifyUser(String uid, String token) {
         try {
             Properties properties = BaseGlobal.getInstance().properties;
-           // String productCode = properties.getProperty("quick_sdk_product_code_"+subChannel);
-            URIBuilder uriBuilder = new URIBuilder(properties.getProperty("msy_sdk_verify_api_url"));
-           // String nToken = URLEncoder.encode(token, String.valueOf(StandardCharsets.UTF_8));
-            //uriBuilder.addParameter("product_code", productCode);
-            uriBuilder.addParameter("uid", uid);
-            uriBuilder.addParameter("token", token);
-           // uriBuilder.addParameter("channel_code", ""); // 必须传渠道 ID
+            String jsonBody = String.format(
+                    "{\"user_id\":\"%s\",\"token\":\"%s\"}",
+                    uid, token
+            );
+            // uriBuilder.addParameter("channel_code", ""); // 必须传渠道 ID
             LOGGER.info("MsySDK 验证参数, token:{}, uid:{}",token,uid);
-
-            HttpGet httpGet = new HttpGet(uriBuilder.build().toString());
-            CloseableHttpResponse response = httpClient.execute(httpGet);
+            // 3. 创建 POST 请求
+            HttpPost httpPost = new HttpPost(properties.getProperty("msy_sdk_verify_api_url"));
+
+            // 4. 设置 JSON 请求体和头部
+            StringEntity entity = new StringEntity(jsonBody, StandardCharsets.UTF_8);
+            entity.setContentType("application/json"); // 关键:设置为 JSON 类型
+            httpPost.setEntity(entity);
+            httpPost.setHeader("Content-Type", "application/json; charset=UTF-8");
+            httpPost.setHeader("Accept", "application/json"); // 期望 JSON 响应
+            //HttpPost httpGet = new HttpPost(uriBuilder.build().toString());
+            CloseableHttpResponse response = httpClient.execute(httpPost);
 
             String result = EntityUtils.toString(response.getEntity());
             response.close();
             JsonObject jsonObject = GSON.fromJson(result, JsonObject.class);
-            boolean state = jsonObject.get("status").getAsBoolean();
+            int state = jsonObject.get("status").getAsInt();
             LOGGER.info("MsySDK 验证结果:{}", result);
-             if(!state){
-                String content = jsonObject.get("message").getAsString();
-                LOGGER.info("MSYSdk parseLoginResult content={}",content);
+             if(state!=200){
+                LOGGER.info("MSYSdk parseLoginResult content={}",state);
                 return false;
             }
             return true;
@@ -71,16 +79,27 @@ public class MsySDK {
         }
 
     }
-        public static boolean verifyCallback(String nt_data, String sign, String md5Sign) {
-        if (nt_data == null || sign == null || md5Sign == null) {
-            LOGGER.error("参数不可为空,nt_data={}, sign={}, md5Sign={}", nt_data, sign, md5Sign);
+
+    private static URIBuilder getUriBuilder(String uid, String token) throws URISyntaxException {
+        Properties properties = BaseGlobal.getInstance().properties;
+        // String productCode = properties.getProperty("quick_sdk_product_code_"+subChannel);
+        URIBuilder uriBuilder = new URIBuilder(properties.getProperty("msy_sdk_verify_api_url"));
+        // String nToken = URLEncoder.encode(token, String.valueOf(StandardCharsets.UTF_8));
+        //uriBuilder.addParameter("product_code", productCode);
+        uriBuilder.addParameter("uid", uid);
+        uriBuilder.addParameter("token", token);
+        return uriBuilder;
+    }
+
+    public static boolean verifyCallback(String orderId, String price,int status,String sign, String extend) {
+        if (orderId == null || sign == null) {
+            LOGGER.error("参数不可为空,nt_data={}, sign={}", orderId, sign);
             return false;
         }
         Properties properties = BaseGlobal.getInstance().properties;
         String md5Key = properties.getProperty("Msy_sdk_md5key_");
-        String rawString = nt_data + sign + md5Key;
+        String rawString = orderId+price+status+extend+ md5Key;
         LOGGER.info("rawString = {}", rawString);
-
         try {
             MessageDigest md = MessageDigest.getInstance("MD5");
 
@@ -95,7 +114,7 @@ public class MsySDK {
                 hexString.append(hex);
             }
             LOGGER.info("hexString.toString() = {}", hexString);
-            return hexString.toString().equals(md5Sign);
+            return hexString.toString().equals(sign);
         } catch (Exception e) {
             e.printStackTrace();
             LOGGER.error("MD5 算法不可用:", e);
@@ -103,17 +122,9 @@ public class MsySDK {
         }
     }
 
-        public static DBObject saveDB(String nt_data) throws Exception {
+        public static DBObject saveDB(String orderId, String price,int status,String sign, String extend) throws Exception {
         Properties properties = BaseGlobal.getInstance().properties;
-        String callBackKey = properties.getProperty("msy_sdk_callback_key");
-        String decoded = decode(nt_data, callBackKey);
-        LOGGER.info("解码结果 = {}", decoded);
-
-        Map<String, String> fields = XmlParser.parseNtData(decoded);
-        String param = fields.get("extras_params");
-        LOGGER.info("param = {}", param);
-
-        String orderId = fields.get("out_order_no");
+        //String callBackKey = properties.getProperty("msy_sdk_callback_key");
         DBObject payInfo = new BasicDBObject();
         payInfo.put("cporderId", orderId);
 
@@ -125,7 +136,7 @@ public class MsySDK {
         payInfo = payInfoList.get(0);
 
         // 比较订单金额
-        BigDecimal money = new BigDecimal(fields.get("amount"));
+        BigDecimal money = new BigDecimal(price);
         int processedMoney = money.multiply(BigDecimal.valueOf(100))
                 .intValueExact();
 
@@ -137,13 +148,13 @@ public class MsySDK {
             LOGGER.error("金额不一致,请检查!");
             return null; 
         }
-        payInfo.put("gameorderId", fields.get("order_no"));
-        payInfo.put("billno", orderId);
+       // payInfo.put("gameorderId", fields.get("order_no"));
+        //payInfo.put("billno", orderId);
 
 //        payInfo.put("uid", fields.get("channel_uid"));
 //        payInfo.put("openId", uid);
 //            dbObject.put("region", serverId);
-        payInfo.put("channel", "msy");
+        payInfo.put("channel", "wanba");
 //        payInfo.put("gameorderId", fields.get("game_order"));
 //            dbObject.put("cporderId", platform);
 //        payInfo.put("creattime", fields.get("pay_time"));

+ 8 - 5
src/main/java/com/ljsd/controller/GetServerListController.java

@@ -88,7 +88,7 @@ public class GetServerListController extends HttpServlet {
 
             List<DBObject> serverInfoList = BaseGlobal.getInstance().mongoDBPool.find(_COLLECTION_NAME, req);
             SortedSet<String> newServerList = new TreeSet<>();
-            String maxNumServerId = "";
+            String maxNumServerId = "0";
             int maxNum = 0;
 //            int shenheNum = 0; //记录 审核服数量
 //            for (DBObject serverInfo : serverInfoList) {
@@ -108,11 +108,11 @@ public class GetServerListController extends HttpServlet {
 //                String server_version2 = serverInfo.get("server_version").toString();
                 int num = getOnlineNum(server_id);
                 if (whiteList != null && (state == -1 || state == 1 || state == 0)) {
-                    state = 0;
+                    state = 2;
                 } else if (ipList != null && ipList.size() > 0 && (state == -1 || state == 1 || state == 0)) {
                     state = 2;
                 } else if (blackList != null) {
-                    state = 1;
+                    state = 0;
                 } else {
                     if (state == 5) {
                         state = getState(server_id, num);
@@ -128,8 +128,11 @@ public class GetServerListController extends HttpServlet {
                 if (System.currentTimeMillis()/1000 < time) {
                     continue;
                 }
-                if (state == 2 && maxNum < num) {
-                    maxNum = num;
+//                if (state == 2 && maxNum < num) {
+//                    maxNum = num;
+//                    maxNumServerId = server_id;
+//                }
+                if (state == 2 &&  Integer.parseInt(maxNumServerId) < Integer.parseInt(server_id)) {
                     maxNumServerId = server_id;
                 }
 

+ 1 - 1
src/main/java/com/ljsd/controller/LoginV2Controller.java

@@ -68,7 +68,7 @@ public class LoginV2Controller extends HttpServlet {
                 ok = MockXingTuSDK.verifyUser(token);
             } else if (channel.equals("737yx")) {
                 ok = Mock737YXSDK.verifyUser(uid);
-            } else if (channel.equals("Msy")){
+            } else if (channel.equals("wanba")){
                 ok = MsySDK.verifyUser(uid,token);
             } else {
                 resMsg.setMsg("不支持该渠道");

+ 10 - 5
src/main/java/com/ljsd/controller/PayCallback2Controller.java

@@ -49,16 +49,21 @@ public class PayCallback2Controller extends HttpServlet {
         response.setContentType("application/json; charset=utf-8");
         LOGGER.info("PayCallbackController json params = {}",RequestLogger.logRequestParams(request));
         String sign = request.getParameter("sign");
-        String nt_data = request.getParameter("nt_data");
-        String md5Sign = request.getParameter("md5Sign");
+        String orderId = request.getParameter("out_trade_no");
+        String price = request.getParameter("price");
+        //Double price = request.getParameter("price").isEmpty() ? null : Double.parseDouble(request.getParameter("price"));
+        int status = Integer.parseInt(request.getParameter("pay_status"));
+        String extend = request.getParameter("extend");
+        String uid = request.getParameter("user_id");
+        LOGGER.info("抖音巨量平台支付回调参数sign:{},orderId:{},price:{},status:{},extend:{}",sign,orderId,price,status,extend);
         ResMsg resMsg = new ResMsg();
         resMsg.setCode(1);
         DBObject payInfo = new BasicDBObject();
         try (PrintWriter out = response.getWriter();){
             boolean ok = false;
-            ok = MsySDK.verifyCallback(nt_data, sign, md5Sign);
+            ok = MsySDK.verifyCallback(orderId,price,status, sign, extend);
             if (ok) {
-                payInfo = MsySDK.saveDB(nt_data);
+                payInfo = MsySDK.saveDB(extend,price,status, sign, extend);
             }
 
             if (!ok) {
@@ -92,7 +97,7 @@ public class PayCallback2Controller extends HttpServlet {
                 resMsg.setMsg("发货失败");
                 return;
             }
-            out.print("SUCCESS");
+            out.print("success");
         }catch (Exception e){
             e.printStackTrace();
         }

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

@@ -1,5 +1,6 @@
 package com.ljsd.jieling.thrift.pool;
 
+import com.ljsd.controller.PayCallback2Controller;
 import com.ljsd.jieling.thrift.idl.RPCRequestIFace;
 import com.ljsd.jieling.thrift.idl.RechargeResult;
 import com.ljsd.jieling.thrift.idl.Result;
@@ -7,6 +8,8 @@ import org.apache.thrift.protocol.TBinaryProtocol;
 import org.apache.thrift.protocol.TProtocol;
 import org.apache.thrift.transport.TSocket;
 import org.apache.thrift.transport.TTransport;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 public class ThriftClient {
 
@@ -14,6 +17,7 @@ public class ThriftClient {
     private static final String SERVER_IP = "127.0.0.1";
 //    private static final int SERVER_PORT = 7915;
     private static final int TIMEOUT_MS = 3000;
+    private static final Logger LOGGER = LoggerFactory.getLogger(ThriftClient.class);
 
     /**
      * 调用发货接口 deliveryRecharge
@@ -24,9 +28,9 @@ public class ThriftClient {
         TTransport transport = null;
         try {
             int port = getPort(serverId);
+            //LOGGER.info("端口, payInfo = {}", port);
             transport = new TSocket(SERVER_IP, port, TIMEOUT_MS);
             transport.open();
-
             TProtocol protocol = new TBinaryProtocol(transport);
             RPCRequestIFace.Client client = new RPCRequestIFace.Client(protocol);
             return client.deliveryRecharge(uid, goodsId, openId, orderId, orderTime, amount);