From 1adf59bd4dc1f881e0a97365c350daf99c43f6ad Mon Sep 17 00:00:00 2001 From: qyx <565485304@qq.com> Date: Fri, 21 Jan 2022 16:01:01 +0800 Subject: [PATCH] =?UTF-8?q?[=E6=96=B0=E5=A2=9E=E5=8A=9F=E8=83=BD](master):?= =?UTF-8?q?=20=E5=88=9D=E5=A7=8B=E5=8C=96=E9=A1=B9=E7=9B=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 提交巨量回调代码 --- .gitignore | 33 ++ .jpb/jpb-settings.xml | 14 + README.md | 4 + pom.xml | 87 ++++ .../adcallback/AdCallbackApplication.java | 23 ++ .../api/callback/JuliangAuthCallbackAPI.java | 43 ++ .../JuliangMobileMonitorCallbackAPI.java | 125 ++++++ .../adcallback/api/common/CommonResponse.java | 134 ++++++ .../adcallback/api/common/ResponseCode.java | 48 +++ .../api/constants/RequestDetailConstant.java | 11 + .../api/constants/RequestInfoConstant.java | 32 ++ .../AdOriginalityManageController.java | 74 ++++ .../api/controller/BaseController.java | 11 + .../FeiyuSourceManageController.java | 23 ++ .../JuliangMobileMonitorController.java | 61 +++ .../api/controller/TokenManageController.java | 49 +++ ...JuliangMobileMonitorCallbackRequestVO.java | 40 ++ .../common/constant/JuliangConstant.java | 35 ++ .../adcallback/common/pojo/JlBackdataDTO.java | 36 ++ .../pojo/convert/JlBackdataConvert.java | 41 ++ .../common/request/JuliangRequestHeader.java | 48 +++ .../common/request/JuliangRequestParam.java | 26 ++ .../adcallback/common/util/FileUtil.java | 382 ++++++++++++++++++ .../adcallback/config/AuditingConfig.java | 15 + .../config/DefaultAuditorAwareImpl.java | 15 + .../config/SpringMVCConfiguration.java | 25 ++ .../TbJlBackdataEntityRepository.java | 18 + .../repository/TbJlTokenEntityRepository.java | 7 + .../repository/entity/TbJlBackdataEntity.java | 104 +++++ .../repository/entity/TbJlTokenEntity.java | 62 +++ .../service/AdOriginalityManageService.java | 14 + .../service/FeiyuSourceManageService.java | 4 + .../service/JuliangMobileMonitorService.java | 13 + .../service/TokenManageService.java | 36 ++ .../impl/AdOriginalityManageServiceImpl.java | 38 ++ .../impl/FeiyuSourceManageServiceImpl.java | 8 + .../impl/JuliangMobileMonitorServiceImpl.java | 88 ++++ .../service/impl/TokenManageServiceImpl.java | 122 ++++++ .../FixedTimeAutoRefreshJuliangTokenTask.java | 50 +++ src/main/resources/application-dev.yml | 47 +++ src/main/resources/application-online.yml | 45 +++ src/main/resources/application-prod.yml | 45 +++ src/main/resources/application.yml | 55 +++ src/main/resources/logback.xml | 83 ++++ .../AdCallbackApplicationTests.java | 13 + 45 files changed, 2287 insertions(+) create mode 100644 .gitignore create mode 100644 .jpb/jpb-settings.xml create mode 100644 README.md create mode 100644 pom.xml create mode 100644 src/main/java/com/baiyee/adcallback/AdCallbackApplication.java create mode 100644 src/main/java/com/baiyee/adcallback/api/callback/JuliangAuthCallbackAPI.java create mode 100644 src/main/java/com/baiyee/adcallback/api/callback/JuliangMobileMonitorCallbackAPI.java create mode 100644 src/main/java/com/baiyee/adcallback/api/common/CommonResponse.java create mode 100644 src/main/java/com/baiyee/adcallback/api/common/ResponseCode.java create mode 100644 src/main/java/com/baiyee/adcallback/api/constants/RequestDetailConstant.java create mode 100644 src/main/java/com/baiyee/adcallback/api/constants/RequestInfoConstant.java create mode 100644 src/main/java/com/baiyee/adcallback/api/controller/AdOriginalityManageController.java create mode 100644 src/main/java/com/baiyee/adcallback/api/controller/BaseController.java create mode 100644 src/main/java/com/baiyee/adcallback/api/controller/FeiyuSourceManageController.java create mode 100644 src/main/java/com/baiyee/adcallback/api/controller/JuliangMobileMonitorController.java create mode 100644 src/main/java/com/baiyee/adcallback/api/controller/TokenManageController.java create mode 100644 src/main/java/com/baiyee/adcallback/api/vo/JuliangMobileMonitorCallbackRequestVO.java create mode 100644 src/main/java/com/baiyee/adcallback/common/constant/JuliangConstant.java create mode 100644 src/main/java/com/baiyee/adcallback/common/pojo/JlBackdataDTO.java create mode 100644 src/main/java/com/baiyee/adcallback/common/pojo/convert/JlBackdataConvert.java create mode 100644 src/main/java/com/baiyee/adcallback/common/request/JuliangRequestHeader.java create mode 100644 src/main/java/com/baiyee/adcallback/common/request/JuliangRequestParam.java create mode 100644 src/main/java/com/baiyee/adcallback/common/util/FileUtil.java create mode 100644 src/main/java/com/baiyee/adcallback/config/AuditingConfig.java create mode 100644 src/main/java/com/baiyee/adcallback/config/DefaultAuditorAwareImpl.java create mode 100644 src/main/java/com/baiyee/adcallback/config/SpringMVCConfiguration.java create mode 100644 src/main/java/com/baiyee/adcallback/repository/TbJlBackdataEntityRepository.java create mode 100644 src/main/java/com/baiyee/adcallback/repository/TbJlTokenEntityRepository.java create mode 100644 src/main/java/com/baiyee/adcallback/repository/entity/TbJlBackdataEntity.java create mode 100644 src/main/java/com/baiyee/adcallback/repository/entity/TbJlTokenEntity.java create mode 100644 src/main/java/com/baiyee/adcallback/service/AdOriginalityManageService.java create mode 100644 src/main/java/com/baiyee/adcallback/service/FeiyuSourceManageService.java create mode 100644 src/main/java/com/baiyee/adcallback/service/JuliangMobileMonitorService.java create mode 100644 src/main/java/com/baiyee/adcallback/service/TokenManageService.java create mode 100644 src/main/java/com/baiyee/adcallback/service/impl/AdOriginalityManageServiceImpl.java create mode 100644 src/main/java/com/baiyee/adcallback/service/impl/FeiyuSourceManageServiceImpl.java create mode 100644 src/main/java/com/baiyee/adcallback/service/impl/JuliangMobileMonitorServiceImpl.java create mode 100644 src/main/java/com/baiyee/adcallback/service/impl/TokenManageServiceImpl.java create mode 100644 src/main/java/com/baiyee/adcallback/task/FixedTimeAutoRefreshJuliangTokenTask.java create mode 100644 src/main/resources/application-dev.yml create mode 100644 src/main/resources/application-online.yml create mode 100644 src/main/resources/application-prod.yml create mode 100644 src/main/resources/application.yml create mode 100644 src/main/resources/logback.xml create mode 100644 src/test/java/com/baiyee/adcallback/AdCallbackApplicationTests.java diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..549e00a --- /dev/null +++ b/.gitignore @@ -0,0 +1,33 @@ +HELP.md +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ diff --git a/.jpb/jpb-settings.xml b/.jpb/jpb-settings.xml new file mode 100644 index 0000000..988ee6a --- /dev/null +++ b/.jpb/jpb-settings.xml @@ -0,0 +1,14 @@ + + + + + \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..e06c60c --- /dev/null +++ b/README.md @@ -0,0 +1,4 @@ +## 百度广告投放平台检测 - 百度营销 + https://dev2.baidu.com/content?sceneType=0&pageId=101214&nodeId=662&subhead= +## 广电通 - 腾讯广告 + https://developers.e.qq.com/docs/guide/conversion/new_version/dianjijiance \ No newline at end of file diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..5217d2d --- /dev/null +++ b/pom.xml @@ -0,0 +1,87 @@ + + + 4.0.0 + + org.springframework.boot + spring-boot-starter-parent + 2.3.2.RELEASE + + + com.baiyee + ad-callback + 0.0.1-SNAPSHOT + ad-callback + ad-callback + + 1.8 + true + true + + + + org.springframework.boot + spring-boot-starter-data-jpa + + + org.springframework.boot + spring-boot-starter-web + + + + org.springframework.boot + spring-boot-starter-test + test + + + + org.projectlombok + lombok + + + + cn.hutool + hutool-all + 5.7.16 + + + + + com.alibaba + druid-spring-boot-starter + 1.1.22 + + + + + mysql + mysql-connector-java + runtime + + + + org.apache.poi + poi-ooxml + 5.1.0 + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + org.apache.maven.plugins + maven-surefire-plugin + + + ${maven.test.skip} + ${maven.test.failure.ignore} + + + + + + diff --git a/src/main/java/com/baiyee/adcallback/AdCallbackApplication.java b/src/main/java/com/baiyee/adcallback/AdCallbackApplication.java new file mode 100644 index 0000000..1a869d0 --- /dev/null +++ b/src/main/java/com/baiyee/adcallback/AdCallbackApplication.java @@ -0,0 +1,23 @@ +package com.baiyee.adcallback; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cache.annotation.EnableCaching; +import org.springframework.scheduling.annotation.EnableScheduling; + +/** + * 广告回调程序 + * + * @author q + * @date 2022/01/05 + */ +@SpringBootApplication +// 开启定时任务功能 +@EnableScheduling +public class AdCallbackApplication { + + public static void main(String[] args) { + SpringApplication.run(AdCallbackApplication.class, args); + } + +} diff --git a/src/main/java/com/baiyee/adcallback/api/callback/JuliangAuthCallbackAPI.java b/src/main/java/com/baiyee/adcallback/api/callback/JuliangAuthCallbackAPI.java new file mode 100644 index 0000000..41c176f --- /dev/null +++ b/src/main/java/com/baiyee/adcallback/api/callback/JuliangAuthCallbackAPI.java @@ -0,0 +1,43 @@ +package com.baiyee.adcallback.api.callback; + +import com.baiyee.adcallback.service.TokenManageService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import javax.servlet.http.HttpServletRequest; + +/** + * juliang身份验证回调api + * + * @author q + * @date 2022/01/05 + */ +@RestController +@RequestMapping(value = ("/jl")) +public class JuliangAuthCallbackAPI { + + @Autowired + private TokenManageService tokenManageService; + + @RequestMapping(value = "/callback") + public void julaingAuthCallbackReqUrl(HttpServletRequest request){ + // 授权链接的回调地址 + // 需要与callback address相同**,否则会报错 + System.out.println(request.getParameter("redirect")); + // 授权成功后,开发者通回调地址获取的授权码auth code,可用于获取 Access Token。 + // 注意auth_code有效时间为10分钟,且只可使用一次 + System.out.println(request.getParameter("auth_code")); + // 这里是一个自定义的字段 + // state=your_custom_params& + // 用于拼装授权URL时传递自定义信息,授权成功回调时会原样带回。 + // 常见应用:比如将广告主账号作为自定义参数,回调时以区分授权码对应的广告主。 + System.out.println(request.getParameter("state")); + + + } + +// https://xx.tuoz.net/login?redirect=%2Fdashboard%3Fstate%3Dyour_custom_params&auth_code=3819efd33fcaba807c0f65ac252b5b58495e5223 + + +} diff --git a/src/main/java/com/baiyee/adcallback/api/callback/JuliangMobileMonitorCallbackAPI.java b/src/main/java/com/baiyee/adcallback/api/callback/JuliangMobileMonitorCallbackAPI.java new file mode 100644 index 0000000..c785f27 --- /dev/null +++ b/src/main/java/com/baiyee/adcallback/api/callback/JuliangMobileMonitorCallbackAPI.java @@ -0,0 +1,125 @@ +package com.baiyee.adcallback.api.callback; + +import cn.hutool.core.util.ObjectUtil; +import cn.hutool.core.util.StrUtil; +import com.baiyee.adcallback.api.common.CommonResponse; +import com.baiyee.adcallback.api.common.ResponseCode; +import com.baiyee.adcallback.api.vo.JuliangMobileMonitorCallbackRequestVO; +import com.baiyee.adcallback.common.pojo.JlBackdataDTO; +import com.baiyee.adcallback.common.pojo.convert.JlBackdataConvert; +import com.baiyee.adcallback.service.AdOriginalityManageService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +import static com.baiyee.adcallback.common.constant.JuliangConstant.IMEI_TAG; + +/** + * juliang移动监控回调的api + * + * @author q + * @date 2022/01/06 + * @see + */ +@RestController +@RequestMapping(value = ("/jl")) +@Slf4j +public class JuliangMobileMonitorCallbackAPI { + + + + private final AdOriginalityManageService adOriginalityManageService; + + public JuliangMobileMonitorCallbackAPI(AdOriginalityManageService adOriginalityManageService) { + this.adOriginalityManageService = adOriginalityManageService; + } + + + /** + * julaing身份验证回调url请求 + *

