package com.ljsd.channel; import com.ljsd.redis.RedisUtil; import com.ljsd.util.BaseGlobal; import com.ljsd.util.TimeUtil; import com.ljsd.util.XmlParser; 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.utils.URIBuilder; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; import org.apache.http.util.EntityUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.nio.charset.StandardCharsets; import java.security.MessageDigest; import java.util.List; import java.util.Map; import java.util.Properties; import static javax.management.Query.eq; public class MockQuickSDK { private static final Logger LOGGER = LoggerFactory.getLogger(MockQuickSDK.class); private static final String QUICK_SDK_PRODUCT_CODE="74323196251398220690098816635773"; private static final String QUICK_SDK_PRODUCT_KEY="20562534"; private static final String QUICK_SDK_CALLBACK_KEY="05803023623721638274057263988239"; private static final String QUICK_SDK_VERIFY_API_URL="https://checkuser.gamedachen.com/v2/checkUserInfo"; private static final CloseableHttpClient httpClient = HttpClients.createDefault(); private final static String _COLLECTION_PAY = "pay"; public static boolean verifyUser(String uid, String token) { try { URIBuilder uriBuilder = new URIBuilder(QUICK_SDK_VERIFY_API_URL); uriBuilder.addParameter("token", token); uriBuilder.addParameter("product_code", QUICK_SDK_PRODUCT_CODE); uriBuilder.addParameter("uid", uid); uriBuilder.addParameter("channel_code", ""); // 必须传渠道 ID HttpGet httpGet = new HttpGet(uriBuilder.build().toString()); CloseableHttpResponse response = httpClient.execute(httpGet); String result = EntityUtils.toString(response.getEntity()); response.close(); return result.equals("1"); } catch (Exception e) { e.printStackTrace(); LOGGER.error("QuickSDK 验证异常:", e); return false; } } 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); return false; } String rawString = nt_data + sign + QUICK_SDK_CALLBACK_KEY; try { MessageDigest md = MessageDigest.getInstance("MD5"); byte[] hashBytes = md.digest(rawString.getBytes(StandardCharsets.UTF_8)); StringBuilder hexString = new StringBuilder(); for (byte b : hashBytes) { String hex = Integer.toHexString(0xFF & b); if (hex.length() == 1) { hexString.append('0'); // 补前导零(如 0x0A → "0a") } hexString.append(hex); } boolean success = hexString.toString().equals(md5Sign); if (success) { } return hexString.toString().equals(md5Sign); } catch (Exception e) { e.printStackTrace(); LOGGER.error("MD5 算法不可用:", e); return false; } } public static DBObject saveDB(String nt_data) throws Exception { Map fields = XmlParser.parseNtData(nt_data); String param = fields.get("extras_params"); LOGGER.info("param = {}", param); String orderId = fields.get("game_order"); DBObject payInfo = new BasicDBObject(); payInfo.put("cporderId", orderId); List payInfoList = BaseGlobal.getInstance().mongoDBPool.find(_COLLECTION_PAY, payInfo); if (payInfoList.size() != 1) { return null; } payInfo = new BasicDBObject(); payInfo.put("billno", fields.get("order_no")); payInfo.put("uid", fields.get("channel_uid")); // payInfo.put("openId", uid); // dbObject.put("region", serverId); payInfo.put("channel", "quick"); // payInfo.put("gameorderId", fields.get("game_order")); // dbObject.put("cporderId", platform); payInfo.put("creattime", fields.get("pay_time")); payInfo.put("callbaktime", TimeUtil.getTimeNow()); BaseGlobal.getInstance().mongoDBPool.save(_COLLECTION_PAY, payInfo); return payInfo; } private static String generateSign(String appId, String appSecret, String userId) { String raw = appId + appSecret + userId; return raw.hashCode() + ""; } }