|
|
@@ -0,0 +1,156 @@
|
|
|
+package cn.com.ctop.job.bytedance.data.service.impl;
|
|
|
+
|
|
|
+import cn.com.ctop.job.bytedance.config.DianZhongConfig;
|
|
|
+import cn.com.ctop.job.bytedance.data.entity.DianzhongDistributorConfig;
|
|
|
+import cn.com.ctop.job.bytedance.data.entity.DianzhongMovieConfig;
|
|
|
+import cn.com.ctop.job.bytedance.data.mapper.DianzhongConfigMapper;
|
|
|
+import cn.com.ctop.job.bytedance.data.service.IDianzhongConfigService;
|
|
|
+import cn.com.ctop.job.bytedance.data.utils.HttpUtils;
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.codec.digest.DigestUtils;
|
|
|
+import org.apache.commons.lang.StringUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+
|
|
|
+@Service
|
|
|
+@Slf4j
|
|
|
+public class DianzhongConfigServiceImpl implements IDianzhongConfigService {
|
|
|
+ @Autowired
|
|
|
+ DianZhongConfig dianZhongConfig;
|
|
|
+ @Resource
|
|
|
+ DianzhongConfigMapper dianzhongConfigMapper;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void pullChannelInfo() {
|
|
|
+ for (DianZhongConfig.DZConfig dzAuth : dianZhongConfig.getDzConfig()){
|
|
|
+ String url = "https://routine.wqxsw.com/flames/channel/query/channelInfoList";
|
|
|
+ JSONObject requestJson = initRequestJson2(dzAuth);
|
|
|
+ System.out.println("请求点众渠道用户列表接口,参数:" + requestJson.toJSONString());
|
|
|
+ String res = HttpUtils.httpPostRequest(url, requestJson, null);
|
|
|
+ System.out.println("点众回调渠道用户列表接口返回结果:" + res);
|
|
|
+ if (StringUtils.isEmpty(res)){
|
|
|
+ log.error("点众渠道用户列表接口返回结果为空");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ JSONObject resObj = JSONObject.parseObject(res);
|
|
|
+ int code = resObj.getIntValue("retCode");
|
|
|
+ if (code != 0){
|
|
|
+ log.error("点众渠道用户列表接口返回错误,code: {}, msg: {}", code, resObj.getString("retMsg"));
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ JSONObject data = resObj.getJSONObject("data");
|
|
|
+ JSONArray channelInfoList = data.getJSONArray("channelInfoList");
|
|
|
+ if (channelInfoList == null || channelInfoList.isEmpty()) {
|
|
|
+ log.info("点众渠道用户列表接口没有返回数据");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ for (int i = 0; i < channelInfoList.size(); i++) {
|
|
|
+ JSONObject obj = channelInfoList.getJSONObject(i);
|
|
|
+ DianzhongDistributorConfig config = new DianzhongDistributorConfig();
|
|
|
+ config.setDistributorId(obj.getString("channelId"));
|
|
|
+ config.setDistributorName(obj.getString("userName"));
|
|
|
+ config.setNickName(obj.getString("nickName"));
|
|
|
+ config.setDianzhongAccountId(dzAuth.getClientId());
|
|
|
+ config.setChannelCreateTime( obj.getString("createTime"));
|
|
|
+ config.setJumpType( obj.getString("jumpType"));
|
|
|
+ config.setOfAppid( obj.getString("ofAppid"));
|
|
|
+ config.setCreateBy("system");
|
|
|
+ config.setUpdateBy("system");
|
|
|
+
|
|
|
+ dianzhongConfigMapper.insertDistributorConfigSelective(config);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ //获取调用点众接口的必要参数
|
|
|
+ private JSONObject initRequestJson(DianZhongConfig.DZConfig authConfig){
|
|
|
+ JSONObject object = new JSONObject();
|
|
|
+ String clientId = authConfig.getClientId();
|
|
|
+ String token = authConfig.getToken();
|
|
|
+ object.put("clientId", clientId);
|
|
|
+ long timestamp = System.currentTimeMillis() / 1000;
|
|
|
+ object.put("timestamp", String.valueOf(timestamp));
|
|
|
+ System.out.println(clientId + token + timestamp);
|
|
|
+ String signKey = DigestUtils.md5Hex(
|
|
|
+ clientId + token + timestamp
|
|
|
+ ).toLowerCase();
|
|
|
+ object.put("signKey", signKey);
|
|
|
+ return object;
|
|
|
+ }
|
|
|
+
|
|
|
+ private JSONObject initRequestJson2(DianZhongConfig.DZConfig authConfig){
|
|
|
+ JSONObject object = new JSONObject();
|
|
|
+ String clientId = authConfig.getClientId();
|
|
|
+ String token = authConfig.getToken();
|
|
|
+ object.put("clientId", clientId);
|
|
|
+ long timestamp = System.currentTimeMillis();
|
|
|
+ object.put("timestamp", String.valueOf(timestamp));
|
|
|
+ System.out.println(clientId + token + timestamp);
|
|
|
+ String signKey = DigestUtils.md5Hex(
|
|
|
+ clientId + token + timestamp
|
|
|
+ ).toLowerCase();
|
|
|
+ object.put("signKey", signKey);
|
|
|
+ return object;
|
|
|
+ }
|
|
|
+
|
|
|
+// private DianZhongConfig.DZConfig getAuthConfig(){
|
|
|
+// return dianZhongConfig.getDzConfig().get(0);
|
|
|
+// }
|
|
|
+ //废弃
|
|
|
+@Override
|
|
|
+public void pullMovieInfo(String date, Long channelId) {
|
|
|
+ String url = "https://video.wqxsw.com/api/channelapi/books";
|
|
|
+ JSONObject requestJson = initRequestJson(dianZhongConfig.getDzConfig().get(0));
|
|
|
+ requestJson.put("date", date);
|
|
|
+ if (channelId != null){
|
|
|
+ requestJson.put("channelId", channelId);
|
|
|
+ }
|
|
|
+ System.out.println("请求点众书籍列表接口,参数:" + requestJson.toJSONString());
|
|
|
+ String res = HttpUtils.httpPostRequest(url, requestJson, null);
|
|
|
+ if (StringUtils.isEmpty(res)){
|
|
|
+ log.error("点众书籍列表接口返回结果为空");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ JSONObject resObj = JSONObject.parseObject(res);
|
|
|
+ int code = resObj.getIntValue("code");
|
|
|
+ if (code >1){
|
|
|
+ log.error("点众书籍列表接口返回错误,code: {}, msg: {}", code, resObj.getString("msg"));
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ JSONArray data = resObj.getJSONArray("data");
|
|
|
+ if (data == null || data.isEmpty()) {
|
|
|
+ System.out.println(res);
|
|
|
+ log.info("点众书籍列表接口没有返回数据");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ for (int i = 0; i < data.size(); i++) {
|
|
|
+ JSONObject m = data.getJSONObject(i);
|
|
|
+ DianzhongMovieConfig config = new DianzhongMovieConfig();
|
|
|
+ config.setMovieId(m.getString("bookId"));
|
|
|
+ config.setMovieName(m.getString("bookName"));
|
|
|
+ config.setIntroduction(m.getString("introduction"));
|
|
|
+ config.setWordCount(m.getInteger("totalWordSize"));
|
|
|
+ config.setCoverImgUrl(m.getString("coverWap"));
|
|
|
+ config.setType1(m.getString("bookTypeOneText"));
|
|
|
+ config.setType2(m.getString("bookTypeTwoText"));
|
|
|
+ config.setType3(m.getString("bookTypeThreeText"));
|
|
|
+ config.setFirstShelfTime(m.getString("firstShelfTime"));
|
|
|
+ config.setShowTitle(m.getString("showTitle"));
|
|
|
+ config.setUpdateBy("system");
|
|
|
+ config.setCreateBy("system");
|
|
|
+
|
|
|
+ System.out.println(JSONObject.toJSONString(config));
|
|
|
+ dianzhongConfigMapper.insertConfigSelective(config);
|
|
|
+ }
|
|
|
+}
|
|
|
+}
|