|
|
@@ -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"));
|