|
|
@@ -1,6 +1,7 @@
|
|
|
package cn.com.ctop.job.bytedance.data.service.impl;
|
|
|
|
|
|
import cn.com.ctop.job.bytedance.data.entity.BytedanceErrorLog;
|
|
|
+import cn.com.ctop.job.bytedance.data.entity.ChangDuAppDistributor;
|
|
|
import cn.com.ctop.job.bytedance.data.entity.ChangDuOrder;
|
|
|
import cn.com.ctop.job.bytedance.data.entity.ChannelChangdunovelInfo;
|
|
|
import cn.com.ctop.job.bytedance.data.mapper.BytedancePromoterReportMapper;
|
|
|
@@ -17,9 +18,7 @@ import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
+import java.util.*;
|
|
|
|
|
|
@Service
|
|
|
@Slf4j
|
|
|
@@ -88,7 +87,110 @@ public class ChannelServiceImpl implements IChannelService {
|
|
|
e.printStackTrace();
|
|
|
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
+ @Override
|
|
|
+ public void getDistributorConfig() {
|
|
|
+ try {
|
|
|
+ List<JSONObject> distributorApp = getDistributorApp();
|
|
|
+ Set<ChangDuAppDistributor> adds = new HashSet<>();
|
|
|
+ for (JSONObject appDistributor : distributorApp) {
|
|
|
+ String appId = appDistributor.getString("app_id");
|
|
|
+ String apiKey = appDistributor.getString("api_key");
|
|
|
+ String distributorId = appDistributor.getString("distributor_id");
|
|
|
+ String changduAccountId = appDistributor.getString("changdu_account_id");
|
|
|
+ int thisPageIndex = 0;
|
|
|
+ int pageSize = 50;
|
|
|
+ int totalPageIndex = 0;
|
|
|
+ while (thisPageIndex <= totalPageIndex) {
|
|
|
+ String url = "https://www.changdunovel.com/novelsale/openapi/wx/get_bound_package_list/v1/";
|
|
|
+ String ts = String.valueOf(System.currentTimeMillis()).substring(0, 10);
|
|
|
+ String sign = getSign(distributorId, apiKey, ts);
|
|
|
+ Map<String, Object> params = new JSONObject();
|
|
|
+ params.put("distributor_id", distributorId);
|
|
|
+ params.put("ts", ts);
|
|
|
+ params.put("sign", sign);
|
|
|
+ params.put("app_id", appId);
|
|
|
+ params.put("page_index", thisPageIndex);
|
|
|
+ params.put("page_size", pageSize);
|
|
|
+ String s = HttpUtils.httpGet(url, params, null);
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(s);
|
|
|
+ if (!Check.isNull(jsonObject)) {
|
|
|
+ Integer code = jsonObject.getInteger("code");
|
|
|
+ if (code == 200) {
|
|
|
+ int total = jsonObject.getIntValue("total");
|
|
|
+ totalPageIndex = (int) Math.ceil(total * 1.0 / pageSize) - 1;
|
|
|
+ JSONArray result = jsonObject.getJSONArray("wx_package_info_open_list");
|
|
|
+ if (!Check.isNull(result)) {
|
|
|
+ for (int i = 0; i < result.size(); i++) {
|
|
|
+ JSONObject resultJson = result.getJSONObject(i);
|
|
|
+ ChangDuAppDistributor distributorConfig = JSONObject.parseObject(resultJson.toJSONString(), ChangDuAppDistributor.class);
|
|
|
+ distributorConfig.setChangduAccountId(changduAccountId);
|
|
|
+ distributorConfig.setChannelType(3);
|
|
|
+ distributorConfig.setApiKey(apiKey);
|
|
|
+ log.info("番茄获取小程序绑定的渠道信息 {}", distributorConfig);
|
|
|
+ adds.add(distributorConfig);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ log.error("番茄获取小程序绑定的渠道信息失败,返回信息:{}", jsonObject);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ log.error("番茄获取小程序绑定的渠道信息失败,返回信息为空。");
|
|
|
+ }
|
|
|
+ thisPageIndex = thisPageIndex + 1;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!Check.isNull(adds)) {
|
|
|
+ channelMapper.insertChangduDistributorApp(adds);
|
|
|
+ channelMapper.insertChangduDistributorConfig(adds);
|
|
|
+ channelMapper.insertChannelAccountInfo(adds);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<JSONObject> getDistributorApp() {
|
|
|
+ List<JSONObject> appDistributors = new ArrayList<>();
|
|
|
+ try {
|
|
|
+ List<JSONObject> list = channelMapper.getDistributorKey();
|
|
|
+ for (JSONObject didKey : list) {
|
|
|
+ String changduAccountId = didKey.getString("changduAccountId");
|
|
|
+ String distributorId = didKey.getString("distributorId");
|
|
|
+ String apiKey = didKey.getString("apiKey");
|
|
|
+ String url = "https://www.changdunovel.com/novelsale/openapi/package_info/v1/";
|
|
|
+ String ts = String.valueOf(System.currentTimeMillis()).substring(0, 10);
|
|
|
+ String sign = getSign(distributorId, apiKey, ts);
|
|
|
+ Map<String, Object> params = new JSONObject();
|
|
|
+ params.put("distributor_id", distributorId);
|
|
|
+ params.put("ts", ts);
|
|
|
+ params.put("sign", sign);
|
|
|
+ String s = HttpUtils.httpGet(url, params, null);
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(s);
|
|
|
+ if (!Check.isNull(jsonObject)) {
|
|
|
+ Integer code = jsonObject.getInteger("code");
|
|
|
+ if (code == 200) {
|
|
|
+ JSONArray result = jsonObject.getJSONArray("result");
|
|
|
+ if (!Check.isNull(result)) {
|
|
|
+ for (int i = 0; i < result.size(); i++) {
|
|
|
+ JSONObject resultJson = result.getJSONObject(i);
|
|
|
+ resultJson.put("changdu_account_id", changduAccountId);
|
|
|
+ resultJson.put("api_key", apiKey);
|
|
|
+ log.info("番茄获取账户内快应用/公众号列表 {}", resultJson);
|
|
|
+ appDistributors.add(resultJson);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ log.error("番茄获取账户内快应用/公众号列表失败,返回信息:{}", jsonObject);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ return appDistributors;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -196,7 +298,7 @@ public class ChannelServiceImpl implements IChannelService {
|
|
|
order.setMovieName(channelMapper.getMovieName(order.getMovieId()));
|
|
|
order.setDyingMovieId(dyingMovieId);
|
|
|
order.setDyingMovieName(dyingMovieName);
|
|
|
- log.info("常读order:[{}]",order);
|
|
|
+ log.info("常读order:[{}]", order);
|
|
|
adds.add(order);
|
|
|
}
|
|
|
}
|
|
|
@@ -235,6 +337,11 @@ public class ChannelServiceImpl implements IChannelService {
|
|
|
return channelMapper.getChangDuRetryJob();
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public List<JSONObject> getChannelInfoList() {
|
|
|
+ return channelMapper.getChannelInfoList();
|
|
|
+ }
|
|
|
+
|
|
|
private static String getSign(String distributorId, String secretKey, String ts) {
|
|
|
return SecureUtil.md5(distributorId + secretKey + ts).toLowerCase();
|
|
|
}
|