袁野 2 months ago
parent 199fcc9f7c
commit 8ed1c9b5b3
  1. 1
      cweb/src/main/java/com/hfkj/config/AuthConfig.java
  2. 81
      cweb/src/main/java/com/hfkj/controller/GoodsController.java
  3. 48
      cweb/src/main/java/com/hfkj/controller/notify/TaoBaoNotify.java
  4. 90
      service/src/main/java/com/hfkj/common/utils/OrderUtil.java
  5. 53
      service/src/main/java/com/hfkj/service/order/BsOrderService.java
  6. 117
      service/src/main/java/com/hfkj/service/order/Impl/BsOrderServiceImpl.java
  7. 59
      service/src/main/java/com/hfkj/service/order/OrderBusinessService.java
  8. 24
      service/src/main/java/com/hfkj/service/pdd/PddService.java
  9. 77
      service/src/main/java/com/hfkj/service/taobao/TaoBaoService.java

@ -95,6 +95,7 @@ public class AuthConfig implements WebMvcConfigurer {
.excludePathPatterns("/client/*")
.excludePathPatterns("/test/*")
.excludePathPatterns("/goods/*")
.excludePathPatterns("/taoBaoNotify/*")
;
}

@ -4,24 +4,27 @@ import com.alibaba.fastjson.JSONObject;
import com.hfkj.common.exception.ErrorCode;
import com.hfkj.common.exception.ErrorHelp;
import com.hfkj.common.exception.SysCode;
import com.hfkj.common.security.UserCenter;
import com.hfkj.common.utils.ResponseMsgUtil;
import com.hfkj.entity.BsOrder;
import com.hfkj.model.*;
import com.hfkj.service.goods.GoodsDataService;
import com.hfkj.service.order.BsOrderService;
import com.hfkj.service.pdd.PddService;
import com.hfkj.service.taobao.TaoBaoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Controller
@RequestMapping(value="/goods")
@ -32,6 +35,11 @@ public class GoodsController {
@Resource
private GoodsDataService goodsDataService;
@Autowired
private UserCenter userCenter;
@Resource
private BsOrderService bsOrderService;
@RequestMapping(value="/goodsList",method = RequestMethod.GET)
@ResponseBody
@ -57,7 +65,7 @@ public class GoodsController {
} else if (type == 2) {
JSONObject object = PddService.authority();
boolean generateAuthorityUrl = object.getJSONObject("authorityQueryResponse").getInteger("bind") == 0;
if (!generateAuthorityUrl && title != null) {
if (generateAuthorityUrl && title != null) {
goodsList = new ArrayList<>();
JSONObject jsonObject = PddService.promotion();
JSONObject promotion = jsonObject.getJSONObject("rpPromotionUrlGenerateResponse").getJSONArray("urlList").getJSONObject(0);
@ -85,6 +93,29 @@ public class GoodsController {
}
}
@RequestMapping(value="/create",method = RequestMethod.POST)
@ResponseBody
@ApiOperation(value = "创建订单")
public ResponseData create(@RequestBody JSONObject jsonObject) {
try {
// 用户session
UserSessionObject userSession = userCenter.getSessionModel(UserSessionObject.class);
if (userSession == null) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.ACCOUNT_LOGIN_NOT, "");
}
jsonObject.put("userId", userSession.getUser().getId());
jsonObject.put("userPhone", userSession.getUser().getPhone());
return ResponseMsgUtil.success(bsOrderService.create(jsonObject));
} catch (Exception e) {
log.error("error!",e);
return ResponseMsgUtil.exception(e);
}
}
@RequestMapping(value="/createCommand",method = RequestMethod.GET)
@ResponseBody
@ApiOperation(value = "淘口令生成")
@ -114,10 +145,14 @@ public class GoodsController {
) {
try {
JSONObject object = PddService.authority();
Map<String , Object> map = new HashMap<>();
map.put("searchId" , searchId);
map.put("goodsSign" , goodsSign);
JSONObject object = PddService.authority("139");
boolean generateAuthorityUrl = object.getJSONObject("authorityQueryResponse").getInteger("bind") == 0;
JSONObject jsonObject = PddService.promotion(searchId , goodsSign , generateAuthorityUrl);
JSONObject jsonObject = PddService.promotion(searchId , goodsSign , generateAuthorityUrl , map.toString());
return ResponseMsgUtil.success(jsonObject.getJSONObject("goodsPromotionUrlGenerateResponse").getJSONArray("goodsPromotionUrlList").getJSONObject(0));
} catch (Exception e) {
@ -125,4 +160,36 @@ public class GoodsController {
return ResponseMsgUtil.exception(e);
}
}
@RequestMapping(value="/publisher",method = RequestMethod.GET)
@ResponseBody
@ApiOperation(value = "淘宝客-公用-私域用户备案")
public ResponseData publisher(@RequestParam(value = "token" , required = false) String token
) {
try {
JSONObject jsonObject = TaoBaoService.publisher(token);
return ResponseMsgUtil.success(jsonObject);
} catch (Exception e) {
log.error("error!",e);
return ResponseMsgUtil.exception(e);
}
}
@RequestMapping(value="/getToken",method = RequestMethod.GET)
@ResponseBody
@ApiOperation(value = "获取Access Token")
public ResponseData getToken(@RequestParam(value = "code" , required = false) String code
) {
try {
JSONObject jsonObject = TaoBaoService.getToken(code);
return ResponseMsgUtil.success(jsonObject);
} catch (Exception e) {
log.error("error!",e);
return ResponseMsgUtil.exception(e);
}
}
}

@ -0,0 +1,48 @@
package com.hfkj.controller.notify;
import com.alibaba.fastjson.JSONObject;
import com.hfkj.service.taobao.TaoBaoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.servlet.http.HttpServletResponse;
import java.io.PrintWriter;
@Controller
@RequestMapping(value = "/taoBaoNotify")
@Api(value = "淘宝业务通知")
public class TaoBaoNotify {
private static Logger log = LoggerFactory.getLogger(TaoBaoService.class);
@RequestMapping(value = "/notify", method = RequestMethod.POST)
@ApiOperation(value = "回调")
@ResponseBody
public void notify(@RequestBody String reqBodyStr, HttpServletResponse response) {
try {
JSONObject dataObject = JSONObject.parseObject(reqBodyStr, JSONObject.class);
log.info("============淘宝回调任务Start=============");
log.info("淘宝-回调参数: " + dataObject);
log.info("============淘宝回调任务End=============");
response.setCharacterEncoding("UTF-8");
response.setContentType("text/html;charset=utf-8");
PrintWriter writer= response.getWriter();
writer.write("SUCCESS");
} catch (Exception e) {
log.error("WechatPayController --> wechatNotify() error!", e);
}
}
}

@ -0,0 +1,90 @@
package com.hfkj.common.utils;
import com.alibaba.fastjson.JSONObject;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.Random;
/**
* 订单工具类
* @className: OrderUtil
* @author: HuRui
* @date: 2022/8/26
**/
public class OrderUtil {
/**
* 生成交易订单号
* @return
* @throws Exception
*/
public static String generateOrderNo(){
try {
// 5位随机数 + 1位线程生成数
String randomNum = (new Random().nextInt(8999) + 1000) + IDGenerator.nextId(1);
// 生成订单号
return DateUtil.date2String(new Date(),"yyyyMMddHHmmss") + randomNum;
} catch (Exception e) {
return null;
}
}
/**
* 生成合同订单订单号
* @return
* @throws Exception
*/
public static String generateContractNo(){
try {
// 5位随机数 + 1位线程生成数
String randomNum = (new Random().nextInt(8999) + 1000) + IDGenerator.nextId(1);
// 生成订单号
return DateUtil.date2String(new Date(),"yyyyMMdd") + randomNum;
} catch (Exception e) {
return null;
}
}
/**
* 生成子订单号
* @return
* @throws Exception
*/
public static String generateChildOrderNo() {
// 生成子订单号
return IDGenerator.nextId(16);
}
/**
* 生成退款订单号
* @return
* @throws Exception
*/
public static String generateRefundOrderNo() throws Exception {
// 5位随机数 + 1位线程生成数
String randomNum = (new Random().nextInt(899999) + 10000) + IDGenerator.nextId(1);
// 生成订单号
return DateUtil.date2String(new Date(),"yyyyMMddHHmmss") + randomNum;
}
/**
* 查询物流单号
* @return
* @throws Exception
*/
public static JSONObject getLogisticsMsg(String num , String mobile) {
String appcode = "f9ace4c915054ca697a76fb9a4e1e8c0";
Map<String, String> headers = new HashMap<>();
headers.put("Authorization", "APPCODE " + appcode);
Map<String, String> querys = new HashMap<>();
querys.put("number", num);
querys.put("mobile", mobile);
return HttpsUtils.doGet("https://express3.market.alicloudapi.com/express3" , querys ,headers);
}
}

@ -0,0 +1,53 @@
package com.hfkj.service.order;
import com.alibaba.fastjson.JSONObject;
import com.hfkj.entity.BsOrder;
/**
* @className: BsOrderService
* @author: HuRui
* @date: 2024/4/29
**/
public interface BsOrderService {
/**
* 编辑数据
* @param order
* @return
*/
BsOrder editData(BsOrder order);
/**
* 更新缓存
* @param order
* @return
*/
BsOrder cache(BsOrder order);
/**
* 删除缓存
* @param orderNo
* @return
*/
void cacheDelete(String orderNo);
/**
* 创建订单
* @param jsonObject 订单
* @return
*/
JSONObject create(JSONObject jsonObject) throws Exception;
/**
* @MethodName findByOrderNo
* @Description: 查询订单
* @param orderNo 订单号
* @return: com.hfkj.entity.BsOrder
* @Author: Sum1Dream
* @Date: 2024/9/24 下午3:08
*/
BsOrder findByOrderNo(String orderNo);
}

@ -0,0 +1,117 @@
package com.hfkj.service.order.Impl;
import com.alibaba.fastjson.JSONObject;
import com.hfkj.common.utils.OrderUtil;
import com.hfkj.common.utils.RedisUtil;
import com.hfkj.dao.BsOrderMapper;
import com.hfkj.entity.BsOrder;
import com.hfkj.entity.BsOrderExample;
import com.hfkj.service.order.BsOrderService;
import com.hfkj.service.order.OrderBusinessService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.annotation.OrderUtils;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Service("bsOrderService")
public class BsOrderServiceImpl implements BsOrderService {
// 缓存前缀KEY
public final static String CACHE_KEY = "ORDER:";
// 订单缓存时间 7天
public final static Integer CACHE_TIME = 60*60*24*7;
@Autowired
private RedisUtil redisUtil;
@Resource
private BsOrderMapper bsOrderMapper;
@Resource
private OrderBusinessService orderBusinessService;
@Override
public BsOrder editData(BsOrder order) {
bsOrderMapper.updateByPrimaryKey(order);
// 删除缓存
cacheDelete(order.getOrderNo());
return order;
}
@Override
public BsOrder cache(BsOrder order) {
// 缓存
redisUtil.set(CACHE_KEY + order.getOrderNo(), order, CACHE_TIME);
return order;
}
@Override
public void cacheDelete(String orderNo) {
// 缓存
redisUtil.del(CACHE_KEY + orderNo);
}
@Override
public JSONObject create(JSONObject body) throws Exception {
BsOrder order = new BsOrder();
order.setOrderNo(OrderUtil.generateOrderNo());
order.setUpdateTime(new Date());
order.setCreateTime(new Date());
order.setStatus(20);
order.setTotalPrice(body.getBigDecimal("totalPrice"));
order.setUserPhone(body.getString("phone"));
order.setUserId(body.getLong("userId"));
Map<String , Object> map = new HashMap<>();
map.put("orderNo", order.getOrderNo());
map.put("uid", order.getUserId());
map.put("searchId", body.getString("searchId"));
map.put("goodsSign", body.getString("goodsSign"));
order.setCustomparameters(map.toString());
order.setGoodsName(body.getString("goodsName"));
order.setType(body.getInteger("type"));
order.setImg(body.getString("img"));
bsOrderMapper.insert(order);
// 淘宝订单业务
if (body.getInteger("type") == 1) {
}
// 拼多多订单业务
if (body.getInteger("type") == 2) {
return orderBusinessService.pddUrl(order);
}
return null;
}
@Override
public BsOrder findByOrderNo(String orderNo) {
Object o = redisUtil.get(CACHE_KEY + orderNo);
// 查询没有缓存的时候
if (o == null) {
BsOrderExample example = new BsOrderExample();
example.createCriteria().andOrderNoEqualTo(orderNo);
List<BsOrder> list = bsOrderMapper.selectByExample(example);
if (list.size() > 0) {
cache(list.get(0));
return list.get(0);
}
return null;
}
return (BsOrder) o;
}
}

@ -0,0 +1,59 @@
package com.hfkj.service.order;
import com.alibaba.fastjson.JSONObject;
import com.hfkj.common.exception.ErrorCode;
import com.hfkj.common.exception.ErrorHelp;
import com.hfkj.common.exception.SysCode;
import com.hfkj.dao.BsOrderMapper;
import com.hfkj.entity.BsOrder;
import com.hfkj.service.pdd.PddService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import java.util.HashMap;
import java.util.Map;
/**
* 创建订单业务
* @className: OrderBusinessService
* @author: HuRui
* @date: 2024/5/7
**/
@Component
public class OrderBusinessService {
Logger log = LoggerFactory.getLogger(OrderBusinessService.class);
// 淘口令生成业务
public JSONObject taobaoUrl(BsOrder bsOrder) {
return null;
}
//多多进宝推广链接生成
public JSONObject pddUrl(BsOrder bsOrder) throws Exception{
JSONObject jsonObject = JSONObject.parseObject(bsOrder.getCustomparameters());
String goodsSign = jsonObject.getString("goodsSign");
String searchId = jsonObject.getString("searchId");
if (searchId == null) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "缺少searchId!");
}
if (goodsSign == null) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "缺少goodsSign!");
}
// 判断是否需要授权
JSONObject object = PddService.authority(bsOrder.getCustomparameters());
boolean generateAuthorityUrl = object.getJSONObject("authorityQueryResponse").getInteger("bind") == 0;
JSONObject o = PddService.promotion(searchId , goodsSign , generateAuthorityUrl , bsOrder.getCustomparameters());
return o.getJSONObject("goodsPromotionUrlGenerateResponse").getJSONArray("goodsPromotionUrlList").getJSONObject(0);
}
}