+ * 1. 首先需要广告主在计划上填写监测链接 + * exp: https://mybest.custom.com/click/?aid=__AID__&cid=__CID__&callback_url=__CALLBACK_URL__ + *

+ * ps. 其中下划线的部分,就是我们替换后的真实广告信息(非 ASC 字符,进行了 url encode) + * ps. 在头条客户端中,用户真实产生了广告点击的时候,我们会把相应的字段换成真实的广告信息,发送给广告主。 + * ps. 为了获得更高的安全性,推荐您使用HTTPS通道 + * ps. 支持HTTP GET方法发送请求,这种方式下请求参数需要包含在请求的URL中 + *

+ * 2. 我们采用的配置为 + * 平台配置 exp: &__AID__&__AIDNAME__&__ADVERTISERID__&__CID__&__CTYPE__&__CSITE__&__IMEI__&__IDFA__&__OAID__&__OS__&__MAC__&__MAC1__&__IP__&__GEO__&__TS__&__CALLBACKURL__&__MODEL__&__CAID12__ + * 测试 exp: aid=1645988237525045&aidname=testaidname1&advertiserid=1631857582073864&cid=1650703686054530&ctype=2&csite=33013&imei=0c2bd03c39f19845bf54ea0abafae70e&idfa=4FCFEFA1-096D-4176-B352-1870ED6DB777&oaid=97e7ef3f-e5f2-d0b8-ccfc-f79bbeaf4841&os=0&mac=df97bc5021e14256e141b2f036df5a3c&mac1=4d0433eb614f5d5ad409a65395426cbe&ip=61.158.146.195&geo=35.7x122.4x100.0&ts=1575194434000&callbackurl=https://ad.toutiao.com/track/activate/?callback=EJiw267wvfQCGKf2g74ZIPD89-vIATAMOAFCIjIwMTkxMTI3MTQxMTEzMDEwMDI2MDc3MjE1MTUwNTczNTBIAQ==&os=0&muid=db94e6a60a9c6661e3e03a7d301c25b6&model=iPhone12%2c2&caid12=f949f306494646edfee1f939698e1fb1 + * + */ + @RequestMapping(value = "/monitor") + public CommonResponse julaingMonitorUrlCallbackReqUrl( + @RequestParam(value = "aid", defaultValue = "") String aid, + @RequestParam(value = "aidname", defaultValue = "") String aidName, + @RequestParam(value = "advertiserid", defaultValue = "") String advertiserId, + @RequestParam(value = "cid", defaultValue = "") Long cid, + @RequestParam(value = "ctype", defaultValue = "") Integer ctype, + @RequestParam(value = "csite", defaultValue = "") Integer csite, + @RequestParam(value = "imei", defaultValue = "") String imei, + @RequestParam(value = "idfa", defaultValue = "") String idfa, + @RequestParam(value = "oaid", defaultValue = "") String oaid, + @RequestParam(value = "os", defaultValue = "") Integer os, + @RequestParam(value = "mac", defaultValue = "") String mac, + @RequestParam(value = "mac1", defaultValue = "") String mac1, + @RequestParam(value = "ip", defaultValue = "") String ip, + @RequestParam(value = "geo", defaultValue = "") String geo, + @RequestParam(value = "TIMESTAMP", defaultValue = "") Long ts, + @RequestParam(value = "callback_url", defaultValue = "") String callbackUrl, + @RequestParam(value = "model", defaultValue = "") String model, + @RequestParam(value = "caid1", defaultValue = "") String caid12 + + ) { + JuliangMobileMonitorCallbackRequestVO vo = new JuliangMobileMonitorCallbackRequestVO( + aid,aidName,advertiserId,cid,ctype,csite,imei,idfa,oaid,os,mac,mac1,ip,geo,ts,callbackUrl,model,caid12 + ); + + + if (ObjectUtil.isNull(vo)) { + return CommonResponse.createByErrorMessage(ResponseCode.EMPTY_ARGUMENT.getDesc()); + } + // 请求过滤规则,过滤掉不用的数据 + if (preRuleForReq(vo)){ + log.error("================================= [not right imei data ,{} ] =================================",vo); + return CommonResponse.createBySuccess(); + } + + log.info("================================= [one request comming, JuliangMobileMonitorCallbackAPI|julaingMonitorUrlCallbackReqUrl, vo is {} ] =================================", vo); + + + JlBackdataDTO jlBackdataDTO = new JlBackdataDTO(); + JlBackdataConvert.voCovertToDTO(vo, jlBackdataDTO); + + adOriginalityManageService.handleMonitorUrlCallbackDataThenSave(); + + return CommonResponse.createBySuccess(); + } + + /** + * 之前的规则要求 + * + * @return boolean + */ + private boolean preRuleForReq(JuliangMobileMonitorCallbackRequestVO vo) { + + String imei = vo.getImei(); + if (StrUtil.isBlank(imei)){ + return Boolean.TRUE; + } + + if (StrUtil.isNotBlank(imei) && StrUtil.equalsIgnoreCase(IMEI_TAG,imei)){ + return Boolean.TRUE; + } + return Boolean.FALSE; + + } + +// https://xx.tuoz.net/login?redirect=%2Fdashboard%3Fstate%3Dyour_custom_params&auth_code=3819efd33fcaba807c0f65ac252b5b58495e5223 + + + +} diff --git a/src/main/java/com/baiyee/adcallback/api/common/CommonResponse.java b/src/main/java/com/baiyee/adcallback/api/common/CommonResponse.java new file mode 100644 index 0000000..00c0a1a --- /dev/null +++ b/src/main/java/com/baiyee/adcallback/api/common/CommonResponse.java @@ -0,0 +1,134 @@ +package com.baiyee.adcallback.api.common; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import lombok.Getter; +import lombok.NoArgsConstructor; + +import java.io.Serializable; + + +/** + * + * JsonInclude.Include.NON_EMPTY 属性为 空("") 或者为 NULL 都不序列化,则返回的json是没有这个字段的。这样对移动端会更省流量 + * + * @param 返回的对象实体 + * @author q + */ +@JsonSerialize +@Getter +@JsonInclude(JsonInclude.Include.NON_EMPTY) +@NoArgsConstructor +public class CommonResponse implements Serializable { + + /** + * 成功还是失败的状态标识 0,成功 1,失败 + */ + private int status; + + /** + * 返回信息 + */ + private String msg; + + /** + * 返回的结果数据 + */ + private T data; + + + /* + * 封装所有的构造器为私有的 + */ + + private CommonResponse(int status) { + this.status = status; + } + + private CommonResponse(int status, T data) { // ps: 当调用T为String类型时候,会默认调用下面的ServerResponse(int status, String msg)类型的构造器 + this.status = status; + this.data = data; + } + + private CommonResponse(int status, String msg, T data) { + this.status = status; + this.msg = msg; + this.data = data; + } + + private CommonResponse(int status, String msg) { + this.status = status; + this.msg = msg; + } + + + /* + * 对外开放调用的静态方法,用来调用私有构造器,来返回成功结果给前台 + */ + + /** + * @return 返回成功码和默认的成功信息 + */ + public static CommonResponse createBySuccess() { + return new CommonResponse(ResponseCode.SUCCESS.getCode(),ResponseCode.SUCCESS.getDesc()); + } + + /** + * + * @param msg 定义的成功信息 + * @return 返回成功码和成功信息 + */ + public static CommonResponse createBySuccessMessage(String msg) { + return new CommonResponse(ResponseCode.SUCCESS.getCode(), msg); + } + + /** + * + * @param data 传入实体 + * @return 返回成功码和数据 + */ + public static CommonResponse createBySuccess(T data) { + return new CommonResponse(ResponseCode.SUCCESS.getCode(), data); + } + + /** + * + * @param msg 传入信息 + * @param data 传入实体 + * @return 返回成功码和成功信息和数据 + */ + public static CommonResponse createBySuccess(String msg, T data) { + return new CommonResponse(ResponseCode.SUCCESS.getCode(), msg, data); + } + + /* + 对外开放调用的静态方法,用来调用私有构造器,来返回失败结果给前台 + */ + + /** + * + * @return 返回错误码和默认的错误 + */ + public static CommonResponse createByError(){ + return new CommonResponse(ResponseCode.ERROR.getCode(),ResponseCode.ERROR.getDesc()); + } + + /** + * + * @param errorMessage 定义的错误信息 + * @return 返回错误码和错误信息(传入) + */ + public static CommonResponse createByErrorMessage(String errorMessage){ + return new CommonResponse(ResponseCode.ERROR.getCode(),errorMessage); + } + + /** + * + * @param errorCode 错误码 + * @param errorMessage 错误信息 + * @return 返回错误码(传入)和错误信息(传入) + */ + public static CommonResponse createByErrorCodeMessage(int errorCode,String errorMessage){ + return new CommonResponse(errorCode,errorMessage); + } +} diff --git a/src/main/java/com/baiyee/adcallback/api/common/ResponseCode.java b/src/main/java/com/baiyee/adcallback/api/common/ResponseCode.java new file mode 100644 index 0000000..e90870c --- /dev/null +++ b/src/main/java/com/baiyee/adcallback/api/common/ResponseCode.java @@ -0,0 +1,48 @@ +package com.baiyee.adcallback.api.common; + +/** + * Description: 自定义Response响应返回体 -> 这边采用的是 + * @author q + */ +public enum ResponseCode { + + /** + * 成功 + */ + SUCCESS(0,"SUCCESS"), + /** + * 失败 + */ + ERROR(1,"ERROR"), + + + /* + * 请求参数校验 + */ + ILLEGAL_ARGUMENT(1,"请求参数格式错误"), + EMPTY_ARGUMENT(1,"请求参数为空"), + + /* + * 请求结果性的错误 + */ + NO_REASON_ERROR(1,"未知异常错误发生"), + SYSTEM_ERROR(1,"系统异常"), + DECRYPT_ERROR(1,"解密错误,请联系相关人员"); + + private final int code; + private final String desc; + + ResponseCode(int code, String desc){ + this.code = code; + this.desc = desc; + } + + public int getCode() { + return code; + } + + public String getDesc() { + return desc; + } + +} diff --git a/src/main/java/com/baiyee/adcallback/api/constants/RequestDetailConstant.java b/src/main/java/com/baiyee/adcallback/api/constants/RequestDetailConstant.java new file mode 100644 index 0000000..34e39db --- /dev/null +++ b/src/main/java/com/baiyee/adcallback/api/constants/RequestDetailConstant.java @@ -0,0 +1,11 @@ +package com.baiyee.adcallback.api.constants; + +/** + * 详细的请求参数验证 - 错误信息 + */ +public class RequestDetailConstant { + + public static final String REQUEST_ADDR_EMPTY = "请求的地址为空"; + + public static final String REQUEST_PARAMS_EMPTY = "请求参数为空"; +} diff --git a/src/main/java/com/baiyee/adcallback/api/constants/RequestInfoConstant.java b/src/main/java/com/baiyee/adcallback/api/constants/RequestInfoConstant.java new file mode 100644 index 0000000..1beb40d --- /dev/null +++ b/src/main/java/com/baiyee/adcallback/api/constants/RequestInfoConstant.java @@ -0,0 +1,32 @@ +package com.baiyee.adcallback.api.constants; + +/** + * 请求信息常量类 + */ +public class RequestInfoConstant { + + /** + * 客户端请求地址标识名称 + */ + public static final String CUSTOMER_IP_ADDR_KEY = "customer_ip_addr_key"; + + /** + * 正式环境对应服务器绑定的域名 + */ + public static final String PROD_SERVER_HOST = "http://bc.tuoz.net/"; + + /** + * 本地开发路径 - 应用于本地服务器 + */ + public static final String DEV_SERVER_HOST = "http://localhost:6666/"; + + /** + * Http请求调用失败 重试次数 + */ + public static final int RETRY_COUNT = 3; + + /** + * 默认的超时时长 默认是2000ms + */ + public static final int DEFAULT_TIMEOUT_NUMBER = 20000; +} diff --git a/src/main/java/com/baiyee/adcallback/api/controller/AdOriginalityManageController.java b/src/main/java/com/baiyee/adcallback/api/controller/AdOriginalityManageController.java new file mode 100644 index 0000000..cb251d6 --- /dev/null +++ b/src/main/java/com/baiyee/adcallback/api/controller/AdOriginalityManageController.java @@ -0,0 +1,74 @@ +package com.baiyee.adcallback.api.controller; + +import com.baiyee.adcallback.api.common.CommonResponse; + +/** + * 广告创意管理控制器 + * + * API doc + * @see 创意Api + * + * @author q + * @date 2022/01/05 + */ +public class AdOriginalityManageController { + + + /** + * 获取的创意列表 + * + * @see + * + * @return {@link CommonResponse} + */ + public CommonResponse getListOfOriginality(){ + return CommonResponse.createBySuccess(); + + } + + + /** + * 创建广告创意 + * + * @see + * + * @return {@link CommonResponse} + */ + public CommonResponse createOriginality(){ + return CommonResponse.createBySuccess(); + } + + /** + * 创意的细节 + * + * @see + * + * @return {@link CommonResponse} + */ + public CommonResponse detailsOfOriginality(){ + return CommonResponse.createBySuccess(); + } + + + /** + * 编辑创意 + * + * @see + * + * @return {@link CommonResponse} + */ + public CommonResponse editOriginality(){ + return CommonResponse.createBySuccess(); + } + + /** + * 更新创意状态 + * + * @return {@link CommonResponse} + */ + public CommonResponse updateOriginalityState(){ + return CommonResponse.createBySuccess(); + } + + +} diff --git a/src/main/java/com/baiyee/adcallback/api/controller/BaseController.java b/src/main/java/com/baiyee/adcallback/api/controller/BaseController.java new file mode 100644 index 0000000..41154c3 --- /dev/null +++ b/src/main/java/com/baiyee/adcallback/api/controller/BaseController.java @@ -0,0 +1,11 @@ +package com.baiyee.adcallback.api.controller; + +/** + * 基本控制器 + * + * @author q + * @date 2022/01/05 + */ +public class BaseController { + +} diff --git a/src/main/java/com/baiyee/adcallback/api/controller/FeiyuSourceManageController.java b/src/main/java/com/baiyee/adcallback/api/controller/FeiyuSourceManageController.java new file mode 100644 index 0000000..c67d46a --- /dev/null +++ b/src/main/java/com/baiyee/adcallback/api/controller/FeiyuSourceManageController.java @@ -0,0 +1,23 @@ +package com.baiyee.adcallback.api.controller; + + +import com.baiyee.adcallback.api.common.CommonResponse; + +/** + * 飞鱼 源管理控制器 + * + * @author q + * @date 2022/01/05 + */ +public class FeiyuSourceManageController { + + /** + * 得到飞鱼线索列表 + * + * @return {@link CommonResponse} + */ + public CommonResponse getListOfFeiyuSource(){ + return CommonResponse.createBySuccess(); + } + +} diff --git a/src/main/java/com/baiyee/adcallback/api/controller/JuliangMobileMonitorController.java b/src/main/java/com/baiyee/adcallback/api/controller/JuliangMobileMonitorController.java new file mode 100644 index 0000000..6b3ee29 --- /dev/null +++ b/src/main/java/com/baiyee/adcallback/api/controller/JuliangMobileMonitorController.java @@ -0,0 +1,61 @@ +package com.baiyee.adcallback.api.controller; + +import com.baiyee.adcallback.api.common.CommonResponse; +import com.baiyee.adcallback.service.JuliangMobileMonitorService; +import org.springframework.format.annotation.DateTimeFormat; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +import javax.servlet.http.HttpServletResponse; +import java.time.LocalDate; +import java.util.Date; +import java.util.List; + +/** + * juliang移动监控控制器 + * + * @author q + * @date 2022/01/10 + */ +@RestController +@RequestMapping("/jl") +public class JuliangMobileMonitorController { + + + private final JuliangMobileMonitorService juliangMobileMonitorService; + + public JuliangMobileMonitorController(JuliangMobileMonitorService juliangMobileMonitorService) { + this.juliangMobileMonitorService = juliangMobileMonitorService; + } + + + /** + * 得到形式db imei列表 + * + * @return {@link CommonResponse} + */ + @GetMapping("/getimei") + public CommonResponse getImeiListFormDB() { + + List result = juliangMobileMonitorService.queryByImeiAdvancedMode(); + + return CommonResponse.createBySuccess(result); + } + + + /** + * imei下载到文件 + * + * @param date 日期 格式 yyyy-MM-dd + * @param response 响应 + */ + @GetMapping("/download") + public void downloadImeiToFile(@RequestParam(value = "startDate") @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")Date startDate, + @RequestParam(value = "endDate") @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")Date endDate, + HttpServletResponse response){ + + juliangMobileMonitorService.downloadImeiFile(response, startDate, endDate); + } +} diff --git a/src/main/java/com/baiyee/adcallback/api/controller/TokenManageController.java b/src/main/java/com/baiyee/adcallback/api/controller/TokenManageController.java new file mode 100644 index 0000000..6972062 --- /dev/null +++ b/src/main/java/com/baiyee/adcallback/api/controller/TokenManageController.java @@ -0,0 +1,49 @@ +package com.baiyee.adcallback.api.controller; + +import com.baiyee.adcallback.api.common.CommonResponse; +import com.baiyee.adcallback.service.TokenManageService; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RestController; + +/** + * 令牌管理控制器 + * + * @author q + * @date 2022/01/05 + */ +@RestController(value = "/token") +public class TokenManageController { + + private final TokenManageService tokenManageService; + + public TokenManageController(TokenManageService tokenManageService) { + this.tokenManageService = tokenManageService; + } + + /** + * 获取访问令牌 - 这里 + * + * @see + * + * @return {@link CommonResponse} + */ + @PostMapping(value = "/get") + public CommonResponse getAccessToken(){ + tokenManageService.getAccessToken(); + return CommonResponse.createBySuccess(); + } + + /** + * 刷新令牌 - 类似于手动刷新接口 - 配合后台的过期时间内的规定频率的刷新 + * + * @return {@link CommonResponse} + */ + @PostMapping(value = "/refresh") + public CommonResponse refreshToken(){ + tokenManageService.refreshToken(); + return CommonResponse.createBySuccess(); + } + + + +} diff --git a/src/main/java/com/baiyee/adcallback/api/vo/JuliangMobileMonitorCallbackRequestVO.java b/src/main/java/com/baiyee/adcallback/api/vo/JuliangMobileMonitorCallbackRequestVO.java new file mode 100644 index 0000000..72d0b7b --- /dev/null +++ b/src/main/java/com/baiyee/adcallback/api/vo/JuliangMobileMonitorCallbackRequestVO.java @@ -0,0 +1,40 @@ +package com.baiyee.adcallback.api.vo; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.io.Serializable; + +/** + * juliang移动监控调请求 vo + * + * @author q + * @date 2022/01/07 + */ +@Data +@AllArgsConstructor +@NoArgsConstructor +public class JuliangMobileMonitorCallbackRequestVO implements Serializable { + + + private String aid; + private String aidName; + private String advertiserId; + private Long cid; + private Integer ctype; + private Integer csite; + private String imei; + private String idfa; + private String oaid; + private Integer os; + private String mac; + private String mac1; + private String ip; + private String geo; + private Long ts; + private String callbackUrl; + private String model; + private String caid12; +} diff --git a/src/main/java/com/baiyee/adcallback/common/constant/JuliangConstant.java b/src/main/java/com/baiyee/adcallback/common/constant/JuliangConstant.java new file mode 100644 index 0000000..b505fa7 --- /dev/null +++ b/src/main/java/com/baiyee/adcallback/common/constant/JuliangConstant.java @@ -0,0 +1,35 @@ +package com.baiyee.adcallback.common.constant; + +/** + * juliang常数 + * + * @author q + * @date 2022/01/05 + */ +public class JuliangConstant { + + /** + * 回调地址 + */ + public static final String BACK_URL = "http://cb.tuoz.net"; + + + /** + * 获取Access Token 的 url + */ + public static final String GET_ACCESS_TOKEN_URL = "https://ad.oceanengine.com/open_api/oauth2/access_token/"; + + /** + * 刷新Access Token 的 url + */ + public static final String REFRESH_ACCESS_TOKEN_URL = "https://ad.oceanengine.com/open_api/oauth2/refresh_token/"; + + /** + * 获取已授权账户 - 这个接口的详细信息关联与 Token 表的 advertiser_ids 字段 + */ + public static final String ADVERTISER_LIST_URL = "https://ad.oceanengine.com/open_api/oauth2/advertiser/get/"; + + public static final String IMEI_TAG = "__IMEI__"; + + +} diff --git a/src/main/java/com/baiyee/adcallback/common/pojo/JlBackdataDTO.java b/src/main/java/com/baiyee/adcallback/common/pojo/JlBackdataDTO.java new file mode 100644 index 0000000..e695c50 --- /dev/null +++ b/src/main/java/com/baiyee/adcallback/common/pojo/JlBackdataDTO.java @@ -0,0 +1,36 @@ +package com.baiyee.adcallback.common.pojo; + +import cn.hutool.core.bean.BeanUtil; +import com.baiyee.adcallback.api.vo.JuliangMobileMonitorCallbackRequestVO; +import com.baiyee.adcallback.repository.entity.TbJlBackdataEntity; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.io.Serializable; + +@Data +@AllArgsConstructor +@NoArgsConstructor +public class JlBackdataDTO implements Serializable { + + private String aid; + private String aidName; + private String advertiserId; + private Long cid; + private Integer ctype; + private Integer csite; + private String imei; + private String idfa; + private String oaid; + private Integer os; + private String mac; + private String mac1; + private String ip; + private String geo; + private Long ts; + private String callbackUrl; + private String model; + private String caid12; + +} diff --git a/src/main/java/com/baiyee/adcallback/common/pojo/convert/JlBackdataConvert.java b/src/main/java/com/baiyee/adcallback/common/pojo/convert/JlBackdataConvert.java new file mode 100644 index 0000000..119a35e --- /dev/null +++ b/src/main/java/com/baiyee/adcallback/common/pojo/convert/JlBackdataConvert.java @@ -0,0 +1,41 @@ +package com.baiyee.adcallback.common.pojo.convert; + +import cn.hutool.core.bean.BeanUtil; +import cn.hutool.core.util.ObjectUtil; +import com.baiyee.adcallback.api.vo.JuliangMobileMonitorCallbackRequestVO; +import com.baiyee.adcallback.common.pojo.JlBackdataDTO; +import com.baiyee.adcallback.repository.entity.TbJlBackdataEntity; + +public class JlBackdataConvert { + + /** + * 私有化构造 + */ + private JlBackdataConvert(){} + + private static final ThreadLocal context = new ThreadLocal<>(); + + /** + * vo 转换为 dto -> 存放在当前线程上下文中 + * + * @param vo 对象 + */ + public static void voCovertToDTO(JuliangMobileMonitorCallbackRequestVO vo, JlBackdataDTO dto) { + BeanUtil.copyProperties(vo, dto, true); + context.set(dto); + } + + /** + * 转换为实体 + * + * @return {@link TbJlBackdataEntity} + */ + public static TbJlBackdataEntity covertToEntity(TbJlBackdataEntity entity) { + JlBackdataDTO jlBackdataDTO = context.get(); + if (ObjectUtil.isNotNull(jlBackdataDTO)){ + BeanUtil.copyProperties(jlBackdataDTO, entity, true); + } + context.remove(); + return entity; + } +} diff --git a/src/main/java/com/baiyee/adcallback/common/request/JuliangRequestHeader.java b/src/main/java/com/baiyee/adcallback/common/request/JuliangRequestHeader.java new file mode 100644 index 0000000..9484b44 --- /dev/null +++ b/src/main/java/com/baiyee/adcallback/common/request/JuliangRequestHeader.java @@ -0,0 +1,48 @@ +package com.baiyee.adcallback.common.request; + + +import lombok.Getter; +import lombok.Setter; +import org.springframework.beans.factory.annotation.Value; + +/** + * 巨量请求头常数 + * + * @author q + * @date 2022/01/05 + */ +public class JuliangRequestHeader { + + + /** + * 请求消息类型 content-type + */ + public static final String CONTEN_TTYPE = "application/json"; + + public static final String X_Debug_Mode_NAME = "X-Debug-Mode"; + + /** + * 允许值:1(开启);Debugger模式仅适用于接口测试使用(不适合线上生产环境), + * 目前频控限制为20次/分钟, + * 建议在遇到调用接口报错后,在header中传入此段,以获取错误help message。 + */ + + public static String X_DEBUGMODE_VALUE; + + public static String getXDebugModeValue(){ + return X_DEBUGMODE_VALUE; + } + + @Value("${x-debug.mode}") + public void setXDebugmodeValue(String xDebugmodeValue) { + JuliangRequestHeader.X_DEBUGMODE_VALUE = xDebugmodeValue; + } + + /** + * 授权access-token,获取方法见接口文档【获取Access-Token】 + * @see + */ + @Setter + @Getter + public String accessToken; +} diff --git a/src/main/java/com/baiyee/adcallback/common/request/JuliangRequestParam.java b/src/main/java/com/baiyee/adcallback/common/request/JuliangRequestParam.java new file mode 100644 index 0000000..f26a2f9 --- /dev/null +++ b/src/main/java/com/baiyee/adcallback/common/request/JuliangRequestParam.java @@ -0,0 +1,26 @@ +package com.baiyee.adcallback.common.request; + +/** + * juliang请求参数 + * + * @author q + * @date 2022/01/05 + */ +public class JuliangRequestParam { + + /** + * 开发者申请的应用APP_ID,可通过“应用管理”界面查看 + */ + public static final String APPID = "1720560676257815"; + + /** + * 开发者应用的私钥Secret,可通过“应用管理”界面查看(确保填入secret与app_id对应以免报错!) + * 这个可以进行重置 + */ + public static final String SECRET = "343e2d0e55713607bdd34da957603f66f578ebe5"; + + /** + * 授权类型 - 1 + */ + public static final String GRANT_TYPE_AUTH_CODE = "auth_code"; +} diff --git a/src/main/java/com/baiyee/adcallback/common/util/FileUtil.java b/src/main/java/com/baiyee/adcallback/common/util/FileUtil.java new file mode 100644 index 0000000..19b4253 --- /dev/null +++ b/src/main/java/com/baiyee/adcallback/common/util/FileUtil.java @@ -0,0 +1,382 @@ +/* + * Copyright 2019-2020 Zheng Jie + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.baiyee.adcallback.common.util; + +import cn.hutool.core.io.IoUtil; +import cn.hutool.core.util.IdUtil; +import cn.hutool.core.util.RandomUtil; +import cn.hutool.poi.excel.BigExcelWriter; +import cn.hutool.poi.excel.ExcelUtil; +import org.apache.tomcat.util.http.fileupload.IOUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.web.multipart.MultipartFile; + +import javax.servlet.ServletOutputStream; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.*; +import java.security.MessageDigest; +import java.text.DecimalFormat; +import java.text.SimpleDateFormat; +import java.time.Instant; +import java.util.Date; +import java.util.List; +import java.util.Map; + +/** + * File工具类,扩展 hutool 工具包 + * + * @author Zheng Jie + * @date 2018-12-27 + */ +public class FileUtil extends cn.hutool.core.io.FileUtil { + private static final Logger log = LoggerFactory.getLogger(FileUtil.class); + /** + * 系统临时目录 + *
+ * windows 包含路径分割符,但Linux 不包含, + * 在windows \\==\ 前提下, + * 为安全起见 同意拼装 路径分割符, + *

