diff --git a/bweb/src/main/java/com/bweb/controller/TestController.java b/bweb/src/main/java/com/bweb/controller/TestController.java index b8603aa..8ea4479 100644 --- a/bweb/src/main/java/com/bweb/controller/TestController.java +++ b/bweb/src/main/java/com/bweb/controller/TestController.java @@ -6,21 +6,19 @@ import com.hfkj.common.exception.SysCode; import com.hfkj.common.utils.*; import com.hfkj.config.CommonSysConst; -import com.hfkj.entity.BsMerPayConfig; -import com.hfkj.entity.BsOrder; -import com.hfkj.entity.BsUserCard; +import com.hfkj.jd.JdPostService; import com.hfkj.jd.JdService; import com.hfkj.mer.BsMerPayConfigService; import com.hfkj.model.ResponseData; -import com.hfkj.model.order.OrderModel; -import com.hfkj.qianzhu.CinemaService; import com.hfkj.service.card.BsUserCardService; import com.hfkj.service.hlt.HuiLianTongUnionCardService; import com.hfkj.service.order.BsOrderService; import com.hfkj.service.order.OrderPayService; import com.hfkj.service.pay.huift.TradeService; -import com.hfkj.sysenum.mer.PayPlatformEnum; +import com.jd.open.api.sdk.domain.vopsp.CategoryInfoGoodsProvider.response.getCategoryInfoList.GetCategoryInfoGoodsResp; +import com.jd.open.api.sdk.domain.vopsp.SkuInfoGoodsProvider.response.getSkuDetailInfo.GetSkuPoolInfoGoodsResp; +import com.jd.open.api.sdk.response.vopdz.VopAddressConvertFourAreaByDetailStrResponse; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.apache.commons.lang3.StringUtils; @@ -42,14 +40,10 @@ public class TestController { private static Logger log = LoggerFactory.getLogger(TestController.class); @Resource private TradeService huiftTradeService; + @Resource - private BsOrderService orderService; - @Resource - private BsMerPayConfigService merPayConfigService; - @Resource - private OrderPayService orderPayService; - @Resource - private BsUserCardService userCardService; + private JdService jdService; + @RequestMapping(value="/thirdPayResult",method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "查询V家园订单交易状态") @@ -118,13 +112,98 @@ public class TestController { } } - @RequestMapping(value="/getAccessToken",method = RequestMethod.GET) + @RequestMapping(value="/getSkuPoolInfo",method = RequestMethod.GET) + @ResponseBody + @ApiOperation(value = "getSkuPoolInfo") + public ResponseData getSkuPoolInfo() { + try { + + return ResponseMsgUtil.success(JdPostService.getSkuPoolInfo(jdService.getToken())); + + } catch (Exception e) { + log.error("error!",e); + return ResponseMsgUtil.exception(e); + } + } + + @RequestMapping(value="/querySkuByPage",method = RequestMethod.GET) + @ResponseBody + @ApiOperation(value = "querySkuByPage") + public ResponseData querySkuByPage() { + try { + + return ResponseMsgUtil.success(JdPostService.querySkuByPage(jdService.getToken() , "7028" , 0).getOpenRpcResult().getResult().getSkus()); + + } catch (Exception e) { + log.error("error!",e); + return ResponseMsgUtil.exception(e); + } + } + + @RequestMapping(value="/getSkuDetailInfo",method = RequestMethod.GET) + @ResponseBody + @ApiOperation(value = "getSkuDetailInfo") + public ResponseData getSkuDetailInfo() { + try { + + GetSkuPoolInfoGoodsResp detail = JdPostService.getSkuDetailInfo(jdService.getToken() , 1235014L).getOpenRpcResult().getResult(); + return ResponseMsgUtil.success(detail); + + } catch (Exception e) { + log.error("error!",e); + return ResponseMsgUtil.exception(e); + } + } + + @RequestMapping(value="/getSkuImageList",method = RequestMethod.GET) + @ResponseBody + @ApiOperation(value = "getSkuImageList") + public ResponseData getSkuImageList() { + try { + + return ResponseMsgUtil.success(JdPostService.getSkuImageList(jdService.getToken() , "1235014")); + + } catch (Exception e) { + log.error("error!",e); + return ResponseMsgUtil.exception(e); + } + } + + @RequestMapping(value="/getSellPrice",method = RequestMethod.GET) @ResponseBody - @ApiOperation(value = "getAccessToken") - public ResponseData getAccessToken() { + @ApiOperation(value = "批量查询商品售卖价") + public ResponseData getSellPrice() { try { - return ResponseMsgUtil.success(JdService.getAccessToken()); + return ResponseMsgUtil.success(JdPostService.getSellPrice(jdService.getToken() , "1235014")); + + } catch (Exception e) { + log.error("error!",e); + return ResponseMsgUtil.exception(e); + } + } + + @RequestMapping(value="/getCategoryInfoList",method = RequestMethod.GET) + @ResponseBody + @ApiOperation(value = "获取分类") + public ResponseData getCategoryInfoList() { + try { + + return ResponseMsgUtil.success(JdPostService.getCategoryInfoList(jdService.getToken() , "1235014")); + + } catch (Exception e) { + log.error("error!",e); + return ResponseMsgUtil.exception(e); + } + } + + @RequestMapping(value="/getGoodsJd",method = RequestMethod.GET) + @ResponseBody + @ApiOperation(value = "更新商品") + public ResponseData getGoodsJd() { + try { + jdService.getGoodsJd(); + return ResponseMsgUtil.success(""); } catch (Exception e) { log.error("error!",e); @@ -132,4 +211,22 @@ public class TestController { } } + + + @RequestMapping(value="/convertFourAreaByDetailStr",method = RequestMethod.GET) + @ResponseBody + @ApiOperation(value = "地址详情转换京东地址编码") + public ResponseData convertFourAreaByDetailStr(@RequestParam(value = "address", required = false) String address + ) { + try { + + VopAddressConvertFourAreaByDetailStrResponse response = JdPostService.convertFourAreaByDetailStr(jdService.getToken() , address); + + return ResponseMsgUtil.success(response.getOpenRpcResult().getResult()); + + } catch (Exception e) { + log.error("error!",e); + return ResponseMsgUtil.exception(e); + } + } } diff --git a/cweb/lib/open-api-sdk-2.0-jd.jar b/cweb/lib/open-api-sdk-2.0-jd.jar new file mode 100644 index 0000000..6c1b46c Binary files /dev/null and b/cweb/lib/open-api-sdk-2.0-jd.jar differ diff --git a/cweb/pom.xml b/cweb/pom.xml index c7a574c..416d520 100644 --- a/cweb/pom.xml +++ b/cweb/pom.xml @@ -31,6 +31,13 @@ 1.0.21 ${basedir}/lib/open-platform-sdk-1.0.21.jar + + jd.skd + jd-open-sdk + system + 2.0 + ${basedir}/lib/open-api-sdk-2.0-jd.jar + diff --git a/cweb/src/main/java/com/cweb/controller/goods/DeliveryAddressController.java b/cweb/src/main/java/com/cweb/controller/goods/DeliveryAddressController.java index d63deee..72854c1 100644 --- a/cweb/src/main/java/com/cweb/controller/goods/DeliveryAddressController.java +++ b/cweb/src/main/java/com/cweb/controller/goods/DeliveryAddressController.java @@ -6,10 +6,13 @@ import com.hfkj.common.exception.SysCode; import com.hfkj.common.security.UserCenter; import com.hfkj.common.utils.ResponseMsgUtil; import com.hfkj.entity.GoodsUserAddress; +import com.hfkj.jd.JdPostService; +import com.hfkj.jd.JdService; import com.hfkj.model.ResponseData; import com.hfkj.model.UserSessionObject; import com.hfkj.service.goods.GoodsUserAddressService; import com.hfkj.service.goods.impl.GoodsUserAddressServiceImpl; +import com.jd.open.api.sdk.response.vopdz.VopAddressConvertFourAreaByDetailStrResponse; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.slf4j.Logger; @@ -34,6 +37,9 @@ public class DeliveryAddressController { @Resource private GoodsUserAddressServiceImpl goodsUserAddressService; + @Resource + private JdService jdService; + @RequestMapping(value = "/getDeliveryAddressList", method = RequestMethod.GET) @ResponseBody @@ -71,7 +77,7 @@ public class DeliveryAddressController { map.put("userId", userSession.getUser().getId()); List list = deliveryAddressService.getList(map); - if (list.size() == 0) { + if (list.isEmpty()) { deliveryAddress.setWhetherDefault(true); } @@ -80,12 +86,22 @@ public class DeliveryAddressController { deliveryAddress.getWhetherDefault() == null || deliveryAddress.getConsignee() == null || deliveryAddress.getPhone() == null || - deliveryAddress.getRegionName() == null || - deliveryAddress.getRegionId() == null + deliveryAddress.getRegionName() == null ) { throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); } + VopAddressConvertFourAreaByDetailStrResponse response = JdPostService.convertFourAreaByDetailStr(jdService.getToken() , deliveryAddress.getRegionName() + deliveryAddress.getAddress()); + + // 判断response是否为空,并且response的OpenRpcResult的success属性是否为true + if (response != null && response.getOpenRpcResult().getSuccess()) { + deliveryAddress.setProvinceId(response.getOpenRpcResult().getResult().getProvinceId()); + deliveryAddress.setCityId(response.getOpenRpcResult().getResult().getCityId()); + deliveryAddress.setCountyId(response.getOpenRpcResult().getResult().getCountyId()); + deliveryAddress.setTownId(response.getOpenRpcResult().getResult().getTownId()); + } + + deliveryAddress.setUserId(userSession.getUser().getId()); deliveryAddress.setCreateTime(new Date()); deliveryAddress.setUpdateTime(new Date()); @@ -114,8 +130,7 @@ public class DeliveryAddressController { deliveryAddress.getWhetherDefault() == null || deliveryAddress.getConsignee() == null || deliveryAddress.getPhone() == null || - deliveryAddress.getRegionName() == null || - deliveryAddress.getRegionId() == null + deliveryAddress.getRegionName() == null ) { log.error("GoodsDetailController -> insertProduct() error!"); throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); @@ -132,6 +147,19 @@ public class DeliveryAddressController { throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "当前收货地址异常!"); } + VopAddressConvertFourAreaByDetailStrResponse response = JdPostService.convertFourAreaByDetailStr(jdService.getToken() , deliveryAddress.getRegionName() + deliveryAddress.getAddress()); + + if (response != null && response.getOpenRpcResult().getSuccess()) { + deliveryAddress.setProvinceId(response.getOpenRpcResult().getResult().getProvinceId()); + deliveryAddress.setProvinceName(response.getOpenRpcResult().getResult().getProvinceName()); + deliveryAddress.setCityId(response.getOpenRpcResult().getResult().getCityId()); + deliveryAddress.setCityName(response.getOpenRpcResult().getResult().getCityName()); + deliveryAddress.setCountyId(response.getOpenRpcResult().getResult().getCountyId()); + deliveryAddress.setCountyName(response.getOpenRpcResult().getResult().getCountyName()); + deliveryAddress.setTownId(response.getOpenRpcResult().getResult().getTownId()); + deliveryAddress.setTownName(response.getOpenRpcResult().getResult().getTownName()); + } + deliveryAddress.setUserId(userSession.getUser().getId()); deliveryAddress.setCreateTime(goodsDeliveryAddress.getCreateTime()); deliveryAddress.setUpdateTime(new Date()); diff --git a/cweb/src/main/java/com/cweb/controller/goods/ShoppingCartController.java b/cweb/src/main/java/com/cweb/controller/goods/ShoppingCartController.java index 5baf924..a444865 100644 --- a/cweb/src/main/java/com/cweb/controller/goods/ShoppingCartController.java +++ b/cweb/src/main/java/com/cweb/controller/goods/ShoppingCartController.java @@ -125,6 +125,7 @@ public class ShoppingCartController { shoppingCart.setSpecsName(specs.getName()); shoppingCart.setLoseEfficacy(false); shoppingCart.setMerId(goodsMsg.getMerId()); + shoppingCart.setSource(goodsMsg.getChildType()); shoppingCart.setMerName(goodsMsg.getMerName()); shoppingCart.setWhetherCheck(true); shoppingCart.setStatus(1); diff --git a/cweb/src/main/java/com/cweb/controller/jd/JdController.java b/cweb/src/main/java/com/cweb/controller/jd/JdController.java new file mode 100644 index 0000000..9b15f04 --- /dev/null +++ b/cweb/src/main/java/com/cweb/controller/jd/JdController.java @@ -0,0 +1,97 @@ +package com.cweb.controller.jd; + +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.jd.JdPostService; +import com.hfkj.jd.JdService; +import com.hfkj.model.ResponseData; + +import com.jd.open.api.sdk.response.vopdz.VopAddressConvertFourAreaByDetailStrResponse; +import com.jd.open.api.sdk.response.vopdz.VopAddressQueryJdAreaIdListResponse; +import com.jd.open.api.sdk.response.vopdz.VopAddressVerifyAreaFourIdOpenReqResponse; +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.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.ResponseBody; + +import javax.annotation.Resource; + + +@Controller +@RequestMapping(value="/jd") +@Api(value="京东") +public class JdController { + + Logger log = LoggerFactory.getLogger(JdController.class); + + @Resource + private JdService jdService; + + @RequestMapping(value="/queryJdAreaIdList",method = RequestMethod.GET) + @ResponseBody + @ApiOperation(value = "查询四级地址ID列表") + public ResponseData queryJdAreaIdList(@RequestParam(value = "areaLevel", required = false) Integer areaLevel, + @RequestParam(value = "areaId", required = false) Long areaId + ) { + try { + + VopAddressQueryJdAreaIdListResponse response = JdPostService.queryJdAreaIdList(jdService.getToken() , areaLevel , areaId); + + if (!response.getOpenRpcResult().getSuccess()) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未查询到任何信息!"); + } + + return ResponseMsgUtil.success(response.getOpenRpcResult().getResult().getAreaInfoList()); + + } catch (Exception e) { + log.error("error!",e); + return ResponseMsgUtil.exception(e); + } + } + + @RequestMapping(value="/verifyAreaFourIdOpenReq",method = RequestMethod.GET) + @ResponseBody + @ApiOperation(value = "验证四级地址ID有效性") + public ResponseData verifyAreaFourIdOpenReq(@RequestParam(value = "provinceId", required = false) Long provinceId, + @RequestParam(value = "cityId", required = false) Long cityId, + @RequestParam(value = "countyId", required = false) Long countyId, + @RequestParam(value = "townId", required = false) Long townId + ) { + try { + + VopAddressVerifyAreaFourIdOpenReqResponse response = JdPostService.verifyAreaFourIdOpenReq(jdService.getToken() , provinceId , cityId , countyId , townId); + + return ResponseMsgUtil.success(response.getOpenRpcResult().getSuccess()); + + } catch (Exception e) { + log.error("error!",e); + return ResponseMsgUtil.exception(e); + } + } + + @RequestMapping(value="/convertFourAreaByDetailStr",method = RequestMethod.GET) + @ResponseBody + @ApiOperation(value = "地址详情转换京东地址编码") + public ResponseData convertFourAreaByDetailStr(@RequestParam(value = "address", required = false) String address + ) { + try { + + VopAddressConvertFourAreaByDetailStrResponse response = JdPostService.convertFourAreaByDetailStr(jdService.getToken() , address); + + return ResponseMsgUtil.success(response.getOpenRpcResult().getResult()); + + } catch (Exception e) { + log.error("error!",e); + return ResponseMsgUtil.exception(e); + } + } + +} diff --git a/order/src/main/java/com/order/controller/OrderPayController.java b/order/src/main/java/com/order/controller/OrderPayController.java index 208b579..a3a364d 100644 --- a/order/src/main/java/com/order/controller/OrderPayController.java +++ b/order/src/main/java/com/order/controller/OrderPayController.java @@ -7,16 +7,14 @@ import com.hfkj.common.exception.SysCode; import com.hfkj.common.security.UserCenter; import com.hfkj.common.utils.ResponseMsgUtil; import com.hfkj.config.CommonSysConst; -import com.hfkj.entity.BsMerPayConfig; -import com.hfkj.entity.BsOrderOutside; -import com.hfkj.entity.BsUserCard; -import com.hfkj.entity.BsUserLoginLog; +import com.hfkj.entity.*; import com.hfkj.mer.BsMerPayConfigService; import com.hfkj.model.ResponseData; import com.hfkj.model.UserSessionObject; import com.hfkj.model.order.OrderChildModel; import com.hfkj.model.order.OrderModel; import com.hfkj.service.card.BsUserCardService; +import com.hfkj.service.goods.GoodsVpdService; import com.hfkj.service.order.BsOrderChildService; import com.hfkj.service.order.BsOrderOutsideService; import com.hfkj.service.order.BsOrderService; @@ -71,12 +69,8 @@ public class OrderPayController { private TradeService huiftTradeService; @Resource private BsMerPayConfigService merPayConfigService; - - @Resource - private BsOrderOutsideService bsOrderOutsideService; - @Resource - private BsUserLoginLogService bsUserLoginLogService; + private GoodsVpdService goodsVpdService; @RequestMapping(value="/wechat",method = RequestMethod.POST) @ResponseBody @@ -204,6 +198,19 @@ public class OrderPayController { signSecret = HuiftConfig.signSecret95; } + if (order.getOrderChildList().get(0).getProductSpecId() != null) { + GoodsVpd goodsVpd = goodsVpdService.queryDetailBySpecsId(order.getOrderChildList().get(0).getProductSpecId()); + + if (goodsVpd != null) { + if (goodsVpd.getSource().equals(9)) { + shopCode = HuiftConfig.shopcode01; + signSecret = HuiftConfig.signSecret01; + } + } + } + + + // 请求支付渠道 JSONObject thirdPreOrder = huiftTradeService.thirdPreOrder(order , shopCode , signSecret); for (OrderChildModel orderChild : order.getOrderChildList()) { diff --git a/order/src/main/java/com/order/controller/notify/JdNotify.java b/order/src/main/java/com/order/controller/notify/JdNotify.java index 061f66c..41cd47b 100644 --- a/order/src/main/java/com/order/controller/notify/JdNotify.java +++ b/order/src/main/java/com/order/controller/notify/JdNotify.java @@ -2,12 +2,14 @@ package com.order.controller.notify; import com.alibaba.fastjson.JSONObject; import com.hfkj.common.utils.HttpsUtils; +import com.hfkj.common.utils.RedisUtil; import com.hfkj.config.CommonSysConst; -import com.hfkj.jd.JdService; +import com.hfkj.jd.JdPostService; 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.*; @@ -19,31 +21,11 @@ import java.io.PrintWriter; @RequestMapping(value = "/jdNotify") @Api(value = "京东回调") public class JdNotify { - private static final Logger log = LoggerFactory.getLogger(JdService.class); + private static final Logger log = LoggerFactory.getLogger(JdPostService.class); - @RequestMapping(value = "/notify", method = RequestMethod.POST) - @ApiOperation(value = "回调") - @ResponseBody - public void notify(@RequestBody String reqBodyStr, HttpServletRequest request, 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); - } - } + @Autowired + private RedisUtil redisUtil; @RequestMapping(value = "/callbackToken", method = RequestMethod.GET) @ApiOperation(value = "token回调") @@ -52,14 +34,16 @@ public class JdNotify { try { log.info("============token回调任务Start============="); - log.info("token回调-回调参数: " + code); + log.info("token回调 code-回调参数: " + code); JSONObject object = new JSONObject(); object.put("app_key", CommonSysConst.getSysConfig().getJDAppKey()); object.put("app_secret", CommonSysConst.getSysConfig().getJDAppSecret()); object.put("code", code); object.put("grant_type", "authorization_code"); - JSONObject jsonObject = HttpsUtils.doGet("https://open-oauth.jd.com/oauth2/authorizeForVOP", object); - log.info("token回调-回调参数: " + jsonObject); + JSONObject jsonObject = HttpsUtils.doGet("https://open-oauth.jd.com/oauth2/access_token", object); + log.info("token回调 jsonObject-回调参数: " + jsonObject); + log.info("token回调 access_token-回调参数: " + jsonObject.getString("access_token")); + redisUtil.set("access_token", jsonObject.getString("access_token") , jsonObject.getInteger("expires_in") - 10000); log.info("============token回调任务End============="); } catch (Exception e) { diff --git a/order/src/main/java/com/order/controller/notify/MeiTuanController.java b/order/src/main/java/com/order/controller/notify/MeiTuanController.java index bb881d0..8a0da23 100644 --- a/order/src/main/java/com/order/controller/notify/MeiTuanController.java +++ b/order/src/main/java/com/order/controller/notify/MeiTuanController.java @@ -275,7 +275,20 @@ public class MeiTuanController { BsOrderMeituan orderMeiTuan = bsOrderMeiTuanService.findOrderMeiTuanBySqtBizOrderId(object.getString("sqtBizOrderId")); if (orderMeiTuan != null) { - bsOrderMeiTuanService.orderFinish(orderMeiTuan.getChildOrderNo()); + if (object.getInteger("changeType").equals(10)) { + if (object.getString("firstBusinessType").equals("020")) { + if (object.getString("changeStatus").equals("9")) { + bsOrderMeiTuanService.orderFinish(orderMeiTuan.getChildOrderNo()); + } + } + if (object.getString("firstBusinessType").equals("010")) { + if (object.getString("changeStatus").equals("10")) { + bsOrderMeiTuanService.orderFinish(orderMeiTuan.getChildOrderNo()); + } + } + } + + } JSONObject data = new JSONObject(); data.put("status", 0); diff --git a/order/src/main/resources/dev/logback.xml b/order/src/main/resources/dev/logback.xml index 63b61cb..160c7e6 100644 --- a/order/src/main/resources/dev/logback.xml +++ b/order/src/main/resources/dev/logback.xml @@ -329,7 +329,7 @@ UTF-8 - + diff --git a/service/src/main/java/com/hfkj/entity/GoodsUserAddressWithBLOBs.java b/service/src/main/java/com/hfkj/entity/GoodsUserAddressWithBLOBs.java deleted file mode 100644 index d336c93..0000000 --- a/service/src/main/java/com/hfkj/entity/GoodsUserAddressWithBLOBs.java +++ /dev/null @@ -1,63 +0,0 @@ -package com.hfkj.entity; - -import java.io.Serializable; - -/** - * goods_user_address - * @author - */ -public class GoodsUserAddressWithBLOBs extends GoodsUserAddress implements Serializable { - /** - * 一级地址编号 - */ - private String provinceId; - - /** - * 二级地址编号 - */ - private String cityId; - - /** - * 三级地址编号 - */ - private String countyId; - - /** - * 四级地址编号 - */ - private String townId; - - private static final long serialVersionUID = 1L; - - public String getProvinceId() { - return provinceId; - } - - public void setProvinceId(String provinceId) { - this.provinceId = provinceId; - } - - public String getCityId() { - return cityId; - } - - public void setCityId(String cityId) { - this.cityId = cityId; - } - - public String getCountyId() { - return countyId; - } - - public void setCountyId(String countyId) { - this.countyId = countyId; - } - - public String getTownId() { - return townId; - } - - public void setTownId(String townId) { - this.townId = townId; - } -} \ No newline at end of file diff --git a/service/src/main/java/com/hfkj/jd/Impl/JdServiceImpl.java b/service/src/main/java/com/hfkj/jd/Impl/JdServiceImpl.java new file mode 100644 index 0000000..1300d10 --- /dev/null +++ b/service/src/main/java/com/hfkj/jd/Impl/JdServiceImpl.java @@ -0,0 +1,292 @@ +package com.hfkj.jd.Impl; + +import com.hfkj.common.utils.RedisUtil; +import com.hfkj.entity.*; +import com.hfkj.jd.JdPostService; +import com.hfkj.jd.JdService; +import com.hfkj.service.BsMerService; +import com.hfkj.service.BsProductConfigService; +import com.hfkj.service.goods.*; +import com.hfkj.sysenum.order.OrderChildProductTypeEnum; +import com.jd.open.api.sdk.domain.vopsp.SkuInfoGoodsProvider.response.getSellPrice.GetSellPriceGoodsResp; +import com.jd.open.api.sdk.domain.vopsp.SkuInfoGoodsProvider.response.getSellPrice.OpenRpcResult; +import com.jd.open.api.sdk.domain.vopsp.SkuInfoGoodsProvider.response.getSkuDetailInfo.GetSkuPoolInfoGoodsResp; +import com.jd.open.api.sdk.domain.vopsp.SkuInfoGoodsProvider.response.getSkuImageList.GetSkuImageGoodsResp; +import com.jd.open.api.sdk.domain.vopsp.SkuInfoGoodsProvider.response.getSkuImageList.SkuImageItemGoodsResp; +import com.jd.open.api.sdk.domain.vopsp.SkuPoolGoodsProvider.response.getSkuPoolInfo.GetSkuPoolInfoItemGoodsResp; +import com.jd.open.api.sdk.response.vopsp.VopGoodsGetSkuDetailInfoResponse; +import com.jd.open.api.sdk.response.vopsp.VopGoodsGetSkuImageListResponse; +import com.jd.open.api.sdk.response.vopsp.VopGoodsGetSkuPoolInfoResponse; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.math.BigDecimal; +import java.math.RoundingMode; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + + +@Service("jdService") +public class JdServiceImpl implements JdService { + + @Autowired + private RedisUtil redisUtil; + + @Resource + private BsMerService bsMerService; + + @Resource + private GoodsTypeService goodsTypeService; + + @Resource + private GoodsBrandService goodsBrandService; + + @Resource + private BsProductConfigService productConfigService; + + @Resource + private GoodsMsgService goodsMsgService; + + @Resource + private GoodsSpecsService goodsSpecsService; + + @Override + public String getToken() throws Exception { + Object token = redisUtil.get("access_token"); + + if (token == null) { + // 请求回调 会在回调存入参数 + JdPostService.getAccessToken(); + getToken(); + } + + return token.toString(); + } + + @Override + public void getGoodsJd() throws Exception { + // 获取京东商品池 + VopGoodsGetSkuPoolInfoResponse sku = JdPostService.getSkuPoolInfo(getToken()); + // 获取sku列表 + List skuList = sku.getOpenRpcResult().getResult().getSkuPoolList(); + + // 初始化商品信息 + GoodsMsg goodsMsg; + // 初始化商品规格 + GoodsSpecs goodsSpecs; + + BsMer bsMer = bsMerService.getDetail("166241009282"); + // 查询分类 + List goodsType = goodsTypeService.getList(new HashMap<>()); + List brands = goodsBrandService.getList(new HashMap<>()); + Map goodsMap = new HashMap<>(); + goodsMap.put("type", 3); + List goodsMsgs = goodsMsgService.getList(goodsMap); + List goodsSpecsList = goodsSpecsService.getList(new HashMap<>()); + BsProductConfig productConfig = productConfigService.queryDetail(OrderChildProductTypeEnum.type6.getCode()); + + for (GetSkuPoolInfoItemGoodsResp skuPoolInfoItemGoodsResp : skuList) { + + // 根据sku查询商品 + List skuIdList = JdPostService.querySkuByPage(getToken(), skuPoolInfoItemGoodsResp.getBizPoolId(), 0).getOpenRpcResult().getResult().getSkus(); + for (Long aLong : skuIdList) { + + // 根据skuId 查询商品详情 + VopGoodsGetSkuDetailInfoResponse skuDetail = JdPostService.getSkuDetailInfo(getToken(), aLong); + GetSkuPoolInfoGoodsResp detail = skuDetail.getOpenRpcResult().getResult(); + if (detail != null) { + // 根据skuId 查询商品售价 + OpenRpcResult priceResponse = JdPostService.getSellPrice(getToken(), String.valueOf(aLong)).getOpenRpcResult(); + if (priceResponse.getSuccess()) { + GetSellPriceGoodsResp price = priceResponse.getResult().get(0); + // 根据skuId 查询商品图片 + + com.jd.open.api.sdk.domain.vopsp.SkuInfoGoodsProvider.response.getSkuImageList.OpenRpcResult imageListResponse = JdPostService.getSkuImageList(getToken(), String.valueOf(aLong)).getOpenRpcResult(); + if (imageListResponse.getSuccess()) { + GetSkuImageGoodsResp img = imageListResponse.getResult().get(0); + // 查询分类 + String[] categoryS = detail.getCategory().split(";"); + + // 查询一级分类 + String category1 = JdPostService.getCategoryInfoList(getToken(), categoryS[0]).getOpenRpcResult().getResult().get(0).getCategoryName(); + // 查询二级分类 + String category2 = JdPostService.getCategoryInfoList(getToken(), categoryS[1]).getOpenRpcResult().getResult().get(0).getCategoryName(); + + GoodsType goodsType1 = goodsType.stream().filter(s -> s.getTitle().equals(category1)).findFirst().orElse(null); + GoodsType goodsType2 = goodsType.stream().filter(s -> s.getTitle().equals(category2)).findFirst().orElse(null); + + // 如果goodsType1为null,则创建一个新的GoodsType对象 + if (goodsType1 == null) { + goodsType1 = new GoodsType(); + // 设置title为category1 + goodsType1.setTitle(category1); + // 设置status为1 + goodsType1.setStatus(1); + goodsType1.setBusinessType(1); + // 设置sort为8 + goodsType1.setSort(8); + // 设置createTime为当前时间 + goodsType1.setCreateTime(new Date()); + // 设置updateTime为当前时间 + goodsType1.setUpdateTime(new Date()); + // 调用goodsTypeService的create方法,将goodsType1对象保存到数据库中 + goodsTypeService.create(goodsType1); + goodsType.add(goodsType1); + } + if (goodsType2 == null) { + goodsType2 = new GoodsType(); + // 设置title为category2 + goodsType2.setTitle(category2); + goodsType2.setParentId(goodsType1.getId()); + // 设置status为1 + goodsType2.setStatus(1); + // 设置businessType为1 + goodsType2.setBusinessType(1); + // 设置sort为8 + goodsType2.setSort(1); + // 设置createTime为当前时间 + goodsType2.setCreateTime(new Date()); + // 设置updateTime为当前时间 + goodsType2.setUpdateTime(new Date()); + // 调用goodsTypeService的create方法,将goodsType2对象保存到数据库中 + goodsTypeService.create(goodsType2); + goodsType.add(goodsType2); + } else { + goodsType2.setParentId(goodsType1.getId()); + goodsType2.setUpdateTime(new Date()); + goodsTypeService.update(goodsType2); + } + // 从brands中筛选出title等于detail.getBrandName()的元素,并返回第一个元素,如果没有找到则返回null + GoodsBrand goodsBrand = brands.stream().filter(s -> s.getTitle().equals(detail.getBrandName())).findFirst().orElse(null); + // 如果goodsBrand为null,则创建一个新的GoodsBrand对象 + if (goodsBrand == null) { + goodsBrand = new GoodsBrand(); + // 设置title为detail.getBrandName() + goodsBrand.setTitle(detail.getBrandName()); + // 设置status为1 + goodsBrand.setStatus(1); + // 设置createTime为当前时间 + goodsBrand.setCreateTime(new Date()); + // 设置updateTime为当前时间 + goodsBrand.setUpdateTime(new Date()); + // 调用goodsBrandService的create方法,将goodsBrand对象保存到数据库中 + goodsBrandService.create(goodsBrand); + brands.add(goodsBrand); + } + + // 创建一个GoodsMsg对象 + goodsMsg = new GoodsMsg(); + // 设置更新时间为当前时间 + goodsMsg.setUpdateTime(new Date()); + // 设置商家ID为bsMer的ID + goodsMsg.setMerId(bsMer.getId()); + // 设置商家名称为bsMer的名称 + goodsMsg.setMerName(bsMer.getMerName()); + // 设置商品名称为detail.getGoodsName() + goodsMsg.setTitle(detail.getSkuName()); + // 设置商品类型为3 + goodsMsg.setType(1); + // 设置商品状态为1 + goodsMsg.setStatus(1); + // 设置商品子类型为1 + goodsMsg.setChildType(1); + // 设置商品品牌ID + goodsMsg.setGoodsBrand(goodsBrand.getId()); + // 设置商品品牌名称 + goodsMsg.setGoodsBrandName(goodsBrand.getTitle()); + // 设置商品类型ID + goodsMsg.setGoodsType(goodsType2.getId()); + // 设置商品类型名称 + goodsMsg.setGoodsTypeName(goodsType2.getTitle()); + // 设置商品类型父级ID + goodsMsg.setGoodsTypeParent(goodsType1.getId()); + // 设置商品类型父级名称 + goodsMsg.setGoodsTypeParentName(goodsType1.getTitle()); + goodsMsg.setThirdId(aLong.toString()); + StringBuilder imgS = new StringBuilder(); + // 遍历商品图片列表 + for (SkuImageItemGoodsResp skuImage : img.getSkuImageList()) { + // 如果图片是主图 + if (skuImage.getIsPrimary() == 1) { + // 设置主图 + goodsMsg.setListImg("https://img13.360buyimg.com/n1/" + skuImage.getShortPath()); + } + // 如果图片不是主图 + if (skuImage.getIsPrimary() == 0) { + + imgS.append("https://img13.360buyimg.com/n1/").append(skuImage.getShortPath()).append(","); + + } + } + + if (imgS.length() > 0) { + imgS.deleteCharAt(imgS.length() - 1); + } + + // 设置轮播图 + goodsMsg.setBannerImg(String.valueOf(imgS)); + // 设置详情图 + goodsMsg.setDetailImg(String.valueOf(imgS)); + GoodsMsg msg = goodsMsgs.stream().filter(s -> s.getThirdId().equals(aLong.toString())).findFirst().orElse(null); + + if (msg != null) { + goodsMsg.setId(msg.getId()); + // 更新商品信息 + goodsMsgService.update(goodsMsg); + } else { + // 设置销售数量为0 + goodsMsg.setSaleNum(0); + goodsMsg.setCreateTime(new Date()); + // 创建商品信息 + goodsMsgService.create(goodsMsg); + + } + + // 创建商品规格 + goodsSpecs = new GoodsSpecs(); + // 设置商品ID + goodsSpecs.setGoodsId(goodsMsg.getId()); + // 设置商品名称 + goodsSpecs.setName(detail.getSpuName()); + // 设置更新时间 + goodsSpecs.setUpdateTime(new Date()); + // 设置采购限制 + goodsSpecs.setPurLimit(99999); + // 设置状态 + goodsSpecs.setStatus(1); + goodsSpecs.setThirdId(aLong.toString()); + // 设置库存 + goodsSpecs.setStock(10000); + BigDecimal profitPrice = price.getSalePrice().multiply(productConfig.getDiscount().divide(new BigDecimal(100) , 2, RoundingMode.HALF_UP)); + // 设置销售价格 + goodsSpecs.setSalePrice(profitPrice.add(price.getSalePrice())); + // 设置原价 + goodsSpecs.setOriginalPrice(price.getMarketPrice()); + // 设置展示图片 + goodsSpecs.setShowImg(goodsMsg.getListImg()); + + GoodsSpecs specs = goodsSpecsList.stream().filter(s -> s.getThirdId().equals(aLong.toString())).findFirst().orElse(null); + + if (specs != null) { + goodsSpecs.setId(specs.getId()); + // 更新商品规格 + goodsSpecsService.update(goodsSpecs); + } else { + // 设置创建时间 + goodsSpecs.setCreateTime(new Date()); + // 创建商品规格 + goodsSpecsService.create(goodsSpecs); + } + } + + } + } + + + } + } + } +} diff --git a/service/src/main/java/com/hfkj/jd/JdPostService.java b/service/src/main/java/com/hfkj/jd/JdPostService.java new file mode 100644 index 0000000..095b2a3 --- /dev/null +++ b/service/src/main/java/com/hfkj/jd/JdPostService.java @@ -0,0 +1,303 @@ +package com.hfkj.jd; + +import com.alibaba.fastjson.JSONObject; +import com.hfkj.common.utils.HttpsUtils; +import com.hfkj.common.utils.RsaCoderUtils; +import com.hfkj.config.CommonSysConst; +import com.hfkj.entity.BsOrderGoods; +import com.hfkj.entity.GoodsUserAddress; +import com.jd.open.api.sdk.DefaultJdClient; +import com.jd.open.api.sdk.JdClient; +import com.jd.open.api.sdk.domain.vopdd.OperaOrderOpenProvider.request.submitOrder.*; +import com.jd.open.api.sdk.domain.vopkc.SkuInfoGoodsProvider.request.getNewStockById.AreaBaseInfoGoodsReq; +import com.jd.open.api.sdk.domain.vopkc.SkuInfoGoodsProvider.request.getNewStockById.GetStockByIdGoodsReq; +import com.jd.open.api.sdk.domain.vopkc.SkuInfoGoodsProvider.request.getNewStockById.SkuNumBaseGoodsReq; +import com.jd.open.api.sdk.request.vopdd.VopOrderSubmitOrderRequest; +import com.jd.open.api.sdk.request.vopdz.VopAddressConvertFourAreaByDetailStrRequest; +import com.jd.open.api.sdk.request.vopdz.VopAddressQueryJdAreaIdListRequest; +import com.jd.open.api.sdk.request.vopdz.VopAddressVerifyAreaFourIdOpenReqRequest; +import com.jd.open.api.sdk.request.vopkc.VopGoodsGetNewStockByIdRequest; +import com.jd.open.api.sdk.request.vopsp.*; +import com.jd.open.api.sdk.response.vopdd.VopOrderSubmitOrderResponse; +import com.jd.open.api.sdk.response.vopdz.VopAddressConvertFourAreaByDetailStrResponse; +import com.jd.open.api.sdk.response.vopdz.VopAddressQueryJdAreaIdListResponse; +import com.jd.open.api.sdk.response.vopdz.VopAddressVerifyAreaFourIdOpenReqResponse; +import com.jd.open.api.sdk.response.vopkc.VopGoodsGetNewStockByIdResponse; +import com.jd.open.api.sdk.response.vopsp.*; +import org.apache.commons.codec.digest.DigestUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.annotation.Resource; +import java.net.URLEncoder; +import java.util.ArrayList; +import java.util.List; + +/** + * @ClassName JdService + * @Author Sum1Dream + * @Description 京东服务 + * @Date 2024/10/11 下午3:25 + **/ +public class JdPostService { + private static Logger log = LoggerFactory.getLogger(JdPostService.class); + + /** + * UTF_8 + */ + public static final String UTF_8 = "utf-8"; + /** + * 用户名 + */ + private static final String USERNAME = "惠兑重庆VOP", + /** + * 明文密码,后续需要通过RSA加密 + */ + PLAINTEXT_PASSWORD = "hdcs1234", + /** + * 回调地址,注册应用时配置的授权回调地址 + */ + REDIRECT_URI = CommonSysConst.getSysConfig().getDomainName() + "/order/jdNotify/callbackToken", + /** + * 请求地址 + */ + SERVER_URL = "https://api.jd.com/routerjson", + /** + * RSA私钥 + */ + PRIVATE_RSA_KEY = "MIICdwIBADANBgkqhkiG9w0BAQEFAASCAmEwggJdAgEAAoGBAMEtt0kF02YBxPXzXyqzCtr1zkuj8NXLiqqSCDAfU6zWB1T1GUEpCfNukPBeZ9nXGj+jbTom8RFllNXbnOkW01Zn2VoyePh8TRWQbToXi+i/JQ162GzpF0GdPsUhJSrB5Z2QzK4UVXXkpPHhQHR8NKQhvTRkoRLfOy+oXWL8PS2hAgMBAAECgYBySo/j/jRiZ62WLlUhuCg1/7P8AJSeiPwTiq6Zeg9RdJeF5jT43kTq54GNFO2wbpkzCYe4Hg4GUulJ1dLx/PUvYquRpM4jGznxDxBA10mNyjx0O+SHcY+ZlOYWIKhEq4MeeJhtHhoFrlgcMNIyofhRDbFzrRak48GrcZDQC4/cIQJBAPwxtEwMnetPveLExR1UsygdVKwoWoGNL5Hkhcx6b2N2Qapk5aHB5haUEXeg1ShrL4C/kE1lsMAIdpVS9lWd4x0CQQDEGASnnB2oPHjvNfj88klpYTvPJRi3ORQPtlfz36kv+29QFxB9Mt1u39ttopw5G2x7QvTtL542w878brrmS8lVAkEA4k7QFjZ0N8cVBLvCjrGFG4hGhT6pCPxjJa5GCtoLvttNzdRA5EkVaklw60LeRSj6NbSxj2Kjm498qj8KYoYOWQJATJhRISMy1mcgmdeMNUlycW4gjY4g9FigRG7mNgU0MeDVnwQTVcQLiGZ6cH2m5guXOSJzRz5lX2DmteWOrawGrQJBAMKLfeTnYkVpXw9MABcR/9L9myG3FKwOHBIqD0wK+QVahi9byFk8GFXD4OlBQ1ZSxHqsUuxWqLVSa3sWBCKpLo8="; + + + // 获取token + public static JSONObject getAccessToken() throws Exception { + String encodeRedirectUri = URLEncoder.encode(REDIRECT_URI, UTF_8); + String encodeUsername = URLEncoder.encode(USERNAME, UTF_8); + String md5Password = DigestUtils.md5Hex(PLAINTEXT_PASSWORD); + String ciphertextPassword = RsaCoderUtils.encryptByPrivateKey(md5Password, PRIVATE_RSA_KEY); + String encodePassword = URLEncoder.encode(ciphertextPassword, UTF_8); + + JSONObject object = new JSONObject(); + object.put("app_key", CommonSysConst.getSysConfig().getJDAppKey()); + object.put("redirect_uri", encodeRedirectUri); + object.put("username", encodeUsername); + object.put("password", encodePassword); + object.put("response_type", "code"); + object.put("scope", "snsapi_base"); + return HttpsUtils.doGet("https://open-oauth.jd.com/oauth2/authorizeForVOP", object); + } + + // 查询四级地址ID列表 + public static VopAddressQueryJdAreaIdListResponse queryJdAreaIdList(String token , Integer areaLevel , Long areaId) throws Exception { + JdClient client=new DefaultJdClient(SERVER_URL, token,CommonSysConst.getSysConfig().getJDAppKey(),CommonSysConst.getSysConfig().getJDAppSecret()); + VopAddressQueryJdAreaIdListRequest request=new VopAddressQueryJdAreaIdListRequest(); + request.setAreaLevel(areaLevel); + request.setJdAreaId(areaId); + return client.execute(request); + } + + //验证四级地址ID有效性 + public static VopAddressVerifyAreaFourIdOpenReqResponse verifyAreaFourIdOpenReq (String token , Long provinceId , Long cityId , Long countyId , Long townId) throws Exception { + JdClient client=new DefaultJdClient(SERVER_URL,token,CommonSysConst.getSysConfig().getJDAppKey(),CommonSysConst.getSysConfig().getJDAppSecret()); + VopAddressVerifyAreaFourIdOpenReqRequest request=new VopAddressVerifyAreaFourIdOpenReqRequest(); + request.setProvinceId(provinceId); + request.setCityId(cityId); + request.setTownId(townId); + request.setCountyId(countyId); + return client.execute(request); + } + + // 地址详情转换京东地址编码 + public static VopAddressConvertFourAreaByDetailStrResponse convertFourAreaByDetailStr(String token , String address) throws Exception { + JdClient client=new DefaultJdClient(SERVER_URL,token,CommonSysConst.getSysConfig().getJDAppKey(),CommonSysConst.getSysConfig().getJDAppSecret()); + VopAddressConvertFourAreaByDetailStrRequest request=new VopAddressConvertFourAreaByDetailStrRequest(); + request.setAddressDetailStr(address); + return client.execute(request); + } + // 查询商品池编号 + public static VopGoodsGetSkuPoolInfoResponse getSkuPoolInfo(String token) throws Exception { + JdClient client=new DefaultJdClient(SERVER_URL,token,CommonSysConst.getSysConfig().getJDAppKey(),CommonSysConst.getSysConfig().getJDAppSecret()); + VopGoodsGetSkuPoolInfoRequest request=new VopGoodsGetSkuPoolInfoRequest(); + return client.execute(request); + } + + // 根据商品池获取所有商品信息 + public static VopGoodsQuerySkuByPageResponse querySkuByPage(String token , String bizPoolId , Integer offset) throws Exception { + JdClient client=new DefaultJdClient(SERVER_URL,token,CommonSysConst.getSysConfig().getJDAppKey(),CommonSysConst.getSysConfig().getJDAppSecret()); + VopGoodsQuerySkuByPageRequest request=new VopGoodsQuerySkuByPageRequest(); + request.setBizPoolId(bizPoolId); + request.setOffset(offset); + request.setPageSize(10); + return client.execute(request); + } + + // 获取商品详情及商品扩展信息 + public static VopGoodsGetSkuDetailInfoResponse getSkuDetailInfo(String token , Long skuId) throws Exception { + JdClient client=new DefaultJdClient(SERVER_URL,token,CommonSysConst.getSysConfig().getJDAppKey(),CommonSysConst.getSysConfig().getJDAppSecret()); + VopGoodsGetSkuDetailInfoRequest request=new VopGoodsGetSkuDetailInfoRequest(); + request.setSkuId(skuId); + return client.execute(request); + } + + // 查询商品图片 + public static VopGoodsGetSkuImageListResponse getSkuImageList(String token , String skuId) throws Exception { + JdClient client=new DefaultJdClient(SERVER_URL,token,CommonSysConst.getSysConfig().getJDAppKey(),CommonSysConst.getSysConfig().getJDAppSecret()); + VopGoodsGetSkuImageListRequest request=new VopGoodsGetSkuImageListRequest(); + request.setSkuId(skuId); + return client.execute(request); + } + + // 批量查询商品售卖价 + public static VopGoodsGetSellPriceResponse getSellPrice(String token , String skuId) throws Exception { + JdClient client=new DefaultJdClient(SERVER_URL,token,CommonSysConst.getSysConfig().getJDAppKey(),CommonSysConst.getSysConfig().getJDAppSecret()); + VopGoodsGetSellPriceRequest request=new VopGoodsGetSellPriceRequest(); + request.setSkuId(skuId); + return client.execute(request); + } + + // 根据分类id查询分类信息 + public static VopGoodsGetCategoryInfoListResponse getCategoryInfoList(String token , String CategoryId) throws Exception { + JdClient client=new DefaultJdClient(SERVER_URL,token,CommonSysConst.getSysConfig().getJDAppKey(),CommonSysConst.getSysConfig().getJDAppSecret()); + VopGoodsGetCategoryInfoListRequest request=new VopGoodsGetCategoryInfoListRequest(); + request.setCategoryId(CategoryId); + return client.execute(request); + } + + // 校验商品购买区域是否受限 + public static VopGoodsCheckAreaLimitListResponse checkAreaLimitList(String token , String skuId , Long provinceId , Long cityId , Long countyId , Long townId) throws Exception { + JdClient client=new DefaultJdClient(SERVER_URL,token,CommonSysConst.getSysConfig().getJDAppKey(),CommonSysConst.getSysConfig().getJDAppSecret()); + VopGoodsCheckAreaLimitListRequest request=new VopGoodsCheckAreaLimitListRequest(); + request.setSkuId(skuId); + request.setProvinceId(provinceId); + request.setCityId(cityId); + request.setCountyId(countyId); + request.setTownId(townId == null ? 0 : townId); + return client.execute(request); + } + + // 提交预占订单服务 + public static VopOrderSubmitOrderResponse submitOrder(String token , GoodsUserAddress address , String orderNo , Integer skuNum , Long skuId) throws Exception { + // 创建京东客户端 + JdClient client=new DefaultJdClient(SERVER_URL,token,CommonSysConst.getSysConfig().getJDAppKey(),CommonSysConst.getSysConfig().getJDAppSecret()); + // 创建订单提交请求 + VopOrderSubmitOrderRequest request=new VopOrderSubmitOrderRequest(); + // 创建订单提交请求参数 + SubmitOrderOpenReq submitOrderOpenReq=new SubmitOrderOpenReq(); + // 设置订单提交状态类型 + submitOrderOpenReq.setSubmitStateType(0); + // 设置第三方订单号 + submitOrderOpenReq.setThirdOrderId(orderNo); + + // 创建订单提交商品列表 + List submitOrderOpenSkus = new ArrayList<>(); + // 创建订单提交商品信息 + SkuInfoOrderOpenReq skuInfoOrderOpenReq=new SkuInfoOrderOpenReq(); + // 设置商品数量 + skuInfoOrderOpenReq.setSkuNum(skuNum); + // 设置商品ID + skuInfoOrderOpenReq.setSkuId(skuId); + // 将商品信息添加到商品列表 + submitOrderOpenSkus.add(skuInfoOrderOpenReq); + // 设置订单提交商品列表 + submitOrderOpenReq.setSkuInfoList(submitOrderOpenSkus); + + // 创建订单提交支付信息 + PaymentInfoOrderOpenReq paymentInfoOrderOpenReq=new PaymentInfoOrderOpenReq(); + // 设置支付类型 + // 1:货到付款 4:预存款 5:公司转账 101:京东金采 102:商城金采(一般不适用,仅限确认开通商城账期的特殊情况使用,请与业务确认后使用) 20为混合支付 + paymentInfoOrderOpenReq.setPaymentType(4); + // 设置订单提交支付信息 + submitOrderOpenReq.setPaymentInfo(paymentInfoOrderOpenReq); + + // 创建订单提交收货人信息 + ConsigneeInfoOrderOpenReq infoOrderOpenReq = new ConsigneeInfoOrderOpenReq(); + // 设置收货人地址 + infoOrderOpenReq.setConsigneeAddress(address.getAddress()); + // 设置收货人姓名 + infoOrderOpenReq.setConsigneeName(address.getConsignee()); + // 设置收货人手机号 + infoOrderOpenReq.setConsigneeMobile(address.getPhone()); + // 设置收货人电话 + infoOrderOpenReq.setConsigneePhone(address.getPhone()); + // 设置收货人省份ID + infoOrderOpenReq.setConsigneeProvinceId(address.getProvinceId()); + // 设置收货人城市ID + infoOrderOpenReq.setConsigneeCityId(address.getCityId()); + // 设置收货人区县ID + infoOrderOpenReq.setConsigneeCountyId(address.getCountyId()); + // 设置收货人乡镇ID + infoOrderOpenReq.setConsigneeTownId(address.getTownId()); + // 设置订单提交收货人信息 + submitOrderOpenReq.setConsigneeInfo(infoOrderOpenReq); + + // 创建订单提交发票信息 + InvoiceInfoOrderOpenReq invoiceInfoOrderOpenReq = new InvoiceInfoOrderOpenReq(); + // 设置发票类型 + invoiceInfoOrderOpenReq.setInvoiceType(24); + // 设置发票开具类型 + invoiceInfoOrderOpenReq.setInvoicePutType(2); + // 设置发票抬头 + invoiceInfoOrderOpenReq.setInvoiceCompanyName("惠兑礼品(重庆)有限公司"); + invoiceInfoOrderOpenReq.setInvoiceRegCompanyName("惠兑礼品(重庆)有限公司"); + invoiceInfoOrderOpenReq.setInvoiceRegPhone("13983618575"); + // 设置发票抬头 + invoiceInfoOrderOpenReq.setInvoiceSelectedTitle(5); + // 设置发票类型 + invoiceInfoOrderOpenReq.setInvoiceContentType(1); + // 设置发票姓名 + invoiceInfoOrderOpenReq.setInvoiceName("魏涛"); + // 设置发票电话 + invoiceInfoOrderOpenReq.setInvoicePhone("13983618575"); + // 设置发票地址 + invoiceInfoOrderOpenReq.setInvoiceAddress("重庆渝中区国贸中心1308"); + // 设置发票开户银行 + invoiceInfoOrderOpenReq.setInvoiceRegBank("中国民生银行股份有限公司重庆大坪支行"); + // 设置发票纳税人识别号 + invoiceInfoOrderOpenReq.setInvoiceRegCode("91500103322277192B"); + // 设置发票注册地址 + invoiceInfoOrderOpenReq.setInvoiceRegAddress("重庆渝中区国贸中心1308"); + // 设置发票开户银行账号 + invoiceInfoOrderOpenReq.setInvoiceRegBankAccount("172792234"); + // 设置发票省份ID + invoiceInfoOrderOpenReq.setInvoiceProvinceId(4L); + // 设置发票城市ID + invoiceInfoOrderOpenReq.setInvoiceCityId(51026L); + // 设置发票区县ID + invoiceInfoOrderOpenReq.setInvoiceCountyId(58459L); + // 设置订单提交发票信息 + submitOrderOpenReq.setInvoiceInfo(invoiceInfoOrderOpenReq); + + + // 设置订单提交请求参数 + request.setSubmitOrderOpenReq(submitOrderOpenReq); + // 执行订单提交请求 + return client.execute(request); + } + + // 批量获取库存接口 + public static VopGoodsGetNewStockByIdResponse getNewStockById(String token , Long skuId , Long provinceId , Long cityId , Long countyId , Long townId) throws Exception { + JdClient client=new DefaultJdClient(SERVER_URL,token,CommonSysConst.getSysConfig().getJDAppKey(),CommonSysConst.getSysConfig().getJDAppSecret()); + VopGoodsGetNewStockByIdRequest request=new VopGoodsGetNewStockByIdRequest(); + GetStockByIdGoodsReq getStockByIdGoodsReq=new GetStockByIdGoodsReq(); + List skuNumBaseGoodsReqs = new ArrayList<>(); + SkuNumBaseGoodsReq skuNumBaseGoodsReq=new SkuNumBaseGoodsReq(); + skuNumBaseGoodsReq.setSkuId(skuId); + skuNumBaseGoodsReq.setSkuNumber(1); + skuNumBaseGoodsReqs.add(skuNumBaseGoodsReq); + getStockByIdGoodsReq.setSkuNumInfoList(skuNumBaseGoodsReqs); + + AreaBaseInfoGoodsReq areaBaseInfoGoodsReq=new AreaBaseInfoGoodsReq(); + areaBaseInfoGoodsReq.setCityId(cityId); + areaBaseInfoGoodsReq.setCountyId(countyId); + areaBaseInfoGoodsReq.setProvinceId(provinceId); + areaBaseInfoGoodsReq.setTownId(townId == null ? 0 : townId); + getStockByIdGoodsReq.setAreaInfo(areaBaseInfoGoodsReq); + + request.setGetStockByIdGoodsReq(getStockByIdGoodsReq); + return client.execute(request); + } + + + + + +} diff --git a/service/src/main/java/com/hfkj/jd/JdService.java b/service/src/main/java/com/hfkj/jd/JdService.java index 46143bc..483406c 100644 --- a/service/src/main/java/com/hfkj/jd/JdService.java +++ b/service/src/main/java/com/hfkj/jd/JdService.java @@ -1,63 +1,25 @@ package com.hfkj.jd; -import com.alibaba.fastjson.JSONObject; -import com.hfkj.common.utils.HttpsUtils; -import com.hfkj.common.utils.RsaCoderUtils; -import com.hfkj.config.CommonSysConst; -import com.hfkj.meituan.MeiTuanService; -import com.jd.open.api.sdk.DefaultJdClient; -import com.jd.open.api.sdk.JdClient; -import org.apache.commons.codec.digest.DigestUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +public interface JdService { -import java.net.URLEncoder; -import java.util.Map; - -/** - * @ClassName JdService - * @Author Sum1Dream - * @Description 京东服务 - * @Date 2024/10/11 下午3:25 - **/ -public class JdService { - private static Logger log = LoggerFactory.getLogger(JdService.class); - - /** - * UTF_8 - */ - public static final String UTF_8 = "utf-8"; - /** - * 用户名 - */ - private static final String USERNAME = "惠兑重庆VOP", /** - * 明文密码,后续需要通过RSA加密 + * @MethodName getToken + * @Description: 获取token + * @param + * @return: java.lang.String + * @Author: Sum1Dream + * @Date: 2024/10/16 下午3:21 */ - PLAINTEXT_PASSWORD = "hdcs1234", - /** - * 回调地址,注册应用时配置的授权回调地址 - */ - REDIRECT_URI = CommonSysConst.getSysConfig().getDomainName() + "/order/jdNotify/callbackToken", - /** - * RSA私钥 - */ - PRIVATE_RSA_KEY = "MIICdwIBADANBgkqhkiG9w0BAQEFAASCAmEwggJdAgEAAoGBAMEtt0kF02YBxPXzXyqzCtr1zkuj8NXLiqqSCDAfU6zWB1T1GUEpCfNukPBeZ9nXGj+jbTom8RFllNXbnOkW01Zn2VoyePh8TRWQbToXi+i/JQ162GzpF0GdPsUhJSrB5Z2QzK4UVXXkpPHhQHR8NKQhvTRkoRLfOy+oXWL8PS2hAgMBAAECgYBySo/j/jRiZ62WLlUhuCg1/7P8AJSeiPwTiq6Zeg9RdJeF5jT43kTq54GNFO2wbpkzCYe4Hg4GUulJ1dLx/PUvYquRpM4jGznxDxBA10mNyjx0O+SHcY+ZlOYWIKhEq4MeeJhtHhoFrlgcMNIyofhRDbFzrRak48GrcZDQC4/cIQJBAPwxtEwMnetPveLExR1UsygdVKwoWoGNL5Hkhcx6b2N2Qapk5aHB5haUEXeg1ShrL4C/kE1lsMAIdpVS9lWd4x0CQQDEGASnnB2oPHjvNfj88klpYTvPJRi3ORQPtlfz36kv+29QFxB9Mt1u39ttopw5G2x7QvTtL542w878brrmS8lVAkEA4k7QFjZ0N8cVBLvCjrGFG4hGhT6pCPxjJa5GCtoLvttNzdRA5EkVaklw60LeRSj6NbSxj2Kjm498qj8KYoYOWQJATJhRISMy1mcgmdeMNUlycW4gjY4g9FigRG7mNgU0MeDVnwQTVcQLiGZ6cH2m5guXOSJzRz5lX2DmteWOrawGrQJBAMKLfeTnYkVpXw9MABcR/9L9myG3FKwOHBIqD0wK+QVahi9byFk8GFXD4OlBQ1ZSxHqsUuxWqLVSa3sWBCKpLo8="; + String getToken() throws Exception; - public static JSONObject getAccessToken() throws Exception { - String encodeRedirectUri = URLEncoder.encode(REDIRECT_URI, UTF_8); - String encodeUsername = URLEncoder.encode(USERNAME, UTF_8); - String md5Password = DigestUtils.md5Hex(PLAINTEXT_PASSWORD); - String ciphertextPassword = RsaCoderUtils.encryptByPrivateKey(md5Password, PRIVATE_RSA_KEY); - String encodePassword = URLEncoder.encode(ciphertextPassword, UTF_8); - JSONObject object = new JSONObject(); - object.put("app_key", CommonSysConst.getSysConfig().getJDAppKey()); - object.put("redirect_uri", encodeRedirectUri); - object.put("username", encodeUsername); - object.put("password", encodePassword); - object.put("response_type", "code"); - object.put("scope", "snsapi_base"); - return HttpsUtils.doGet("https://open-oauth.jd.com/oauth2/authorizeForVOP", object); - } + /** + * @MethodName getGoodsJd + * @Description: 获取京东商品信息 + * @param + * @return: void + * @Author: Sum1Dream + * @Date: 2024/10/16 下午3:21 + */ + void getGoodsJd() throws Exception; } diff --git a/service/src/main/java/com/hfkj/service/order/OrderCreateService.java b/service/src/main/java/com/hfkj/service/order/OrderCreateService.java index 5d35d79..8976c04 100644 --- a/service/src/main/java/com/hfkj/service/order/OrderCreateService.java +++ b/service/src/main/java/com/hfkj/service/order/OrderCreateService.java @@ -9,6 +9,8 @@ import com.hfkj.common.exception.SysCode; import com.hfkj.common.utils.RandomUtils; import com.hfkj.common.utils.StarbucksUtil; import com.hfkj.entity.*; +import com.hfkj.jd.JdPostService; +import com.hfkj.jd.JdService; import com.hfkj.model.order.OrderChildModel; import com.hfkj.model.order.OrderModel; import com.hfkj.qianzhu.CinemaService; @@ -22,6 +24,11 @@ import com.hfkj.service.goods.*; import com.hfkj.service.hlt.HuiLianTongUnionCardService; import com.hfkj.sysenum.GoodsVpdSourceEnum; import com.hfkj.sysenum.order.*; +import com.jd.open.api.sdk.domain.vopsp.SkuInfoGoodsProvider.response.getSellPrice.OpenRpcResult; +import com.jd.open.api.sdk.response.vopdd.VopOrderSubmitOrderResponse; +import com.jd.open.api.sdk.response.vopdz.VopAddressConvertFourAreaByDetailStrResponse; +import com.jd.open.api.sdk.response.vopkc.VopGoodsGetNewStockByIdResponse; +import com.jd.open.api.sdk.response.vopsp.VopGoodsCheckAreaLimitListResponse; import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -54,6 +61,7 @@ public class OrderCreateService { private GoodsVpdService goodsVpdService; @Resource private GoodsUserAddressService goodsUserAddressService; + @Resource private BsOrderGoodsService bsOrderGoodsService; @Resource @@ -74,6 +82,8 @@ public class OrderCreateService { private SecConfigService secConfigService; @Resource private BsOrderMeiTuanService bsOrderMeiTuanService; + @Resource + private JdService jdService; /** * 事务产品 @@ -225,12 +235,14 @@ public class OrderCreateService { if (goodsMsg.getType() != 1) { throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "当前商品不属于实物产品不可下单!"); } + // 查询商品规格 GoodsSpecs goodsSpecs = goodsSpecsService.queryDetail(orderChild.getProductSpecId()); if (goodsSpecs == null) { throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未知的商品规格"); } + JSONObject object = new JSONObject((Map) orderChild.getBusiness()); orderChild.setMerId(goodsMsg.getMerId()); @@ -254,6 +266,14 @@ public class OrderCreateService { } else { jsonObject = new JSONObject((Map) orderChild.getBusiness()); } + BsOrderGoods orderGoods = new BsOrderGoods(); + // 判断是否是京东产品 + if (goodsMsg.getType() == 1) { + if (goodsMsg.getChildType() != null && goodsMsg.getChildType().equals(1)) { + orderGoods = jdGoods(orderGoods , address, goodsMsg.getThirdId(), goodsSpecs , orderChild.getChildOrderNo() , orderChild.getProductCount()); + } + + } // 查询商品虚拟信息 GoodsJump goodsJump = goodsJumpService.queryDetailBySpecsId(goodsSpecs.getId()); @@ -262,7 +282,7 @@ public class OrderCreateService { jsonObject.put("goodsJump", goodsJump); // 创建实物订单 - BsOrderGoods orderGoods = new BsOrderGoods(); + orderGoods.setOrderNo(orderChild.getOrderNo()); orderGoods.setChildOrderNo(orderChild.getChildOrderNo()); orderGoods.setMerId(orderChild.getMerId()); @@ -549,4 +569,88 @@ public class OrderCreateService { return orderChild; } + + private BsOrderGoods jdGoods(BsOrderGoods orderGoods , GoodsUserAddress address , String skuId , GoodsSpecs goodsSpecs , String orderNo , Integer num) throws Exception { + //校验商品购买区域是否受限 + if (address.getProvinceId() == null) { + // 根据详细地址获取四级地址信息 + VopAddressConvertFourAreaByDetailStrResponse response = JdPostService.convertFourAreaByDetailStr(jdService.getToken() , address.getRegionName() + address.getAddress()); + + // 如果获取成功,则将四级地址信息设置到address对象中 + if (response != null && response.getOpenRpcResult().getSuccess()) { + address.setProvinceId(response.getOpenRpcResult().getResult().getProvinceId()); + address.setProvinceName(response.getOpenRpcResult().getResult().getProvinceName()); + address.setCityId(response.getOpenRpcResult().getResult().getCityId()); + address.setCityName(response.getOpenRpcResult().getResult().getCityName()); + address.setCountyId(response.getOpenRpcResult().getResult().getCountyId()); + address.setCountyName(response.getOpenRpcResult().getResult().getCountyName()); + address.setTownId(response.getOpenRpcResult().getResult().getTownId()); + address.setTownName(response.getOpenRpcResult().getResult().getTownName()); + } + + // 更新address对象的更新时间 + address.setUpdateTime(new Date()); + goodsUserAddressService.update(address); + } + + // 检查商品是否在指定地区限制范围内 + VopGoodsCheckAreaLimitListResponse checkAreaLimitListResponse = JdPostService.checkAreaLimitList(jdService.getToken() , skuId , address.getProvinceId() , address.getCityId() , address.getCountyId() , address.getTownId()); + if (checkAreaLimitListResponse != null && checkAreaLimitListResponse.getOpenRpcResult().getSuccess()) { + // 返回是否在限制范围内 + if (checkAreaLimitListResponse.getOpenRpcResult().getResult().get(0).getIsAreaRestrict()) { + throw ErrorHelp.genException(SysCode.System , ErrorCode.COMMON_ERROR , "当前地区不可销售该商品!" ); + } + + } + + // 根据skuId 查询商品售价 + OpenRpcResult priceResponse = JdPostService.getSellPrice(jdService.getToken(), skuId).getOpenRpcResult(); + + if (priceResponse != null && priceResponse.getSuccess()) { + if (goodsSpecs.getSalePrice().compareTo(priceResponse.getResult().get(0).getSalePrice()) < 0) { + throw ErrorHelp.genException(SysCode.System , ErrorCode.COMMON_ERROR , "商品已售罄!" ); + } + } + + // 查询库存 + VopGoodsGetNewStockByIdResponse stockResponse = JdPostService.getNewStockById(jdService.getToken() , Long.valueOf(skuId), address.getProvinceId() , address.getCityId() , address.getCountyId() , address.getTownId()); + + if (!checkStock(stockResponse.getOpenRpcResult().getResult().get(0).getStockStateType())) { + throw ErrorHelp.genException(SysCode.System , ErrorCode.COMMON_ERROR , "商品已售罄!" ); + } + + + // 提交订单 + VopOrderSubmitOrderResponse submitOrderResponse = JdPostService.submitOrder(jdService.getToken() , address , orderNo, num , Long.valueOf(skuId) ); + + if (submitOrderResponse != null && !submitOrderResponse.getVopOrderRpcResult().getSuccess()) { + throw ErrorHelp.genException(SysCode.System , ErrorCode.COMMON_ERROR , "下单失败!" ); + } + orderGoods.setThirdOrderNo(submitOrderResponse.getVopOrderRpcResult().getResult().getThirdOrderId()); + + return orderGoods; + + } + + + // 校验库存 + private Boolean checkStock(Integer stock) { + if (stock == null ) { + return false; + } + if (stock == 34) { + return false; + } + if (stock == 35) { + return false; + } + if (stock == 36) { + return false; + + } + if (stock == 99) { + return false; + } + return true; + } } diff --git a/service/src/main/java/com/hfkj/service/pay/huift/config/HuiftConfig.java b/service/src/main/java/com/hfkj/service/pay/huift/config/HuiftConfig.java index 5d5339f..9bd894d 100644 --- a/service/src/main/java/com/hfkj/service/pay/huift/config/HuiftConfig.java +++ b/service/src/main/java/com/hfkj/service/pay/huift/config/HuiftConfig.java @@ -24,6 +24,9 @@ public class HuiftConfig { public final static String shopcode95 = "b4b121b6-ec5c-44e1-a020-d2f21e754b55"; public final static String signSecret95 = "4AA9E79115848B797B53FBD830B402F4"; + public final static String shopcode01 = "e9b60994-e5ed-4baf-b097-92e09c0a8a8a"; + public final static String signSecret01 = "277E7873C1CDD59ED533BCE65FDD143E"; + /** * 参数排序 * @param param diff --git a/service/src/main/java/com/hfkj/sysenum/order/OrderChildProductTypeEnum.java b/service/src/main/java/com/hfkj/sysenum/order/OrderChildProductTypeEnum.java index d68457e..f815034 100644 --- a/service/src/main/java/com/hfkj/sysenum/order/OrderChildProductTypeEnum.java +++ b/service/src/main/java/com/hfkj/sysenum/order/OrderChildProductTypeEnum.java @@ -16,6 +16,7 @@ public enum OrderChildProductTypeEnum { type3(3, "千猪电影票"), type4(4, "千猪星巴克"), type5(5, "美团"), + type6(6, "京东"), ; private int code; diff --git a/service/src/main/java/com/hfkj/yushang/YuShangService.java b/service/src/main/java/com/hfkj/yushang/YuShangService.java index 9b8f5a5..6f9e853 100644 --- a/service/src/main/java/com/hfkj/yushang/YuShangService.java +++ b/service/src/main/java/com/hfkj/yushang/YuShangService.java @@ -71,8 +71,7 @@ public class YuShangService { param.put("AppKey", CommonSysConst.getSysConfig().getYuShangAppKey()); param.put("timestamp", new Date().getTime()); param.put("CustomerIP", "127.0.0.1"); - param.put("sign", MD5Util.encode(GenerateSign.paramSortYuShang(param,CommonSysConst.getSysConfig().getYuShangAppSecret()).getBytes()).toLowerCase()); - + param.put("sign", MD5Util.encode(GenerateSign.paramSortYuShang(param,CommonSysConst.getSysConfig().getYuShangAppSecret()).getBytes())); log.info("请求接口:" + postUrl); log.info("请求参数:" + JSONObject.toJSONString(param)); diff --git a/service/src/main/resources/dev/commonConfig.properties b/service/src/main/resources/dev/commonConfig.properties index 1b6df48..177e784 100644 --- a/service/src/main/resources/dev/commonConfig.properties +++ b/service/src/main/resources/dev/commonConfig.properties @@ -78,9 +78,9 @@ mtAccessKey=DVNKSHSDHHJ6-TK mtSecretKey=lj2YDjGnqroY1OuR5zriWg== mtPostUrl=https://waimai-openapi.apigw.test.meituan.com/api/sqt/open/login/h5/loginFree/redirection?test_open_swimlane=test-open -yuShangAppKey=211394653 -yuShangAppSecret=cyQpQKMaGUG186iEZRt1uQ== -yuShangPostUrl=http://mbsmemberwebapi.test.onfishes.com/ +yuShangAppKey=211395334 +yuShangAppSecret=VxNTJua4FkmRVgIm8HgCSg== +yuShangPostUrl=http://mbapiq.mbs.scyshy.com/ haiOilPostUrl = https://test-oil.dctpay.com haiOilAppid = hf7356c71fb97ab0 diff --git a/service/src/main/resources/prod/commonConfig.properties b/service/src/main/resources/prod/commonConfig.properties index 0f63b39..90aa198 100644 --- a/service/src/main/resources/prod/commonConfig.properties +++ b/service/src/main/resources/prod/commonConfig.properties @@ -77,9 +77,9 @@ HgApiKey=3fd74e7c16b04681a0f481c5bc0a96d3 HgMemberId=1622808562621276161 HgPostUrl=http://113.250.49.100:8088/recharge/ -yuShangAppKey=211394653 -yuShangAppSecret=cyQpQKMaGUG186iEZRt1uQ== -yuShangPostUrl=http://mbsmemberwebapi.test.onfishes.com/ +yuShangAppKey=211395334 +yuShangAppSecret=VxNTJua4FkmRVgIm8HgCSg== +yuShangPostUrl=http://mbapiq.mbs.scyshy.com/ haiOilPostUrl = https://oil.dctpay.com