@ -59,7 +59,7 @@ public class PddService {
* @Author: Sum1Dream
* @Date: 2024/9/13 下午5:08
*/
public static JSONObject promotion(String searchId , String goodsSign , Boolean generateAuthorityUrl) throws Exception {
public static JSONObject promotion(String searchId , String goodsSign , Boolean generateAuthorityUrl , String customParameters) throws Exception {
log.info("============ 拼多多请求-START =============");
String clientId = "71a050c5d93d4169a237539af44c7c33";
@ -72,6 +72,8 @@ public class PddService {
List<String> goodsSignList = new ArrayList<>();
goodsSignList.add(goodsSign);
request.setGoodsSignList(goodsSignList);
request.setCustomParameters(customParameters);
request.setGenerateAuthorityUrl(generateAuthorityUrl);
PddDdkGoodsPromotionUrlGenerateResponse response = client.syncInvoke(request);
@ -120,6 +122,26 @@ public class PddService {
* @Author: Sum1Dream
* @Date: 2024/9/13 下午5:42
*/
public static JSONObject authority(String customParameters) throws Exception {
log.info("============ 拼多多请求-START =============");
String clientId = "71a050c5d93d4169a237539af44c7c33";
String clientSecret = "b96def667dd28660d09f19ba2e9e9f23d810d563";
PopClient client = new PopHttpClient(clientId, clientSecret);
PddDdkMemberAuthorityQueryRequest request = new PddDdkMemberAuthorityQueryRequest();
request.setPid("41483885_294044603");
request.setCustomParameters(customParameters);
PddDdkMemberAuthorityQueryResponse response = client.syncInvoke(request);
log.info("请求接口:" + "authority");
log.info("请求参数:" + JSONObject.toJSONString(request));
log.info("响应参数:" + JsonUtil.transferToJson(response));
log.info("============ 拼多多请求-END ==============");
return JSONObject.parseObject(JSON.toJSONString(response));
}
public static JSONObject authority() throws Exception {
log.info("============ 拼多多请求-START =============");

@ -3,14 +3,24 @@ package com.hfkj.service.taobao;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.hfkj.common.exception.ErrorCode;
import com.hfkj.common.exception.ErrorHelp;
import com.hfkj.common.exception.SysCode;
import com.hfkj.common.utils.ResponseMsgUtil;
import com.hfkj.entity.SecDictionary;
import com.hfkj.model.*;
import com.hfkj.service.sec.SecDictionaryService;
import com.taobao.top.DefaultTopApiClient;
import com.taobao.top.TopApiClient;
import com.taobao.top.ability304.Ability304;
import com.taobao.top.ability304.request.TaobaoTopAuthTokenCreateRequest;
import com.taobao.top.ability304.response.TaobaoTopAuthTokenCreateResponse;
import com.taobao.top.ability375.Ability375;
import com.taobao.top.ability375.request.TaobaoTbkTpwdCreateRequest;
import com.taobao.top.ability375.response.TaobaoTbkTpwdCreateResponse;
import com.taobao.top.ability425.Ability425;
import com.taobao.top.ability425.request.TaobaoTbkScPublisherInfoSaveRequest;
import com.taobao.top.ability425.response.TaobaoTbkScPublisherInfoSaveResponse;
import com.taobao.top.defaultability.Defaultability;
import com.taobao.top.defaultability.domain.TaobaoTbkOptimusTouMaterialIdsGetMaterialQuery;
import com.taobao.top.defaultability.request.TaobaoTbkDgMaterialOptionalUpgradeRequest;
@ -20,10 +30,7 @@ import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
public class TaoBaoService {
@ -110,4 +117,68 @@ public class TaoBaoService {
}
/**
* @MethodName publisher
* @Description: 淘宝客-公用-私域用户备案
* @param token
* @return: com.alibaba.fastjson.JSONObject
* @Author: Sum1Dream
* @Date: 2024/9/23 上午11:40
*/
public static JSONObject publisher(String token) throws Exception {
log.info("============ 淘宝客-公用-私域用户备案-START =============");
TopApiClient client = new DefaultTopApiClient(appKey,appsecret,url);
Ability425 apiPackage = new Ability425(client);
// create domain
// create request
TaobaoTbkScPublisherInfoSaveRequest request = new TaobaoTbkScPublisherInfoSaveRequest();
request.setInviterCode("JIIIVF");
request.setInfoType(1L);
request.setNote("元气");
TaobaoTbkScPublisherInfoSaveResponse response = apiPackage.taobaoTbkScPublisherInfoSave(request,token);
log.info("请求接口:" + "taobaoTbkScPublisherInfoSave");
log.info("请求参数:" + JSONObject.toJSONString(request));
log.info("响应参数:" + response);
log.info("============ 淘宝客-公用-私域用户备案--END ==============");
if(!response.isSuccess()){
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, response.getSubMsg());
}
return JSONObject.parseObject(JSON.toJSONString(response));
}
/**
* @MethodName getToken
* @Description:获取Access Token
* @param code
* @return: com.alibaba.fastjson.JSONObject
* @Author: Sum1Dream
* @Date: 2024/9/23 上午11:57
*/
public static JSONObject getToken(String code) throws Exception {
log.info("============ 获取Access Token-START =============");
TopApiClient client = new DefaultTopApiClient(appKey,appsecret,url);
Ability304 apiPackage = new Ability304(client);
// create domain
// create request
TaobaoTopAuthTokenCreateRequest request = new TaobaoTopAuthTokenCreateRequest();
request.setCode(code);
TaobaoTopAuthTokenCreateResponse response = apiPackage.taobaoTopAuthTokenCreate(request);
log.info("请求接口:" + "taobaoTopAuthTokenCreate");
log.info("请求参数:" + JSONObject.toJSONString(request));
log.info("响应参数:" + response);
log.info("============ 获取Access Token--END ==============");
if(!response.isSuccess()){
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, response.getSubMsg());
}
return JSONObject.parseObject(JSON.toJSONString(response));
}
}

Loading…
Cancel
Save