+     *       java.io.tmpdir
+     *       windows : C:\Users/xxx\AppData\Local\Temp\
+     *       linux: /temp
+     * 
+ */ + public static final String SYS_TEM_DIR = System.getProperty("java.io.tmpdir") + File.separator; + /** + * 定义GB的计算常量 + */ + private static final int GB = 1024 * 1024 * 1024; + /** + * 定义MB的计算常量 + */ + private static final int MB = 1024 * 1024; + /** + * 定义KB的计算常量 + */ + private static final int KB = 1024; + + + /** + * 默认的生成文件前缀 + */ + private static final String PRE_FILE = "out_task_"; + + /** + * 字段分隔符 (目前用于随机文件名中,...) [后续使用范围进行自行补充] + */ + private static final String SEPARATOR = "_"; + + /** + * 随机字符串的长度 (目前用于随机文件名中,...) [后续使用范围进行自行补充] + */ + private static final int RANDOM_STRING_LENGTH = 6; + + /** + * 格式化小数 + */ + private static final DecimalFormat DF = new DecimalFormat("0.00"); + + /** + * MultipartFile转File + */ + public static File toFile(MultipartFile multipartFile) { + // 获取文件名 + String fileName = multipartFile.getOriginalFilename(); + // 获取文件后缀 + String prefix = "." + getExtensionName(fileName); + File file = null; + try { + // 用uuid作为文件名,防止生成的临时文件重复 + file = File.createTempFile(IdUtil.simpleUUID(), prefix); + // MultipartFile to File + multipartFile.transferTo(file); + } catch (IOException e) { + log.error(e.getMessage(), e); + } + return file; + } + + /** + * 获取文件扩展名,不带 . + */ + public static String getExtensionName(String filename) { + if ((filename != null) && (filename.length() > 0)) { + int dot = filename.lastIndexOf('.'); + if ((dot > -1) && (dot < (filename.length() - 1))) { + return filename.substring(dot + 1); + } + } + return filename; + } + + /** + * Java文件操作 获取不带扩展名的文件名 + */ + public static String getFileNameNoEx(String filename) { + if ((filename != null) && (filename.length() > 0)) { + int dot = filename.lastIndexOf('.'); + if ((dot > -1) && (dot < (filename.length()))) { + return filename.substring(0, dot); + } + } + return filename; + } + + /** + * 文件大小转换 + */ + public static String getSize(long size) { + String resultSize; + if (size / GB >= 1) { + //如果当前Byte的值大于等于1GB + resultSize = DF.format(size / (float) GB) + "GB "; + } else if (size / MB >= 1) { + //如果当前Byte的值大于等于1MB + resultSize = DF.format(size / (float) MB) + "MB "; + } else if (size / KB >= 1) { + //如果当前Byte的值大于等于1KB + resultSize = DF.format(size / (float) KB) + "KB "; + } else { + resultSize = size + "B "; + } + return resultSize; + } + + /** + * inputStream 转 File + */ + static File inputStreamToFile(InputStream ins, String name) throws Exception { + File file = new File(SYS_TEM_DIR + name); + if (file.exists()) { + return file; + } + OutputStream os = new FileOutputStream(file); + int bytesRead; + int len = 8192; + byte[] buffer = new byte[len]; + while ((bytesRead = ins.read(buffer, 0, len)) != -1) { + os.write(buffer, 0, bytesRead); + } + os.close(); + ins.close(); + return file; + } + + /** + * 将文件名解析成文件的上传路径 + */ + public static File upload(MultipartFile file, String filePath) { + Date date = new Date(); + SimpleDateFormat format = new SimpleDateFormat("yyyyMMddhhmmssS"); + String name = getFileNameNoEx(file.getOriginalFilename()); + String suffix = getExtensionName(file.getOriginalFilename()); + String nowStr = "-" + format.format(date); + try { + String fileName = name + nowStr + "." + suffix; + String path = filePath + fileName; + // getCanonicalFile 可解析正确各种路径 + File dest = new File(path).getCanonicalFile(); + // 检测是否存在目录 + if (!dest.getParentFile().exists()) { + if (!dest.getParentFile().mkdirs()) { + System.out.println("was not successful."); + } + } + // 文件写入 + file.transferTo(dest); + return dest; + } catch (Exception e) { + log.error(e.getMessage(), e); + } + return null; + } + + /** + * 导出excel + */ + public static void downloadExcel(List> list, HttpServletResponse response) throws IOException { + String tempPath = SYS_TEM_DIR + IdUtil.fastSimpleUUID() + ".xlsx"; + File file = new File(tempPath); + BigExcelWriter writer = ExcelUtil.getBigWriter(file); + // 一次性写出内容,使用默认样式,强制输出标题 + writer.write(list, true); + //response为HttpServletResponse对象 + response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8"); + //test.xls是弹出下载对话框的文件名,不能为中文,中文请自行编码 + response.setHeader("Content-Disposition", "attachment;filename=学习资料.xlsx"); + ServletOutputStream out = response.getOutputStream(); + // 终止后删除临时文件 + file.deleteOnExit(); + writer.flush(out, true); + //此处记得关闭输出Servlet流 + IoUtil.close(out); + } + + /** + * 导入excel文件 + * + * @param file 传入服务器加载的文件 + * @param response + * @throws IOException + */ + public static void downloadExcel(File file, HttpServletResponse response) throws IOException { + BigExcelWriter writer = ExcelUtil.getBigWriter(file); + //response为HttpServletResponse对象 + response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8"); + //test.xls是弹出下载对话框的文件名,不能为中文,中文请自行编码 + response.setHeader("Content-Disposition", "attachment;filename=file.xlsx"); + ServletOutputStream out = response.getOutputStream(); + // 终止后删除临时文件 + file.deleteOnExit(); + writer.flush(out, true); + //此处记得关闭输出Servlet流 + IoUtil.close(out); + } + + public static String getFileType(String type) { + String documents = "txt doc pdf ppt pps xlsx xls docx"; + String music = "mp3 wav wma mpa ram ra aac aif m4a"; + String video = "avi mpg mpe mpeg asf wmv mov qt rm mp4 flv m4v webm ogv ogg"; + String image = "bmp dib pcp dif wmf gif jpg tif eps psd cdr iff tga pcd mpt png jpeg"; + if (image.contains(type)) { + return "图片"; + } else if (documents.contains(type)) { + return "文档"; + } else if (music.contains(type)) { + return "音乐"; + } else if (video.contains(type)) { + return "视频"; + } else { + return "其他"; + } + } + + public static void checkSize(long maxSize, long size) { + // 1M + int len = 1024 * 1024; + if (size > (maxSize * len)) { + throw new RuntimeException("文件超出规定大小"); + } + } + + /** + * 判断两个文件是否相同 + */ + public static boolean check(File file1, File file2) { + String img1Md5 = getMd5(file1); + String img2Md5 = getMd5(file2); + return img1Md5.equals(img2Md5); + } + + /** + * 判断两个文件是否相同 + */ + public static boolean check(String file1Md5, String file2Md5) { + return file1Md5.equals(file2Md5); + } + + private static byte[] getByte(File file) { + // 得到文件长度 + byte[] b = new byte[(int) file.length()]; + try { + InputStream in = new FileInputStream(file); + try { + System.out.println(in.read(b)); + } catch (IOException e) { + log.error(e.getMessage(), e); + } + } catch (FileNotFoundException e) { + log.error(e.getMessage(), e); + return null; + } + return b; + } + + private static String getMd5(byte[] bytes) { + // 16进制字符 + char[] hexDigits = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'}; + try { + MessageDigest mdTemp = MessageDigest.getInstance("MD5"); + mdTemp.update(bytes); + byte[] md = mdTemp.digest(); + int j = md.length; + char[] str = new char[j * 2]; + int k = 0; + // 移位 输出字符串 + for (byte byte0 : md) { + str[k++] = hexDigits[byte0 >>> 4 & 0xf]; + str[k++] = hexDigits[byte0 & 0xf]; + } + return new String(str); + } catch (Exception e) { + log.error(e.getMessage(), e); + } + return null; + } + + /** + * 下载文件 + * + * @param request / + * @param response / + * @param file / + */ + public static void downloadFile(HttpServletRequest request, HttpServletResponse response, File file, boolean deleteOnExit) { + response.setCharacterEncoding(request.getCharacterEncoding()); + response.setContentType("application/octet-stream"); + FileInputStream fis = null; + try { + fis = new FileInputStream(file); + response.setHeader("Content-Disposition", "attachment; filename=" + file.getName()); + IOUtils.copy(fis, response.getOutputStream()); + response.flushBuffer(); + } catch (Exception e) { + log.error(e.getMessage(), e); + } finally { + if (fis != null) { + try { + fis.close(); + if (deleteOnExit) { + file.deleteOnExit(); + } + } catch (IOException e) { + log.error(e.getMessage(), e); + } + } + } + } + + public static String getMd5(File file) { + return getMd5(getByte(file)); + } + + + /** + * 构建随机文件名规则 + * + * @return 构建好的随机文件名 + */ + public static String buildOnlyFileNameRule(){ + String fileName = PRE_FILE + + RandomUtil.randomString(RANDOM_STRING_LENGTH) + + SEPARATOR + + Instant.now().getEpochSecond(); + return fileName; + } +} diff --git a/src/main/java/com/baiyee/adcallback/config/AuditingConfig.java b/src/main/java/com/baiyee/adcallback/config/AuditingConfig.java new file mode 100644 index 0000000..1d1cb79 --- /dev/null +++ b/src/main/java/com/baiyee/adcallback/config/AuditingConfig.java @@ -0,0 +1,15 @@ +package com.baiyee.adcallback.config; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.data.domain.AuditorAware; +import org.springframework.data.jpa.repository.config.EnableJpaAuditing; + +@Configuration +@EnableJpaAuditing +public class AuditingConfig { + @Bean + public AuditorAware auditorProvider() { + return new DefaultAuditorAwareImpl(); + } +} diff --git a/src/main/java/com/baiyee/adcallback/config/DefaultAuditorAwareImpl.java b/src/main/java/com/baiyee/adcallback/config/DefaultAuditorAwareImpl.java new file mode 100644 index 0000000..7bb7f3f --- /dev/null +++ b/src/main/java/com/baiyee/adcallback/config/DefaultAuditorAwareImpl.java @@ -0,0 +1,15 @@ +package com.baiyee.adcallback.config; + +import org.springframework.data.domain.AuditorAware; + +import java.util.Optional; + +public class DefaultAuditorAwareImpl implements AuditorAware { + @Override + public Optional getCurrentAuditor() { + + String testName = "test123"; + + return Optional.of(testName); + } +} diff --git a/src/main/java/com/baiyee/adcallback/config/SpringMVCConfiguration.java b/src/main/java/com/baiyee/adcallback/config/SpringMVCConfiguration.java new file mode 100644 index 0000000..8b2091e --- /dev/null +++ b/src/main/java/com/baiyee/adcallback/config/SpringMVCConfiguration.java @@ -0,0 +1,25 @@ +package com.baiyee.adcallback.config; + +import org.springframework.context.annotation.Bean; +import org.springframework.core.convert.ConversionService; +import org.springframework.format.datetime.standard.DateTimeFormatterRegistrar; +import org.springframework.format.support.FormattingConversionServiceFactoryBean; +import org.springframework.stereotype.Component; + +import java.time.format.DateTimeFormatter; +import java.util.Collections; + +@Component +public class SpringMVCConfiguration { + + + @Bean + public ConversionService conversionService() { + FormattingConversionServiceFactoryBean factory = new FormattingConversionServiceFactoryBean(); + DateTimeFormatterRegistrar registrar = new DateTimeFormatterRegistrar(); + registrar.setDateFormatter(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")); + factory.setFormatterRegistrars(Collections.singleton(registrar)); + factory.afterPropertiesSet(); + return factory.getObject(); + } +} diff --git a/src/main/java/com/baiyee/adcallback/repository/TbJlBackdataEntityRepository.java b/src/main/java/com/baiyee/adcallback/repository/TbJlBackdataEntityRepository.java new file mode 100644 index 0000000..320f13d --- /dev/null +++ b/src/main/java/com/baiyee/adcallback/repository/TbJlBackdataEntityRepository.java @@ -0,0 +1,18 @@ +package com.baiyee.adcallback.repository; + +import com.baiyee.adcallback.repository.entity.TbJlBackdataEntity; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; + +import java.util.Date; +import java.util.List; + +public interface TbJlBackdataEntityRepository extends JpaRepository { + + + @Query(value = "SELECT imei FROM tb_jl_backdata WHERE imei != '' AND imei != '__IMEI__'", nativeQuery = true) + List queryAllImei(); + + @Query(value = "SELECT imei FROM tb_jl_backdata WHERE imei != '' AND imei != '__IMEI__' AND gmt_create > :startDate AND gmt_create < :endDate", nativeQuery = true) + List queryAllImeiByDate(Date startDate, Date endDate); +} \ No newline at end of file diff --git a/src/main/java/com/baiyee/adcallback/repository/TbJlTokenEntityRepository.java b/src/main/java/com/baiyee/adcallback/repository/TbJlTokenEntityRepository.java new file mode 100644 index 0000000..67cd731 --- /dev/null +++ b/src/main/java/com/baiyee/adcallback/repository/TbJlTokenEntityRepository.java @@ -0,0 +1,7 @@ +package com.baiyee.adcallback.repository; + +import com.baiyee.adcallback.repository.entity.TbJlTokenEntity; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface TbJlTokenEntityRepository extends JpaRepository { +} \ No newline at end of file diff --git a/src/main/java/com/baiyee/adcallback/repository/entity/TbJlBackdataEntity.java b/src/main/java/com/baiyee/adcallback/repository/entity/TbJlBackdataEntity.java new file mode 100644 index 0000000..2822128 --- /dev/null +++ b/src/main/java/com/baiyee/adcallback/repository/entity/TbJlBackdataEntity.java @@ -0,0 +1,104 @@ +package com.baiyee.adcallback.repository.entity; + +import com.fasterxml.jackson.annotation.JsonFormat; +import lombok.Data; +import org.springframework.data.annotation.CreatedDate; +import org.springframework.data.annotation.LastModifiedBy; +import org.springframework.data.annotation.LastModifiedDate; +import org.springframework.data.jpa.domain.support.AuditingEntityListener; +import org.springframework.format.annotation.DateTimeFormat; + +import javax.persistence.*; +import java.sql.Timestamp; +import java.util.Date; +import java.util.Objects; + +/** + * 结核病jl backdata实体 + * + * @author q + * @date 2022/01/07 + */ +@Entity +@Table(name = "tb_jl_backdata", schema = "db_ad", catalog = "") +@Data +@EntityListeners(AuditingEntityListener.class) +public class TbJlBackdataEntity { + + + @Id + @Column(name = "id", nullable = false) + @GeneratedValue(strategy = GenerationType.IDENTITY) + private long id; + + @CreatedDate + @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss") + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") + @Column(name = "gmt_create", nullable = false) + private Date gmtCreate; + + @LastModifiedDate + @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss") + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") + @Column(name = "gmt_modify", nullable = false) + private Date gmtModify; + + @LastModifiedBy + @Column(name = "operator", nullable = false, length = 255) + private String operator; + @Basic + @Column(name = "aid", nullable = false, length = 255) + private String aid; + @Basic + @Column(name = "aid_name", nullable = false, length = 255) + private String aidName; + @Basic + @Column(name = "advertiser_id", nullable = false, length = 255) + private String advertiserId; + @Basic + @Column(name = "cid", nullable = false) + private long cid; + @Basic + @Column(name = "ctype", nullable = false) + private byte ctype; + @Basic + @Column(name = "csite", nullable = false) + private int csite; + @Basic + @Column(name = "imei", nullable = false, length = 255) + private String imei; + @Basic + @Column(name = "idfa", nullable = false, length = 255) + private String idfa; + @Basic + @Column(name = "oaid", nullable = false, length = 255) + private String oaid; + @Basic + @Column(name = "os", nullable = false) + private byte os; + @Basic + @Column(name = "mac", nullable = false, length = 255) + private String mac; + @Basic + @Column(name = "mac1", nullable = false, length = 255) + private String mac1; + @Basic + @Column(name = "ip", nullable = false, length = 255) + private String ip; + @Basic + @Column(name = "geo", nullable = false, length = 255) + private String geo; + @Basic + @Column(name = "ts", nullable = false) + private long ts; + @Basic + @Column(name = "callback_url", nullable = false, length = 255) + private String callbackUrl; + @Basic + @Column(name = "model", nullable = false, length = 255) + private String model; + @Basic + @Column(name = "caid12", nullable = false, length = 255) + private String caid12; + +} diff --git a/src/main/java/com/baiyee/adcallback/repository/entity/TbJlTokenEntity.java b/src/main/java/com/baiyee/adcallback/repository/entity/TbJlTokenEntity.java new file mode 100644 index 0000000..b78c173 --- /dev/null +++ b/src/main/java/com/baiyee/adcallback/repository/entity/TbJlTokenEntity.java @@ -0,0 +1,62 @@ +package com.baiyee.adcallback.repository.entity; + +import com.fasterxml.jackson.annotation.JsonFormat; +import lombok.Data; +import org.springframework.data.annotation.CreatedDate; +import org.springframework.data.annotation.LastModifiedBy; +import org.springframework.data.annotation.LastModifiedDate; +import org.springframework.data.jpa.domain.support.AuditingEntityListener; +import org.springframework.format.annotation.DateTimeFormat; + +import javax.persistence.*; +import java.sql.Timestamp; +import java.util.Date; +import java.util.Objects; + +@Entity +@Table(name = "tb_jl_token", schema = "db_ad", catalog = "") +@Data +@EntityListeners(AuditingEntityListener.class) +public class TbJlTokenEntity { + + @Id + @Column(name = "id") + @GeneratedValue(strategy = GenerationType.IDENTITY) + private long id; + @Column(name = "gmt_create") + @CreatedDate + @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss") + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private Date gmtCreate; + @LastModifiedDate + @Column(name = "gmt_modify") + @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss") + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private Date gmtModify; + @Basic + @LastModifiedBy + @Column(name = "operator") + private String operator; + @Basic + @Column(name = "access_token") + private String accessToken; + @Basic + @Column(name = "expires_in") + private int expiresIn; + @Basic + @Column(name = "refresh_token") + private String refreshToken; + @Basic + @Column(name = "refresh_token_expires_in") + private int refreshTokenExpiresIn; + @Basic + @Column(name = "advertiser_ids") + private String advertiserIds; + @Basic + @Column(name = "auth_code") + private String authCode; + @Basic + @Column(name = "state") + private String state; + +} diff --git a/src/main/java/com/baiyee/adcallback/service/AdOriginalityManageService.java b/src/main/java/com/baiyee/adcallback/service/AdOriginalityManageService.java new file mode 100644 index 0000000..5433e51 --- /dev/null +++ b/src/main/java/com/baiyee/adcallback/service/AdOriginalityManageService.java @@ -0,0 +1,14 @@ +package com.baiyee.adcallback.service; + +/** + * 广告创意管理服务 + * + * @author q + * @date 2022/01/07 + */ +public interface AdOriginalityManageService { + /** + * 处理监测数据然后保存回调 + */ + void handleMonitorUrlCallbackDataThenSave(); +} diff --git a/src/main/java/com/baiyee/adcallback/service/FeiyuSourceManageService.java b/src/main/java/com/baiyee/adcallback/service/FeiyuSourceManageService.java new file mode 100644 index 0000000..12e34ed --- /dev/null +++ b/src/main/java/com/baiyee/adcallback/service/FeiyuSourceManageService.java @@ -0,0 +1,4 @@ +package com.baiyee.adcallback.service; + +public interface FeiyuSourceManageService { +} diff --git a/src/main/java/com/baiyee/adcallback/service/JuliangMobileMonitorService.java b/src/main/java/com/baiyee/adcallback/service/JuliangMobileMonitorService.java new file mode 100644 index 0000000..7c78ad6 --- /dev/null +++ b/src/main/java/com/baiyee/adcallback/service/JuliangMobileMonitorService.java @@ -0,0 +1,13 @@ +package com.baiyee.adcallback.service; + +import javax.servlet.http.HttpServletResponse; +import java.time.LocalDate; +import java.util.Date; +import java.util.List; + +public interface JuliangMobileMonitorService { + + List queryByImeiAdvancedMode(); + + void downloadImeiFile(HttpServletResponse response, Date startDate, Date endDate); +} diff --git a/src/main/java/com/baiyee/adcallback/service/TokenManageService.java b/src/main/java/com/baiyee/adcallback/service/TokenManageService.java new file mode 100644 index 0000000..f9ab68b --- /dev/null +++ b/src/main/java/com/baiyee/adcallback/service/TokenManageService.java @@ -0,0 +1,36 @@ +package com.baiyee.adcallback.service; + +import com.baiyee.adcallback.repository.entity.TbJlTokenEntity; + +/** + * 令牌管理服务 + * + * @author q + * @date 2022/01/05 + */ +public interface TokenManageService { + + /** + * 保存回调参数 + * + */ + void saveCallbackParam(); + + + /** + * 查询回调参数 + * + * @return {@link TbJlTokenEntity} + */ + TbJlTokenEntity queryCallbackParam(); + + /** + * 获取访问令牌 + */ + void getAccessToken(); + + /** + * 刷新令牌 + */ + void refreshToken(); +} diff --git a/src/main/java/com/baiyee/adcallback/service/impl/AdOriginalityManageServiceImpl.java b/src/main/java/com/baiyee/adcallback/service/impl/AdOriginalityManageServiceImpl.java new file mode 100644 index 0000000..82f3af1 --- /dev/null +++ b/src/main/java/com/baiyee/adcallback/service/impl/AdOriginalityManageServiceImpl.java @@ -0,0 +1,38 @@ +package com.baiyee.adcallback.service.impl; + +import cn.hutool.core.util.ObjectUtil; +import com.baiyee.adcallback.common.pojo.convert.JlBackdataConvert; +import com.baiyee.adcallback.repository.TbJlBackdataEntityRepository; +import com.baiyee.adcallback.repository.entity.TbJlBackdataEntity; +import com.baiyee.adcallback.service.AdOriginalityManageService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; + +/** + * 广告创意管理服务impl + * + * @author q + * @date 2022/01/07 + */ +@Service +@Slf4j +public class AdOriginalityManageServiceImpl implements AdOriginalityManageService { + + private final TbJlBackdataEntityRepository repository; + + public AdOriginalityManageServiceImpl(TbJlBackdataEntityRepository repository) { + this.repository = repository; + } + + @Override + public void handleMonitorUrlCallbackDataThenSave() { + + TbJlBackdataEntity entity = new TbJlBackdataEntity(); + TbJlBackdataEntity backEntity = JlBackdataConvert.covertToEntity(entity); + + TbJlBackdataEntity save = repository.save(backEntity); + if (ObjectUtil.isNull(save)){ + log.error("============================= [save a data fail save is {} ] =============================", save); + } + } +} diff --git a/src/main/java/com/baiyee/adcallback/service/impl/FeiyuSourceManageServiceImpl.java b/src/main/java/com/baiyee/adcallback/service/impl/FeiyuSourceManageServiceImpl.java new file mode 100644 index 0000000..cbbf07a --- /dev/null +++ b/src/main/java/com/baiyee/adcallback/service/impl/FeiyuSourceManageServiceImpl.java @@ -0,0 +1,8 @@ +package com.baiyee.adcallback.service.impl; + +import com.baiyee.adcallback.service.FeiyuSourceManageService; +import org.springframework.stereotype.Service; + +@Service +public class FeiyuSourceManageServiceImpl implements FeiyuSourceManageService { +} diff --git a/src/main/java/com/baiyee/adcallback/service/impl/JuliangMobileMonitorServiceImpl.java b/src/main/java/com/baiyee/adcallback/service/impl/JuliangMobileMonitorServiceImpl.java new file mode 100644 index 0000000..98fbaf9 --- /dev/null +++ b/src/main/java/com/baiyee/adcallback/service/impl/JuliangMobileMonitorServiceImpl.java @@ -0,0 +1,88 @@ +package com.baiyee.adcallback.service.impl; + +import cn.hutool.core.collection.CollectionUtil; +import cn.hutool.core.date.DateUtil; +import cn.hutool.core.util.ObjectUtil; +import com.baiyee.adcallback.common.util.FileUtil; +import com.baiyee.adcallback.repository.TbJlBackdataEntityRepository; +import com.baiyee.adcallback.service.JuliangMobileMonitorService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.format.annotation.DateTimeFormat; +import org.springframework.stereotype.Service; +import org.springframework.web.bind.annotation.RequestParam; + +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.time.LocalDate; +import java.util.*; + + +/** + * impl juliang移动监控服务 + * + * @author q + * @date 2022/01/10 + */ +@Service +@Slf4j +public class JuliangMobileMonitorServiceImpl implements JuliangMobileMonitorService { + + + private final TbJlBackdataEntityRepository tbJlBackdataEntityRepository; + + public JuliangMobileMonitorServiceImpl(TbJlBackdataEntityRepository tbJlBackdataEntityRepository) { + this.tbJlBackdataEntityRepository = tbJlBackdataEntityRepository; + } + + /** + * 查询imei先进模式 + * + * @return {@link List}<{@link String}> + */ + @Override + public List queryByImeiAdvancedMode() { + + List entities = tbJlBackdataEntityRepository.queryAllImei(); + + + List results = new ArrayList<>(1000); + + Map resultByCountMap = CollectionUtil.countMap(entities); + + resultByCountMap.forEach((k, v) -> { + results.add(k + "," + v); + }); + + return results; + } + + @Override + public void downloadImeiFile(HttpServletResponse response, + @RequestParam(value = "startDate") @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")Date startDate, + @RequestParam(value = "endDate")@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date endDate) { + + + List entities = tbJlBackdataEntityRepository.queryAllImeiByDate(startDate, endDate); + + Map resultByCountMap = CollectionUtil.countMap(entities); + + List> list = new ArrayList<>(); + + resultByCountMap.forEach( + (k, v) -> { + Map map = new LinkedHashMap<>(); + map.put("imei", k); + map.put("weight", v); + list.add(map); + } + ); + + try { + FileUtil.downloadExcel(list, response); + } catch (IOException e) { + log.error("============================================== [downloadExcel error!] =============================================="); + } + } + + +} diff --git a/src/main/java/com/baiyee/adcallback/service/impl/TokenManageServiceImpl.java b/src/main/java/com/baiyee/adcallback/service/impl/TokenManageServiceImpl.java new file mode 100644 index 0000000..f0fe9cc --- /dev/null +++ b/src/main/java/com/baiyee/adcallback/service/impl/TokenManageServiceImpl.java @@ -0,0 +1,122 @@ +package com.baiyee.adcallback.service.impl; + +import cn.hutool.core.util.ObjectUtil; +import cn.hutool.core.util.StrUtil; +import cn.hutool.http.HttpRequest; +import com.baiyee.adcallback.api.constants.RequestInfoConstant; +import com.baiyee.adcallback.common.constant.JuliangConstant; +import com.baiyee.adcallback.common.request.JuliangRequestParam; +import com.baiyee.adcallback.repository.entity.TbJlTokenEntity; +import com.baiyee.adcallback.service.TokenManageService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; + +/** + * 令牌管理服务impl + * + * @author q + * @date 2022/01/05 + */ +@Service +@Slf4j +public class TokenManageServiceImpl implements TokenManageService { + + + /** + * 保存回调参数 + */ + @Override + public void saveCallbackParam() { + + } + + /** + * 查询回调参数 + * + * @return {@link TbJlTokenEntity} 回调参数返回结果集 + */ + @Override + public TbJlTokenEntity queryCallbackParam() { + return null; + } + + /** + * 获取访问令牌 + * + * 执行逻辑 + *

+ * Access-Token是调用接口时,操作指定广告账户的身份凭证,有效期为24小时 + * Refresh-Token用于生成新access_token和refresh_token并且刷新时效达到续期的目的 + *

+ * 由于Access_Token有效期(默认1天)较短,当Access_Token超时后,可以使用refresh_token进行刷新,每次刷新都会产生新的access_token和Refresh_Token,同时重置二者的有效期。 + *

+ * 为防止Token刷新后新token由于某些原因可能存储失败,导致无法使用问题,刷新后历史Token将保留10分钟的有效时间,具体场景逻辑如下: + *

+ * 场景一:Token被刷新 + * 只要Token刷新成功获得了新的Access_Token和Refresh_Token,老的Access_Token和Refresh_Token将继续保留10分钟的有效期,10分钟后会自动过期;如果10分钟内对老的Token再次刷新,不再刷新老Token的时间,即老Token刷新后的10分钟有效期从第一次刷新时间开始。 + *

+ * 场景二:重新授权获得新的auth_code + * 同以往,只要重新授权了,那历史auth_code和Token将立即失效; + *

+ * 场景三:广告主取消授权 + * 同以往,APPID下与此广告主相关的auth_code和Token立即过期; + * + * 从数据库中拿令牌 - 令牌的获取会定时通过定时任务进行刷新 + */ + @Override + public void getAccessToken() { + // 初始化参数 + String reqParam = buildGetTokenReqParam(); + if (StrUtil.isBlank(reqParam)){ + return; + } + + // 发送获取 Access_Token 请求 + String result = HttpRequest + .post(JuliangConstant.GET_ACCESS_TOKEN_URL) + .timeout(RequestInfoConstant.DEFAULT_TIMEOUT_NUMBER) + // 允许值:1(开启);Debugger模式仅适用于接口测试使用(不适合线上生产环境),目前频控限制为20次/分钟,建议在遇到调用接口报错后,在header中传入此段,以获取错误help message。 +// .header(JuliangRequestHeader.X_Debug_Mode_NAME,JuliangRequestHeader.X_DEBUGMODE_VALUE,true) + .body(reqParam) + .execute().body(); + + // todo 返回的 Access_Token 存入到数据库中 + } + + + /** + * 构建授权获取请求消息参数 + * + * @return 返回请求消息体 + */ + private String buildGetTokenReqParam(){ + // 准备 auth_code + TbJlTokenEntity tbJlTokenEntity = queryCallbackParam(); + String authCode = ""; + if (ObjectUtil.isNotNull(tbJlTokenEntity)){ + authCode = tbJlTokenEntity.getAuthCode(); + if (StrUtil.isBlank(authCode)){ + log.error("========[authCode is empty ]========"); + return null; + } + } + + // 拼接 查询参数为 json + return String.format( + "{\"app_id\": \"%s\", \"secret\": \"%s\", \"grant_type\": \"%s\", \"auth_code\": \"%s\"}", + JuliangRequestParam.APPID, + JuliangRequestParam.SECRET, + JuliangRequestParam.GRANT_TYPE_AUTH_CODE, + authCode + ); + } + + + /** + * 刷新令牌 + */ + @Override + public void refreshToken() { + + } +} diff --git a/src/main/java/com/baiyee/adcallback/task/FixedTimeAutoRefreshJuliangTokenTask.java b/src/main/java/com/baiyee/adcallback/task/FixedTimeAutoRefreshJuliangTokenTask.java new file mode 100644 index 0000000..eb6ff6c --- /dev/null +++ b/src/main/java/com/baiyee/adcallback/task/FixedTimeAutoRefreshJuliangTokenTask.java @@ -0,0 +1,50 @@ +package com.baiyee.adcallback.task; + +import cn.hutool.core.date.DateUtil; +import cn.hutool.core.util.ObjectUtil; +import cn.hutool.core.util.StrUtil; +import cn.hutool.http.HttpRequest; +import com.baiyee.adcallback.api.constants.RequestInfoConstant; +import com.baiyee.adcallback.common.constant.JuliangConstant; +import com.baiyee.adcallback.common.request.JuliangRequestParam; +import com.baiyee.adcallback.repository.entity.TbJlTokenEntity; +import com.baiyee.adcallback.service.TokenManageService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.scheduling.annotation.Scheduled; +import org.springframework.stereotype.Component; + + +/** + * 巨量引擎 - 固定的时间自动刷新令牌任务 + * + * @author q + * @date 2022/01/06 + */ +@Component +@Slf4j +public class FixedTimeAutoRefreshJuliangTokenTask { + + private final TokenManageService tokenManageService; + + public FixedTimeAutoRefreshJuliangTokenTask(TokenManageService tokenManageService) { + this.tokenManageService = tokenManageService; + } + + + /** + * 定时任务驱动的执行规则 + */ + @Scheduled(cron = "0 0 23 1/1 * ?") + public void scheduledRule() { + log.info(" =============================== [定时刷新Token任务已经执行, 执行时间为 {} ] ===============================", DateUtil.date()); + execute(); + log.info(" =============================== [定时刷新Token任务执行完成, 执行时间为 {} ] ===============================", DateUtil.date()); + } + + /** + * 执行 + */ + public void execute() { + tokenManageService.refreshToken(); + } +} diff --git a/src/main/resources/application-dev.yml b/src/main/resources/application-dev.yml new file mode 100644 index 0000000..fd173cc --- /dev/null +++ b/src/main/resources/application-dev.yml @@ -0,0 +1,47 @@ +x-debug: + mode: '1' +#配置数据源 +spring: + datasource: + druid: + db-type: com.alibaba.druid.pool.DruidDataSource + driverClassName: com.mysql.cj.jdbc.Driver + url: jdbc:mysql://localhost:3306/db_ad?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf8&useSSL=false&rewriteBatchedStatements=true + username: root + password: root + # 初始连接数 + initial-size: 5 + # 最小连接数 + min-idle: 10 + # 最大连接数 + max-active: 20 + # 获取连接超时时间 + max-wait: 5000 + # 连接有效性检测时间 + time-between-eviction-runs-millis: 60000 + # 连接在池中最小生存的时间 + min-evictable-idle-time-millis: 300000 + # 连接在池中最大生存的时间 + max-evictable-idle-time-millis: 900000 + test-while-idle: true + test-on-borrow: false + test-on-return: false + # # 检测连接是否有效 + validation-query: select 1 + # 配置监控统计 + webStatFilter: + enabled: true + stat-view-servlet: + enabled: true + url-pattern: /druid/* + reset-enable: false + filter: + stat: + enabled: true + # 记录慢SQL + log-slow-sql: true + slow-sql-millis: 1000 + merge-sql: true + wall: + config: + multi-statement-allow: true \ No newline at end of file diff --git a/src/main/resources/application-online.yml b/src/main/resources/application-online.yml new file mode 100644 index 0000000..035700f --- /dev/null +++ b/src/main/resources/application-online.yml @@ -0,0 +1,45 @@ +#配置数据源 +spring: + datasource: + druid: + db-type: com.alibaba.druid.pool.DruidDataSource + driverClassName: com.mysql.cj.jdbc.Driver + url: jdbc:mysql://rm-bp1693kl5d490o5cn.mysql.rds.aliyuncs.com:3306/db_ad?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf8&useSSL=false&rewriteBatchedStatements=true + username: prod + password: yuyou@RDS9495 + # 初始连接数 + initial-size: 5 + # 最小连接数 + min-idle: 10 + # 最大连接数 + max-active: 20 + # 获取连接超时时间 + max-wait: 5000 + # 连接有效性检测时间 + time-between-eviction-runs-millis: 60000 + # 连接在池中最小生存的时间 + min-evictable-idle-time-millis: 300000 + # 连接在池中最大生存的时间 + max-evictable-idle-time-millis: 900000 + test-while-idle: true + test-on-borrow: false + test-on-return: false + # 检测连接是否有效 + validation-query: select 1 + # 配置监控统计 + webStatFilter: + enabled: true + stat-view-servlet: + enabled: true + url-pattern: /druid/* + reset-enable: false + filter: + stat: + enabled: true + # 记录慢SQL + log-slow-sql: true + slow-sql-millis: 1000 + merge-sql: true + wall: + config: + multi-statement-allow: true diff --git a/src/main/resources/application-prod.yml b/src/main/resources/application-prod.yml new file mode 100644 index 0000000..9e88f0b --- /dev/null +++ b/src/main/resources/application-prod.yml @@ -0,0 +1,45 @@ +#配置数据源 +spring: + datasource: + druid: + db-type: com.alibaba.druid.pool.DruidDataSource + driverClassName: com.mysql.cj.jdbc.Driver + url: jdbc:mysql://localhost:3306/db_ad?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf8&useSSL=false&rewriteBatchedStatements=true + username: root + password: Yuyou@2020 + # 初始连接数 + initial-size: 5 + # 最小连接数 + min-idle: 10 + # 最大连接数 + max-active: 20 + # 获取连接超时时间 + max-wait: 5000 + # 连接有效性检测时间 + time-between-eviction-runs-millis: 60000 + # 连接在池中最小生存的时间 + min-evictable-idle-time-millis: 300000 + # 连接在池中最大生存的时间 + max-evictable-idle-time-millis: 900000 + test-while-idle: true + test-on-borrow: false + test-on-return: false + # 检测连接是否有效 + validation-query: select 1 + # 配置监控统计 + webStatFilter: + enabled: true + stat-view-servlet: + enabled: true + url-pattern: /druid/* + reset-enable: false + filter: + stat: + enabled: true + # 记录慢SQL + log-slow-sql: true + slow-sql-millis: 1000 + merge-sql: true + wall: + config: + multi-statement-allow: true diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml new file mode 100644 index 0000000..5a92511 --- /dev/null +++ b/src/main/resources/application.yml @@ -0,0 +1,55 @@ +server: + port: 9191 +spring: + application: + name: ad-callback + profiles: + active: prod + jackson: + time-zone: GMT+8 + date-format: yyyy-MM-dd HH:mm:ss + serialization: + #格式化输出 + indent_output: true + #忽略无法转换的对象 + fail_on_empty_beans: false + #设置空如何序列化 + defaultPropertyInclusion: NON_EMPTY + deserialization: + #允许对象忽略json中不存在的属性 + fail_on_unknown_properties: false + parser: + #允许出现特殊字符和转义符 + allow_unquoted_control_chars: true + #允许出现单引号 + allow_single_quotes: true + + # 配置 Jpa + jpa: + properties: + hibernate: + ddl-auto: none + dialect: org.hibernate.dialect.MySQL5InnoDBDialect + open-in-view: true + + redis: + #数据库索引 + database: 0 + host: 127.0.0.1 + port: 6379 + password: + # 连接超时时间 + timeout: 5000 + +# 配置日志 +logging: + config: classpath:logback.xml + +# 线程池配置 +short: + chain: + task: + corePoolSize: 4 + maxPoolSize: 32 + queueCapacity: 100 + ThreadNamePrefix: 'XXX-' \ No newline at end of file diff --git a/src/main/resources/logback.xml b/src/main/resources/logback.xml new file mode 100644 index 0000000..8f15a7f --- /dev/null +++ b/src/main/resources/logback.xml @@ -0,0 +1,83 @@ + + + ad-callback + + + + + + + + + + %highlight([%-5level]) %cyan(%d{yyyy-MM-dd#HH:mm:ss.SSS}) %yellow([Thread:%thread]) %magenta([Logger:%logger]) -> %msg%n + utf-8 + + + + + + ${LOG_DIR}/ad-callback-log.log + + + + ${LOG_DIR}/history/%d{yyyy-MM-dd}.gz + 30 + + + true + + + ${LOG_PATTERN} + utf-8 + + + + + INFO + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/test/java/com/baiyee/adcallback/AdCallbackApplicationTests.java b/src/test/java/com/baiyee/adcallback/AdCallbackApplicationTests.java new file mode 100644 index 0000000..733ecc5 --- /dev/null +++ b/src/test/java/com/baiyee/adcallback/AdCallbackApplicationTests.java @@ -0,0 +1,13 @@ +package com.baiyee.adcallback; + +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest +class AdCallbackApplicationTests { + + @Test + void contextLoads() { + } + +}