抢单账户配置
This commit is contained in:
@@ -34,6 +34,9 @@ public class HxrAdminBuyService {
|
||||
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 "
|
||||
+ "(KHTML, like Gecko) Chrome/148.0.0.0 Safari/537.36 Edg/148.0.0.0";
|
||||
|
||||
/** 与 hxrd 前端 DevTools 一致,使用 {@code Token} 而非小写 {@code token}。 */
|
||||
private static final String HEADER_TOKEN = "Token";
|
||||
|
||||
private static final ObjectMapper JSON = new ObjectMapper()
|
||||
.setPropertyNamingStrategy(PropertyNamingStrategies.SNAKE_CASE);
|
||||
|
||||
@@ -101,16 +104,21 @@ public class HxrAdminBuyService {
|
||||
.followRedirects(HttpClient.Redirect.NORMAL)
|
||||
.build();
|
||||
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("hxr /api/order/buy request id={} sellerId={} tokenPrefix={} body={} signPayload=id={}&noncestr={}&seller_id={}×tamp={}",
|
||||
goodsId, sellerId, abbreviate(resolvedToken, 8), bodyJson, goodsId, noncestr, sellerId, timestamp);
|
||||
}
|
||||
|
||||
HttpRequest request = HttpRequest.newBuilder()
|
||||
.uri(URI.create(buyApiUrl.trim()))
|
||||
.timeout(Duration.ofSeconds(120))
|
||||
.header("Accept", "application/json,*/*")
|
||||
.header("Accept-Language", "zh-CN,zh;q=0.9,en;q=0.8")
|
||||
.header("Content-Type", "application/json;charset=UTF-8")
|
||||
.header("Content-Type", "application/json")
|
||||
.header("Origin", ctx.origin())
|
||||
.header("Referer", ctx.referer())
|
||||
.header("User-Agent", USER_AGENT)
|
||||
.header("token", resolvedToken)
|
||||
.header(HEADER_TOKEN, resolvedToken)
|
||||
.header("S", sign)
|
||||
.header("T", String.valueOf(timestamp))
|
||||
.header("N", noncestr)
|
||||
@@ -134,8 +142,12 @@ public class HxrAdminBuyService {
|
||||
int code = root.path("code").asInt(-1);
|
||||
String msg = root.path("msg").asText("");
|
||||
if (code != 0) {
|
||||
log.warn("hxr /api/order/buy api code={} msg={} id={} sellerId={}",
|
||||
code, msg, goodsId, sellerId);
|
||||
log.warn("hxr /api/order/buy api code={} msg={} id={} sellerId={} tokenPrefix={} body={}",
|
||||
code, msg, goodsId, sellerId, abbreviate(resolvedToken, 8), abbreviate(bodyText, 200));
|
||||
if (code == 500 && "网络请求失败".equals(msg)) {
|
||||
log.warn("hxr /api/order/buy 鉴权失败常见原因:Token 与浏览器不一致或已过期、goodsApiAppStr 错误;"
|
||||
+ "请在 rush-buy 请求体传入浏览器 DevTools 中 Token 头的值,并核对 lb_third_integration_config.goods_api_token / goods_api_app_str");
|
||||
}
|
||||
}
|
||||
return new BuyApiResult(code == 0, code, msg);
|
||||
}
|
||||
|
||||
@@ -41,6 +41,8 @@ public class HxrAdminGoodsService {
|
||||
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 "
|
||||
+ "(KHTML, like Gecko) Chrome/148.0.0.0 Safari/537.36 Edg/148.0.0.0";
|
||||
|
||||
private static final String HEADER_TOKEN = "Token";
|
||||
|
||||
private static final ObjectMapper JSON = new ObjectMapper()
|
||||
.setPropertyNamingStrategy(PropertyNamingStrategies.SNAKE_CASE)
|
||||
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
|
||||
@@ -132,7 +134,7 @@ public class HxrAdminGoodsService {
|
||||
.header("Origin", ctx.origin())
|
||||
.header("Referer", ctx.referer())
|
||||
.header("User-Agent", USER_AGENT)
|
||||
.header("token", resolvedToken)
|
||||
.header(HEADER_TOKEN, resolvedToken)
|
||||
.header("S", sign)
|
||||
.header("T", String.valueOf(timestamp))
|
||||
.header("N", noncestr)
|
||||
|
||||
@@ -155,7 +155,7 @@ public class HxrAdminOrderSelectService {
|
||||
}
|
||||
String refererHeader = referer;
|
||||
if (refererHeader == null || refererHeader.isBlank()) {
|
||||
refererHeader = "https://hxrdhoutai.hxrdsm.cn222/app/admin/order/index";
|
||||
refererHeader = "https://22222/app/admin/order/index";
|
||||
}
|
||||
|
||||
HttpClient client = HttpClient.newBuilder()
|
||||
|
||||
@@ -117,7 +117,7 @@ public class HxrAdminUserService {
|
||||
stripQuery(properties.getUserSelectUrl()),
|
||||
USER_SELECT_PAGE_SIZE,
|
||||
cookieHeader,
|
||||
"https://hxrdhoutai.hxrdsm.cn222/app/admin/user/index");
|
||||
"https://22222/app/admin/user/index");
|
||||
return fetchUserSelectPage(page, ctx);
|
||||
}
|
||||
|
||||
@@ -228,7 +228,7 @@ public class HxrAdminUserService {
|
||||
.header("Accept-Language", "zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6")
|
||||
.header("Cookie", cookieHeader)
|
||||
.header("Priority", "u=1, i")
|
||||
.header("Referer", "https://hxrdhoutai.hxrdsm.cn222/app/admin/user/index")
|
||||
.header("Referer", "https://22222/app/admin/user/index")
|
||||
.header("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/148.0.0.0 Safari/537.36 Edg/148.0.0.0")
|
||||
.GET()
|
||||
.build();
|
||||
@@ -294,7 +294,7 @@ public class HxrAdminUserService {
|
||||
.header("Accept", "application/json, text/javascript, */*; q=0.01")
|
||||
.header("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8")
|
||||
.header("Cookie", cookieHeader)
|
||||
.header("Referer", "https://hxrdhoutai.hxrdsm.cn222/app/admin/user/index")
|
||||
.header("Referer", "https://22222/app/admin/user/index")
|
||||
.header("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/148.0.0.0 Safari/537.36 Edg/148.0.0.0")
|
||||
.POST(HttpRequest.BodyPublishers.ofString(form, StandardCharsets.UTF_8))
|
||||
.build();
|
||||
|
||||
26
src/main/java/com/rj/service/ILbBuyAccountService.java
Normal file
26
src/main/java/com/rj/service/ILbBuyAccountService.java
Normal file
@@ -0,0 +1,26 @@
|
||||
package com.rj.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.rj.entity.LbBuyAccount;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public interface ILbBuyAccountService extends IService<LbBuyAccount> {
|
||||
|
||||
Map<String, Object> add(LbBuyAccount entity);
|
||||
|
||||
Map<String, Object> update(LbBuyAccount entity);
|
||||
|
||||
Map<String, Object> deleteById(String id);
|
||||
|
||||
Map<String, Object> pageQuery(Integer current,
|
||||
Integer size,
|
||||
String tenantId,
|
||||
String tenantName,
|
||||
String loginAccount,
|
||||
String nickname,
|
||||
String referrerPhone,
|
||||
String referrerName,
|
||||
String createTimeStart,
|
||||
String createTimeEnd);
|
||||
}
|
||||
268
src/main/java/com/rj/service/impl/LbBuyAccountServiceImpl.java
Normal file
268
src/main/java/com/rj/service/impl/LbBuyAccountServiceImpl.java
Normal file
@@ -0,0 +1,268 @@
|
||||
package com.rj.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.rj.entity.LbBuyAccount;
|
||||
import com.rj.mapper.LbBuyAccountMapper;
|
||||
import com.rj.service.ILbBuyAccountService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
public class LbBuyAccountServiceImpl
|
||||
extends ServiceImpl<LbBuyAccountMapper, LbBuyAccount>
|
||||
implements ILbBuyAccountService {
|
||||
|
||||
private static final DateTimeFormatter DATE_TIME_FORMATTER =
|
||||
DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
||||
|
||||
@Override
|
||||
public Map<String, Object> add(LbBuyAccount entity) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
try {
|
||||
Map<String, Object> validation = validateRequiredForAdd(entity);
|
||||
if (validation != null) {
|
||||
return validation;
|
||||
}
|
||||
trimStringFields(entity);
|
||||
defaultIntegerFields(entity);
|
||||
|
||||
if (entity.getId() == null || entity.getId().trim().isEmpty()) {
|
||||
entity.setId(UUID.randomUUID().toString());
|
||||
}
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
if (entity.getCreateTime() == null) {
|
||||
entity.setCreateTime(now);
|
||||
}
|
||||
entity.setUpdateTime(now);
|
||||
|
||||
boolean ok = this.save(entity);
|
||||
result.put("success", ok);
|
||||
result.put("message", ok ? "新增成功" : "新增失败");
|
||||
if (ok) {
|
||||
result.put("data", entity);
|
||||
}
|
||||
return result;
|
||||
} catch (Exception e) {
|
||||
log.error("抢单账号配置新增异常", e);
|
||||
result.put("success", false);
|
||||
result.put("message", "新增异常:" + e.getMessage());
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> update(LbBuyAccount entity) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
try {
|
||||
if (entity.getId() == null || entity.getId().trim().isEmpty()) {
|
||||
result.put("success", false);
|
||||
result.put("message", "id不能为空");
|
||||
return result;
|
||||
}
|
||||
trimStringFields(entity);
|
||||
entity.setUpdateTime(LocalDateTime.now());
|
||||
boolean ok = this.updateById(entity);
|
||||
result.put("success", ok);
|
||||
result.put("message", ok ? "编辑成功" : "编辑失败");
|
||||
if (ok) {
|
||||
result.put("data", this.getById(entity.getId()));
|
||||
}
|
||||
return result;
|
||||
} catch (Exception e) {
|
||||
log.error("抢单账号配置编辑异常", e);
|
||||
result.put("success", false);
|
||||
result.put("message", "编辑异常:" + e.getMessage());
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> deleteById(String id) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
try {
|
||||
if (id == null || id.trim().isEmpty()) {
|
||||
result.put("success", false);
|
||||
result.put("message", "id不能为空");
|
||||
return result;
|
||||
}
|
||||
boolean ok = this.removeById(id.trim());
|
||||
result.put("success", ok);
|
||||
result.put("message", ok ? "删除成功" : "删除失败");
|
||||
return result;
|
||||
} catch (Exception e) {
|
||||
log.error("抢单账号配置删除异常", e);
|
||||
result.put("success", false);
|
||||
result.put("message", "删除异常:" + e.getMessage());
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> pageQuery(Integer current,
|
||||
Integer size,
|
||||
String tenantId,
|
||||
String tenantName,
|
||||
String loginAccount,
|
||||
String nickname,
|
||||
String referrerPhone,
|
||||
String referrerName,
|
||||
String createTimeStart,
|
||||
String createTimeEnd) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
try {
|
||||
if (current == null || current < 1) {
|
||||
current = 1;
|
||||
}
|
||||
if (size == null || size < 1) {
|
||||
size = 10;
|
||||
}
|
||||
|
||||
LambdaQueryWrapper<LbBuyAccount> queryWrapper = new LambdaQueryWrapper<>();
|
||||
if (tenantId != null && !tenantId.trim().isEmpty()) {
|
||||
queryWrapper.eq(LbBuyAccount::getTenantId, tenantId.trim());
|
||||
}
|
||||
if (tenantName != null && !tenantName.trim().isEmpty()) {
|
||||
queryWrapper.like(LbBuyAccount::getTenantName, tenantName.trim());
|
||||
}
|
||||
if (loginAccount != null && !loginAccount.trim().isEmpty()) {
|
||||
queryWrapper.like(LbBuyAccount::getLoginAccount, loginAccount.trim());
|
||||
}
|
||||
if (nickname != null && !nickname.trim().isEmpty()) {
|
||||
queryWrapper.like(LbBuyAccount::getNickname, nickname.trim());
|
||||
}
|
||||
if (referrerPhone != null && !referrerPhone.trim().isEmpty()) {
|
||||
queryWrapper.like(LbBuyAccount::getReferrerPhone, referrerPhone.trim());
|
||||
}
|
||||
if (referrerName != null && !referrerName.trim().isEmpty()) {
|
||||
queryWrapper.like(LbBuyAccount::getReferrerName, referrerName.trim());
|
||||
}
|
||||
|
||||
LocalDateTime start = parseDateTime(createTimeStart);
|
||||
if (createTimeStart != null && !createTimeStart.trim().isEmpty() && start == null) {
|
||||
result.put("success", false);
|
||||
result.put("message", "createTimeStart 格式错误,请使用 yyyy-MM-dd HH:mm:ss");
|
||||
return result;
|
||||
}
|
||||
LocalDateTime end = parseDateTime(createTimeEnd);
|
||||
if (createTimeEnd != null && !createTimeEnd.trim().isEmpty() && end == null) {
|
||||
result.put("success", false);
|
||||
result.put("message", "createTimeEnd 格式错误,请使用 yyyy-MM-dd HH:mm:ss");
|
||||
return result;
|
||||
}
|
||||
if (start != null) {
|
||||
queryWrapper.ge(LbBuyAccount::getCreateTime, start);
|
||||
}
|
||||
if (end != null) {
|
||||
queryWrapper.le(LbBuyAccount::getCreateTime, end);
|
||||
}
|
||||
|
||||
queryWrapper.orderByDesc(LbBuyAccount::getUpdateTime)
|
||||
.orderByDesc(LbBuyAccount::getCreateTime);
|
||||
|
||||
Page<LbBuyAccount> page = this.page(new Page<>(current, size), queryWrapper);
|
||||
result.put("success", true);
|
||||
result.put("message", "查询成功");
|
||||
result.put("data", page.getRecords());
|
||||
result.put("total", page.getTotal());
|
||||
result.put("current", page.getCurrent());
|
||||
result.put("size", page.getSize());
|
||||
result.put("pages", page.getPages());
|
||||
return result;
|
||||
} catch (Exception e) {
|
||||
log.error("抢单账号配置查询异常", e);
|
||||
result.put("success", false);
|
||||
result.put("message", "查询异常:" + e.getMessage());
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
private Map<String, Object> validateRequiredForAdd(LbBuyAccount entity) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
if (entity.getTenantId() == null || entity.getTenantId().trim().isEmpty()) {
|
||||
result.put("success", false);
|
||||
result.put("message", "tenantId不能为空");
|
||||
return result;
|
||||
}
|
||||
if (entity.getTenantName() == null || entity.getTenantName().trim().isEmpty()) {
|
||||
result.put("success", false);
|
||||
result.put("message", "tenantName不能为空");
|
||||
return result;
|
||||
}
|
||||
if (entity.getLoginAccount() == null || entity.getLoginAccount().trim().isEmpty()) {
|
||||
result.put("success", false);
|
||||
result.put("message", "loginAccount不能为空");
|
||||
return result;
|
||||
}
|
||||
if (entity.getLoginPassword() == null || entity.getLoginPassword().trim().isEmpty()) {
|
||||
result.put("success", false);
|
||||
result.put("message", "loginPassword不能为空");
|
||||
return result;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static void trimStringFields(LbBuyAccount entity) {
|
||||
if (entity.getTenantId() != null) {
|
||||
entity.setTenantId(entity.getTenantId().trim());
|
||||
}
|
||||
if (entity.getTenantName() != null) {
|
||||
entity.setTenantName(entity.getTenantName().trim());
|
||||
}
|
||||
if (entity.getLoginAccount() != null) {
|
||||
entity.setLoginAccount(entity.getLoginAccount().trim());
|
||||
}
|
||||
if (entity.getLoginPassword() != null) {
|
||||
entity.setLoginPassword(entity.getLoginPassword().trim());
|
||||
}
|
||||
if (entity.getNickname() != null) {
|
||||
entity.setNickname(entity.getNickname().trim());
|
||||
}
|
||||
if (entity.getReferrerPhone() != null) {
|
||||
entity.setReferrerPhone(entity.getReferrerPhone().trim());
|
||||
}
|
||||
if (entity.getReferrerName() != null) {
|
||||
entity.setReferrerName(entity.getReferrerName().trim());
|
||||
}
|
||||
if (entity.getLoginUrl() != null) {
|
||||
entity.setLoginUrl(entity.getLoginUrl().trim());
|
||||
}
|
||||
}
|
||||
|
||||
private static void defaultIntegerFields(LbBuyAccount entity) {
|
||||
if (entity.getMaxGrabAmount() == null) {
|
||||
entity.setMaxGrabAmount(0);
|
||||
}
|
||||
if (entity.getMaxGrabCount() == null) {
|
||||
entity.setMaxGrabCount(0);
|
||||
}
|
||||
if (entity.getLatestRechargePoints() == null) {
|
||||
entity.setLatestRechargePoints(0);
|
||||
}
|
||||
if (entity.getRemainingPoints() == null) {
|
||||
entity.setRemainingPoints(0);
|
||||
}
|
||||
if (entity.getTotalPoints() == null) {
|
||||
entity.setTotalPoints(0);
|
||||
}
|
||||
}
|
||||
|
||||
private static LocalDateTime parseDateTime(String text) {
|
||||
if (text == null || text.trim().isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
return LocalDateTime.parse(text.trim(), DATE_TIME_FORMATTER);
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -445,7 +445,7 @@ public class LbGoodsServiceImpl extends ServiceImpl<LbGoodsMapper, LbGoods> impl
|
||||
return result;
|
||||
}
|
||||
|
||||
int maxAttempts = maxBuyCount * 10;
|
||||
int maxAttempts = maxBuyCount * 2;
|
||||
List<Map<String, Object>> details = new ArrayList<>();
|
||||
int successCount = 0;
|
||||
int failCount = 0;
|
||||
|
||||
Reference in New Issue
Block a user