master
parent
e0c724fccf
commit
41843a2e53
Binary file not shown.
@ -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); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -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; |
|
||||||
} |
|
||||||
} |
|
@ -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<GetSkuPoolInfoItemGoodsResp> skuList = sku.getOpenRpcResult().getResult().getSkuPoolList(); |
||||||
|
|
||||||
|
// 初始化商品信息
|
||||||
|
GoodsMsg goodsMsg; |
||||||
|
// 初始化商品规格
|
||||||
|
GoodsSpecs goodsSpecs; |
||||||
|
|
||||||
|
BsMer bsMer = bsMerService.getDetail("166241009282"); |
||||||
|
// 查询分类
|
||||||
|
List<GoodsType> goodsType = goodsTypeService.getList(new HashMap<>()); |
||||||
|
List<GoodsBrand> brands = goodsBrandService.getList(new HashMap<>()); |
||||||
|
Map<String, Object> goodsMap = new HashMap<>(); |
||||||
|
goodsMap.put("type", 3); |
||||||
|
List<GoodsMsg> goodsMsgs = goodsMsgService.getList(goodsMap); |
||||||
|
List<GoodsSpecs> goodsSpecsList = goodsSpecsService.getList(new HashMap<>()); |
||||||
|
BsProductConfig productConfig = productConfigService.queryDetail(OrderChildProductTypeEnum.type6.getCode()); |
||||||
|
|
||||||
|
for (GetSkuPoolInfoItemGoodsResp skuPoolInfoItemGoodsResp : skuList) { |
||||||
|
|
||||||
|
// 根据sku查询商品
|
||||||
|
List<Long> 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); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -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<SkuInfoOrderOpenReq> 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<SkuNumBaseGoodsReq> 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); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} |
@ -1,63 +1,25 @@ |
|||||||
package com.hfkj.jd; |
package com.hfkj.jd; |
||||||
|
|
||||||
import com.alibaba.fastjson.JSONObject; |
public interface JdService { |
||||||
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; |
|
||||||
|
|
||||||
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", |
String getToken() throws Exception; |
||||||
/** |
|
||||||
* 回调地址,注册应用时配置的授权回调地址 |
|
||||||
*/ |
|
||||||
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="; |
|
||||||
|
|
||||||
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()); |
* @MethodName getGoodsJd |
||||||
object.put("redirect_uri", encodeRedirectUri); |
* @Description: 获取京东商品信息 |
||||||
object.put("username", encodeUsername); |
* @param |
||||||
object.put("password", encodePassword); |
* @return: void |
||||||
object.put("response_type", "code"); |
* @Author: Sum1Dream |
||||||
object.put("scope", "snsapi_base"); |
* @Date: 2024/10/16 下午3:21 |
||||||
return HttpsUtils.doGet("https://open-oauth.jd.com/oauth2/authorizeForVOP", object); |
*/ |
||||||
} |
void getGoodsJd() throws Exception; |
||||||
} |
} |
||||||
|
Loading…
Reference in new issue