|
|
@@ -12,12 +12,16 @@ import cn.com.ctop.job.adq.data.utils.HttpUtils;
|
|
|
import cn.com.ctop.job.adq.utils.doris.sink.DorisMultiTableStreamLoadManager;
|
|
|
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;
|
|
|
@@ -263,7 +267,7 @@ public class AdqAdIncomeServiceImpl implements IAdqAdIncomeService {
|
|
|
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("ad_slot_name", adSlotMap.get(dataJson.getString("ad_slot")));
|
|
|
dataJson.put("stat_date", dataJson.getString("date").replace("-", ""));
|
|
|
reports.add(dataJson);
|
|
|
}
|
|
|
@@ -503,7 +507,7 @@ public class AdqAdIncomeServiceImpl implements IAdqAdIncomeService {
|
|
|
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);
|
|
|
+ log.error("查询流量主广告金账户余额获取token为空 [{}]{}", appId, appletId);
|
|
|
return;
|
|
|
}
|
|
|
int pageSize = 500;
|
|
|
@@ -547,22 +551,22 @@ public class AdqAdIncomeServiceImpl implements IAdqAdIncomeService {
|
|
|
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("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"));
|
|
|
+ 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);
|
|
|
+ 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","-","-",
|
|
|
+ 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)) {
|
|
|
@@ -607,8 +611,8 @@ public class AdqAdIncomeServiceImpl implements IAdqAdIncomeService {
|
|
|
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"));
|
|
|
+ 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;
|
|
|
@@ -663,4 +667,90 @@ public class AdqAdIncomeServiceImpl implements IAdqAdIncomeService {
|
|
|
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<>();
|
|
|
+ System.out.println(jsonObject);
|
|
|
+ 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);
|
|
|
+ System.out.println(dataJson.toJSONString());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } 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();
|
|
|
+ }
|
|
|
}
|