Browse Source

saveAdvRecordV2加签名

master
nili 8 months ago
parent
commit
d59ed960e5
  1. 1
      game-dao/src/main/java/awesome/group/game/dao/bean/MatrixApp.java
  2. 5
      game-dao/src/main/java/awesome/group/game/dao/mapper/MatrixAdvRecordMapper.java
  3. 23
      game-service/src/main/java/awesome/group/game/service/MatrixService.java
  4. 29
      game-service/src/main/java/awesome/group/game/service/bo/MatrixAdvRecordEditBo.java
  5. 7
      game-web/src/main/java/awesome/group/game/web/controller/MatrixController.java

1
game-dao/src/main/java/awesome/group/game/dao/bean/MatrixApp.java

@ -13,4 +13,5 @@ public class MatrixApp {
private String url; private String url;
private Long income;//分 private Long income;//分
private String channel; private String channel;
private String secret;
} }

5
game-dao/src/main/java/awesome/group/game/dao/mapper/MatrixAdvRecordMapper.java

@ -1,14 +1,15 @@
package awesome.group.game.dao.mapper; package awesome.group.game.dao.mapper;
import awesome.group.game.dao.bean.MatrixAdvRecord; import awesome.group.game.dao.bean.MatrixAdvRecord;
import awesome.group.game.dao.bean.MatrixApp;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Insert; import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select; import org.apache.ibatis.annotations.Select;
public interface MatrixAdvRecordMapper extends BaseMapper<MatrixAdvRecord> { public interface MatrixAdvRecordMapper extends BaseMapper<MatrixAdvRecord> {
@Select("select id from matrix_app where code = #{code}") @Select("select * from matrix_app where code = #{code}")
Integer queryAppId(String code); MatrixApp queryApp(String code);
@Select("select count(*) from matrix_white_device where channel = #{channel} and device_id = #{deviceId}") @Select("select count(*) from matrix_white_device where channel = #{channel} and device_id = #{deviceId}")
Integer queryWhitelist(String channel, String deviceId); Integer queryWhitelist(String channel, String deviceId);

23
game-service/src/main/java/awesome/group/game/service/MatrixService.java

@ -5,6 +5,7 @@ import awesome.group.game.dao.bean.MatrixApp;
import awesome.group.game.dao.mapper.MatrixAdvRecordMapper; import awesome.group.game.dao.mapper.MatrixAdvRecordMapper;
import awesome.group.game.dao.mapper.MatrixAppMapper; import awesome.group.game.dao.mapper.MatrixAppMapper;
import awesome.group.game.service.bo.MatrixAdvRecordEditBo; import awesome.group.game.service.bo.MatrixAdvRecordEditBo;
import awesome.group.game.service.util.EncryptUtil;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.Assert; import org.springframework.util.Assert;
@ -21,13 +22,13 @@ public class MatrixService {
public void saveRecord(MatrixAdvRecordEditBo bo, String ip) { public void saveRecord(MatrixAdvRecordEditBo bo, String ip) {
Assert.isTrue(StringUtils.hasText(bo.appCode), "appCode不能为空"); Assert.isTrue(StringUtils.hasText(bo.appCode), "appCode不能为空");
Integer appId = mapper.queryAppId(bo.appCode); MatrixApp app = mapper.queryApp(bo.appCode);
if (appId == null) { if (app == null) {
return;//非法请求,直接忽略 return;//非法请求,直接忽略
} }
MatrixAdvRecord record = new MatrixAdvRecord(); MatrixAdvRecord record = new MatrixAdvRecord();
record.setDeviceId(bo.deviceId); record.setDeviceId(bo.deviceId);
record.setAppId(appId); record.setAppId(app.getId());
record.setPlatform(bo.platform); record.setPlatform(bo.platform);
record.setAdvType(bo.advType); record.setAdvType(bo.advType);
record.setEcpm(bo.advType > 1000 ? 0 : bo.ecpm); record.setEcpm(bo.advType > 1000 ? 0 : bo.ecpm);
@ -38,6 +39,22 @@ public class MatrixService {
mapper.insert(record); mapper.insert(record);
} }
public void saveRecordV2(MatrixAdvRecordEditBo bo, String ip) {
if (!StringUtils.hasText(bo.appCode) || !StringUtils.hasText(bo.sign)) {
return;
}
MatrixApp app = mapper.queryApp(bo.appCode);
if (app == null) {
return;
}
String secret = app.getSecret();
String str = bo.getSignStr(secret);
if (!bo.sign.equalsIgnoreCase(EncryptUtil.sha1(str))) {
return;
}
saveRecord(bo, ip);
}
public boolean whiteList(String deviceId, String appCode) { public boolean whiteList(String deviceId, String appCode) {
MatrixApp app = appMapper.queryByCode(appCode); MatrixApp app = appMapper.queryByCode(appCode);
if (app == null) { if (app == null) {

29
game-service/src/main/java/awesome/group/game/service/bo/MatrixAdvRecordEditBo.java

@ -1,5 +1,9 @@
package awesome.group.game.service.bo; package awesome.group.game.service.bo;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class MatrixAdvRecordEditBo { public class MatrixAdvRecordEditBo {
public String deviceId; public String deviceId;
public String appCode; public String appCode;
@ -11,6 +15,31 @@ public class MatrixAdvRecordEditBo {
public String ip; public String ip;
public Integer advId; public Integer advId;
public String sign;
public MatrixAdvRecordEditBo() { public MatrixAdvRecordEditBo() {
} }
public String getSignStr(String secret) {
Map<String, Object> map = new HashMap<>();
map.put("deviceId", deviceId);
map.put("appCode", appCode);
map.put("platform", platform);
map.put("advType", advType);
map.put("ecpm", ecpm);
map.put("deviceBrand", deviceBrand);
map.put("deviceName", deviceName);
map.put("advId", advId);
List<String> keys = map.keySet().stream().sorted().toList();
for (String k : keys) {
if (map.get(k) == null) {
continue;
}
sign += k + "=" + map.get(k) + "&";
}
// 不同批次 key 会变化
sign += "secret=" + secret;
return sign;
}
} }

7
game-web/src/main/java/awesome/group/game/web/controller/MatrixController.java

@ -21,6 +21,13 @@ public class MatrixController {
return new R<>(R.CODE_SUCCESS, "ok", null); return new R<>(R.CODE_SUCCESS, "ok", null);
} }
@PostMapping("/saveAdvRecordV2")
@RestApi
public R<Void> saveAdvRecordV2(@RequestBody MatrixAdvRecordEditBo bo) {
matrixService.saveRecordV2(bo, RequestContext.getIpAddr(RequestContext.getRequest()));
return new R<>(R.CODE_SUCCESS, "ok", null);
}
@GetMapping("/whiteList") @GetMapping("/whiteList")
@RestApi @RestApi
public R<Boolean> whiteList(@RequestParam String deviceId, @RequestParam String appCode){ public R<Boolean> whiteList(@RequestParam String deviceId, @RequestParam String appCode){

Loading…
Cancel
Save