|
@@ -1,747 +0,0 @@
|
|
|
-package cn.com.ctop.job.adq.data.service.impl;
|
|
|
|
|
-
|
|
|
|
|
-import cn.com.ctop.job.adq.data.entity.AdqErrorLog;
|
|
|
|
|
-import cn.com.ctop.job.adq.data.entity.AdqPublisherAdunitGeneral;
|
|
|
|
|
-import cn.com.ctop.job.adq.data.mapper.AdqAdIncomeMapper;
|
|
|
|
|
-import cn.com.ctop.job.adq.data.mapper.AdqErrorLogMapper;
|
|
|
|
|
-import cn.com.ctop.job.adq.data.service.IAdqAdIncomeService;
|
|
|
|
|
-import cn.com.ctop.job.adq.data.utils.AlertUtils;
|
|
|
|
|
-import cn.com.ctop.job.adq.data.utils.Check;
|
|
|
|
|
-import cn.com.ctop.job.adq.data.utils.DateUtils;
|
|
|
|
|
-import cn.com.ctop.job.adq.data.utils.HttpUtils;
|
|
|
|
|
-import com.alibaba.fastjson.JSONArray;
|
|
|
|
|
-import com.alibaba.fastjson.JSONObject;
|
|
|
|
|
-import com.google.gson.Gson;
|
|
|
|
|
-import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
-import org.springframework.data.redis.core.RedisTemplate;
|
|
|
|
|
-import org.springframework.stereotype.Service;
|
|
|
|
|
-
|
|
|
|
|
-import javax.annotation.Resource;
|
|
|
|
|
-import javax.crypto.Mac;
|
|
|
|
|
-import javax.crypto.spec.SecretKeySpec;
|
|
|
|
|
-import java.nio.charset.StandardCharsets;
|
|
|
|
|
-import java.util.ArrayList;
|
|
|
|
|
-import java.util.HashMap;
|
|
|
|
|
-import java.util.List;
|
|
|
|
|
-import java.util.Map;
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
-@Service
|
|
|
|
|
-@Slf4j
|
|
|
|
|
-public class AdqAdIncomeServiceImpl implements IAdqAdIncomeService {
|
|
|
|
|
- @Resource
|
|
|
|
|
- private RedisTemplate redis2Template_db5;
|
|
|
|
|
- @Resource
|
|
|
|
|
- private AdqAdIncomeMapper adqAdIncomeMapper;
|
|
|
|
|
- @Autowired
|
|
|
|
|
- private AdqErrorLogMapper adqErrorLogMapper;
|
|
|
|
|
-
|
|
|
|
|
- private static final Map<String, String> adSlotMap = new HashMap<String, String>() {{
|
|
|
|
|
- put("SLOT_ID_BIZ_BOTTOM", "公众号底部广告");
|
|
|
|
|
- put("SLOT_ID_BIZ_MID_CONTEXT", "公众号文中广告");
|
|
|
|
|
- put("SLOT_ID_BIZ_VIDEO_END", "公众号视频后贴");
|
|
|
|
|
- put("SLOT_ID_BIZ_SPONSOR", "公众号互选广告");
|
|
|
|
|
- put("SLOT_ID_BIZ_CPS", "公众号返佣商品");
|
|
|
|
|
- put("SLOT_ID_WEAPP_BANNER", "小程序banner");
|
|
|
|
|
- put("SLOT_ID_WEAPP_REWARD_VIDEO", "小程序激励视频");
|
|
|
|
|
- put("SLOT_ID_WEAPP_INTERSTITIAL", "小程序插屏广告");
|
|
|
|
|
- put("SLOT_ID_WEAPP_VIDEO_FEEDS", "小程序视频广告");
|
|
|
|
|
- put("SLOT_ID_WEAPP_VIDEO_BEGIN", "小程序视频前贴");
|
|
|
|
|
- put("SLOT_ID_WEAPP_BOX", "小程序格子广告");
|
|
|
|
|
- put("SLOT_ID_WEAPP_TEMPLATE", "小程序原生模板广告");
|
|
|
|
|
- put("SLOT_ID_WEAPP_COVER", "封面广告");
|
|
|
|
|
- }};
|
|
|
|
|
-
|
|
|
|
|
- public List<JSONObject> getAdqAdIncomeRetryJob() {
|
|
|
|
|
- return adqAdIncomeMapper.queryAdqAdIncomeRetryJob();
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- public List<JSONObject> getAdqIaaMiniApp(String appId) {
|
|
|
|
|
- return adqAdIncomeMapper.queryAdqIaaMiniApp(appId);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- public List<JSONObject> getAdqAllMiniApp(String appId) {
|
|
|
|
|
- return adqAdIncomeMapper.queryAdqAllMiniApp(appId);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- public void getAdqAdIncome(String startDt, String endDt, String appId, Long appletId, Integer page, Integer isLog, Long errId, Integer isSend) {
|
|
|
|
|
- if (page == 1) {
|
|
|
|
|
- getAdqAdIncomeCover(startDt, endDt, appId, appletId, page, isLog, errId, isSend);
|
|
|
|
|
- }
|
|
|
|
|
- try {
|
|
|
|
|
- String url = "https://api.weixin.qq.com/publisher/stat";
|
|
|
|
|
- Object tokenObj = redis2Template_db5.opsForValue().get("wechat-applet-access-token-key-" + appletId);
|
|
|
|
|
- if (tokenObj == null) {
|
|
|
|
|
- log.error("微小广告细分数据拉取获取token为空 [{}] {}~{} {}", appId, startDt, endDt, appletId);
|
|
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
- int pageSize = 90;
|
|
|
|
|
- Map<String, Object> paramsMap = new HashMap<>();
|
|
|
|
|
- paramsMap.put("access_token", tokenObj.toString());
|
|
|
|
|
- paramsMap.put("action", "publisher_adunit_general");
|
|
|
|
|
- paramsMap.put("page", page);
|
|
|
|
|
- paramsMap.put("page_size", pageSize);
|
|
|
|
|
- paramsMap.put("start_date", startDt);
|
|
|
|
|
- paramsMap.put("end_date", endDt);
|
|
|
|
|
- String s = HttpUtils.httpGet(url, paramsMap, null);
|
|
|
|
|
- JSONObject jsonObject = JSONObject.parseObject(s);
|
|
|
|
|
- List<AdqPublisherAdunitGeneral> reports = new ArrayList<>();
|
|
|
|
|
- int totalPage = 1;
|
|
|
|
|
- if (!Check.isNull(jsonObject)) {
|
|
|
|
|
- Integer code = jsonObject.getInteger("ret");
|
|
|
|
|
- if (code == 2009) {
|
|
|
|
|
- return; //无效的流量主
|
|
|
|
|
- }
|
|
|
|
|
- if (code == 0) {
|
|
|
|
|
- JSONArray list = jsonObject.getJSONArray("list");
|
|
|
|
|
- Integer totalNum = jsonObject.getInteger("total_num");
|
|
|
|
|
- totalPage = (int) Math.ceil(totalNum * 1.0 / pageSize);
|
|
|
|
|
- if (!Check.isNull(list)) {
|
|
|
|
|
- for (int i = 0; i < list.size(); i++) {
|
|
|
|
|
- JSONObject dataJson = list.getJSONObject(i);
|
|
|
|
|
- JSONObject statItem = dataJson.getJSONObject("stat_item");
|
|
|
|
|
- statItem.put("ad_unit_id", dataJson.getString("ad_unit_id"));
|
|
|
|
|
- statItem.put("ad_unit_name", dataJson.getString("ad_unit_name"));
|
|
|
|
|
- AdqPublisherAdunitGeneral report = JSONObject.parseObject(statItem.toJSONString(), AdqPublisherAdunitGeneral.class);
|
|
|
|
|
- report.setAppId(appId);
|
|
|
|
|
- report.setStatDate(Integer.valueOf(report.getDate().replace("-", "")));
|
|
|
|
|
- report.setAdSlotName(adSlotMap.get(report.getAdSlot()));
|
|
|
|
|
- //System.out.println(report);
|
|
|
|
|
- reports.add(report);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- } else {
|
|
|
|
|
- log.error("微小广告细分数据拉取失败,app_id:{} {}~{},返回信息:{}", appId, startDt, endDt, jsonObject);
|
|
|
|
|
- insertErrorLog(isLog, System.currentTimeMillis(), "adq_ma_ad_income", startDt, endDt,
|
|
|
|
|
- jsonObject.fluentPut("app_id", appId).fluentPut("applet_id", appletId).toJSONString());
|
|
|
|
|
- }
|
|
|
|
|
- } else {
|
|
|
|
|
- log.error("微小广告细分数据拉取失败,app_id:{} {}~{},返回为空。", appId, startDt, endDt);
|
|
|
|
|
- insertErrorLog(isLog, System.currentTimeMillis(), "adq_ma_ad_income", startDt, endDt,
|
|
|
|
|
- new JSONObject().fluentPut("app_id", appId).fluentPut("applet_id", appletId).fluentPut("msg", "返回为空").toJSONString());
|
|
|
|
|
- }
|
|
|
|
|
- if (!Check.isNull(reports)) {
|
|
|
|
|
- adqAdIncomeMapper.insertAdqAdIncome(reports);
|
|
|
|
|
- //adqAdIncomeMapper.insertAdqAdIncomeSD(reports);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- if (totalPage > page) {
|
|
|
|
|
- getAdqAdIncome(startDt, endDt, appId, appletId, page + 1, isLog, errId, isSend);
|
|
|
|
|
- } else {
|
|
|
|
|
- log.info("微小广告细分数据拉取完成,app_id:{} {}~{} page:{}。", appId, startDt, endDt, page);
|
|
|
|
|
- if (errId != null) {
|
|
|
|
|
- adqErrorLogMapper.deleteInfoByErrorId(errId);
|
|
|
|
|
- }
|
|
|
|
|
- if (isSend != null && isSend == 1) {
|
|
|
|
|
- AlertUtils.sendMessage(System.currentTimeMillis(), startDt, endDt, 3, "daily", 1, "adq_ma_ad_income");
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- } catch (Exception e) {
|
|
|
|
|
- log.error("微小广告细分数据拉取失败,app_id:{} {}~{}。", appId, startDt, endDt, e);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- private void getAdqAdIncomeCover(String startDt, String endDt, String appId, Long appletId, Integer page, Integer isLog, Long errId, Integer isSend) {
|
|
|
|
|
- try {
|
|
|
|
|
- String url = "https://api.weixin.qq.com/publisher/stat";
|
|
|
|
|
- Object tokenObj = redis2Template_db5.opsForValue().get("wechat-applet-access-token-key-" + appletId);
|
|
|
|
|
- if (tokenObj == null) {
|
|
|
|
|
- log.error("微小广告封面广告数据拉取获取token为空 [{}] {}~{} {}", appId, startDt, endDt, appletId);
|
|
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
- int pageSize = 90;
|
|
|
|
|
- Map<String, Object> paramsMap = new HashMap<>();
|
|
|
|
|
- paramsMap.put("access_token", tokenObj.toString());
|
|
|
|
|
- paramsMap.put("action", "publisher_adpos_general");
|
|
|
|
|
- paramsMap.put("ad_slot", "SLOT_ID_WEAPP_COVER");
|
|
|
|
|
- paramsMap.put("page", page);
|
|
|
|
|
- paramsMap.put("page_size", pageSize);
|
|
|
|
|
- paramsMap.put("start_date", startDt);
|
|
|
|
|
- paramsMap.put("end_date", endDt);
|
|
|
|
|
- String s = HttpUtils.httpGet(url, paramsMap, null);
|
|
|
|
|
- JSONObject jsonObject = JSONObject.parseObject(s);
|
|
|
|
|
- List<AdqPublisherAdunitGeneral> reports = new ArrayList<>();
|
|
|
|
|
- int totalPage = 1;
|
|
|
|
|
- if (!Check.isNull(jsonObject)) {
|
|
|
|
|
- Integer code = jsonObject.getInteger("ret");
|
|
|
|
|
- JSONObject baseResp = jsonObject.getJSONObject("base_resp");
|
|
|
|
|
- if (baseResp != null) {
|
|
|
|
|
- code = baseResp.getInteger("ret");
|
|
|
|
|
- }
|
|
|
|
|
- if (code == 2009) {
|
|
|
|
|
- return; //无效的流量主
|
|
|
|
|
- }
|
|
|
|
|
- if (code == 0) {
|
|
|
|
|
- JSONArray list = jsonObject.getJSONArray("list");
|
|
|
|
|
- Integer totalNum = jsonObject.getInteger("total_num");
|
|
|
|
|
- totalPage = (int) Math.ceil(totalNum * 1.0 / pageSize);
|
|
|
|
|
- if (!Check.isNull(list)) {
|
|
|
|
|
- for (int i = 0; i < list.size(); i++) {
|
|
|
|
|
- JSONObject dataJson = list.getJSONObject(i);
|
|
|
|
|
- dataJson.put("ad_unit_id", "SLOT_ID_WEAPP_COVER");
|
|
|
|
|
- dataJson.put("ad_unit_name", "封面广告");
|
|
|
|
|
- AdqPublisherAdunitGeneral report = JSONObject.parseObject(dataJson.toJSONString(), AdqPublisherAdunitGeneral.class);
|
|
|
|
|
- report.setAppId(appId);
|
|
|
|
|
- report.setStatDate(Integer.valueOf(report.getDate().replace("-", "")));
|
|
|
|
|
- report.setAdSlotName(adSlotMap.get(report.getAdSlot()));
|
|
|
|
|
- //System.out.println(report);
|
|
|
|
|
- reports.add(report);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- } else {
|
|
|
|
|
- log.error("微小广告封面广告数据拉取失败,app_id:{} {}~{},返回信息:{}", appId, startDt, endDt, jsonObject);
|
|
|
|
|
- insertErrorLog(isLog, System.currentTimeMillis(), "adq_ma_ad_income", startDt, endDt,
|
|
|
|
|
- jsonObject.fluentPut("app_id", appId).fluentPut("applet_id", appletId).toJSONString());
|
|
|
|
|
- }
|
|
|
|
|
- } else {
|
|
|
|
|
- log.error("微小广告封面广告数据拉取失败,app_id:{} {}~{},返回为空。", appId, startDt, endDt);
|
|
|
|
|
- insertErrorLog(isLog, System.currentTimeMillis(), "adq_ma_ad_income", startDt, endDt,
|
|
|
|
|
- new JSONObject().fluentPut("app_id", appId).fluentPut("applet_id", appletId).fluentPut("msg", "返回为空").toJSONString());
|
|
|
|
|
- }
|
|
|
|
|
- if (!Check.isNull(reports)) {
|
|
|
|
|
- adqAdIncomeMapper.insertAdqAdIncome(reports);
|
|
|
|
|
- //adqAdIncomeMapper.insertAdqAdIncomeSD(reports);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- if (totalPage > page) {
|
|
|
|
|
- getAdqAdIncomeCover(startDt, endDt, appId, appletId, page + 1, isLog, errId, isSend);
|
|
|
|
|
- } else {
|
|
|
|
|
- log.info("微小广告封面广告数据拉取完成,app_id:{} {}~{} page:{}。", appId, startDt, endDt, page);
|
|
|
|
|
- if (errId != null) {
|
|
|
|
|
- adqErrorLogMapper.deleteInfoByErrorId(errId);
|
|
|
|
|
- }
|
|
|
|
|
- if (isSend != null && isSend == 1) {
|
|
|
|
|
- AlertUtils.sendMessage(System.currentTimeMillis(), startDt, endDt, 3, "daily", 1, "adq_ma_ad_income");
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- } catch (Exception e) {
|
|
|
|
|
- log.error("微小广告封面广告数据拉取失败,app_id:{} {}~{}。", appId, startDt, endDt, e);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- //获取小程序广告汇总数据
|
|
|
|
|
- public void getAdqAdPosIncome(String startDt, String endDt, String appId, Long appletId, Integer page, Integer isLog, Long errId, Integer isSend) {
|
|
|
|
|
- try {
|
|
|
|
|
- String url = "https://api.weixin.qq.com/publisher/stat";
|
|
|
|
|
- Object tokenObj = redis2Template_db5.opsForValue().get("wechat-applet-access-token-key-" + appletId);
|
|
|
|
|
- if (tokenObj == null) {
|
|
|
|
|
- log.error("微小获取小程序广告汇总数据获取token为空 [{}] {}~{} {}", appId, startDt, endDt, appletId);
|
|
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
- int pageSize = 90;
|
|
|
|
|
- Map<String, Object> paramsMap = new HashMap<>();
|
|
|
|
|
- paramsMap.put("access_token", tokenObj.toString());
|
|
|
|
|
- paramsMap.put("action", "publisher_adpos_general");
|
|
|
|
|
- paramsMap.put("page", page);
|
|
|
|
|
- paramsMap.put("page_size", pageSize);
|
|
|
|
|
- paramsMap.put("start_date", startDt);
|
|
|
|
|
- paramsMap.put("end_date", endDt);
|
|
|
|
|
- String s = HttpUtils.httpGet(url, paramsMap, null);
|
|
|
|
|
- JSONObject jsonObject = JSONObject.parseObject(s);
|
|
|
|
|
- List<JSONObject> reports = new ArrayList<>();
|
|
|
|
|
- int totalPage = 1;
|
|
|
|
|
- if (!Check.isNull(jsonObject)) {
|
|
|
|
|
- Integer code = jsonObject.getInteger("ret");
|
|
|
|
|
- JSONObject baseResp = jsonObject.getJSONObject("base_resp");
|
|
|
|
|
- if (baseResp != null) {
|
|
|
|
|
- code = baseResp.getInteger("ret");
|
|
|
|
|
- }
|
|
|
|
|
- if (code == 2009) {
|
|
|
|
|
- return; //无效的流量主
|
|
|
|
|
- }
|
|
|
|
|
- if (code == 0) {
|
|
|
|
|
- JSONArray list = jsonObject.getJSONArray("list");
|
|
|
|
|
- Integer totalNum = jsonObject.getInteger("total_num");
|
|
|
|
|
- totalPage = (int) Math.ceil(totalNum * 1.0 / pageSize);
|
|
|
|
|
- if (!Check.isNull(list)) {
|
|
|
|
|
- for (int i = 0; i < list.size(); i++) {
|
|
|
|
|
- JSONObject dataJson = list.getJSONObject(i);
|
|
|
|
|
- dataJson.put("app_id", appId);
|
|
|
|
|
- dataJson.put("ad_slot_name", adSlotMap.get(dataJson.getString("ad_slot")));
|
|
|
|
|
- dataJson.put("stat_date", dataJson.getString("date").replace("-", ""));
|
|
|
|
|
- reports.add(dataJson);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- } else {
|
|
|
|
|
- log.error("微小获取小程序广告汇总数据失败,app_id:{} {}~{},返回信息:{}", appId, startDt, endDt, jsonObject);
|
|
|
|
|
- insertErrorLog(isLog, System.currentTimeMillis(), "adq_publisher_adpos_general", startDt, endDt,
|
|
|
|
|
- jsonObject.fluentPut("app_id", appId).fluentPut("applet_id", appletId).toJSONString());
|
|
|
|
|
- }
|
|
|
|
|
- } else {
|
|
|
|
|
- log.error("微小获取小程序广告汇总数据失败,app_id:{} {}~{},返回为空。", appId, startDt, endDt);
|
|
|
|
|
- insertErrorLog(isLog, System.currentTimeMillis(), "adq_publisher_adpos_general", startDt, endDt,
|
|
|
|
|
- new JSONObject().fluentPut("app_id", appId).fluentPut("applet_id", appletId).fluentPut("msg", "返回为空").toJSONString());
|
|
|
|
|
- }
|
|
|
|
|
- if (!Check.isNull(reports)) {
|
|
|
|
|
- adqAdIncomeMapper.insertAdqAdPosIncome(reports);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- if (totalPage > page) {
|
|
|
|
|
- getAdqAdPosIncome(startDt, endDt, appId, appletId, page + 1, isLog, errId, isSend);
|
|
|
|
|
- } else {
|
|
|
|
|
- log.info("微小获取小程序广告汇总数据完成,app_id:{} {}~{} page:{}。", appId, startDt, endDt, page);
|
|
|
|
|
- if (errId != null) {
|
|
|
|
|
- adqErrorLogMapper.deleteInfoByErrorId(errId);
|
|
|
|
|
- }
|
|
|
|
|
- if (isSend != null && isSend == 1) {
|
|
|
|
|
- AlertUtils.sendMessage(System.currentTimeMillis(), startDt, endDt, 3, "daily", 1, "adq_ma_ad_income");
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- } catch (Exception e) {
|
|
|
|
|
- log.error("微小获取小程序广告汇总数据失败,app_id:{} {}~{}。", appId, startDt, endDt, e);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- private void insertErrorLog(Integer isLog, Long advertiserId, String dataDimension, String startDate, String endDate, String msg) {
|
|
|
|
|
- if (isLog != null && isLog == 1) {
|
|
|
|
|
- AdqErrorLog errorInfo = new AdqErrorLog();
|
|
|
|
|
- errorInfo.setAdvertiserId(advertiserId);
|
|
|
|
|
- errorInfo.setStartDate(startDate);
|
|
|
|
|
- errorInfo.setEndDate(endDate);
|
|
|
|
|
- errorInfo.setDataDimension(dataDimension);
|
|
|
|
|
- errorInfo.setDataType("daily");
|
|
|
|
|
- errorInfo.setMsg(msg);
|
|
|
|
|
- adqErrorLogMapper.replaceErrorInfo(errorInfo);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- public void getAdqAdUnitList(String appId, Long appletId, Integer page) {
|
|
|
|
|
- try {
|
|
|
|
|
- String url = "https://api.weixin.qq.com/publisher/stat";
|
|
|
|
|
- Object tokenObj = redis2Template_db5.opsForValue().get("wechat-applet-access-token-key-" + appletId);
|
|
|
|
|
- if (tokenObj == null) {
|
|
|
|
|
- log.error("微小获取小程序广告位清单拉取获取token为空 {} {}", appId, appletId);
|
|
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
- int pageSize = 100;
|
|
|
|
|
- Map<String, Object> paramsMap = new HashMap<>();
|
|
|
|
|
- paramsMap.put("access_token", tokenObj.toString());
|
|
|
|
|
- paramsMap.put("action", "get_adunit_list");
|
|
|
|
|
- paramsMap.put("page", page);
|
|
|
|
|
- paramsMap.put("page_size", pageSize);
|
|
|
|
|
- String s = HttpUtils.httpGet(url, paramsMap, null);
|
|
|
|
|
- JSONObject jsonObject = JSONObject.parseObject(s);
|
|
|
|
|
- int totalPage = 1;
|
|
|
|
|
- if (!Check.isNull(jsonObject)) {
|
|
|
|
|
- Integer code = jsonObject.getInteger("ret");
|
|
|
|
|
- if (code == 2009) {
|
|
|
|
|
- return; //无效的流量主
|
|
|
|
|
- }
|
|
|
|
|
- if (code == 0) {
|
|
|
|
|
- JSONArray list = jsonObject.getJSONArray("ad_unit");
|
|
|
|
|
- Integer totalNum = jsonObject.getInteger("total_num");
|
|
|
|
|
- totalPage = (int) Math.ceil(totalNum * 1.0 / pageSize);
|
|
|
|
|
- if (!Check.isNull(list)) {
|
|
|
|
|
- for (int i = 0; i < list.size(); i++) {
|
|
|
|
|
- JSONObject adUnitJson = list.getJSONObject(i);
|
|
|
|
|
- adUnitJson.put("ad_unit_size", adUnitJson.getString("ad_unit_size"));
|
|
|
|
|
- adUnitJson.put("templ_type_list", adUnitJson.getString("templ_type_list"));
|
|
|
|
|
- adUnitJson.put("app_id", appId);
|
|
|
|
|
- adUnitJson.put("ad_slot_name", adSlotMap.get(adUnitJson.getString("ad_slot")));
|
|
|
|
|
- }
|
|
|
|
|
- adqAdIncomeMapper.insertAdUnitList(list);
|
|
|
|
|
- }
|
|
|
|
|
- } else {
|
|
|
|
|
- log.error("微小获取小程序广告位清单拉取失败,app_id:{} ,返回信息:{}", appId, jsonObject);
|
|
|
|
|
- }
|
|
|
|
|
- } else {
|
|
|
|
|
- log.error("微小获取小程序广告位清单拉取失败,app_id:{} ,返回为空。", appId);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- if (totalPage > page) {
|
|
|
|
|
- getAdqAdUnitList(appId, appletId, page + 1);
|
|
|
|
|
- } else {
|
|
|
|
|
- log.info("微小获取小程序广告位清单拉取完成,app_id:{} page:{}。", appId, page);
|
|
|
|
|
- }
|
|
|
|
|
- } catch (Exception e) {
|
|
|
|
|
- log.error("微小获取小程序广告位清单拉取失败,app_id:{}。", appId, e);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- public void getAdqAdIncomeRate(String appId, Long appletId, String startDate, String endDate) {
|
|
|
|
|
- try {
|
|
|
|
|
- Object tokenObj = redis2Template_db5.opsForValue().get("wechat-applet-access-token-key-" + appletId);
|
|
|
|
|
- if (tokenObj == null) {
|
|
|
|
|
- log.error("微小广告分成比例获取token为空 {} {}", appId, appletId);
|
|
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
- String url = "https://api.weixin.qq.com/wedata/wedata_get_data?access_token=" + tokenObj;
|
|
|
|
|
- Map<String, Object> paramsMap = new HashMap<>();
|
|
|
|
|
- paramsMap.put("chart_id", "1001001002");
|
|
|
|
|
- paramsMap.put("target_id", "");
|
|
|
|
|
- paramsMap.put("begin_date", startDate.replace("-", ""));
|
|
|
|
|
- paramsMap.put("end_date", endDate.replace("-", ""));
|
|
|
|
|
- paramsMap.put("time_unit", 0);
|
|
|
|
|
- String s = HttpUtils.httpPostRequest(url, paramsMap, null);
|
|
|
|
|
- JSONObject jsonObject = JSONObject.parseObject(s);
|
|
|
|
|
- JSONArray results = new JSONArray();
|
|
|
|
|
- if (!Check.isNull(jsonObject)) {
|
|
|
|
|
- Integer code = jsonObject.getInteger("errcode");
|
|
|
|
|
- if (code == 0) {
|
|
|
|
|
- JSONArray list = jsonObject.getJSONArray("chart_result");
|
|
|
|
|
- if (!Check.isNull(list)) {
|
|
|
|
|
- JSONArray chartData = list.getJSONObject(0).getJSONArray("chart_data");
|
|
|
|
|
- for (int i = 0; i < chartData.size(); i++) {
|
|
|
|
|
- JSONObject chartJson = chartData.getJSONObject(i);
|
|
|
|
|
- JSONArray value = chartJson.getJSONArray("value");
|
|
|
|
|
- if (!Check.isNull(value)) {
|
|
|
|
|
- JSONObject result = new JSONObject();
|
|
|
|
|
- result.put("stat_date", value.getInteger(0));
|
|
|
|
|
- result.put("app_id", appId);
|
|
|
|
|
- result.put("share_rate", value.getDoubleValue(1));
|
|
|
|
|
- result.put("ad_give_rate", value.getDoubleValue(2));
|
|
|
|
|
- results.add(result);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- }
|
|
|
|
|
- } else {
|
|
|
|
|
- log.error("微小广告分成比例拉取失败,app_id:{} ,返回信息:{}", appId, jsonObject);
|
|
|
|
|
- }
|
|
|
|
|
- } else {
|
|
|
|
|
- log.error("微小广告分成比例拉取失败,app_id:{} ,返回为空。", appId);
|
|
|
|
|
- }
|
|
|
|
|
- if (!Check.isNull(results)) {
|
|
|
|
|
- adqAdIncomeMapper.insertAdIncomeRate(results);
|
|
|
|
|
- }
|
|
|
|
|
- log.info("微小广告分成比例拉取完成,app_id:{} {}~{}", appId, startDate, endDate);
|
|
|
|
|
- } catch (Exception e) {
|
|
|
|
|
- log.error("微小广告分成比例拉取失败,app_id:{}。", appId, e);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- /*
|
|
|
|
|
- 查询流量主每日广告金收入
|
|
|
|
|
- https://developers.weixin.qq.com/minigame/dev/guide/open-ability/ad/adq.html#_1%E3%80%81%E6%9F%A5%E8%AF%A2%E6%B5%81%E9%87%8F%E4%B8%BB%E6%AF%8F%E6%97%A5%E5%B9%BF%E5%91%8A%E9%87%91%E6%94%B6%E5%85%A5
|
|
|
|
|
- */
|
|
|
|
|
- public void getGameGiftList(String startDt, String endDt, String appId, Long appletId, Integer page, Integer isLog, Long errId, Integer isSend) {
|
|
|
|
|
- try {
|
|
|
|
|
- String url = "https://api.weixin.qq.com/publisher/stat";
|
|
|
|
|
- Object tokenObj = redis2Template_db5.opsForValue().get("wechat-applet-access-token-key-" + appletId);
|
|
|
|
|
- if (tokenObj == null) {
|
|
|
|
|
- log.error("微小查询流量主每日广告金收入获取token为空 [{}] {}~{} {}", appId, startDt, endDt, appletId);
|
|
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
- int pageSize = 500;
|
|
|
|
|
- Map<String, Object> paramsMap = new HashMap<>();
|
|
|
|
|
- paramsMap.put("access_token", tokenObj.toString());
|
|
|
|
|
- paramsMap.put("action", "general_action");
|
|
|
|
|
- paramsMap.put("cmd", "get_game_gift_list");
|
|
|
|
|
- paramsMap.put("ad_fund_type", "drama");
|
|
|
|
|
- paramsMap.put("page", page);
|
|
|
|
|
- paramsMap.put("page_size", pageSize);
|
|
|
|
|
- paramsMap.put("begin_date", startDt.replace("-", ""));
|
|
|
|
|
- paramsMap.put("end_date", endDt.replace("-", ""));
|
|
|
|
|
- String s = HttpUtils.httpGet(url, paramsMap, null);
|
|
|
|
|
- JSONObject jsonObject = JSONObject.parseObject(s);
|
|
|
|
|
- int totalPage = 1;
|
|
|
|
|
- ArrayList<JSONObject> reports = new ArrayList<>();
|
|
|
|
|
- if (!Check.isNull(jsonObject)) {
|
|
|
|
|
- Integer code = jsonObject.getInteger("ret");
|
|
|
|
|
- JSONObject baseResp = jsonObject.getJSONObject("base_resp");
|
|
|
|
|
- if (baseResp != null) {
|
|
|
|
|
- code = baseResp.getInteger("ret");
|
|
|
|
|
- }
|
|
|
|
|
- if (2009 == code) {
|
|
|
|
|
- return; //无效的流量主
|
|
|
|
|
- }
|
|
|
|
|
- if (code == 0) {
|
|
|
|
|
- JSONArray list = jsonObject.getJSONArray("game_gift_detail");
|
|
|
|
|
- Integer totalNum = jsonObject.getInteger("total_num");
|
|
|
|
|
- totalPage = (int) Math.ceil(totalNum * 1.0 / pageSize);
|
|
|
|
|
- if (!Check.isNull(list)) {
|
|
|
|
|
- for (int i = 0; i < list.size(); i++) {
|
|
|
|
|
- JSONObject dataJson = list.getJSONObject(i);
|
|
|
|
|
- dataJson.put("stat_date", dataJson.getString("date").replace("-", ""));
|
|
|
|
|
- dataJson.put("app_id", appId);
|
|
|
|
|
- reports.add(dataJson);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- } else {
|
|
|
|
|
- log.error("微小查询流量主每日广告金收入拉取失败,app_id:{} {}~{},返回信息:{}", appId, startDt, endDt, jsonObject);
|
|
|
|
|
- insertErrorLog(isLog, System.currentTimeMillis(), "adq_ma_game_gift_list", startDt, endDt,
|
|
|
|
|
- jsonObject.fluentPut("app_id", appId).fluentPut("applet_id", appletId).toJSONString());
|
|
|
|
|
- }
|
|
|
|
|
- } else {
|
|
|
|
|
- log.error("微小查询流量主每日广告金收入拉取失败,app_id:{} {}~{},返回为空。", appId, startDt, endDt);
|
|
|
|
|
- insertErrorLog(isLog, System.currentTimeMillis(), "adq_ma_game_gift_list", startDt, endDt,
|
|
|
|
|
- new JSONObject().fluentPut("app_id", appId).fluentPut("applet_id", appletId).fluentPut("msg", "返回为空").toJSONString());
|
|
|
|
|
- }
|
|
|
|
|
- if (!Check.isNull(reports)) {
|
|
|
|
|
- adqAdIncomeMapper.insertAdqGameGiftList(reports);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- if (totalPage > page) {
|
|
|
|
|
- getGameGiftList(startDt, endDt, appId, appletId, page + 1, isLog, errId, isSend);
|
|
|
|
|
- } else {
|
|
|
|
|
- log.info("微小查询流量主每日广告金收入拉取完成,app_id:{} {}~{} page:{}。", appId, startDt, endDt, page);
|
|
|
|
|
- if (errId != null) {
|
|
|
|
|
- adqErrorLogMapper.deleteInfoByErrorId(errId);
|
|
|
|
|
- }
|
|
|
|
|
- if (isSend != null && isSend == 1) {
|
|
|
|
|
- AlertUtils.sendMessage(System.currentTimeMillis(), startDt, endDt, 3, "daily", 1, "adq_ma_game_gift_list");
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- } catch (Exception e) {
|
|
|
|
|
- log.error("微小查询流量主每日广告金收入拉取失败,app_id:{} {}~{}。", appId, startDt, endDt, e);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- /*
|
|
|
|
|
- 查询流量主广告金账户余额
|
|
|
|
|
- https://developers.weixin.qq.com/minigame/dev/guide/open-ability/ad/adq.html#_1%E3%80%81%E6%9F%A5%E8%AF%A2%E6%B5%81%E9%87%8F%E4%B8%BB%E6%AF%8F%E6%97%A5%E5%B9%BF%E5%91%8A%E9%87%91%E6%94%B6%E5%85%A5
|
|
|
|
|
- */
|
|
|
|
|
- public void getGameDiviceSave(String appId, Long appletId, Integer page, Integer isLog, Long errId, Integer isSend) {
|
|
|
|
|
- try {
|
|
|
|
|
- String url = "https://api.weixin.qq.com/publisher/stat";
|
|
|
|
|
- Object tokenObj = redis2Template_db5.opsForValue().get("wechat-applet-access-token-key-" + appletId);
|
|
|
|
|
- if (tokenObj == null) {
|
|
|
|
|
- log.error("查询流量主广告金账户余额获取token为空 [{}]{}", appId, appletId);
|
|
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
- int pageSize = 500;
|
|
|
|
|
- Map<String, Object> paramsMap = new HashMap<>();
|
|
|
|
|
- paramsMap.put("access_token", tokenObj.toString());
|
|
|
|
|
- paramsMap.put("action", "general_action");
|
|
|
|
|
- paramsMap.put("cmd", "get_game_divice_save");
|
|
|
|
|
- paramsMap.put("ad_fund_type", "drama");
|
|
|
|
|
- paramsMap.put("sub_account", "GAME_DEVIDE");
|
|
|
|
|
- paramsMap.put("page", page);
|
|
|
|
|
- paramsMap.put("page_size", pageSize);
|
|
|
|
|
- String s = HttpUtils.httpGet(url, paramsMap, null);
|
|
|
|
|
- JSONObject jsonObject = JSONObject.parseObject(s);
|
|
|
|
|
- int totalPage = 1;
|
|
|
|
|
- ArrayList<JSONObject> reports = new ArrayList<>();
|
|
|
|
|
- ArrayList<JSONObject> reportsDaily = new ArrayList<>();
|
|
|
|
|
- if (!Check.isNull(jsonObject)) {
|
|
|
|
|
- Integer code = jsonObject.getInteger("ret");
|
|
|
|
|
- JSONObject baseResp = jsonObject.getJSONObject("base_resp");
|
|
|
|
|
- if (baseResp != null) {
|
|
|
|
|
- code = baseResp.getInteger("ret");
|
|
|
|
|
- }
|
|
|
|
|
- if (2009 == code) {
|
|
|
|
|
- return; //无效的流量主
|
|
|
|
|
- }
|
|
|
|
|
- if (code == 0) {
|
|
|
|
|
- Long expireBalance = jsonObject.getLong("expire_balance");
|
|
|
|
|
- String expireTime = jsonObject.getString("expire_time");
|
|
|
|
|
- Long totalBalance = jsonObject.getLong("total_balance");
|
|
|
|
|
- reports.add(new JSONObject()
|
|
|
|
|
- .fluentPut("stat_date", DateUtils.getNowDate("yyyyMMdd"))
|
|
|
|
|
- .fluentPut("app_id", appId)
|
|
|
|
|
- .fluentPut("expire_balance", expireBalance)
|
|
|
|
|
- .fluentPut("expire_time", expireTime)
|
|
|
|
|
- .fluentPut("total_balance", totalBalance));
|
|
|
|
|
-
|
|
|
|
|
- JSONArray list = jsonObject.getJSONArray("game_save_detail");
|
|
|
|
|
- Integer totalNum = jsonObject.getInteger("total_num");
|
|
|
|
|
- totalPage = (int) Math.ceil(totalNum * 1.0 / pageSize);
|
|
|
|
|
- if (!Check.isNull(list)) {
|
|
|
|
|
- for (int i = 0; i < list.size(); i++) {
|
|
|
|
|
- JSONObject dataJson = list.getJSONObject(i);
|
|
|
|
|
- JSONObject report = new JSONObject();
|
|
|
|
|
- report.put("stat_date", DateUtils.dateFormatTransform(dataJson.getString("date"), "yyyy年MM月dd日", "yyyyMMdd"));
|
|
|
|
|
- report.put("app_id", appId);
|
|
|
|
|
- report.put("game_save_detail_amt", dataJson.getLong("amt"));
|
|
|
|
|
- report.put("game_save_detail_expire_time", dataJson.getString("expire_time"));
|
|
|
|
|
- report.put("game_save_detail_sett_idx", dataJson.getLong("sett_idx"));
|
|
|
|
|
- reportsDaily.add(report);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- } else {
|
|
|
|
|
- log.error("查询流量主广告金账户余额拉取失败,app_id:{},返回信息:{}", appId, jsonObject);
|
|
|
|
|
- insertErrorLog(isLog, System.currentTimeMillis(), "adq_ma_game_divice_save", "-", "-",
|
|
|
|
|
- jsonObject.fluentPut("app_id", appId).fluentPut("applet_id", appletId).toJSONString());
|
|
|
|
|
- }
|
|
|
|
|
- } else {
|
|
|
|
|
- log.error("查询流量主广告金账户余额拉取失败,app_id:{},返回为空。", appId);
|
|
|
|
|
- insertErrorLog(isLog, System.currentTimeMillis(), "adq_ma_game_divice_save", "-", "-",
|
|
|
|
|
- new JSONObject().fluentPut("app_id", appId).fluentPut("applet_id", appletId).fluentPut("msg", "返回为空").toJSONString());
|
|
|
|
|
- }
|
|
|
|
|
- if (!Check.isNull(reports)) {
|
|
|
|
|
- adqAdIncomeMapper.insertAdqGameDiviceSave(reports);
|
|
|
|
|
- }
|
|
|
|
|
- if (!Check.isNull(reportsDaily)) {
|
|
|
|
|
- adqAdIncomeMapper.insertAdqGameDiviceSaveDetail(reportsDaily);
|
|
|
|
|
- }
|
|
|
|
|
- if (totalPage > page) {
|
|
|
|
|
- getGameDiviceSave(appId, appletId, page + 1, isLog, errId, isSend);
|
|
|
|
|
- } else {
|
|
|
|
|
- log.info("查询流量主广告金账户余额拉取完成,app_id:{} page:{}。", appId, page);
|
|
|
|
|
- if (errId != null) {
|
|
|
|
|
- adqErrorLogMapper.deleteInfoByErrorId(errId);
|
|
|
|
|
- }
|
|
|
|
|
- if (isSend != null && isSend == 1) {
|
|
|
|
|
- AlertUtils.sendMessage(System.currentTimeMillis(), "-", "-", 3, "daily", 1, "adq_ma_game_divice_save");
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- } catch (Exception e) {
|
|
|
|
|
- log.error("查询流量主广告金账户余额拉取失败,app_id:{}。", appId, e);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- /*
|
|
|
|
|
- 查询流量主广告金消耗记录
|
|
|
|
|
- https://developers.weixin.qq.com/minigame/dev/guide/open-ability/ad/adq.html#_1%E3%80%81%E6%9F%A5%E8%AF%A2%E6%B5%81%E9%87%8F%E4%B8%BB%E6%AF%8F%E6%97%A5%E5%B9%BF%E5%91%8A%E9%87%91%E6%94%B6%E5%85%A5
|
|
|
|
|
- */
|
|
|
|
|
- public void getGameDiviceTransfer(String startDt, String endDt, String appId, Long appletId, Integer page, Integer isLog, Long errId, Integer isSend) {
|
|
|
|
|
- try {
|
|
|
|
|
- String url = "https://api.weixin.qq.com/publisher/stat";
|
|
|
|
|
- Object tokenObj = redis2Template_db5.opsForValue().get("wechat-applet-access-token-key-" + appletId);
|
|
|
|
|
- if (tokenObj == null) {
|
|
|
|
|
- log.error("微小查询流量主广告金消耗记录获取token为空 [{}] {}~{} {}", appId, startDt, endDt, appletId);
|
|
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
- int pageSize = 500;
|
|
|
|
|
- Map<String, Object> paramsMap = new HashMap<>();
|
|
|
|
|
- paramsMap.put("access_token", tokenObj.toString());
|
|
|
|
|
- paramsMap.put("action", "general_action");
|
|
|
|
|
- paramsMap.put("cmd", "get_game_divice_transfer");
|
|
|
|
|
- paramsMap.put("ad_fund_type", "drama");
|
|
|
|
|
- paramsMap.put("page", page);
|
|
|
|
|
- paramsMap.put("page_size", pageSize);
|
|
|
|
|
- paramsMap.put("begin_date", DateUtils.getTimestampFormat("yyyy-MM-dd HH:mm:ss", startDt + " 00:00:00"));
|
|
|
|
|
- paramsMap.put("end_date", DateUtils.getTimestampFormat("yyyy-MM-dd HH:mm:ss", endDt + " 23:59:59"));
|
|
|
|
|
- String s = HttpUtils.httpGet(url, paramsMap, null);
|
|
|
|
|
- JSONObject jsonObject = JSONObject.parseObject(s);
|
|
|
|
|
- int totalPage = 1;
|
|
|
|
|
- ArrayList<JSONObject> reports = new ArrayList<>();
|
|
|
|
|
- if (!Check.isNull(jsonObject)) {
|
|
|
|
|
- Integer code = jsonObject.getInteger("ret");
|
|
|
|
|
- JSONObject baseResp = jsonObject.getJSONObject("base_resp");
|
|
|
|
|
- if (baseResp != null) {
|
|
|
|
|
- code = baseResp.getInteger("ret");
|
|
|
|
|
- }
|
|
|
|
|
- if (2009 == code) {
|
|
|
|
|
- return; //无效的流量主
|
|
|
|
|
- }
|
|
|
|
|
- if (code == 0) {
|
|
|
|
|
- JSONArray list = jsonObject.getJSONArray("game_transfer_detail");
|
|
|
|
|
- Integer totalNum = jsonObject.getInteger("total_num");
|
|
|
|
|
- totalPage = (int) Math.ceil(totalNum * 1.0 / pageSize);
|
|
|
|
|
- if (!Check.isNull(list)) {
|
|
|
|
|
- for (int i = 0; i < list.size(); i++) {
|
|
|
|
|
- JSONObject dataJson = list.getJSONObject(i);
|
|
|
|
|
- dataJson.put("stat_date", dataJson.getString("date").replace("-", ""));
|
|
|
|
|
- dataJson.put("app_id", appId);
|
|
|
|
|
- reports.add(dataJson);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- } else {
|
|
|
|
|
- log.error("微小查询流量主广告金消耗记录拉取失败,app_id:{} {}~{},返回信息:{}", appId, startDt, endDt, jsonObject);
|
|
|
|
|
- insertErrorLog(isLog, System.currentTimeMillis(), "adq_ma_game_divice_transfer", startDt, endDt,
|
|
|
|
|
- jsonObject.fluentPut("app_id", appId).fluentPut("applet_id", appletId).toJSONString());
|
|
|
|
|
- }
|
|
|
|
|
- } else {
|
|
|
|
|
- log.error("微小查询流量主广告金消耗记录拉取失败,app_id:{} {}~{},返回为空。", appId, startDt, endDt);
|
|
|
|
|
- insertErrorLog(isLog, System.currentTimeMillis(), "adq_ma_game_divice_transfer", startDt, endDt,
|
|
|
|
|
- new JSONObject().fluentPut("app_id", appId).fluentPut("applet_id", appletId).fluentPut("msg", "返回为空").toJSONString());
|
|
|
|
|
- }
|
|
|
|
|
- if (!Check.isNull(reports)) {
|
|
|
|
|
- adqAdIncomeMapper.insertAdqGameDiviceTransfer(reports);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- if (totalPage > page) {
|
|
|
|
|
- getGameDiviceTransfer(startDt, endDt, appId, appletId, page + 1, isLog, errId, isSend);
|
|
|
|
|
- } else {
|
|
|
|
|
- log.info("微小查询流量主广告金消耗记录拉取完成,app_id:{} {}~{} page:{}。", appId, startDt, endDt, page);
|
|
|
|
|
- if (errId != null) {
|
|
|
|
|
- adqErrorLogMapper.deleteInfoByErrorId(errId);
|
|
|
|
|
- }
|
|
|
|
|
- if (isSend != null && isSend == 1) {
|
|
|
|
|
- AlertUtils.sendMessage(System.currentTimeMillis(), startDt, endDt, 3, "daily", 1, "adq_ma_game_divice_transfer");
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- } catch (Exception e) {
|
|
|
|
|
- log.error("微小查询流量主广告金消耗记录拉取失败,app_id:{} {}~{}。", appId, startDt, endDt, e);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- /*
|
|
|
|
|
- query_adver_funds 虚拟支付查询广告金发放记录
|
|
|
|
|
- https://developers.weixin.qq.com/miniprogram/dev/platform-capabilities/business-capabilities/virtual-payment.html#_1-1-%E5%BC%80%E9%80%9A%E6%9D%A1%E4%BB%B6
|
|
|
|
|
- */
|
|
|
|
|
- public void queryVPAdFunds(String startDt, String endDt, String appId, Long appletId, String prodKey, Integer page, Integer isLog, Long errId, Integer isSend) {
|
|
|
|
|
- try {
|
|
|
|
|
- Object tokenObj = redis2Template_db5.opsForValue().get("wechat-applet-access-token-key-" + appletId);
|
|
|
|
|
- if (tokenObj == null) {
|
|
|
|
|
- log.error("虚拟支付查询广告金发放记录获取token为空 [{}] {}~{} {}", appId, startDt, endDt, appletId);
|
|
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
- int pageSize = 500;
|
|
|
|
|
- Map<String, Object> paramsMap = new HashMap<>();
|
|
|
|
|
- paramsMap.put("page", page);
|
|
|
|
|
- paramsMap.put("page_size", pageSize);
|
|
|
|
|
- paramsMap.put("env", 0);
|
|
|
|
|
- HashMap<String, Object> filter = new HashMap<>();
|
|
|
|
|
- filter.put("settle_begin", DateUtils.getTimestampFormat("yyyy-MM-dd HH:mm:ss", startDt + " 00:00:00"));
|
|
|
|
|
- filter.put("settle_end", DateUtils.getTimestampFormat("yyyy-MM-dd HH:mm:ss", endDt + " 23:59:59"));
|
|
|
|
|
- paramsMap.put("filter", filter);
|
|
|
|
|
- String paySig = getWxPaySig("/xpay/query_adver_funds", paramsMap, prodKey);
|
|
|
|
|
- String url = String.format("https://api.weixin.qq.com/xpay/query_adver_funds?access_token=%s&pay_sig=%s", tokenObj, paySig);
|
|
|
|
|
- String s = HttpUtils.httpPostRequest(url, paramsMap, null);
|
|
|
|
|
- JSONObject jsonObject = JSONObject.parseObject(s);
|
|
|
|
|
- int totalPage = 1;
|
|
|
|
|
- ArrayList<JSONObject> reports = new ArrayList<>();
|
|
|
|
|
- if (!Check.isNull(jsonObject)) {
|
|
|
|
|
- Integer code = jsonObject.getInteger("errcode");
|
|
|
|
|
- totalPage = jsonObject.getInteger("total_page");
|
|
|
|
|
- if (code == 0) {
|
|
|
|
|
- JSONArray list = jsonObject.getJSONArray("adver_funds_list");
|
|
|
|
|
- if (!Check.isNull(list)) {
|
|
|
|
|
- for (int i = 0; i < list.size(); i++) {
|
|
|
|
|
- JSONObject dataJson = list.getJSONObject(i);
|
|
|
|
|
- dataJson.put("app_id", appId);
|
|
|
|
|
- reports.add(dataJson);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- } else {
|
|
|
|
|
- log.error("虚拟支付查询广告金发放记录失败,app_id:{} {}~{},返回信息:{}", appId, startDt, endDt, jsonObject);
|
|
|
|
|
- insertErrorLog(isLog, System.currentTimeMillis(), "adq_query_adver_funds", startDt, endDt,
|
|
|
|
|
- jsonObject.fluentPut("app_id", appId).fluentPut("applet_id", appletId).fluentPut("prod_key", prodKey).toJSONString());
|
|
|
|
|
- }
|
|
|
|
|
- } else {
|
|
|
|
|
- log.error("虚拟支付查询广告金发放记录失败,app_id:{} {}~{},返回为空。", appId, startDt, endDt);
|
|
|
|
|
- insertErrorLog(isLog, System.currentTimeMillis(), "adq_query_adver_funds", startDt, endDt,
|
|
|
|
|
- new JSONObject().fluentPut("app_id", appId).fluentPut("applet_id", appletId).fluentPut("prod_key", prodKey).fluentPut("msg", "返回为空").toJSONString());
|
|
|
|
|
- }
|
|
|
|
|
- if (!Check.isNull(reports)) {
|
|
|
|
|
- adqAdIncomeMapper.insertVPAdFunds(reports);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- if (totalPage > page) {
|
|
|
|
|
- queryVPAdFunds(startDt, endDt, appId, appletId, prodKey, page + 1, isLog, errId, isSend);
|
|
|
|
|
- } else {
|
|
|
|
|
- log.info("虚拟支付查询广告金发放记录完成,app_id:{} {}~{} page:{}。", appId, startDt, endDt, page);
|
|
|
|
|
- if (errId != null) {
|
|
|
|
|
- adqErrorLogMapper.deleteInfoByErrorId(errId);
|
|
|
|
|
- }
|
|
|
|
|
- if (isSend != null && isSend == 1) {
|
|
|
|
|
- AlertUtils.sendMessage(System.currentTimeMillis(), startDt, endDt, 3, "daily", 1, "adq_query_adver_funds");
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- } catch (Exception e) {
|
|
|
|
|
- log.error("虚拟支付查询广告金发放记录失败,app_id:{} {}~{}。", appId, startDt, endDt, e);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- private String getWxPaySig(String uri, Map<String, Object> param, String prodKey) throws Exception {
|
|
|
|
|
- String postBody = new Gson().toJson(param);
|
|
|
|
|
- String needSignMsg = uri + "&" + postBody;
|
|
|
|
|
- Mac sha256_HMAC = Mac.getInstance("HmacSHA256");
|
|
|
|
|
- SecretKeySpec secretKey = new SecretKeySpec(prodKey.getBytes(StandardCharsets.UTF_8), "HmacSHA256");
|
|
|
|
|
- sha256_HMAC.init(secretKey);
|
|
|
|
|
- byte[] hashBytes = sha256_HMAC.doFinal(needSignMsg.getBytes(StandardCharsets.UTF_8));
|
|
|
|
|
- StringBuilder hexString = new StringBuilder();
|
|
|
|
|
- for (byte b : hashBytes) {
|
|
|
|
|
- String hex = Integer.toHexString(0xff & b);
|
|
|
|
|
- if (hex.length() == 1) hexString.append('0');
|
|
|
|
|
- hexString.append(hex);
|
|
|
|
|
- }
|
|
|
|
|
- return hexString.toString();
|
|
|
|
|
- }
|
|
|
|
|
-}
|
|
|