|
@@ -0,0 +1,215 @@
|
|
|
|
|
+package com.cyksj.service.advertisement.postdata.impl;
|
|
|
|
|
+
|
|
|
|
|
+import cn.hutool.http.HttpUtil;
|
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
|
|
+import com.cyksj.common.util.*;
|
|
|
|
|
+import com.cyksj.mapper.advertisement.AdvertisementOrderDonMapper;
|
|
|
|
|
+import com.cyksj.mapper.advertisement.AdvertisementOrderPostMapper;
|
|
|
|
|
+import com.cyksj.mapper.advertisement.AdvertisementPopularizeMapper;
|
|
|
|
|
+import com.cyksj.model.entity.*;
|
|
|
|
|
+import com.cyksj.service.advertisement.postdata.AbstractPostDataService;
|
|
|
|
|
+import com.cyksj.service.advertisement.postdata.PostDataFactory;
|
|
|
|
|
+import com.cyksj.service.advertisement.tencent.TenCentActionSetService;
|
|
|
|
|
+import com.cyksj.service.advertisement.tencent.TenCentUserAccessTokenService;
|
|
|
|
|
+import com.cyksj.service.advertisement.tencent.TenCentUserService;
|
|
|
|
|
+import lombok.RequiredArgsConstructor;
|
|
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
|
|
+
|
|
|
|
|
+import javax.annotation.PostConstruct;
|
|
|
|
|
+import java.net.URLDecoder;
|
|
|
|
|
+import java.net.http.HttpRequest;
|
|
|
|
|
+import java.net.http.HttpResponse;
|
|
|
|
|
+import java.nio.charset.StandardCharsets;
|
|
|
|
|
+import java.util.*;
|
|
|
|
|
+
|
|
|
|
|
+/**
|
|
|
|
|
+ * @author chan
|
|
|
|
|
+ * @className DyPostDataService
|
|
|
|
|
+ * @description 微信回传
|
|
|
|
|
+ * @date 2020/12/15 1:35 下午
|
|
|
|
|
+ */
|
|
|
|
|
+
|
|
|
|
|
+@Slf4j
|
|
|
|
|
+@Service("WeChatPostDataService")
|
|
|
|
|
+@RequiredArgsConstructor
|
|
|
|
|
+public class WeChatPostDataService extends AbstractPostDataService {
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ private final AdvertisementOrderPostMapper orderPostMapper;
|
|
|
|
|
+
|
|
|
|
|
+ private final AdvertisementPopularizeMapper popularizeMapper;
|
|
|
|
|
+
|
|
|
|
|
+ private final AdvertisementOrderDonMapper orderDonMapper;
|
|
|
|
|
+
|
|
|
|
|
+ private final TenCentActionSetService tenCentActionSetService;
|
|
|
|
|
+
|
|
|
|
|
+ private final TenCentUserAccessTokenService tenCentUserAccessTokenService;
|
|
|
|
|
+
|
|
|
|
|
+ private final TenCentUserService tenCentUserService;
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void postData(Long orderId, String callback, String evenType) throws Exception {
|
|
|
|
|
+
|
|
|
|
|
+ callback = callback.replaceAll("#", "");
|
|
|
|
|
+ log.info("腾讯广告回传入参id:{}", orderId);
|
|
|
|
|
+
|
|
|
|
|
+ callback = URLDecoder.decode(callback, IoKit.Charsets.UTF_8.getCharset());
|
|
|
|
|
+
|
|
|
|
|
+ Map<String, String> paramMap = HttpUtil.decodeParamMap(callback, StandardCharsets.UTF_8);
|
|
|
|
|
+ AdvertisementOrderDon orderDon = orderDonMapper.selectById(orderId);
|
|
|
|
|
+ AdvertisementPopularize popularize = popularizeMapper.selectById(orderDon.getPopularizeId());
|
|
|
|
|
+
|
|
|
|
|
+ String dataId = popularize.getDataId() != null ? StringUtil.getString(popularize.getDataId()) : paramMap.get("dataId");
|
|
|
|
|
+ //adq
|
|
|
|
|
+ if (dataId != null) {
|
|
|
|
|
+ String clickId = Optional.ofNullable(paramMap.get("click_id")).orElse(Optional.ofNullable(paramMap.get("qz_gdt")).orElse(Optional.ofNullable(paramMap.get("gdt_vid")).orElse("")));
|
|
|
|
|
+
|
|
|
|
|
+ TencentActionSet actionSet = tenCentActionSetService.getOne(Wrappers.lambdaQuery(TencentActionSet.class).eq(TencentActionSet::getUserActionSetId, dataId));
|
|
|
|
|
+ AdvertisementOrderPost orderPost = orderPostMapper.selectOne(Wrappers.lambdaQuery(AdvertisementOrderPost.class).eq(AdvertisementOrderPost::getOrderId, orderId));
|
|
|
|
|
+ orderPost.setType(AdvertisementOrderPost.Type.adq);
|
|
|
|
|
+ orderPostMapper.updateById(orderPost);
|
|
|
|
|
+ if (actionSet != null) {
|
|
|
|
|
+
|
|
|
|
|
+ TencentUser tencentUser = tenCentUserService.getById(actionSet.getUserId());
|
|
|
|
|
+ TencentUserAccessToken accessToken = tenCentUserAccessTokenService.getOne(new QueryWrapper<TencentUserAccessToken>().lambda().eq(TencentUserAccessToken::getTencentUserId, tencentUser.getId()));
|
|
|
|
|
+
|
|
|
|
|
+ String url = "https://api.e.qq.com/v1.3/user_actions/add?access_token=" + accessToken.getAccessToken() +
|
|
|
|
|
+ "×tamp=" + System.currentTimeMillis() / 1000 +
|
|
|
|
|
+ "&nonce=" + Codec.DoDigest.custom().setAlgorithm(Codec.DoDigest.Algorithm.MD5).setStringData("toufang123" + System.currentTimeMillis()).toHexString();
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ List<Map<String, Object>> actions = new ArrayList<>();
|
|
|
|
|
+ Map<String, Object> action = new HashMap<>(8);
|
|
|
|
|
+ action.put("url", callback);
|
|
|
|
|
+ action.put("action_time", System.currentTimeMillis() / 1000);
|
|
|
|
|
+ action.put("action_type", evenType);
|
|
|
|
|
+ Map<Object, Object> trace = new HashMap<>(2);
|
|
|
|
|
+ trace.put("click_id", clickId);
|
|
|
|
|
+ action.put("trace", trace);
|
|
|
|
|
+ actions.add(action);
|
|
|
|
|
+
|
|
|
|
|
+ Map<String, Object> params = new HashMap<>(2);
|
|
|
|
|
+ params.put("user_action_set_id", actionSet.getUserActionSetId());
|
|
|
|
|
+ params.put("account_id", tencentUser.getAccountId());
|
|
|
|
|
+ params.put("actions", actions);
|
|
|
|
|
+
|
|
|
|
|
+ log.info("腾讯广告api回传 参数params:{}", Jsons.toJson(params));
|
|
|
|
|
+ HttpResponse<byte[]> res =
|
|
|
|
|
+ J11HttpC.custom()
|
|
|
|
|
+ .ofPost()
|
|
|
|
|
+ .url(url)
|
|
|
|
|
+ .headers(J11HttpC.ReqType.raw_json)
|
|
|
|
|
+ .body(HttpRequest.BodyPublishers.ofString(Jsons.toJson(params), IoKit.Charsets.UTF_8.getCharset()))
|
|
|
|
|
+ .send(HttpResponse.BodyHandlers.ofByteArray());
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ Map<String, Object> resMap = Jsons.parseObject(res.body(), Map.class);
|
|
|
|
|
+ log.info("腾讯广告api回传:{}", resMap);
|
|
|
|
|
+
|
|
|
|
|
+ String result = StringUtil.getString(resMap.get("code"));
|
|
|
|
|
+ if ("0".equals(result)) {
|
|
|
|
|
+ //修改记录状态
|
|
|
|
|
+ orderPostMapper.updateStatus(orderId);
|
|
|
|
|
+ log.info("回传记录修改状态");
|
|
|
|
|
+
|
|
|
|
|
+ // 判断回传状态
|
|
|
|
|
+ if ("未接入".equals(actionSet.getStatus())) {
|
|
|
|
|
+ actionSet.setStatus("已接入");
|
|
|
|
|
+ tenCentActionSetService.updateById(actionSet);
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ //错误
|
|
|
|
|
+ log.error("腾讯广告回传错误 msg:{}, orderId:{}", StringUtil.getString(resMap.get("message")), orderId);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ //public void postWeChat(Long orderId, String callback, String evenType) throws Exception {
|
|
|
|
|
+ //
|
|
|
|
|
+ // log.info("微信回传入参id:{}", orderId);
|
|
|
|
|
+ // long time = System.currentTimeMillis();
|
|
|
|
|
+ //
|
|
|
|
|
+ // AdvertisementOrderPost orderPost = orderPostMapper.getByOrderId(orderId);
|
|
|
|
|
+ //
|
|
|
|
|
+ // AdvertisementOrderDon orderDon = orderDonMapper.selectById(orderId);
|
|
|
|
|
+ // Long popularizeId = orderDon.getPopularizeId();
|
|
|
|
|
+ // String openId = orderDon.getOpenId();
|
|
|
|
|
+ //
|
|
|
|
|
+ // AdvertisementPopularize popularize = popularizeMapper.selectById(popularizeId);
|
|
|
|
|
+ // String appId;
|
|
|
|
|
+ // String dataId;
|
|
|
|
|
+ //
|
|
|
|
|
+ // String accessToken = weChatService.getAccessToken(appId);
|
|
|
|
|
+ // String url = "https://api.weixin.qq.com/marketing/user_actions/add?version=v1.0&access_token=" + accessToken;
|
|
|
|
|
+ //
|
|
|
|
|
+ // callback = URLDecoder.decode(callback, IoKit.Charsets.UTF_8.getCharset());
|
|
|
|
|
+ //// 兼容性代码
|
|
|
|
|
+ // Map<String, String> paramMap = HttpUtil.decodeParamMap(callback, StandardCharsets.UTF_8);
|
|
|
|
|
+ //
|
|
|
|
|
+ // String clickId = paramMap.get("click_id") != null ? paramMap.get("click_id") : paramMap.get("gdt_vid");
|
|
|
|
|
+ //
|
|
|
|
|
+ // List<Map<String,Object>> actions = new ArrayList<>();
|
|
|
|
|
+ // Map<String,Object> action = new HashMap<>(8);
|
|
|
|
|
+ // action.put("url",callback);
|
|
|
|
|
+ // action.put("action_time", time /1000);
|
|
|
|
|
+ // action.put("action_type",evenType);
|
|
|
|
|
+ //
|
|
|
|
|
+ // Map<Object, Object> trace = new HashMap<>(2);
|
|
|
|
|
+ // trace.put("click_id", clickId);
|
|
|
|
|
+ // action.put("trace", trace);
|
|
|
|
|
+ //
|
|
|
|
|
+ // //测试roi
|
|
|
|
|
+ // if(popularizeId == 416936782416842752L || popularizeId == 421650470746984448L || popularizeId == 436556082228236288L || popularizeId == 451050013800271872L || popularizeId == 454269741779914752L || popularizeId == 435050773403930624L){
|
|
|
|
|
+ // BigDecimal money;
|
|
|
|
|
+ // if(FoundationOrderPost.OrderType.time.getType().equals(orderPost.getOrderType())){
|
|
|
|
|
+ // //次捐
|
|
|
|
|
+ // money = orderDonMapper.selectById(orderId).getMoney();
|
|
|
|
|
+ // }else {
|
|
|
|
|
+ // money = monthlyDonationMapper.selectById(orderId).getMoney();
|
|
|
|
|
+ // }
|
|
|
|
|
+ // Map<Object, Object> actionParam = new HashMap<>(2);
|
|
|
|
|
+ // actionParam.put("value",money);
|
|
|
|
|
+ // action.put("action_param", actionParam);
|
|
|
|
|
+ // }
|
|
|
|
|
+ //
|
|
|
|
|
+ // actions.add(action);
|
|
|
|
|
+ //
|
|
|
|
|
+ // //
|
|
|
|
|
+ // Map<String, Object> params = new HashMap<>(2);
|
|
|
|
|
+ // params.put("user_action_set_id",dataId);
|
|
|
|
|
+ // params.put("actions",actions);
|
|
|
|
|
+ //
|
|
|
|
|
+ // HttpResponse<byte[]> res =
|
|
|
|
|
+ // J11HttpC.custom()
|
|
|
|
|
+ // .ofPost()
|
|
|
|
|
+ // .url(url)
|
|
|
|
|
+ // .headers(J11HttpC.ReqType.raw_json)
|
|
|
|
|
+ // .body(HttpRequest.BodyPublishers.ofString(Jsons.toJson(params), IoKit.Charsets.UTF_8.getCharset()))
|
|
|
|
|
+ // .send(HttpResponse.BodyHandlers.ofByteArray());
|
|
|
|
|
+ //
|
|
|
|
|
+ // Map<String, Object> resMap = Jsons.parseObject(res.body(), Map.class);
|
|
|
|
|
+ // log.info("微信api回传:{}", resMap);
|
|
|
|
|
+ //
|
|
|
|
|
+ // String result = StringUtil.getString(resMap.get("errcode"));
|
|
|
|
|
+ // if ("0".equals(result)) {
|
|
|
|
|
+ // //修改记录状态
|
|
|
|
|
+ // orderPostMapper.updateStatus(orderId);
|
|
|
|
|
+ // log.info("回传记录修改状态");
|
|
|
|
|
+ // }else {
|
|
|
|
|
+ // //错误
|
|
|
|
|
+ // log.error("微信回传错误 msg:{}, orderId:{}",StringUtil.getString(resMap.get("errmsg")),orderId);
|
|
|
|
|
+ // }
|
|
|
|
|
+ //}
|
|
|
|
|
+
|
|
|
|
|
+ @PostConstruct
|
|
|
|
|
+ public void init() {
|
|
|
|
|
+ PostDataFactory.add(this, this.getClass().getSimpleName());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+}
|