From 8362791eb2ba4890d2126429c8eb31d2a7c49342 Mon Sep 17 00:00:00 2001
From: eric <465889110@qq.com>
Date: Mon, 1 Sep 2025 01:12:49 +0800
Subject: [PATCH 1/7] =?UTF-8?q?=E5=95=86=E5=93=81=E5=93=81=E7=B1=BB?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
pom.xml | 15 +
.../pay/alipay/controller/ItemController.java | 130 +++++
.../alipay/service/ImageUploadService.java | 54 ++
.../sczx/pay/alipay/service/ItemService.java | 60 ++
.../service/impl/ImageUploadServiceImpl.java | 301 ++++++++++
.../alipay/service/impl/ItemServiceImpl.java | 515 ++++++++++++++++++
.../pay/alipay/vo/ImageDirectoryRequest.java | 83 +++
.../sczx/pay/alipay/vo/ItemCreateRequest.java | 164 ++++++
.../com/sczx/pay/alipay/vo/OpenResponse.java | 136 +++++
.../com/sczx/pay/utils/AlipayApiCallback.java | 21 +
.../com/sczx/pay/utils/AlipayApiTemplate.java | 50 ++
.../com/sczx/pay/utils/AlipaySdkUtil.java | 242 ++++++++
src/main/resources/application.yml | 15 +-
13 files changed, 1785 insertions(+), 1 deletion(-)
create mode 100644 src/main/java/com/sczx/pay/alipay/controller/ItemController.java
create mode 100644 src/main/java/com/sczx/pay/alipay/service/ImageUploadService.java
create mode 100644 src/main/java/com/sczx/pay/alipay/service/ItemService.java
create mode 100644 src/main/java/com/sczx/pay/alipay/service/impl/ImageUploadServiceImpl.java
create mode 100644 src/main/java/com/sczx/pay/alipay/service/impl/ItemServiceImpl.java
create mode 100644 src/main/java/com/sczx/pay/alipay/vo/ImageDirectoryRequest.java
create mode 100644 src/main/java/com/sczx/pay/alipay/vo/ItemCreateRequest.java
create mode 100644 src/main/java/com/sczx/pay/alipay/vo/OpenResponse.java
create mode 100644 src/main/java/com/sczx/pay/utils/AlipayApiCallback.java
create mode 100644 src/main/java/com/sczx/pay/utils/AlipayApiTemplate.java
create mode 100644 src/main/java/com/sczx/pay/utils/AlipaySdkUtil.java
diff --git a/pom.xml b/pom.xml
index d430497..3142f7c 100644
--- a/pom.xml
+++ b/pom.xml
@@ -186,7 +186,22 @@
wechatpay-java
0.2.14
+
+ com.alipay.sdk
+ alipay-sdk-java
+ 4.39.79.ALL
+
+
+ com.alipay.sdk
+ alipay-sdk-java-v3
+ 2.9.0.ALL
+
+
+ com.github.xiaoymin
+ knife4j-spring-boot-starter
+ 3.0.3
+
commons-codec
diff --git a/src/main/java/com/sczx/pay/alipay/controller/ItemController.java b/src/main/java/com/sczx/pay/alipay/controller/ItemController.java
new file mode 100644
index 0000000..d2ebfc1
--- /dev/null
+++ b/src/main/java/com/sczx/pay/alipay/controller/ItemController.java
@@ -0,0 +1,130 @@
+/**
+ * Alipay.com Inc.
+ * Copyright (c) 2004-2024 All Rights Reserved.
+ */
+package com.sczx.pay.alipay.controller;
+
+import com.alipay.api.domain.AppxCategoryVO;
+import com.alipay.api.internal.util.StringUtils;
+import com.alipay.api.response.AlipayOpenAppItemListQueryResponse;
+import com.alipay.api.response.AlipayOpenAppItemQueryResponse;
+import com.alipay.api.response.AlipayOpenAppItemTemplateQueryResponse;
+import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
+import com.github.xiaoymin.knife4j.annotations.ApiSupport;
+import com.sczx.pay.alipay.service.ItemService;
+import com.sczx.pay.alipay.vo.ItemCreateRequest;
+import com.sczx.pay.alipay.vo.OpenResponse;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import io.swagger.annotations.ApiParam;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.List;
+
+/**
+ * @author jishupei.jsp
+ * @version : ItemController, v0.1 2024年05月11日 2:45 下午 jishupei.jsp Exp $
+ */
+@Api(tags = "普通商品模块")
+@ApiSupport(order = 1)
+@RestController
+@RequestMapping(value = "/item")
+public class ItemController {
+
+ @Autowired
+ private ItemService itemService;
+
+ /**
+ * 类目查询
+ * 获取叶子节点商品类目列表
+ */
+ @ApiOperationSupport(order = 1)
+ @ApiOperation(value = "类目查询", notes = "获取叶子节点商品类目列表")
+ @GetMapping(value = "/category/list")
+ public OpenResponse> categoryList(
+ @ApiParam(value = "商品类型:1-售卖类(实物),2-租赁类(实物),3-付费充值/兑换类(虚拟)") @RequestParam String itemType,
+ @ApiParam(value = "类目状态,默认AUDIT_PASSED", example = "AUDIT_PASSED") @RequestParam(required = false) String catStatus) {
+ return itemService.getCategories(itemType, catStatus);
+ }
+
+ /**
+ * 普通商品模板信息查询
+ */
+ @ApiOperationSupport(order = 2)
+ @ApiOperation(value = "普通商品模板信息查询")
+ @GetMapping(value = "/template/query")
+ public OpenResponse queryTemplate(
+ @ApiParam(value = "类目ID", required = true) @RequestParam String categoryId,
+ @ApiParam(value = "商品类型:1-售卖类(实物),2-租赁类(实物),3-付费充值/兑换类(虚拟)") @RequestParam(required = false) String itemType) {
+ return itemService.queryTemplate(categoryId, itemType);
+ }
+
+ /**
+ * 售卖类(实物)商品创建
+ */
+ @ApiOperation(value = "售卖类(实物)商品创建")
+ @ApiOperationSupport(order = 3)
+ @PostMapping(value = "/sale/create")
+ public OpenResponse saleCreate(@RequestBody ItemCreateRequest request) {
+ return itemService.createSaleItem(request);
+ }
+
+ /**
+ * 租赁类(实物)商品创建
+ */
+ @ApiOperation(value = "租赁类(实物)商品创建")
+ @ApiOperationSupport(order = 4)
+ @PostMapping(value = "/rent/create")
+ public OpenResponse rentCreate(@RequestBody ItemCreateRequest request) {
+ return itemService.createRentItem(request);
+ }
+
+ /**
+ * 付费充值/兑换类(虚拟)商品创建
+ */
+ @ApiOperation(value = "付费充值/兑换类(虚拟)商品创建", notes = "电影/演出/体育赛事票务类商品")
+ @ApiOperationSupport(order = 5)
+ @PostMapping(value = "/virtual/create")
+ public OpenResponse virtualCreate(@RequestBody ItemCreateRequest request) {
+ return itemService.createVirtualItem(request);
+ }
+
+ /**
+ * 售卖类(实物)商品更新
+ */
+ @ApiOperation(value = "商品更新")
+ @ApiOperationSupport(order = 6)
+ @PostMapping(value = "/update")
+ public OpenResponse update(@RequestBody ItemCreateRequest request) {
+ return itemService.updateItem(request);
+ }
+
+ /**
+ * 商品详情查询
+ */
+ @ApiOperation(value = "商品详情查询")
+ @ApiOperationSupport(order = 7)
+ @GetMapping(value = "/query")
+ public OpenResponse query(@ApiParam(value = "支付平台侧商品ID") @RequestParam(required = false) String itemId,
+ @ApiParam(value = "商家侧商品ID") @RequestParam(required = false) String outItemId,
+ @ApiParam(value = "是否查询编辑版本,默认为0", defaultValue = "0") @RequestParam(required = false) String needEditSpu) {
+ return itemService.queryItemDetail(itemId, outItemId,
+ StringUtils.isNumeric(needEditSpu) ? Long.parseLong(needEditSpu) : 0);
+ }
+
+ /**
+ * 分页查询商品列表
+ */
+ @ApiOperation(value = "分页查询商品列表")
+ @ApiOperationSupport(order = 8)
+ @GetMapping(value = "/list/query")
+ public OpenResponse queryList(@ApiParam(value = "支付平台侧商品ID") @RequestParam(required = false) String itemId,
+ @ApiParam(value = "商家侧商品ID") @RequestParam(required = false) String outItemId,
+ @ApiParam(value = "页码", defaultValue = "1") @RequestParam(required = false) String pageNum,
+ @ApiParam(value = "单页大小", defaultValue = "10") @RequestParam(required = false) String pageSize) {
+ return itemService.queryItemList(itemId, outItemId,
+ StringUtils.isNumeric(pageNum) ? Long.parseLong(pageNum) : 1,
+ StringUtils.isNumeric(pageSize) ? Long.parseLong(pageSize) : 10);
+ }
+}
diff --git a/src/main/java/com/sczx/pay/alipay/service/ImageUploadService.java b/src/main/java/com/sczx/pay/alipay/service/ImageUploadService.java
new file mode 100644
index 0000000..70dbbda
--- /dev/null
+++ b/src/main/java/com/sczx/pay/alipay/service/ImageUploadService.java
@@ -0,0 +1,54 @@
+/**
+ * Alipay.com Inc.
+ * Copyright (c) 2004-2024 All Rights Reserved.
+ */
+package com.sczx.pay.alipay.service;
+
+import com.alipay.api.AlipayApiException;
+import com.alipay.api.response.AlipayMarketingImageListQueryResponse;
+import com.alipay.api.response.AlipayMarketingImagedirectoryListQueryResponse;
+import com.sczx.pay.alipay.vo.ImageDirectoryRequest;
+import com.sczx.pay.alipay.vo.OpenResponse;
+
+import java.util.List;
+
+/**
+ * @author jishupei.jsp
+ * @version : ImageUploadService, v0.1 2024年03月14日 10:38 上午 jishupei.jsp Exp $
+ */
+public interface ImageUploadService {
+ /**
+ * 上传图片,返回imageId
+ */
+ String uploadAndReturnId(String imagePath, String uploadScene) throws AlipayApiException;
+
+ /**
+ * 创建图片空间目录
+ */
+ OpenResponse createImageDirectory(ImageDirectoryRequest createRequest);
+
+ /**
+ * 修改图片空间目录
+ */
+ OpenResponse updateImageDirectory(ImageDirectoryRequest updateRequest);
+
+ /**
+ * 分页查询图片空间目录
+ */
+ OpenResponse queryImageDirectoryList(Long pageNum, Long pageSize, ImageDirectoryRequest queryRequest);
+
+ /**
+ * 修改图片信息
+ */
+ OpenResponse updateImage(String imageIndexId, String fileName, String imageDirectoryId);
+
+ /**
+ * 分页查询图片
+ */
+ OpenResponse queryImageList(Long pageNum, Long pageSize, String imageIndexId, String fileName, String imageDirectoryId);
+
+ /**
+ * 删除图片
+ */
+ OpenResponse deleteImage(List imageIndexIdList);
+}
diff --git a/src/main/java/com/sczx/pay/alipay/service/ItemService.java b/src/main/java/com/sczx/pay/alipay/service/ItemService.java
new file mode 100644
index 0000000..889639c
--- /dev/null
+++ b/src/main/java/com/sczx/pay/alipay/service/ItemService.java
@@ -0,0 +1,60 @@
+/**
+ * Alipay.com Inc.
+ * Copyright (c) 2004-2024 All Rights Reserved.
+ */
+package com.sczx.pay.alipay.service;
+
+import com.alipay.api.domain.AppxCategoryVO;
+import com.alipay.api.response.AlipayOpenAppItemListQueryResponse;
+import com.alipay.api.response.AlipayOpenAppItemQueryResponse;
+import com.alipay.api.response.AlipayOpenAppItemTemplateQueryResponse;
+import com.sczx.pay.alipay.vo.ItemCreateRequest;
+import com.sczx.pay.alipay.vo.OpenResponse;
+
+import java.util.List;
+
+/**
+ * @author jishupei.jsp
+ * @version : ItemService, v0.1 2024年05月11日 2:28 下午 jishupei.jsp Exp $
+ */
+public interface ItemService {
+ /**
+ * 获取叶子节点商品类目列表(默认获取类目状态为资质已开通的)
+ */
+ OpenResponse> getCategories(String itemType, String catStatus);
+
+ /**
+ * 查询普通商品模板信息
+ */
+ OpenResponse queryTemplate(String categoryId, String itemType);
+
+ /**
+ * 创建售卖类(实物)商品
+ */
+ OpenResponse createSaleItem(ItemCreateRequest param);
+
+ /**
+ * 创建租赁类(实物)商品
+ */
+ OpenResponse createRentItem(ItemCreateRequest param);
+
+ /**
+ * 创建付费充值/兑换类(虚拟)商品
+ */
+ OpenResponse createVirtualItem(ItemCreateRequest param);
+
+ /**
+ * 修改售卖类(实物)商品
+ */
+ OpenResponse updateItem(ItemCreateRequest param);
+
+ /**
+ * 查询商品详情
+ */
+ OpenResponse queryItemDetail(String itemId, String outItemId, long needEditSpu);
+
+ /**
+ * 分页查询商品列表
+ */
+ OpenResponse queryItemList(String itemId, String outItemId, long pageNum, long pageSize);
+}
diff --git a/src/main/java/com/sczx/pay/alipay/service/impl/ImageUploadServiceImpl.java b/src/main/java/com/sczx/pay/alipay/service/impl/ImageUploadServiceImpl.java
new file mode 100644
index 0000000..5f790d8
--- /dev/null
+++ b/src/main/java/com/sczx/pay/alipay/service/impl/ImageUploadServiceImpl.java
@@ -0,0 +1,301 @@
+/**
+ * Alipay.com Inc.
+ * Copyright (c) 2004-2024 All Rights Reserved.
+ */
+package com.sczx.pay.alipay.service.impl;
+
+import com.alipay.api.AlipayApiException;
+import com.alipay.api.FileItem;
+import com.alipay.api.domain.*;
+import com.alipay.api.internal.util.file.IOUtils;
+import com.alipay.api.request.*;
+import com.alipay.api.response.*;
+import com.sczx.pay.alipay.service.ImageUploadService;
+import com.sczx.pay.alipay.vo.ImageDirectoryRequest;
+import com.sczx.pay.alipay.vo.OpenResponse;
+import com.sczx.pay.utils.AlipayApiCallback;
+import com.sczx.pay.utils.AlipayApiTemplate;
+import com.sczx.pay.utils.AlipaySdkUtil;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.io.IOException;
+import java.util.List;
+
+/**
+ * @author jishupei.jsp
+ * @version : ImageUploadServiceImpl, v0.1 2024年03月14日 10:41 上午 jishupei.jsp Exp $
+ */
+@Service
+public class ImageUploadServiceImpl implements ImageUploadService {
+ private static final Logger logger = LogManager.getLogger(ImageUploadServiceImpl.class);
+
+ @Autowired
+ private AlipaySdkUtil alipaySdkUtil;
+
+ @Override
+ public String uploadAndReturnId(String imagePath, String uploadScene) throws AlipayApiException {
+ // 构造请求参数以调用接口
+ AlipayMarketingImageEnhanceUploadRequest request = new AlipayMarketingImageEnhanceUploadRequest();
+
+ // 设置图片是否需要优化
+ request.setNeedEnhance(true);
+
+ // 设置图片上传场景
+ request.setUploadScene(uploadScene);
+
+ // 设置图片内容
+ try {
+ byte[] bytes = IOUtils.toByteArray(this.getClass().getResourceAsStream("/" + imagePath));
+ FileItem imageContent = new FileItem(StringUtils.substringAfterLast(imagePath, "/"), bytes);
+ request.setImageContent(imageContent);
+ } catch (IOException e) {
+ throw new AlipayApiException("alipay.marketing.image.enhance.upload调用失败:" + e);
+ }
+
+ try {
+ AlipayMarketingImageEnhanceUploadResponse response = alipaySdkUtil.execute(request);
+ logger.info(response.getBody());
+
+ if (response.isSuccess()) {
+ logger.info("alipay.marketing.image.enhance.upload调用成功");
+ return response.getImageId();
+ } else {
+ logger.error("alipay.marketing.image.enhance.upload调用失败");
+ throw new AlipayApiException("alipay.marketing.image.enhance.upload调用失败:" + response.getBody());
+ }
+ } catch (Exception e) {
+ logger.error("alipay.marketing.image.enhance.upload调用失败", e);
+ throw new AlipayApiException("alipay.marketing.image.enhance.upload调用失败:" + e);
+ }
+ }
+
+ @Override
+ public OpenResponse createImageDirectory(ImageDirectoryRequest createRequest) {
+ return AlipayApiTemplate.execute(new AlipayApiCallback() {
+ @Override
+ public AlipayMarketingImagedirectoryCreateResponse process() throws AlipayApiException {
+ // 构造请求参数以调用接口
+ AlipayMarketingImagedirectoryCreateRequest request = new AlipayMarketingImagedirectoryCreateRequest();
+ AlipayMarketingImagedirectoryCreateModel model = new AlipayMarketingImagedirectoryCreateModel();
+
+ // 设置目录名
+ model.setImageDirectoryName(createRequest.getImageDirectoryName());
+
+ // 设置归属父目录id
+ model.setParentDirectoryId(createRequest.getParentDirectoryId());
+
+ request.setBizModel(model);
+ return alipaySdkUtil.execute(request);
+ }
+
+ @Override
+ public String getData(AlipayMarketingImagedirectoryCreateResponse response) {
+ return response.getImageDirectoryId();
+ }
+
+ @Override
+ public String getApiName() {
+ return "alipay.marketing.imagedirectory.create";
+ }
+ });
+ }
+
+ @Override
+ public OpenResponse updateImageDirectory(ImageDirectoryRequest updateRequest) {
+ return AlipayApiTemplate.execute(new AlipayApiCallback() {
+ @Override
+ public AlipayMarketingImagedirectoryModifyResponse process() throws AlipayApiException {
+ // 构造请求参数以调用接口
+ AlipayMarketingImagedirectoryModifyRequest request = new AlipayMarketingImagedirectoryModifyRequest();
+ AlipayMarketingImagedirectoryModifyModel model = new AlipayMarketingImagedirectoryModifyModel();
+
+ // 设置目录id
+ model.setImageDirectoryId(updateRequest.getImageDirectoryId());
+
+ if (StringUtils.isNotBlank(updateRequest.getImageDirectoryName())) {
+ // 设置目录名
+ model.setImageDirectoryName(updateRequest.getImageDirectoryName());
+ }
+
+ if (StringUtils.isNotBlank(updateRequest.getParentDirectoryId())) {
+ // 设置父目录id
+ model.setParentDirectoryId(updateRequest.getParentDirectoryId());
+ }
+
+ request.setBizModel(model);
+ return alipaySdkUtil.execute(request);
+ }
+
+ @Override
+ public Void getData(AlipayMarketingImagedirectoryModifyResponse response) {
+ return null;
+ }
+
+ @Override
+ public String getApiName() {
+ return "alipay.marketing.imagedirectory.modify";
+ }
+ });
+ }
+
+ @Override
+ public OpenResponse queryImageDirectoryList(Long pageNum, Long pageSize, ImageDirectoryRequest queryRequest) {
+ return AlipayApiTemplate.execute(new AlipayApiCallback() {
+ @Override
+ public AlipayMarketingImagedirectoryListQueryResponse process() throws AlipayApiException {
+ // 构造请求参数以调用接口
+ AlipayMarketingImagedirectoryListQueryRequest request = new AlipayMarketingImagedirectoryListQueryRequest();
+ AlipayMarketingImagedirectoryListQueryModel model = new AlipayMarketingImagedirectoryListQueryModel();
+
+ // 设置页码
+ model.setPageNum(pageNum == null ? 1L : pageNum);
+
+ // 设置单页条数
+ model.setPageSize(pageSize == null ? 10L : pageSize);
+
+ if (StringUtils.isNotBlank(queryRequest.getImageDirectoryName())) {
+ // 设置目录名
+ model.setImageDirectoryName(queryRequest.getImageDirectoryName());
+ }
+
+ if (StringUtils.isNotBlank(queryRequest.getImageDirectoryId())) {
+ // 设置目录id
+ model.setImageDirectoryId(queryRequest.getImageDirectoryId());
+ }
+
+ if (StringUtils.isNotBlank(queryRequest.getParentDirectoryId())) {
+ // 设置父目录id
+ model.setParentDirectoryId(queryRequest.getParentDirectoryId());
+ }
+
+ request.setBizModel(model);
+ return alipaySdkUtil.execute(request);
+ }
+
+ @Override
+ public AlipayMarketingImagedirectoryListQueryResponse getData(AlipayMarketingImagedirectoryListQueryResponse response) {
+ return response;
+ }
+
+ @Override
+ public String getApiName() {
+ return "alipay.marketing.imagedirectory.list.query";
+ }
+ });
+ }
+
+ @Override
+ public OpenResponse updateImage(String imageIndexId, String fileName, String imageDirectoryId) {
+ return AlipayApiTemplate.execute(new AlipayApiCallback() {
+ @Override
+ public AlipayMarketingImageModifyResponse process() throws AlipayApiException {
+ // 构造请求参数以调用接口
+ AlipayMarketingImageModifyRequest request = new AlipayMarketingImageModifyRequest();
+ AlipayMarketingImageModifyModel model = new AlipayMarketingImageModifyModel();
+
+ // 设置图索引id
+ model.setImageIndexId(imageIndexId);
+
+ if (StringUtils.isNotBlank(fileName)) {
+ // 设置修改后新文件名
+ model.setFileName(fileName);
+ }
+
+ if (StringUtils.isNotBlank(imageDirectoryId)) {
+ // 设置修改后新目录id
+ model.setImageDirectoryId(imageDirectoryId);
+ }
+
+ request.setBizModel(model);
+ return alipaySdkUtil.execute(request);
+ }
+
+ @Override
+ public Void getData(AlipayMarketingImageModifyResponse response) {
+ return null;
+ }
+
+ @Override
+ public String getApiName() {
+ return "alipay.marketing.image.modify";
+ }
+ });
+ }
+
+ @Override
+ public OpenResponse queryImageList(Long pageNum, Long pageSize, String imageIndexId, String fileName, String imageDirectoryId) {
+ return AlipayApiTemplate.execute(new AlipayApiCallback() {
+ @Override
+ public AlipayMarketingImageListQueryResponse process() throws AlipayApiException {
+ // 构造请求参数以调用接口
+ AlipayMarketingImageListQueryRequest request = new AlipayMarketingImageListQueryRequest();
+ AlipayMarketingImageListQueryModel model = new AlipayMarketingImageListQueryModel();
+
+ // 设置页码
+ model.setPageNum(pageNum == null ? 1L : pageNum);
+
+ // 设置单页条数
+ model.setPageSize(pageSize == null ? 10L : pageSize);
+
+ if (StringUtils.isNotBlank(imageIndexId)) {
+ // 设置图索引id
+ model.setImageIndexId(imageIndexId);
+ }
+
+ if (StringUtils.isNotBlank(fileName)) {
+ // 设置图文件名
+ model.setFileName(fileName);
+ }
+
+ if (StringUtils.isNotBlank(imageDirectoryId)) {
+ // 设置图归属目录id
+ model.setImageDirectoryId(imageDirectoryId);
+ }
+
+ request.setBizModel(model);
+ return alipaySdkUtil.execute(request);
+ }
+
+ @Override
+ public AlipayMarketingImageListQueryResponse getData(AlipayMarketingImageListQueryResponse response) {
+ return response;
+ }
+
+ @Override
+ public String getApiName() {
+ return "alipay.marketing.image.list.query";
+ }
+ });
+ }
+
+ @Override
+ public OpenResponse deleteImage(List imageIndexIdList) {
+ return AlipayApiTemplate.execute(new AlipayApiCallback() {
+ @Override
+ public AlipayMarketingImageDeleteResponse process() throws AlipayApiException {
+ // 构造请求参数以调用接口
+ AlipayMarketingImageDeleteRequest request = new AlipayMarketingImageDeleteRequest();
+ AlipayMarketingImageDeleteModel model = new AlipayMarketingImageDeleteModel();
+
+ model.setImageIndexIdList(imageIndexIdList);
+
+ request.setBizModel(model);
+ return alipaySdkUtil.execute(request);
+ }
+
+ @Override
+ public Void getData(AlipayMarketingImageDeleteResponse response) {
+ return null;
+ }
+
+ @Override
+ public String getApiName() {
+ return "alipay.marketing.image.delete";
+ }
+ });
+ }
+}
diff --git a/src/main/java/com/sczx/pay/alipay/service/impl/ItemServiceImpl.java b/src/main/java/com/sczx/pay/alipay/service/impl/ItemServiceImpl.java
new file mode 100644
index 0000000..24b46fa
--- /dev/null
+++ b/src/main/java/com/sczx/pay/alipay/service/impl/ItemServiceImpl.java
@@ -0,0 +1,515 @@
+package com.sczx.pay.alipay.service.impl;
+
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.alipay.api.AlipayApiException;
+import com.alipay.api.domain.*;
+import com.alipay.api.internal.util.StringUtils;
+import com.alipay.api.request.*;
+import com.alipay.api.response.*;
+import com.sczx.pay.alipay.service.ImageUploadService;
+import com.sczx.pay.alipay.service.ItemService;
+import com.sczx.pay.alipay.vo.ItemCreateRequest;
+import com.sczx.pay.alipay.vo.OpenResponse;
+import com.sczx.pay.utils.AlipayApiCallback;
+import com.sczx.pay.utils.AlipayApiTemplate;
+import com.sczx.pay.utils.AlipaySdkUtil;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.springframework.util.CollectionUtils;
+
+import java.io.UnsupportedEncodingException;
+import java.net.URLEncoder;
+import java.time.LocalDateTime;
+import java.time.format.DateTimeFormatter;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Objects;
+import java.util.Optional;
+
+/**
+ * @author jishupei.jsp
+ * @version : ItemServiceImpl, v0.1 2024年05月11日 2:31 下午 jishupei.jsp Exp $
+ */
+@Service
+public class ItemServiceImpl implements ItemService {
+
+ private static final Logger logger = LogManager.getLogger(ItemServiceImpl.class);
+
+ @Autowired
+ private AlipaySdkUtil alipaySdkUtil;
+
+ @Autowired
+ private ImageUploadService imageUploadService;
+
+ @Override
+ public OpenResponse> getCategories(String itemType, String catStatus) {
+ return AlipayApiTemplate.execute(new AlipayApiCallback, AlipayOpenAppItemAllcategoryQueryResponse>() {
+ @Override
+ public AlipayOpenAppItemAllcategoryQueryResponse process() throws AlipayApiException {
+ // 构造请求参数以调用接口
+ AlipayOpenAppItemAllcategoryQueryRequest request = new AlipayOpenAppItemAllcategoryQueryRequest();
+ AlipayOpenAppItemAllcategoryQueryModel model = new AlipayOpenAppItemAllcategoryQueryModel();
+
+ // 设置商品类型
+ model.setItemType(itemType);
+
+ model.setCatStatus(StringUtils.isEmpty(catStatus) ? "AUDIT_PASSED" : catStatus);
+
+ request.setBizModel(model);
+ return alipaySdkUtil.execute(request);
+ }
+
+ @Override
+ public List getData(AlipayOpenAppItemAllcategoryQueryResponse response) {
+ List cats = response.getCats();
+ if (CollectionUtils.isEmpty(cats)) {
+ return null;
+ }
+ List childs = new ArrayList<>();
+ for (CategoryAndParentVO cat : cats) {
+ if (CollectionUtils.isEmpty(cat.getCatAndParent())) {
+ continue;
+ }
+ // 获取叶子节点(cat_status不为空的是叶子结点)
+ Optional categoryVO = cat.getCatAndParent().stream().filter(Objects::nonNull)
+ .filter(child -> StringUtils.areNotEmpty(child.getCatStatus())).findFirst();
+ categoryVO.ifPresent(childs::add);
+ }
+ return childs;
+ }
+
+ @Override
+ public String getApiName() {
+ return "alipay.open.app.item.allcategory.query";
+ }
+ });
+ }
+
+ @Override
+ public OpenResponse queryTemplate(String categoryId, String itemType) {
+ return AlipayApiTemplate.execute(new AlipayApiCallback() {
+ @Override
+ public AlipayOpenAppItemTemplateQueryResponse process() throws AlipayApiException {
+ // 构造请求参数以调用接口
+ AlipayOpenAppItemTemplateQueryRequest request = new AlipayOpenAppItemTemplateQueryRequest();
+ AlipayOpenAppItemTemplateQueryModel model = new AlipayOpenAppItemTemplateQueryModel();
+
+ // 设置类目id
+ model.setCategoryId(categoryId);
+
+ model.setItemType(itemType);
+
+ request.setBizModel(model);
+ return alipaySdkUtil.execute(request);
+ }
+
+ @Override
+ public AlipayOpenAppItemTemplateQueryResponse getData(AlipayOpenAppItemTemplateQueryResponse response) {
+ return response;
+ }
+
+ @Override
+ public String getApiName() {
+ return "alipay.open.app.item.template.query";
+ }
+ });
+ }
+
+ @Override
+ public OpenResponse createSaleItem(ItemCreateRequest param) {
+ return AlipayApiTemplate.execute(new AlipayApiCallback() {
+
+ @Override
+ public AlipayOpenAppItemCreateResponse process() throws AlipayApiException {
+ // 构造请求参数以调用接口
+ AlipayOpenAppItemCreateRequest request = new AlipayOpenAppItemCreateRequest();
+ AlipayOpenAppItemCreateModel model = getAlipayOpenAppItemCreateModel(param);
+
+ // 设置商品模版类型
+ model.setItemType("1");
+
+ // 设置价格单元
+ model.setPriceUnit("元");
+
+ // 设置属性列表
+ model.setAttrs(getItemAttrs(param, model.getImageList(), model.getItemType()));
+
+ request.setBizModel(model);
+ return alipaySdkUtil.execute(request);
+ }
+
+ @Override
+ public String getData(AlipayOpenAppItemCreateResponse response) {
+ return response.getItemId();
+ }
+
+ @Override
+ public String getApiName() {
+ return "alipay.open.app.item.create";
+ }
+ });
+ }
+
+ @Override
+ public OpenResponse createRentItem(ItemCreateRequest param) {
+ return AlipayApiTemplate.execute(new AlipayApiCallback() {
+
+ @Override
+ public AlipayOpenAppItemCreateResponse process() throws AlipayApiException {
+ // 构造请求参数以调用接口
+ AlipayOpenAppItemCreateRequest request = new AlipayOpenAppItemCreateRequest();
+ AlipayOpenAppItemCreateModel model = getAlipayOpenAppItemCreateModel(param);
+
+ // 设置商品模版类型
+ model.setItemType("2");
+
+ // 设置价格单元
+ model.setPriceUnit("元/日");
+
+ // 设置属性列表
+ model.setAttrs(getItemAttrs(param, model.getImageList(), model.getItemType()));
+
+ request.setBizModel(model);
+ return alipaySdkUtil.execute(request);
+ }
+
+ @Override
+ public String getData(AlipayOpenAppItemCreateResponse response) {
+ return response.getItemId();
+ }
+
+ @Override
+ public String getApiName() {
+ return "alipay.open.app.item.create";
+ }
+ });
+ }
+
+ @Override
+ public OpenResponse createVirtualItem(ItemCreateRequest param) {
+ return AlipayApiTemplate.execute(new AlipayApiCallback() {
+
+ @Override
+ public AlipayOpenAppItemCreateResponse process() throws AlipayApiException {
+ // 构造请求参数以调用接口
+ AlipayOpenAppItemCreateRequest request = new AlipayOpenAppItemCreateRequest();
+ AlipayOpenAppItemCreateModel model = getAlipayOpenAppItemCreateModel(param);
+
+ // 设置商品模版类型
+ model.setItemType("3");
+
+ // 设置价格单元
+ model.setPriceUnit("元");
+
+ // 设置属性列表
+ model.setAttrs(getItemAttrs(param, model.getImageList(), model.getItemType()));
+
+ request.setBizModel(model);
+ return alipaySdkUtil.execute(request);
+ }
+
+ @Override
+ public String getData(AlipayOpenAppItemCreateResponse response) {
+ return response.getItemId();
+ }
+
+ @Override
+ public String getApiName() {
+ return "alipay.open.app.item.create";
+ }
+ });
+ }
+
+ @Override
+ public OpenResponse updateItem(ItemCreateRequest param) {
+ return AlipayApiTemplate.execute(new AlipayApiCallback() {
+
+ @Override
+ public AlipayOpenAppItemModifyResponse process() throws AlipayApiException {
+ // 构造请求参数以调用接口
+ AlipayOpenAppItemModifyRequest request = new AlipayOpenAppItemModifyRequest();
+ AlipayOpenAppItemCreateModel model = getAlipayOpenAppItemCreateModel(param);
+
+ // 设置商品模版类型
+ model.setItemType("1");
+
+ // 设置价格单元
+ model.setPriceUnit("元");
+
+ // 设置属性列表
+ model.setAttrs(getItemAttrs(param, model.getImageList(), model.getItemType()));
+
+ request.setBizModel(model);
+ return alipaySdkUtil.execute(request);
+ }
+
+ @Override
+ public String getData(AlipayOpenAppItemModifyResponse response) {
+ return response.getItemId();
+ }
+
+ @Override
+ public String getApiName() {
+ return "alipay.open.app.item.modify";
+ }
+ });
+ }
+
+ @Override
+ public OpenResponse queryItemDetail(String itemId, String outItemId, long needEditSpu) {
+ return AlipayApiTemplate.execute(new AlipayApiCallback() {
+ @Override
+ public AlipayOpenAppItemQueryResponse process() throws AlipayApiException {
+ // 构造请求参数以调用接口
+ AlipayOpenAppItemQueryRequest request = new AlipayOpenAppItemQueryRequest();
+ AlipayOpenAppItemQueryModel model = new AlipayOpenAppItemQueryModel();
+ if (!StringUtils.isEmpty(itemId)) {
+ // 设置支付宝侧商品id
+ model.setItemId(itemId);
+ }
+
+ if (!StringUtils.isEmpty(outItemId)) {
+ // 设置商家侧商品id
+ model.setOutItemId(outItemId);
+ }
+
+ // 设置是否查询编辑版本
+ model.setNeedEditSpu(needEditSpu);
+
+ request.setBizModel(model);
+
+ return alipaySdkUtil.execute(request);
+ }
+
+ @Override
+ public AlipayOpenAppItemQueryResponse getData(AlipayOpenAppItemQueryResponse response) {
+ return response;
+ }
+
+ @Override
+ public String getApiName() {
+ return "alipay.open.app.item.query";
+ }
+ });
+ }
+
+ @Override
+ public OpenResponse queryItemList(String itemId, String outItemId, long pageNum, long pageSize) {
+ return AlipayApiTemplate.execute(new AlipayApiCallback() {
+ @Override
+ public AlipayOpenAppItemListQueryResponse process() throws AlipayApiException {
+ // 构造请求参数以调用接口
+ AlipayOpenAppItemListQueryRequest request = new AlipayOpenAppItemListQueryRequest();
+ AlipayOpenAppItemListQueryModel model = new AlipayOpenAppItemListQueryModel();
+
+ if (!StringUtils.isEmpty(outItemId)) {
+ // 设置商家侧id列表
+ List outItemIdList = new ArrayList<>();
+ outItemIdList.add(outItemId);
+ model.setOutItemIdList(outItemIdList);
+ }
+
+ if (!StringUtils.isEmpty(itemId)) {
+ // 设置平台侧商品id列表
+ List itemIdList = new ArrayList<>();
+ itemIdList.add(itemId);
+ model.setItemIdList(itemIdList);
+ }
+
+ // 设置页码
+ model.setPageNum(pageNum);
+ // 设置单页大小
+ model.setPageSize(pageSize);
+
+ request.setBizModel(model);
+
+ return alipaySdkUtil.execute(request);
+ }
+
+ @Override
+ public AlipayOpenAppItemListQueryResponse getData(AlipayOpenAppItemListQueryResponse response) {
+ return response;
+ }
+
+ @Override
+ public String getApiName() {
+ return "alipay.open.app.item.list.query";
+ }
+ });
+ }
+
+ private AlipayOpenAppItemCreateModel getAlipayOpenAppItemCreateModel(ItemCreateRequest param) throws AlipayApiException {
+ AlipayOpenAppItemCreateModel model = new AlipayOpenAppItemCreateModel();
+
+ // 设置商家侧商品ID
+ model.setOutItemId(param.getOutItemId());
+
+ // 设置商品名称
+ model.setTitle(param.getProductName());
+
+ // 设置导购描述
+ model.setDesc(param.getProductName());
+
+ // 设置商品主图
+ model.setHeadImg(imageUploadService.uploadAndReturnId("file/head.jpg", "ITEM_HEAD_IMG"));
+
+ // 设置商品图片的文件id列表
+ List imageList = new ArrayList<>();
+ imageList.add(imageUploadService.uploadAndReturnId("file/head.jpg", "ITEM_IMAGE_LIST"));
+ model.setImageList(imageList);
+
+ // 设置商品详情页URL,需要先完成商品详情页组件开发接入
+ try {
+ String url = "plugin-private://2021003177653028/pages/goodsDetail/goodsDetail?outItemId=" + param.getOutItemId();
+ model.setPath("alipays://platformapi/startApp?appId=" + alipaySdkUtil.getAppId()
+ + "&page=" + URLEncoder.encode(url, "utf-8"));
+ } catch (UnsupportedEncodingException e) {
+ throw new AlipayApiException("url解析失败");
+ }
+
+ // 设置类目ID
+ model.setCategoryId(param.getCategoryId());
+
+ // 设置商品售价
+ model.setSalePrice(1L);
+
+ // 设置商品原价
+ model.setOriginalPrice(1000L);
+
+ // 设置库存
+ model.setStockNum(100L);
+
+ // 设置商品售卖状态
+ model.setSaleStatus("AVAILABLE");
+
+ return model;
+ }
+
+ private List getTemplateItemAttrs(String categoryId, String itemType) throws AlipayApiException {
+ OpenResponse templateResponse = queryTemplate(categoryId, itemType);
+ if (!"10000".equals(templateResponse.getCode())) {
+ throw new AlipayApiException("查询普通商品模板失败");
+ }
+
+ if (templateResponse.getData().getAttr() == null) {
+ return null;
+ }
+
+ return templateResponse.getData().getAttr().getItemAttrList();
+ }
+
+ private List getItemAttrs(ItemCreateRequest param, List imageList, String itemType) throws AlipayApiException {
+ List attributes = getTemplateItemAttrs(param.getCategoryId(), itemType);
+ if (CollectionUtils.isEmpty(attributes)) {
+ return null;
+ }
+ List attrs = new ArrayList<>();
+ for (AttributeVO attr : attributes) {
+ AppItemAttrVO appItemAttrVO = new AppItemAttrVO();
+ appItemAttrVO.setAttrKey(attr.getKey());
+
+ switch (attr.getKey()) {
+ // -----BEGIN 普通实物类商品可传入以下属性 -----
+ case "delivery_info":
+ // 商品履约信息
+ if (StringUtils.isEmpty(param.getDeliveryId())) {
+ break;
+ }
+ JSONObject jsonObject = new JSONObject();
+ jsonObject.put("delivery_id", param.getDeliveryId());
+ jsonObject.put("shop_ids", param.getShopIds());
+ JSONArray jsonArray = new JSONArray();
+ jsonArray.add(jsonObject);
+ appItemAttrVO.setAttrValue(JSONArray.toJSONString(jsonArray));
+ break;
+ case "selling_point_tag":
+ // 导购标签
+ appItemAttrVO.setAttrValue("[\"鲜花\",\"盆栽\"]");
+ break;
+ case "white_ground_image":
+ // 商品白底图
+ JSONObject image = new JSONObject();
+ image.put("url_list", imageList);
+ appItemAttrVO.setAttrValue(image.toJSONString());
+ break;
+ case "shipping_time_limit":
+ // 现货发货时效
+ appItemAttrVO.setAttrValue("1");
+ break;
+ // -----END 普通实物类商品可传入以上属性 -----
+
+ // -----BEGIN 租赁类商品可传入以下属性 -----
+ case "rent_from_numbers_of_day":
+ // 起租天数
+ appItemAttrVO.setAttrValue("3");
+ break;
+ case "item_fineness":
+ // 商品成色
+ appItemAttrVO.setAttrValue("secondHand");
+ break;
+ case "whether_support_free_deposit":
+ // 是否支持免押
+ appItemAttrVO.setAttrValue("1");
+ break;
+ case "whether_continue_rent":
+ // 是否可续租
+ appItemAttrVO.setAttrValue("1");
+ break;
+ case "whether_buyout":
+ // 是否可买断
+ appItemAttrVO.setAttrValue("1");
+ break;
+ // -----END 租赁类商品可传入以上属性 -----
+
+ // -----BEGIN 虚拟类(电影/演出/体育赛事/休闲娱乐/运动健身类目)商品可传入以下属性 -----
+ case "sale_time":
+ // 开售时间,明天16:00:00开始
+ appItemAttrVO.setAttrValue(LocalDateTime.now()
+ .plusDays(1)
+ .withHour(16)
+ .withMinute(0)
+ .withSecond(0)
+ .format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
+ break;
+ case "performance_date_range":
+ // 演出日期
+ JSONObject range = new JSONObject();
+ LocalDateTime localDateTime = LocalDateTime.now()
+ .plusMonths(1);
+ // 一个月后开始
+ range.put("start_date", localDateTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")));
+ range.put("end_date", localDateTime
+ .plusDays(1)
+ .format(DateTimeFormatter.ofPattern("yyyy-MM-dd")));
+ appItemAttrVO.setAttrValue(range.toJSONString());
+ break;
+ case "agent_type":
+ // 票务代理类型
+ appItemAttrVO.setAttrValue("1");
+ break;
+ case "performance_area":
+ // 演出举办地区
+ appItemAttrVO.setAttrValue("{\"city_code\":\"120100\"}");
+ break;
+ case "venue_name":
+ // 演出场馆名称
+ appItemAttrVO.setAttrValue("蚂蚁A空间");
+ break;
+ case "post_img":
+ // 演出海报(图片)
+ JSONObject image2 = new JSONObject();
+ image2.put("url_list", imageList);
+ appItemAttrVO.setAttrValue(image2.toJSONString());
+ break;
+ // -----END 虚拟类(电影/演出/体育赛事/休闲娱乐/运动健身类目)商品可传入以上属性 -----
+ }
+ if (!StringUtils.isEmpty(appItemAttrVO.getAttrValue())) {
+ attrs.add(appItemAttrVO);
+ }
+ }
+ return attrs;
+ }
+}
diff --git a/src/main/java/com/sczx/pay/alipay/vo/ImageDirectoryRequest.java b/src/main/java/com/sczx/pay/alipay/vo/ImageDirectoryRequest.java
new file mode 100644
index 0000000..414a608
--- /dev/null
+++ b/src/main/java/com/sczx/pay/alipay/vo/ImageDirectoryRequest.java
@@ -0,0 +1,83 @@
+/**
+ * Alipay.com Inc.
+ * Copyright (c) 2004-2024 All Rights Reserved.
+ */
+package com.sczx.pay.alipay.vo;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+
+import java.io.Serializable;
+
+/**
+ * @author jishupei.jsp
+ * @version : ImageDirectoryRequest, v0.1 2024年05月21日 11:38 上午 jishupei.jsp Exp $
+ */
+@ApiModel(description = "图片空间目录创建模型")
+public class ImageDirectoryRequest implements Serializable {
+
+ private static final long serialVersionUID = -6703393134790409650L;
+
+ @ApiModelProperty(value = "目录名,创建时必填")
+ private String imageDirectoryName;
+
+ @ApiModelProperty(value = "归属父目录ID,创建时必填", example = "0")
+ private String parentDirectoryId;
+
+ @ApiModelProperty(value = "目录ID,更新时必填")
+ private String imageDirectoryId;
+
+ /**
+ * Getter method for property imageDirectoryName.
+ *
+ * @return property value of imageDirectoryName
+ */
+ public String getImageDirectoryName() {
+ return imageDirectoryName;
+ }
+
+ /**
+ * Setter method for property imageDirectoryName.
+ *
+ * @param imageDirectoryName value to be assigned to property imageDirectoryName
+ */
+ public void setImageDirectoryName(String imageDirectoryName) {
+ this.imageDirectoryName = imageDirectoryName;
+ }
+
+ /**
+ * Getter method for property parentDirectoryId.
+ *
+ * @return property value of parentDirectoryId
+ */
+ public String getParentDirectoryId() {
+ return parentDirectoryId;
+ }
+
+ /**
+ * Setter method for property parentDirectoryId.
+ *
+ * @param parentDirectoryId value to be assigned to property parentDirectoryId
+ */
+ public void setParentDirectoryId(String parentDirectoryId) {
+ this.parentDirectoryId = parentDirectoryId;
+ }
+
+ /**
+ * Getter method for property imageDirectoryId.
+ *
+ * @return property value of imageDirectoryId
+ */
+ public String getImageDirectoryId() {
+ return imageDirectoryId;
+ }
+
+ /**
+ * Setter method for property imageDirectoryId.
+ *
+ * @param imageDirectoryId value to be assigned to property imageDirectoryId
+ */
+ public void setImageDirectoryId(String imageDirectoryId) {
+ this.imageDirectoryId = imageDirectoryId;
+ }
+}
diff --git a/src/main/java/com/sczx/pay/alipay/vo/ItemCreateRequest.java b/src/main/java/com/sczx/pay/alipay/vo/ItemCreateRequest.java
new file mode 100644
index 0000000..fbf1773
--- /dev/null
+++ b/src/main/java/com/sczx/pay/alipay/vo/ItemCreateRequest.java
@@ -0,0 +1,164 @@
+/**
+ * Alipay.com Inc.
+ * Copyright (c) 2004-2024 All Rights Reserved.
+ */
+package com.sczx.pay.alipay.vo;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+
+import java.io.Serializable;
+import java.util.List;
+
+/**
+ * @author jishupei.jsp
+ * @version : ItemCreateRequest, v0.1 2024年05月11日 3:31 下午 jishupei.jsp Exp $
+ */
+@ApiModel(description = "普通商品创建模型")
+public class ItemCreateRequest implements Serializable {
+ private static final long serialVersionUID = 89765465465L;
+
+ /**
+ * 类目ID
+ */
+ @ApiModelProperty(value = "类目ID", example = "C001375478", required = true)
+ private String categoryId;
+
+ /**
+ * 商品名称
+ */
+ @ApiModelProperty(value = "商品名称", example = "测试xxx", required = true)
+ private String productName;
+
+ /**
+ * 商家侧商品ID
+ */
+ @ApiModelProperty(value = "商家侧商品ID", example = "10001", required = true)
+ private String outItemId;
+
+ /**
+ * 商家名称
+ */
+ @ApiModelProperty(value = "商家名称")
+ private String merchantName = "测试商家";
+
+ /**
+ * 履约信息ID
+ */
+ @ApiModelProperty(value = "履约信息ID,从履约信息同步接口中返回")
+ private String deliveryId;
+
+ /**
+ * 门店ID列表
+ */
+ @ApiModelProperty(value = "履约信息ID关联的门店ID列表")
+ private List shopIds;
+
+ /**
+ * Getter method for property categoryId.
+ *
+ * @return property value of categoryId
+ */
+ public String getCategoryId() {
+ return categoryId;
+ }
+
+ /**
+ * Setter method for property categoryId.
+ *
+ * @param categoryId value to be assigned to property categoryId
+ */
+ public void setCategoryId(String categoryId) {
+ this.categoryId = categoryId;
+ }
+
+ /**
+ * Getter method for property productName.
+ *
+ * @return property value of productName
+ */
+ public String getProductName() {
+ return productName;
+ }
+
+ /**
+ * Setter method for property productName.
+ *
+ * @param productName value to be assigned to property productName
+ */
+ public void setProductName(String productName) {
+ this.productName = productName;
+ }
+
+ /**
+ * Getter method for property outItemId.
+ *
+ * @return property value of outItemId
+ */
+ public String getOutItemId() {
+ return outItemId;
+ }
+
+ /**
+ * Setter method for property outItemId.
+ *
+ * @param outItemId value to be assigned to property outItemId
+ */
+ public void setOutItemId(String outItemId) {
+ this.outItemId = outItemId;
+ }
+
+ /**
+ * Getter method for property merchantName.
+ *
+ * @return property value of merchantName
+ */
+ public String getMerchantName() {
+ return merchantName;
+ }
+
+ /**
+ * Setter method for property merchantName.
+ *
+ * @param merchantName value to be assigned to property merchantName
+ */
+ public void setMerchantName(String merchantName) {
+ this.merchantName = merchantName;
+ }
+
+ /**
+ * Getter method for property deliveryId.
+ *
+ * @return property value of deliveryId
+ */
+ public String getDeliveryId() {
+ return deliveryId;
+ }
+
+ /**
+ * Setter method for property deliveryId.
+ *
+ * @param deliveryId value to be assigned to property deliveryId
+ */
+ public void setDeliveryId(String deliveryId) {
+ this.deliveryId = deliveryId;
+ }
+
+ /**
+ * Getter method for property shopIds.
+ *
+ * @return property value of shopIds
+ */
+ public List getShopIds() {
+ return shopIds;
+ }
+
+ /**
+ * Setter method for property shopIds.
+ *
+ * @param shopIds value to be assigned to property shopIds
+ */
+ public void setShopIds(List shopIds) {
+ this.shopIds = shopIds;
+ }
+}
diff --git a/src/main/java/com/sczx/pay/alipay/vo/OpenResponse.java b/src/main/java/com/sczx/pay/alipay/vo/OpenResponse.java
new file mode 100644
index 0000000..161df23
--- /dev/null
+++ b/src/main/java/com/sczx/pay/alipay/vo/OpenResponse.java
@@ -0,0 +1,136 @@
+/**
+ * Alipay.com Inc.
+ * Copyright (c) 2004-2024 All Rights Reserved.
+ */
+package com.sczx.pay.alipay.vo;
+
+import com.alipay.api.AlipayApiException;
+import com.alipay.api.AlipayResponse;
+import org.apache.commons.lang3.StringUtils;
+
+import java.io.Serializable;
+
+/**
+ * @author jishupei.jsp
+ * @version : OpenResponse, v0.1 2024年03月26日 7:59 下午 jishupei.jsp Exp $
+ */
+public class OpenResponse implements Serializable {
+ private static final long serialVersionUID = 8943991234L;
+
+ private String code;
+
+ private String msg;
+
+ private String subCode;
+
+ private String subMsg;
+
+ private E data;
+
+ public OpenResponse() {
+ }
+
+ public OpenResponse(AlipayResponse response) {
+ this.code = response.getCode();
+ this.msg = response.getMsg();
+ this.subCode = response.getSubCode();
+ this.subMsg = response.getSubMsg();
+ }
+
+ public OpenResponse(AlipayApiException e) {
+ this.code = "ALIPAY_SDK_ERROR";
+ this.msg = "支付宝SDK调用异常";
+ this.subCode = e.getErrCode();
+ this.subMsg = StringUtils.defaultIfBlank(e.getErrMsg(), e.getMessage());
+ }
+
+ /**
+ * Getter method for property code.
+ *
+ * @return property value of code
+ */
+ public String getCode() {
+ return code;
+ }
+
+ /**
+ * Setter method for property code.
+ *
+ * @param code value to be assigned to property code
+ */
+ public void setCode(String code) {
+ this.code = code;
+ }
+
+ /**
+ * Getter method for property msg.
+ *
+ * @return property value of msg
+ */
+ public String getMsg() {
+ return msg;
+ }
+
+ /**
+ * Setter method for property msg.
+ *
+ * @param msg value to be assigned to property msg
+ */
+ public void setMsg(String msg) {
+ this.msg = msg;
+ }
+
+ /**
+ * Getter method for property subCode.
+ *
+ * @return property value of subCode
+ */
+ public String getSubCode() {
+ return subCode;
+ }
+
+ /**
+ * Setter method for property subCode.
+ *
+ * @param subCode value to be assigned to property subCode
+ */
+ public void setSubCode(String subCode) {
+ this.subCode = subCode;
+ }
+
+ /**
+ * Getter method for property subMsg.
+ *
+ * @return property value of subMsg
+ */
+ public String getSubMsg() {
+ return subMsg;
+ }
+
+ /**
+ * Setter method for property subMsg.
+ *
+ * @param subMsg value to be assigned to property subMsg
+ */
+ public void setSubMsg(String subMsg) {
+ this.subMsg = subMsg;
+ }
+
+ /**
+ * Getter method for property data.
+ *
+ * @return property value of data
+ */
+ public E getData() {
+ return data;
+ }
+
+ /**
+ * Setter method for property data.
+ *
+ * @param data value to be assigned to property data
+ */
+ public void setData(E data) {
+ this.data = data;
+ }
+}
diff --git a/src/main/java/com/sczx/pay/utils/AlipayApiCallback.java b/src/main/java/com/sczx/pay/utils/AlipayApiCallback.java
new file mode 100644
index 0000000..43c1089
--- /dev/null
+++ b/src/main/java/com/sczx/pay/utils/AlipayApiCallback.java
@@ -0,0 +1,21 @@
+/**
+ * Alipay.com Inc.
+ * Copyright (c) 2004-2024 All Rights Reserved.
+ */
+package com.sczx.pay.utils;
+
+import com.alipay.api.AlipayApiException;
+import com.alipay.api.AlipayResponse;
+
+/**
+ * @author jishupei.jsp
+ * @version : AlipayApiCallback, v0.1 2024年03月27日 5:46 下午 jishupei.jsp Exp $
+ */
+public interface AlipayApiCallback {
+
+ R process() throws AlipayApiException;
+
+ T getData(R response);
+
+ String getApiName();
+}
diff --git a/src/main/java/com/sczx/pay/utils/AlipayApiTemplate.java b/src/main/java/com/sczx/pay/utils/AlipayApiTemplate.java
new file mode 100644
index 0000000..e6d1b62
--- /dev/null
+++ b/src/main/java/com/sczx/pay/utils/AlipayApiTemplate.java
@@ -0,0 +1,50 @@
+/**
+ * Alipay.com Inc.
+ * Copyright (c) 2004-2024 All Rights Reserved.
+ */
+package com.sczx.pay.utils;
+
+import com.alibaba.fastjson.JSON;
+import com.alipay.api.AlipayApiException;
+import com.alipay.api.AlipayResponse;
+import com.sczx.pay.alipay.vo.OpenResponse;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+
+/**
+ * @author jishupei.jsp
+ * @version : AlipayApiTemplate, v0.1 2024年03月27日 5:48 下午 jishupei.jsp Exp $
+ */
+public class AlipayApiTemplate {
+
+ private static final Logger logger = LogManager.getLogger(AlipayApiTemplate.class);
+
+ public static OpenResponse execute(AlipayApiCallback callback) {
+ try {
+ //执行
+ R response = callback.process();
+ OpenResponse tOpenResponse = new OpenResponse<>(response);
+ if (response.isSuccess()) {
+ //获取data
+ T data = callback.getData(response);
+ tOpenResponse.setData(data);
+ logger.info(callback.getApiName() + "调用成功:" + response.getBody());
+ } else {
+ logger.error(callback.getApiName() + "调用失败:" + JSON.toJSONString(response));
+ }
+ return tOpenResponse;
+ } catch (AlipayApiException e) {
+ //异常处理
+ logger.error(callback.getApiName() + "调用失败", e);
+ return new OpenResponse<>(e);
+ } catch (Exception e) {
+ //异常处理
+ logger.error(callback.getApiName() + "调用失败", e);
+ OpenResponse response = new OpenResponse<>();
+ response.setCode("SYSTEM_ERROR");
+ response.setMsg("系统错误");
+ response.setSubMsg(e.getMessage());
+ return response;
+ }
+ }
+}
diff --git a/src/main/java/com/sczx/pay/utils/AlipaySdkUtil.java b/src/main/java/com/sczx/pay/utils/AlipaySdkUtil.java
new file mode 100644
index 0000000..439b884
--- /dev/null
+++ b/src/main/java/com/sczx/pay/utils/AlipaySdkUtil.java
@@ -0,0 +1,242 @@
+package com.sczx.pay.utils;
+
+import com.alipay.api.*;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.stereotype.Component;
+
+import javax.annotation.PostConstruct;
+import java.util.HashMap;
+import java.util.Map;
+
+@Component
+@Configuration
+public class AlipaySdkUtil {
+
+ private AlipayClient alipayClient;
+
+ @Value("${alipay.appid}")
+ private String appId;
+
+ // 应用私钥
+ @Value("${alipay.privatekey}")
+ private String privateKey;
+
+ // 商户ID(alipay.pid)
+ @Value("${alipay.pid}")
+ private String pid;
+
+ // 是否使用OpenId(alipay.use_open_id)
+ @Value("${alipay.use_open_id}")
+ private boolean useOpenId;
+
+ // 使用OpenId时必填(alipay.openid)
+ @Value("${alipay.openid}")
+ private String openid;
+
+ // 用户ID,和OpenId二选一(alipay.userid)
+ @Value("${alipay.userid}")
+ private String userid;
+
+ // 是否是服务商(alipay.is_isv)
+ @Value("${alipay.is_isv}")
+ private boolean isIsv;
+
+ // 服务商必填(alipay.app_auth_token)
+ @Value("${alipay.app_auth_token}")
+ private String appAuthToken;
+
+ @Value("${alipay.alipay-public-cert-path}")
+ private String alipayPublicCertPath;
+
+ @Value("${alipay.ali-public-cert-path}")
+ private String aliPublicCertPath;
+
+ @Value("${alipay.alipay-root-cert-path}")
+ private String alipayRootCertPath;
+
+ @PostConstruct
+ public void init() throws AlipayApiException {
+ // 初始化v2 SDK
+ this.alipayClient = new DefaultAlipayClient(getAlipayConfig());
+ }
+
+ public T execute(AlipayRequest request) throws AlipayApiException {
+ if (isIsv) {
+ return alipayClient.certificateExecute(request, null, appAuthToken);
+ }
+ return alipayClient.certificateExecute(request);
+ }
+
+ private AlipayConfig getAlipayConfig() {
+ AlipayConfig alipayConfig = new AlipayConfig();
+ alipayConfig.setServerUrl("https://openapi.alipay.com/gateway.do");
+ alipayConfig.setAppId(appId);
+ alipayConfig.setPrivateKey(privateKey);
+ //设置应用公钥证书路径
+ alipayConfig.setAppCertPath(alipayPublicCertPath);
+ //设置支付宝公钥证书路径
+ alipayConfig.setAlipayPublicCertPath(aliPublicCertPath);
+ //设置支付宝根证书路径
+ alipayConfig.setRootCertPath(alipayRootCertPath);
+ alipayConfig.setFormat("json");
+ alipayConfig.setCharset("UTF-8");
+ alipayConfig.setSignType("RSA2");
+ Map headers = new HashMap<>();
+ headers.put("alipay-sdk-demo", "app-item-0.0.1");
+ alipayConfig.setCustomHeaders(headers);
+
+
+
+ return alipayConfig;
+
+ }
+
+
+
+ /**
+ * Getter method for property pid.
+ *
+ * @return property value of pid
+ */
+ public String getPid() {
+ return pid;
+ }
+
+ /**
+ * Setter method for property pid.
+ *
+ * @param pid value to be assigned to property pid
+ */
+ public void setPid(String pid) {
+ this.pid = pid;
+ }
+
+ /**
+ * Getter method for property appId.
+ *
+ * @return property value of appId
+ */
+ public String getAppId() {
+ return appId;
+ }
+
+ /**
+ * Setter method for property appId.
+ *
+ * @param appId value to be assigned to property appId
+ */
+ public void setAppId(String appId) {
+ this.appId = appId;
+ }
+
+ /**
+ * Getter method for property openid.
+ *
+ * @return property value of openid
+ */
+ public String getOpenid() {
+ return openid;
+ }
+
+ /**
+ * Setter method for property openid.
+ *
+ * @param openid value to be assigned to property openid
+ */
+ public void setOpenid(String openid) {
+ this.openid = openid;
+ }
+
+ /**
+ * Getter method for property userid.
+ *
+ * @return property value of userid
+ */
+ public String getUserid() {
+ return userid;
+ }
+
+ /**
+ * Setter method for property userid.
+ *
+ * @param userid value to be assigned to property userid
+ */
+ public void setUserid(String userid) {
+ this.userid = userid;
+ }
+
+ /**
+ * Getter method for property useOpenId.
+ *
+ * @return property value of useOpenId
+ */
+ public boolean isUseOpenId() {
+ return useOpenId;
+ }
+
+ /**
+ * Setter method for property useOpenId.
+ *
+ * @param useOpenId value to be assigned to property useOpenId
+ */
+ public void setUseOpenId(boolean useOpenId) {
+ this.useOpenId = useOpenId;
+ }
+
+ /**
+ * Getter method for property isIsv.
+ *
+ * @return property value of isIsv
+ */
+ public boolean isv() {
+ return isIsv;
+ }
+
+ /**
+ * Setter method for property isIsv.
+ *
+ * @param isv value to be assigned to property isIsv
+ */
+ public void setIsv(boolean isv) {
+ isIsv = isv;
+ }
+
+ /**
+ * Getter method for property appAuthToken.
+ *
+ * @return property value of appAuthToken
+ */
+ public String getAppAuthToken() {
+ return appAuthToken;
+ }
+
+ /**
+ * Setter method for property appAuthToken.
+ *
+ * @param appAuthToken value to be assigned to property appAuthToken
+ */
+ public void setAppAuthToken(String appAuthToken) {
+ this.appAuthToken = appAuthToken;
+ }
+
+ /**
+ * Getter method for property privateKey.
+ *
+ * @return property value of privateKey
+ */
+ public String getPrivateKey() {
+ return privateKey;
+ }
+
+ /**
+ * Setter method for property privateKey.
+ *
+ * @param privateKey value to be assigned to property privateKey
+ */
+ public void setPrivateKey(String privateKey) {
+ this.privateKey = privateKey;
+ }
+
+
+}
diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml
index c4b27a9..00fd3c2 100644
--- a/src/main/resources/application.yml
+++ b/src/main/resources/application.yml
@@ -64,4 +64,17 @@ wechat:
refund-notify-url: https://www.minbo.wang:8020/api/payment/refundNotify
-cert-path: /root/cert/
\ No newline at end of file
+cert-path: /root/cert/
+
+alipay:
+ pid: 2021004169641281
+ appid: 2021005174658269
+ privatekey: MIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQCQke+mZsxNXJXMn2iUZRkhITWY9qPczwHMgRxl68JRuNzZE2AXhAc2ciF7EGob1y0al4hvJo5JUrDew9Zkv0BocAsPjLma3A9KFgj131xMuLxVvHtktkNSwwW9VIbOOhFAQAy3J9jt8PdEk40UONyu9J5Shjs6jbQ8RogdDuwuzKpNj0ZOTeUqgR6RME4xZ0VqvZe9XhVfq3QtVGttUzOpLPNg6boBy/5RqwC64lVFICMqjKkMW2NklVPBDFO46QwfWEbaA+APnd9bd+9WadyNySPb7kAK8GOlvZYfysy+QkOQdj/oebKWKzdKXpFnF+n52dYzeGTvckt1suDngwAFAgMBAAECggEAcPc39iTZe5HfE9d0FpCxBCw4/1+qRz4SP8SbdiC05Lq5B36WVYm7QRYJh2oaH8sR2XeTCpdsE2tj/Y21l1/Calkyq2HhHlraL5/sPIPeUa0ArVXsbZPmI2N0tq6376l8FWJ3DR876SGjdZh+YtDT0HogxIdS/LwBnB/Y+CvS7fWcqiMjcR4h28RU70CQqxpzYuPfqG6GZmByGyJAcdlhFAYgiksb+qZnkjoaKHsjb61xfUX4z+HGdQLqOlVKfNqIpiO7arXaeAb0RQiB8Lqi7fBvn8LLhlTmM1Hr4gyQO14lJmP5Vp2BIg9m5AC9vRkpZ9l79bUTIepDe9+Ovcx5eQKBgQDWZ5yoz8q8Z5VIfMSVTHO3wpfwOBM92S2c21hTsds7NezsMVqGcTuAcvbMW2i1MwxtS7kahXraRAxZnCDB9ZVJs+88xcgu5QJWZ1rJyrwEwB2gTQhColv+XZW6Ck/J6kk2/PG26rNQG6pg/xrKaMtPnXXyKCsdQTyEpr+mlNIJ2wKBgQCsnf4lIuwftCSm0jI73tO1Bb4U9TCIapKidnIhutbyg6u+hJMUTVDNkjsBnrTN24sSP7Cu4Zs/W4lkDqq86fHNEvnF+FouIfO/CwaGteDBNwXHSLM0D+zEBbK04bfoYi7lYZeDRPygFrM49Sxkp0MAmItDmXqbYRQBlhN1XVzznwKBgQCQ+72fFex1XOJBA0X345v4rlkKMxEn6J2EjXr8FbA3KO8OhQ0/DoD7CkLDzChRJ7UGj4cbXRnHUO69BevM3SHXlhp4ERKeS3Q6M2fcPwDHgZZHGPA2Bw6IQoaGKITt+EUMLx3Q4ILi7+JV9wwJxbV+H+9rEiidfsjKtuuwXMBvswKBgQChpElrCSrH/W8c8FSuD9l7+GapRXkvJW0uyW/S+h1yd66J96erKUNzXW339GAnLWErs4yGFynDyLn9gmaMBR6zBQP0SL5Z2N1hlreDyikvhZDZrtBw/kCexx8zlvMan2Z+0kaJXD6cwuUNfzkVADQUCMTQhpZzjhKn8ZtDGiyCzQKBgQCAhU0khG/ufZfQ089+1G7PAlErBr5MQaG40a2vfIWGtHkYyXq5N/3jow1bd2qsyLuz8mr2sWQeURK+B2xZridf6JtYz3gB+dLw0frlLKk4Q6jeehiRlE8H8tIYe/7KcgTmdIzEbo3lmyGMFAILvr/pSCWeUehQYR9PH91Qyi+Tog==
+ use_open_id: false
+ openid: 111
+ userid: 111
+ is_isv: true
+ app_auth_token: 202502BBe237336d792f49cebda1f2d202d25A23
+ alipay-public-cert-path: /root/cert/appCertPublicKey_2021005174658269.crt
+ ali-public-cert-path: /root/cert/alipayCertPublicKey_RSA2.crt
+ alipay-root-cert-path: /root/cert/alipayRootCert.crt
\ No newline at end of file
From 15e866a97ecdf21a884fa9dff34fc1d9c617a163 Mon Sep 17 00:00:00 2001
From: eric <465889110@qq.com>
Date: Mon, 1 Sep 2025 01:28:06 +0800
Subject: [PATCH 2/7] =?UTF-8?q?=E7=89=88=E6=9C=AC=E5=86=B2=E7=AA=81?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
pom.xml | 2 +-
.../java/com/sczx/pay/alipay/controller/ItemController.java | 3 +--
src/main/resources/application.yml | 2 +-
3 files changed, 3 insertions(+), 4 deletions(-)
diff --git a/pom.xml b/pom.xml
index 3142f7c..89f8d07 100644
--- a/pom.xml
+++ b/pom.xml
@@ -200,7 +200,7 @@
com.github.xiaoymin
knife4j-spring-boot-starter
- 3.0.3
+ 2.0.2
diff --git a/src/main/java/com/sczx/pay/alipay/controller/ItemController.java b/src/main/java/com/sczx/pay/alipay/controller/ItemController.java
index d2ebfc1..6d9b28a 100644
--- a/src/main/java/com/sczx/pay/alipay/controller/ItemController.java
+++ b/src/main/java/com/sczx/pay/alipay/controller/ItemController.java
@@ -10,7 +10,6 @@ import com.alipay.api.response.AlipayOpenAppItemListQueryResponse;
import com.alipay.api.response.AlipayOpenAppItemQueryResponse;
import com.alipay.api.response.AlipayOpenAppItemTemplateQueryResponse;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
-import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import com.sczx.pay.alipay.service.ItemService;
import com.sczx.pay.alipay.vo.ItemCreateRequest;
import com.sczx.pay.alipay.vo.OpenResponse;
@@ -20,6 +19,7 @@ import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
+
import java.util.List;
/**
@@ -27,7 +27,6 @@ import java.util.List;
* @version : ItemController, v0.1 2024年05月11日 2:45 下午 jishupei.jsp Exp $
*/
@Api(tags = "普通商品模块")
-@ApiSupport(order = 1)
@RestController
@RequestMapping(value = "/item")
public class ItemController {
diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml
index 00fd3c2..c720a03 100644
--- a/src/main/resources/application.yml
+++ b/src/main/resources/application.yml
@@ -77,4 +77,4 @@ alipay:
app_auth_token: 202502BBe237336d792f49cebda1f2d202d25A23
alipay-public-cert-path: /root/cert/appCertPublicKey_2021005174658269.crt
ali-public-cert-path: /root/cert/alipayCertPublicKey_RSA2.crt
- alipay-root-cert-path: /root/cert/alipayRootCert.crt
\ No newline at end of file
+ alipay-root-cert-path: /root/cert/alipayRootCert.crt
From 8b6d2a303fea6a2edb1b27b025612e35f329a41e Mon Sep 17 00:00:00 2001
From: eric <465889110@qq.com>
Date: Mon, 1 Sep 2025 01:33:16 +0800
Subject: [PATCH 3/7] 1
---
src/main/resources/application.yml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml
index c720a03..6280c03 100644
--- a/src/main/resources/application.yml
+++ b/src/main/resources/application.yml
@@ -73,7 +73,7 @@ alipay:
use_open_id: false
openid: 111
userid: 111
- is_isv: true
+ is_isv: false
app_auth_token: 202502BBe237336d792f49cebda1f2d202d25A23
alipay-public-cert-path: /root/cert/appCertPublicKey_2021005174658269.crt
ali-public-cert-path: /root/cert/alipayCertPublicKey_RSA2.crt
From 572a1ac63d22b9bef0e62b00466750ca9a0bf73e Mon Sep 17 00:00:00 2001
From: eric <465889110@qq.com>
Date: Mon, 1 Sep 2025 22:40:03 +0800
Subject: [PATCH 4/7] =?UTF-8?q?=E5=B1=A5=E7=BA=A6=E6=A8=A1=E6=9D=BF?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../pay/alipay/controller/ItemController.java | 61 +---
.../pay/alipay/dto/RentItemCreateRequest.java | 294 ++++++++++++++++++
.../com/sczx/pay/alipay/po/RentRuleItem.java | 189 +++++++++++
.../sczx/pay/alipay/service/ItemService.java | 26 +-
.../service/impl/ImageUploadServiceImpl.java | 27 +-
.../alipay/service/impl/ItemServiceImpl.java | 248 ++++-----------
.../sczx/pay/mapper/RentRuleItemMapper.java | 54 ++++
.../resources/mapper/RentRuleItemMapper.xml | 123 ++++++++
8 files changed, 753 insertions(+), 269 deletions(-)
create mode 100644 src/main/java/com/sczx/pay/alipay/dto/RentItemCreateRequest.java
create mode 100644 src/main/java/com/sczx/pay/alipay/po/RentRuleItem.java
create mode 100644 src/main/java/com/sczx/pay/mapper/RentRuleItemMapper.java
create mode 100644 src/main/resources/mapper/RentRuleItemMapper.xml
diff --git a/src/main/java/com/sczx/pay/alipay/controller/ItemController.java b/src/main/java/com/sczx/pay/alipay/controller/ItemController.java
index 6d9b28a..a6e0873 100644
--- a/src/main/java/com/sczx/pay/alipay/controller/ItemController.java
+++ b/src/main/java/com/sczx/pay/alipay/controller/ItemController.java
@@ -10,6 +10,7 @@ import com.alipay.api.response.AlipayOpenAppItemListQueryResponse;
import com.alipay.api.response.AlipayOpenAppItemQueryResponse;
import com.alipay.api.response.AlipayOpenAppItemTemplateQueryResponse;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
+import com.sczx.pay.alipay.po.RentRuleItem;
import com.sczx.pay.alipay.service.ItemService;
import com.sczx.pay.alipay.vo.ItemCreateRequest;
import com.sczx.pay.alipay.vo.OpenResponse;
@@ -59,15 +60,7 @@ public class ItemController {
return itemService.queryTemplate(categoryId, itemType);
}
- /**
- * 售卖类(实物)商品创建
- */
- @ApiOperation(value = "售卖类(实物)商品创建")
- @ApiOperationSupport(order = 3)
- @PostMapping(value = "/sale/create")
- public OpenResponse saleCreate(@RequestBody ItemCreateRequest request) {
- return itemService.createSaleItem(request);
- }
+
/**
* 租赁类(实物)商品创建
@@ -75,55 +68,21 @@ public class ItemController {
@ApiOperation(value = "租赁类(实物)商品创建")
@ApiOperationSupport(order = 4)
@PostMapping(value = "/rent/create")
- public OpenResponse rentCreate(@RequestBody ItemCreateRequest request) {
+ public OpenResponse rentCreate(@RequestBody RentRuleItem request) {
return itemService.createRentItem(request);
}
- /**
- * 付费充值/兑换类(虚拟)商品创建
- */
- @ApiOperation(value = "付费充值/兑换类(虚拟)商品创建", notes = "电影/演出/体育赛事票务类商品")
- @ApiOperationSupport(order = 5)
- @PostMapping(value = "/virtual/create")
- public OpenResponse virtualCreate(@RequestBody ItemCreateRequest request) {
- return itemService.createVirtualItem(request);
- }
+
/**
- * 售卖类(实物)商品更新
+ * 租赁类(实物)履约模板创建
*/
- @ApiOperation(value = "商品更新")
- @ApiOperationSupport(order = 6)
- @PostMapping(value = "/update")
- public OpenResponse update(@RequestBody ItemCreateRequest request) {
- return itemService.updateItem(request);
+ @ApiOperation(value = "租赁类(实物)履约模板创建")
+ @ApiOperationSupport(order = 4)
+ @PostMapping(value = "/template/create")
+ public OpenResponse templateCreate() {
+ return itemService.syncDeliveryInfo();
}
- /**
- * 商品详情查询
- */
- @ApiOperation(value = "商品详情查询")
- @ApiOperationSupport(order = 7)
- @GetMapping(value = "/query")
- public OpenResponse query(@ApiParam(value = "支付平台侧商品ID") @RequestParam(required = false) String itemId,
- @ApiParam(value = "商家侧商品ID") @RequestParam(required = false) String outItemId,
- @ApiParam(value = "是否查询编辑版本,默认为0", defaultValue = "0") @RequestParam(required = false) String needEditSpu) {
- return itemService.queryItemDetail(itemId, outItemId,
- StringUtils.isNumeric(needEditSpu) ? Long.parseLong(needEditSpu) : 0);
- }
- /**
- * 分页查询商品列表
- */
- @ApiOperation(value = "分页查询商品列表")
- @ApiOperationSupport(order = 8)
- @GetMapping(value = "/list/query")
- public OpenResponse queryList(@ApiParam(value = "支付平台侧商品ID") @RequestParam(required = false) String itemId,
- @ApiParam(value = "商家侧商品ID") @RequestParam(required = false) String outItemId,
- @ApiParam(value = "页码", defaultValue = "1") @RequestParam(required = false) String pageNum,
- @ApiParam(value = "单页大小", defaultValue = "10") @RequestParam(required = false) String pageSize) {
- return itemService.queryItemList(itemId, outItemId,
- StringUtils.isNumeric(pageNum) ? Long.parseLong(pageNum) : 1,
- StringUtils.isNumeric(pageSize) ? Long.parseLong(pageSize) : 10);
- }
}
diff --git a/src/main/java/com/sczx/pay/alipay/dto/RentItemCreateRequest.java b/src/main/java/com/sczx/pay/alipay/dto/RentItemCreateRequest.java
new file mode 100644
index 0000000..5feab23
--- /dev/null
+++ b/src/main/java/com/sczx/pay/alipay/dto/RentItemCreateRequest.java
@@ -0,0 +1,294 @@
+package com.sczx.pay.alipay.dto;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+
+import java.io.Serializable;
+import java.util.List;
+
+/**
+ * 实物租赁商品创建请求实体类
+ */
+@ApiModel(value = "com.sczx.pay.alipay.dto.RentItemCreateRequest", description = "实物租赁商品创建请求参数")
+public class RentItemCreateRequest implements Serializable {
+
+ private static final long serialVersionUID = 1L;
+
+ // 基本商品信息
+
+ @ApiModelProperty(value = "商家侧商品ID,要求APPID下全局唯一", required = true, example = "test20230021")
+ private String outItemId;
+
+ @ApiModelProperty(value = "商品名称,最少不低于3个字,最长不超过60个字", required = true, example = "实物租赁商品创建示例")
+ private String title;
+
+ @ApiModelProperty(value = "商品主图,图片宽高为750px*750px,宽高比1:1,800kb以内", required = true,
+ example = "A*pHfaSaEsF_0AAAAAAAAAAAAAATcnAQ")
+ private String headImg;
+
+ @ApiModelProperty(value = "平台类目ID,多级类目只填最后一级", required = true, example = "C001375054")
+ private String categoryId;
+
+ @ApiModelProperty(value = "商品类型,租赁类(实物): 2", required = true, example = "2")
+ private String itemType;
+
+ @ApiModelProperty(value = "商品详情页URL,请填写您的小程序侧商品详情页链接")
+ private String path;
+
+ @ApiModelProperty(value = "商品子图,作为平台详情页组件的轮播图,最多3张")
+ private List imageList;
+
+ // SKU信息
+
+ @ApiModelProperty(value = "SKU数组")
+ private List skus;
+
+ // 商品属性
+
+ @ApiModelProperty(value = "商品属性")
+ private List attrs;
+
+ // Getters and Setters
+
+ public String getOutItemId() {
+ return outItemId;
+ }
+
+ public void setOutItemId(String outItemId) {
+ this.outItemId = outItemId;
+ }
+
+ public String getTitle() {
+ return title;
+ }
+
+ public void setTitle(String title) {
+ this.title = title;
+ }
+
+ public String getHeadImg() {
+ return headImg;
+ }
+
+ public void setHeadImg(String headImg) {
+ this.headImg = headImg;
+ }
+
+ public String getCategoryId() {
+ return categoryId;
+ }
+
+ public void setCategoryId(String categoryId) {
+ this.categoryId = categoryId;
+ }
+
+ public String getItemType() {
+ return itemType;
+ }
+
+ public void setItemType(String itemType) {
+ this.itemType = itemType;
+ }
+
+ public String getPath() {
+ return path;
+ }
+
+ public void setPath(String path) {
+ this.path = path;
+ }
+
+ public List getImageList() {
+ return imageList;
+ }
+
+ public void setImageList(List imageList) {
+ this.imageList = imageList;
+ }
+
+ public List getSkus() {
+ return skus;
+ }
+
+ public void setSkus(List skus) {
+ this.skus = skus;
+ }
+
+ public List getAttrs() {
+ return attrs;
+ }
+
+ public void setAttrs(List attrs) {
+ this.attrs = attrs;
+ }
+
+ /**
+ * 租赁SKU请求实体类
+ */
+ @ApiModel(value = "RentSkuRequest", description = "租赁SKU信息")
+ public static class RentSkuRequest {
+
+ @ApiModelProperty(value = "商家侧SKU ID,要求APPID下全局唯一", required = true)
+ private String outSkuId;
+
+ @ApiModelProperty(value = "售卖状态")
+ private String saleStatus;
+
+ @ApiModelProperty(value = "商品销售属性")
+ private List skuAttrs;
+
+ @ApiModelProperty(value = "SKU类型,枚举值:RENT(租赁sku)、SALE(售卖sku)", example = "RENT")
+ private String skuType;
+
+ @ApiModelProperty(value = "SKU售价,如果有起租天数总租金,该字段不用填写")
+ private Long salePrice;
+
+ @ApiModelProperty(value = "SKU原价,如果有起租天数总租金,该字段不用填写")
+ private Long originalPrice;
+
+ @ApiModelProperty(value = "SKU库存")
+ private Long stockNum;
+
+ @ApiModelProperty(value = "价格单元,租赁sku:元/日,售卖sku:元", example = "元/日")
+ private String priceUnit;
+
+ // Getters and Setters
+
+ public String getOutSkuId() {
+ return outSkuId;
+ }
+
+ public void setOutSkuId(String outSkuId) {
+ this.outSkuId = outSkuId;
+ }
+
+ public String getSaleStatus() {
+ return saleStatus;
+ }
+
+ public void setSaleStatus(String saleStatus) {
+ this.saleStatus = saleStatus;
+ }
+
+ public List getSkuAttrs() {
+ return skuAttrs;
+ }
+
+ public void setSkuAttrs(List skuAttrs) {
+ this.skuAttrs = skuAttrs;
+ }
+
+ public String getSkuType() {
+ return skuType;
+ }
+
+ public void setSkuType(String skuType) {
+ this.skuType = skuType;
+ }
+
+ public Long getSalePrice() {
+ return salePrice;
+ }
+
+ public void setSalePrice(Long salePrice) {
+ this.salePrice = salePrice;
+ }
+
+ public Long getOriginalPrice() {
+ return originalPrice;
+ }
+
+ public void setOriginalPrice(Long originalPrice) {
+ this.originalPrice = originalPrice;
+ }
+
+ public Long getStockNum() {
+ return stockNum;
+ }
+
+ public void setStockNum(Long stockNum) {
+ this.stockNum = stockNum;
+ }
+
+ public String getPriceUnit() {
+ return priceUnit;
+ }
+
+ public void setPriceUnit(String priceUnit) {
+ this.priceUnit = priceUnit;
+ }
+ }
+
+ /**
+ * SKU属性请求实体类 (sku_attrs 销售属性)
+ */
+ @ApiModel(value = "SkuAttrRequest", description = "SKU销售属性信息")
+ public static class SkuAttrRequest {
+
+ @ApiModelProperty(value = "销售属性key", required = true)
+ private String attrKey;
+
+ @ApiModelProperty(value = "销售属性类型,枚举值:spec(规格)、custom(自定义属性)", example = "custom")
+ private String attrType;
+
+ @ApiModelProperty(value = "销售属性值", required = true)
+ private String attrValue;
+
+ // Getters and Setters
+
+ public String getAttrKey() {
+ return attrKey;
+ }
+
+ public void setAttrKey(String attrKey) {
+ this.attrKey = attrKey;
+ }
+
+ public String getAttrType() {
+ return attrType;
+ }
+
+ public void setAttrType(String attrType) {
+ this.attrType = attrType;
+ }
+
+ public String getAttrValue() {
+ return attrValue;
+ }
+
+ public void setAttrValue(String attrValue) {
+ this.attrValue = attrValue;
+ }
+ }
+
+ /**
+ * 商品属性请求实体类 (attrs 商品属性)
+ */
+ @ApiModel(value = "ItemAttrRequest", description = "商品属性信息")
+ public static class ItemAttrRequest {
+
+ @ApiModelProperty(value = "商品属性key", required = true)
+ private String attrKey;
+
+ @ApiModelProperty(value = "商品属性值", required = true)
+ private String attrValue;
+
+ // Getters and Setters
+
+ public String getAttrKey() {
+ return attrKey;
+ }
+
+ public void setAttrKey(String attrKey) {
+ this.attrKey = attrKey;
+ }
+
+ public String getAttrValue() {
+ return attrValue;
+ }
+
+ public void setAttrValue(String attrValue) {
+ this.attrValue = attrValue;
+ }
+ }
+}
diff --git a/src/main/java/com/sczx/pay/alipay/po/RentRuleItem.java b/src/main/java/com/sczx/pay/alipay/po/RentRuleItem.java
new file mode 100644
index 0000000..b32e350
--- /dev/null
+++ b/src/main/java/com/sczx/pay/alipay/po/RentRuleItem.java
@@ -0,0 +1,189 @@
+package com.sczx.pay.alipay.po;
+
+import lombok.Data;
+
+import java.io.Serializable;
+import java.math.BigDecimal;
+
+/**
+ * 车型租赁规则项实体类
+ */
+@Data
+public class RentRuleItem implements Serializable {
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * 车型ID
+ */
+ private Long id;
+
+ /**
+ * 商户商品ID
+ */
+ private String outItemId;
+
+ /**
+ * 阿里商品ID
+ */
+ private String aliItemId;
+
+ /**
+ * 品牌名称
+ */
+ private String brandName;
+
+ /**
+ * 车型名称
+ */
+ private String modelName;
+
+ /**
+ * 电池类别名称
+ */
+ private String categoryName;
+
+ /**
+ * 字典标签
+ */
+ private String dictLabel;
+
+ /**
+ * 套餐名称
+ */
+ private String ruleName;
+
+ /**
+ * 车型照片
+ */
+ private String image;
+
+ /**
+ * 电池规则ID
+ */
+ private Long batteryRuleId;
+
+ /**
+ * 车辆规则ID
+ */
+ private Long carRuleId;
+
+ /**
+ * 车型ID
+ */
+ private Long carModelId;
+
+ /**
+ * 品牌ID
+ */
+ private Long brandId;
+
+ private BigDecimal rentalPrice;
+
+ private Integer rentalDays;
+
+ // Getters and Setters
+
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ public String getOutItemId() {
+ return outItemId;
+ }
+
+ public void setOutItemId(String outItemId) {
+ this.outItemId = outItemId;
+ }
+
+ public String getAliItemId() {
+ return aliItemId;
+ }
+
+ public void setAliItemId(String aliItemId) {
+ this.aliItemId = aliItemId;
+ }
+
+ public String getBrandName() {
+ return brandName;
+ }
+
+ public void setBrandName(String brandName) {
+ this.brandName = brandName;
+ }
+
+ public String getModelName() {
+ return modelName;
+ }
+
+ public void setModelName(String modelName) {
+ this.modelName = modelName;
+ }
+
+ public String getCategoryName() {
+ return categoryName;
+ }
+
+ public void setCategoryName(String categoryName) {
+ this.categoryName = categoryName;
+ }
+
+ public String getDictLabel() {
+ return dictLabel;
+ }
+
+ public void setDictLabel(String dictLabel) {
+ this.dictLabel = dictLabel;
+ }
+
+ public String getRuleName() {
+ return ruleName;
+ }
+
+ public void setRuleName(String ruleName) {
+ this.ruleName = ruleName;
+ }
+
+ public String getImage() {
+ return image;
+ }
+
+ public void setImage(String image) {
+ this.image = image;
+ }
+
+ public Long getBatteryRuleId() {
+ return batteryRuleId;
+ }
+
+ public void setBatteryRuleId(Long batteryRuleId) {
+ this.batteryRuleId = batteryRuleId;
+ }
+
+ public Long getCarRuleId() {
+ return carRuleId;
+ }
+
+ public void setCarRuleId(Long carRuleId) {
+ this.carRuleId = carRuleId;
+ }
+
+ public Long getCarModelId() {
+ return carModelId;
+ }
+
+ public void setCarModelId(Long carModelId) {
+ this.carModelId = carModelId;
+ }
+
+ public Long getBrandId() {
+ return brandId;
+ }
+
+ public void setBrandId(Long brandId) {
+ this.brandId = brandId;
+ }
+}
diff --git a/src/main/java/com/sczx/pay/alipay/service/ItemService.java b/src/main/java/com/sczx/pay/alipay/service/ItemService.java
index 889639c..e3c8fd2 100644
--- a/src/main/java/com/sczx/pay/alipay/service/ItemService.java
+++ b/src/main/java/com/sczx/pay/alipay/service/ItemService.java
@@ -8,6 +8,7 @@ import com.alipay.api.domain.AppxCategoryVO;
import com.alipay.api.response.AlipayOpenAppItemListQueryResponse;
import com.alipay.api.response.AlipayOpenAppItemQueryResponse;
import com.alipay.api.response.AlipayOpenAppItemTemplateQueryResponse;
+import com.sczx.pay.alipay.po.RentRuleItem;
import com.sczx.pay.alipay.vo.ItemCreateRequest;
import com.sczx.pay.alipay.vo.OpenResponse;
@@ -28,33 +29,14 @@ public interface ItemService {
*/
OpenResponse queryTemplate(String categoryId, String itemType);
- /**
- * 创建售卖类(实物)商品
- */
- OpenResponse createSaleItem(ItemCreateRequest param);
-
/**
* 创建租赁类(实物)商品
*/
- OpenResponse createRentItem(ItemCreateRequest param);
+ OpenResponse createRentItem(RentRuleItem param);
/**
- * 创建付费充值/兑换类(虚拟)商品
+ * 根据业务属性写死自提履约信息
*/
- OpenResponse createVirtualItem(ItemCreateRequest param);
+ OpenResponse syncDeliveryInfo();
- /**
- * 修改售卖类(实物)商品
- */
- OpenResponse updateItem(ItemCreateRequest param);
-
- /**
- * 查询商品详情
- */
- OpenResponse queryItemDetail(String itemId, String outItemId, long needEditSpu);
-
- /**
- * 分页查询商品列表
- */
- OpenResponse queryItemList(String itemId, String outItemId, long pageNum, long pageSize);
}
diff --git a/src/main/java/com/sczx/pay/alipay/service/impl/ImageUploadServiceImpl.java b/src/main/java/com/sczx/pay/alipay/service/impl/ImageUploadServiceImpl.java
index 5f790d8..94b8d06 100644
--- a/src/main/java/com/sczx/pay/alipay/service/impl/ImageUploadServiceImpl.java
+++ b/src/main/java/com/sczx/pay/alipay/service/impl/ImageUploadServiceImpl.java
@@ -23,6 +23,10 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.io.IOException;
+import java.io.InputStream;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.util.Base64;
import java.util.List;
/**
@@ -49,8 +53,8 @@ public class ImageUploadServiceImpl implements ImageUploadService {
// 设置图片内容
try {
- byte[] bytes = IOUtils.toByteArray(this.getClass().getResourceAsStream("/" + imagePath));
- FileItem imageContent = new FileItem(StringUtils.substringAfterLast(imagePath, "/"), bytes);
+ String imageBase64 = getImageFromUrlAndConvertToBase64(imagePath);
+ FileItem imageContent = new FileItem("imageContent.jpg",Base64.getDecoder().decode(imageBase64));
request.setImageContent(imageContent);
} catch (IOException e) {
throw new AlipayApiException("alipay.marketing.image.enhance.upload调用失败:" + e);
@@ -298,4 +302,23 @@ public class ImageUploadServiceImpl implements ImageUploadService {
}
});
}
+
+ public String getImageFromUrlAndConvertToBase64(String imageUrl) throws IOException {
+ if (StringUtils.isBlank(imageUrl)) {
+ throw new IllegalArgumentException("图片URL不能为空");
+ }
+
+ URL url = new URL(imageUrl);
+ HttpURLConnection connection = (HttpURLConnection) url.openConnection();
+ connection.setRequestMethod("GET");
+ connection.setConnectTimeout(5000);
+ connection.setReadTimeout(5000);
+
+ try (InputStream inputStream = connection.getInputStream()) {
+ byte[] imageBytes = IOUtils.toByteArray(inputStream);
+ return Base64.getEncoder().encodeToString(imageBytes);
+ } finally {
+ connection.disconnect();
+ }
+ }
}
diff --git a/src/main/java/com/sczx/pay/alipay/service/impl/ItemServiceImpl.java b/src/main/java/com/sczx/pay/alipay/service/impl/ItemServiceImpl.java
index 24b46fa..d816acf 100644
--- a/src/main/java/com/sczx/pay/alipay/service/impl/ItemServiceImpl.java
+++ b/src/main/java/com/sczx/pay/alipay/service/impl/ItemServiceImpl.java
@@ -7,6 +7,7 @@ import com.alipay.api.domain.*;
import com.alipay.api.internal.util.StringUtils;
import com.alipay.api.request.*;
import com.alipay.api.response.*;
+import com.sczx.pay.alipay.po.RentRuleItem;
import com.sczx.pay.alipay.service.ImageUploadService;
import com.sczx.pay.alipay.service.ItemService;
import com.sczx.pay.alipay.vo.ItemCreateRequest;
@@ -21,6 +22,7 @@ import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.io.UnsupportedEncodingException;
+import java.math.BigDecimal;
import java.net.URLEncoder;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
@@ -118,43 +120,9 @@ public class ItemServiceImpl implements ItemService {
});
}
- @Override
- public OpenResponse createSaleItem(ItemCreateRequest param) {
- return AlipayApiTemplate.execute(new AlipayApiCallback() {
-
- @Override
- public AlipayOpenAppItemCreateResponse process() throws AlipayApiException {
- // 构造请求参数以调用接口
- AlipayOpenAppItemCreateRequest request = new AlipayOpenAppItemCreateRequest();
- AlipayOpenAppItemCreateModel model = getAlipayOpenAppItemCreateModel(param);
-
- // 设置商品模版类型
- model.setItemType("1");
-
- // 设置价格单元
- model.setPriceUnit("元");
-
- // 设置属性列表
- model.setAttrs(getItemAttrs(param, model.getImageList(), model.getItemType()));
-
- request.setBizModel(model);
- return alipaySdkUtil.execute(request);
- }
-
- @Override
- public String getData(AlipayOpenAppItemCreateResponse response) {
- return response.getItemId();
- }
-
- @Override
- public String getApiName() {
- return "alipay.open.app.item.create";
- }
- });
- }
@Override
- public OpenResponse createRentItem(ItemCreateRequest param) {
+ public OpenResponse createRentItem(RentRuleItem param) {
return AlipayApiTemplate.execute(new AlipayApiCallback() {
@Override
@@ -189,195 +157,87 @@ public class ItemServiceImpl implements ItemService {
}
@Override
- public OpenResponse createVirtualItem(ItemCreateRequest param) {
- return AlipayApiTemplate.execute(new AlipayApiCallback() {
-
+ public OpenResponse syncDeliveryInfo() {
+ return AlipayApiTemplate.execute(new AlipayApiCallback() {
@Override
- public AlipayOpenAppItemCreateResponse process() throws AlipayApiException {
+ public AlipayOpenAppDeliveryInfoSyncResponse process() throws AlipayApiException {
// 构造请求参数以调用接口
- AlipayOpenAppItemCreateRequest request = new AlipayOpenAppItemCreateRequest();
- AlipayOpenAppItemCreateModel model = getAlipayOpenAppItemCreateModel(param);
+ AlipayOpenAppDeliveryInfoSyncRequest request = new AlipayOpenAppDeliveryInfoSyncRequest();
+ AlipayOpenAppDeliveryInfoSyncModel model = new AlipayOpenAppDeliveryInfoSyncModel();
+ // 设置履约类型
+ model.setDeliveryType("PICKUP");
+ model.setDeliveryName("电动车租赁自提履约");
- // 设置商品模版类型
- model.setItemType("3");
+ // 设置履约信息ID
+ model.setDeliveryId("20250901000800000001");
- // 设置价格单元
- model.setPriceUnit("元");
-
- // 设置属性列表
- model.setAttrs(getItemAttrs(param, model.getImageList(), model.getItemType()));
+ // 设置履约属性
+ List attrs = new ArrayList();
+ AppItemAttrVO attrs0 = new AppItemAttrVO();
+ attrs0.setAttrKey("delivery_name");
+ attrs0.setAttrValue("同城门店自提");
+ attrs.add(attrs0);
+ model.setAttrs(attrs);
request.setBizModel(model);
return alipaySdkUtil.execute(request);
}
@Override
- public String getData(AlipayOpenAppItemCreateResponse response) {
- return response.getItemId();
+ public String getData(AlipayOpenAppDeliveryInfoSyncResponse response) {
+ return response.getDeliveryId();
}
@Override
public String getApiName() {
- return "alipay.open.app.item.create";
+ return "alipay.open.app.delivery.info.sync";
}
});
}
- @Override
- public OpenResponse updateItem(ItemCreateRequest param) {
- return AlipayApiTemplate.execute(new AlipayApiCallback() {
- @Override
- public AlipayOpenAppItemModifyResponse process() throws AlipayApiException {
- // 构造请求参数以调用接口
- AlipayOpenAppItemModifyRequest request = new AlipayOpenAppItemModifyRequest();
- AlipayOpenAppItemCreateModel model = getAlipayOpenAppItemCreateModel(param);
-
- // 设置商品模版类型
- model.setItemType("1");
-
- // 设置价格单元
- model.setPriceUnit("元");
-
- // 设置属性列表
- model.setAttrs(getItemAttrs(param, model.getImageList(), model.getItemType()));
-
- request.setBizModel(model);
- return alipaySdkUtil.execute(request);
- }
-
- @Override
- public String getData(AlipayOpenAppItemModifyResponse response) {
- return response.getItemId();
- }
-
- @Override
- public String getApiName() {
- return "alipay.open.app.item.modify";
- }
- });
- }
-
- @Override
- public OpenResponse queryItemDetail(String itemId, String outItemId, long needEditSpu) {
- return AlipayApiTemplate.execute(new AlipayApiCallback() {
- @Override
- public AlipayOpenAppItemQueryResponse process() throws AlipayApiException {
- // 构造请求参数以调用接口
- AlipayOpenAppItemQueryRequest request = new AlipayOpenAppItemQueryRequest();
- AlipayOpenAppItemQueryModel model = new AlipayOpenAppItemQueryModel();
- if (!StringUtils.isEmpty(itemId)) {
- // 设置支付宝侧商品id
- model.setItemId(itemId);
- }
-
- if (!StringUtils.isEmpty(outItemId)) {
- // 设置商家侧商品id
- model.setOutItemId(outItemId);
- }
-
- // 设置是否查询编辑版本
- model.setNeedEditSpu(needEditSpu);
-
- request.setBizModel(model);
-
- return alipaySdkUtil.execute(request);
- }
-
- @Override
- public AlipayOpenAppItemQueryResponse getData(AlipayOpenAppItemQueryResponse response) {
- return response;
- }
-
- @Override
- public String getApiName() {
- return "alipay.open.app.item.query";
- }
- });
- }
-
- @Override
- public OpenResponse queryItemList(String itemId, String outItemId, long pageNum, long pageSize) {
- return AlipayApiTemplate.execute(new AlipayApiCallback() {
- @Override
- public AlipayOpenAppItemListQueryResponse process() throws AlipayApiException {
- // 构造请求参数以调用接口
- AlipayOpenAppItemListQueryRequest request = new AlipayOpenAppItemListQueryRequest();
- AlipayOpenAppItemListQueryModel model = new AlipayOpenAppItemListQueryModel();
-
- if (!StringUtils.isEmpty(outItemId)) {
- // 设置商家侧id列表
- List outItemIdList = new ArrayList<>();
- outItemIdList.add(outItemId);
- model.setOutItemIdList(outItemIdList);
- }
-
- if (!StringUtils.isEmpty(itemId)) {
- // 设置平台侧商品id列表
- List itemIdList = new ArrayList<>();
- itemIdList.add(itemId);
- model.setItemIdList(itemIdList);
- }
-
- // 设置页码
- model.setPageNum(pageNum);
- // 设置单页大小
- model.setPageSize(pageSize);
-
- request.setBizModel(model);
-
- return alipaySdkUtil.execute(request);
- }
-
- @Override
- public AlipayOpenAppItemListQueryResponse getData(AlipayOpenAppItemListQueryResponse response) {
- return response;
- }
-
- @Override
- public String getApiName() {
- return "alipay.open.app.item.list.query";
- }
- });
- }
-
- private AlipayOpenAppItemCreateModel getAlipayOpenAppItemCreateModel(ItemCreateRequest param) throws AlipayApiException {
+ private AlipayOpenAppItemCreateModel getAlipayOpenAppItemCreateModel(RentRuleItem rentRuleItem) throws AlipayApiException {
AlipayOpenAppItemCreateModel model = new AlipayOpenAppItemCreateModel();
// 设置商家侧商品ID
- model.setOutItemId(param.getOutItemId());
+ model.setOutItemId(rentRuleItem.getOutItemId());
+ // 设置商品名称由品牌、型号、电池规格、租赁类型、套餐名称拼接
+ String title = rentRuleItem.getBrandName() + rentRuleItem.getModelName() +"_"+ rentRuleItem.getCategoryName() + "_" +rentRuleItem.getRentalDays()+ rentRuleItem.getDictLabel()+rentRuleItem.getRuleName();
// 设置商品名称
- model.setTitle(param.getProductName());
+ model.setTitle(title);
// 设置导购描述
- model.setDesc(param.getProductName());
+ model.setDesc(title);
// 设置商品主图
- model.setHeadImg(imageUploadService.uploadAndReturnId("file/head.jpg", "ITEM_HEAD_IMG"));
+ model.setHeadImg(imageUploadService.uploadAndReturnId(rentRuleItem.getImage(), "ITEM_HEAD_IMG"));
// 设置商品图片的文件id列表
List imageList = new ArrayList<>();
imageList.add(imageUploadService.uploadAndReturnId("file/head.jpg", "ITEM_IMAGE_LIST"));
model.setImageList(imageList);
+ model.setItemDetailsPageModel("1");
+
// 设置商品详情页URL,需要先完成商品详情页组件开发接入
- try {
- String url = "plugin-private://2021003177653028/pages/goodsDetail/goodsDetail?outItemId=" + param.getOutItemId();
- model.setPath("alipays://platformapi/startApp?appId=" + alipaySdkUtil.getAppId()
- + "&page=" + URLEncoder.encode(url, "utf-8"));
- } catch (UnsupportedEncodingException e) {
- throw new AlipayApiException("url解析失败");
- }
+// try {
+// String url = "plugin-private://2021003177653028/pages/goodsDetail/goodsDetail?outItemId=" + param.getOutItemId();
+// model.setPath("alipays://platformapi/startApp?appId=" + alipaySdkUtil.getAppId()
+// + "&page=" + URLEncoder.encode(url, "utf-8"));
+// } catch (UnsupportedEncodingException e) {
+// throw new AlipayApiException("url解析失败");
+// }
// 设置类目ID
- model.setCategoryId(param.getCategoryId());
+ model.setCategoryId("C001684401");
// 设置商品售价
- model.setSalePrice(1L);
+ Long rentalPriceInCents = rentRuleItem.getRentalPrice().multiply(new BigDecimal(100)).setScale(0, java.math.RoundingMode.HALF_UP).longValue();
+ model.setSalePrice(rentalPriceInCents);
// 设置商品原价
- model.setOriginalPrice(1000L);
+ model.setOriginalPrice(rentalPriceInCents);
// 设置库存
model.setStockNum(100L);
@@ -401,8 +261,8 @@ public class ItemServiceImpl implements ItemService {
return templateResponse.getData().getAttr().getItemAttrList();
}
- private List getItemAttrs(ItemCreateRequest param, List imageList, String itemType) throws AlipayApiException {
- List attributes = getTemplateItemAttrs(param.getCategoryId(), itemType);
+ private List getItemAttrs(RentRuleItem param, List imageList, String itemType) throws AlipayApiException {
+ List attributes = getTemplateItemAttrs("C001684401", itemType);
if (CollectionUtils.isEmpty(attributes)) {
return null;
}
@@ -415,15 +275,15 @@ public class ItemServiceImpl implements ItemService {
// -----BEGIN 普通实物类商品可传入以下属性 -----
case "delivery_info":
// 商品履约信息
- if (StringUtils.isEmpty(param.getDeliveryId())) {
- break;
- }
- JSONObject jsonObject = new JSONObject();
- jsonObject.put("delivery_id", param.getDeliveryId());
- jsonObject.put("shop_ids", param.getShopIds());
- JSONArray jsonArray = new JSONArray();
- jsonArray.add(jsonObject);
- appItemAttrVO.setAttrValue(JSONArray.toJSONString(jsonArray));
+// if (StringUtils.isEmpty(param.getDeliveryId())) {
+// break;
+// }
+// JSONObject jsonObject = new JSONObject();
+// jsonObject.put("delivery_id", param.getDeliveryId());
+// jsonObject.put("shop_ids", param.getShopIds());
+// JSONArray jsonArray = new JSONArray();
+// jsonArray.add(jsonObject);
+// appItemAttrVO.setAttrValue(JSONArray.toJSONString(jsonArray));
break;
case "selling_point_tag":
// 导购标签
diff --git a/src/main/java/com/sczx/pay/mapper/RentRuleItemMapper.java b/src/main/java/com/sczx/pay/mapper/RentRuleItemMapper.java
new file mode 100644
index 0000000..74f6d7b
--- /dev/null
+++ b/src/main/java/com/sczx/pay/mapper/RentRuleItemMapper.java
@@ -0,0 +1,54 @@
+package com.sczx.pay.mapper;
+
+import com.sczx.pay.alipay.po.RentRuleItem;
+import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
+import java.util.List;
+
+/**
+ * 车型租赁规则项数据访问层
+ */
+@Mapper
+public interface RentRuleItemMapper {
+
+ /**
+ * 根据ID查询车型租赁规则项
+ * @param id 车型ID
+ * @return 车型租赁规则项信息
+ */
+ RentRuleItem selectById(@Param("id") Long id);
+
+ /**
+ * 查询所有车型租赁规则项
+ * @return 车型租赁规则项列表
+ */
+ List selectAll();
+
+ /**
+ * 新增车型租赁规则项
+ * @param zcRentRuleItem 车型租赁规则项信息
+ * @return 影响行数
+ */
+ int insert(RentRuleItem zcRentRuleItem);
+
+ /**
+ * 更新车型租赁规则项
+ * @param zcRentRuleItem 车型租赁规则项信息
+ * @return 影响行数
+ */
+ int update(RentRuleItem zcRentRuleItem);
+
+ /**
+ * 根据ID删除车型租赁规则项
+ * @param id 车型ID
+ * @return 影响行数
+ */
+ int deleteById(@Param("id") Long id);
+
+ /**
+ * 批量插入车型租赁规则项
+ * @param list 车型租赁规则项列表
+ * @return 影响行数
+ */
+ int insertBatch(@Param("list") List list);
+}
diff --git a/src/main/resources/mapper/RentRuleItemMapper.xml b/src/main/resources/mapper/RentRuleItemMapper.xml
new file mode 100644
index 0000000..8bca422
--- /dev/null
+++ b/src/main/resources/mapper/RentRuleItemMapper.xml
@@ -0,0 +1,123 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ id, out_item_id, ali_item_id, brand_name, model_name, category_name,
+ dict_label, rule_name, image, battery_rule_id, car_rule_id, car_model_id, brand_id
+
+
+
+
+
+
+
+
+
+
+ INSERT INTO zc_rent_rule_item (
+ id,
+ out_item_id,
+ ali_item_id,
+ brand_name,
+ model_name,
+ category_name,
+ dict_label,
+ rule_name,
+ image,
+ battery_rule_id,
+ car_rule_id,
+ car_model_id,
+ brand_id
+ ) VALUES (
+ #{id},
+ #{outItemId},
+ #{aliItemId},
+ #{brandName},
+ #{modelName},
+ #{categoryName},
+ #{dictLabel},
+ #{ruleName},
+ #{image},
+ #{batteryRuleId},
+ #{carRuleId},
+ #{carModelId},
+ #{brandId}
+ )
+
+
+
+
+ INSERT INTO zc_rent_rule_item (
+ id, out_item_id, ali_item_id, brand_name, model_name, category_name,
+ dict_label, rule_name, image, battery_rule_id, car_rule_id, car_model_id, brand_id
+ ) VALUES
+
+ (
+ #{item.id},
+ #{item.outItemId},
+ #{item.aliItemId},
+ #{item.brandName},
+ #{item.modelName},
+ #{item.categoryName},
+ #{item.dictLabel},
+ #{item.ruleName},
+ #{item.image},
+ #{item.batteryRuleId},
+ #{item.carRuleId},
+ #{item.carModelId},
+ #{item.brandId}
+ )
+
+
+
+
+
+ UPDATE zc_rent_rule_item
+
+ out_item_id = #{outItemId},
+ ali_item_id = #{aliItemId},
+ brand_name = #{brandName},
+ model_name = #{modelName},
+ category_name = #{categoryName},
+ dict_label = #{dictLabel},
+ rule_name = #{ruleName},
+ image = #{image},
+ battery_rule_id = #{batteryRuleId},
+ car_rule_id = #{carRuleId},
+ car_model_id = #{carModelId},
+ brand_id = #{brandId},
+
+ WHERE id = #{id}
+
+
+
+
+ DELETE FROM zc_rent_rule_item WHERE id = #{id}
+
+
From 3ac19beea6343940d050efaf60d588f052ed92c4 Mon Sep 17 00:00:00 2001
From: eric <465889110@qq.com>
Date: Mon, 1 Sep 2025 22:58:15 +0800
Subject: [PATCH 5/7] =?UTF-8?q?=E6=9F=A5=E8=AF=A2=E5=B1=A5=E7=BA=A6?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../pay/alipay/controller/ItemController.java | 10 +++++++
.../sczx/pay/alipay/service/ItemService.java | 1 +
.../alipay/service/impl/ItemServiceImpl.java | 27 +++++++++++++++++++
3 files changed, 38 insertions(+)
diff --git a/src/main/java/com/sczx/pay/alipay/controller/ItemController.java b/src/main/java/com/sczx/pay/alipay/controller/ItemController.java
index a6e0873..e927bee 100644
--- a/src/main/java/com/sczx/pay/alipay/controller/ItemController.java
+++ b/src/main/java/com/sczx/pay/alipay/controller/ItemController.java
@@ -84,5 +84,15 @@ public class ItemController {
return itemService.syncDeliveryInfo();
}
+ /**
+ * 租赁类(实物)履约模板创建
+ */
+ @ApiOperation(value = "租赁类(实物)履约模板创建")
+ @ApiOperationSupport(order = 4)
+ @PostMapping(value = "/delivery/query")
+ public OpenResponse deliveryQuery() {
+ return itemService.deliveryInfoQuery();
+ }
+
}
diff --git a/src/main/java/com/sczx/pay/alipay/service/ItemService.java b/src/main/java/com/sczx/pay/alipay/service/ItemService.java
index e3c8fd2..c563499 100644
--- a/src/main/java/com/sczx/pay/alipay/service/ItemService.java
+++ b/src/main/java/com/sczx/pay/alipay/service/ItemService.java
@@ -39,4 +39,5 @@ public interface ItemService {
*/
OpenResponse syncDeliveryInfo();
+ OpenResponse deliveryInfoQuery();
}
diff --git a/src/main/java/com/sczx/pay/alipay/service/impl/ItemServiceImpl.java b/src/main/java/com/sczx/pay/alipay/service/impl/ItemServiceImpl.java
index d816acf..971d677 100644
--- a/src/main/java/com/sczx/pay/alipay/service/impl/ItemServiceImpl.java
+++ b/src/main/java/com/sczx/pay/alipay/service/impl/ItemServiceImpl.java
@@ -196,6 +196,33 @@ public class ItemServiceImpl implements ItemService {
}
+ @Override
+ public OpenResponse deliveryInfoQuery() {
+ return AlipayApiTemplate.execute(new AlipayApiCallback() {
+ @Override
+ public AlipayOpenAppDeliveryInfoQueryResponse process() throws AlipayApiException {
+ // 构造请求参数以调用接口
+ AlipayOpenAppDeliveryInfoQueryRequest request = new AlipayOpenAppDeliveryInfoQueryRequest();
+ AlipayOpenAppDeliveryInfoQueryModel model = new AlipayOpenAppDeliveryInfoQueryModel();
+ // 设置履约类型
+ model.setDeliveryType("PICKUP");
+
+ request.setBizModel(model);
+ return alipaySdkUtil.execute(request);
+ }
+
+ @Override
+ public String getData(AlipayOpenAppDeliveryInfoQueryResponse response) {
+ return response.getBody();
+ }
+
+ @Override
+ public String getApiName() {
+ return "alipay.open.app.delivery.info.query";
+ }
+ });
+ }
+
private AlipayOpenAppItemCreateModel getAlipayOpenAppItemCreateModel(RentRuleItem rentRuleItem) throws AlipayApiException {
AlipayOpenAppItemCreateModel model = new AlipayOpenAppItemCreateModel();
From 64177bde9cf8bdbc840db444c03a9eb2888cabe9 Mon Sep 17 00:00:00 2001
From: eric <465889110@qq.com>
Date: Mon, 1 Sep 2025 23:07:41 +0800
Subject: [PATCH 6/7] =?UTF-8?q?=E5=B1=A5=E7=BA=A6=E6=A8=A1=E6=9D=BF?=
=?UTF-8?q?=E6=9F=A5=E8=AF=A2=E6=8E=A5=E5=8F=A3?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../pay/alipay/controller/ItemController.java | 7 +++++
.../sczx/pay/alipay/service/ItemService.java | 3 ++
.../alipay/service/impl/ItemServiceImpl.java | 29 +++++++++++++++++++
3 files changed, 39 insertions(+)
diff --git a/src/main/java/com/sczx/pay/alipay/controller/ItemController.java b/src/main/java/com/sczx/pay/alipay/controller/ItemController.java
index e927bee..6a76506 100644
--- a/src/main/java/com/sczx/pay/alipay/controller/ItemController.java
+++ b/src/main/java/com/sczx/pay/alipay/controller/ItemController.java
@@ -94,5 +94,12 @@ public class ItemController {
return itemService.deliveryInfoQuery();
}
+ @ApiOperation(value = "租赁类(实物)履约模板创建")
+ @ApiOperationSupport(order = 4)
+ @PostMapping(value = "/deliverytemplate/query")
+ public OpenResponse deliveryTemplateQuery() {
+ return itemService.deliveryTemplateQuery();
+ }
+
}
diff --git a/src/main/java/com/sczx/pay/alipay/service/ItemService.java b/src/main/java/com/sczx/pay/alipay/service/ItemService.java
index c563499..8232f0a 100644
--- a/src/main/java/com/sczx/pay/alipay/service/ItemService.java
+++ b/src/main/java/com/sczx/pay/alipay/service/ItemService.java
@@ -40,4 +40,7 @@ public interface ItemService {
OpenResponse syncDeliveryInfo();
OpenResponse deliveryInfoQuery();
+
+ OpenResponse deliveryTemplateQuery();
+
}
diff --git a/src/main/java/com/sczx/pay/alipay/service/impl/ItemServiceImpl.java b/src/main/java/com/sczx/pay/alipay/service/impl/ItemServiceImpl.java
index 971d677..a6e7f03 100644
--- a/src/main/java/com/sczx/pay/alipay/service/impl/ItemServiceImpl.java
+++ b/src/main/java/com/sczx/pay/alipay/service/impl/ItemServiceImpl.java
@@ -223,6 +223,35 @@ public class ItemServiceImpl implements ItemService {
});
}
+
+ @Override
+ public OpenResponse deliveryTemplateQuery() {
+ return AlipayApiTemplate.execute(new AlipayApiCallback() {
+ @Override
+ public AlipayOpenAppDeliveryTemplateQueryResponse process() throws AlipayApiException {
+ // 构造请求参数以调用接口
+ AlipayOpenAppDeliveryTemplateQueryRequest request = new AlipayOpenAppDeliveryTemplateQueryRequest();
+ AlipayOpenAppDeliveryTemplateQueryModel model = new AlipayOpenAppDeliveryTemplateQueryModel();
+ // 设置履约类型
+ model.setDeliveryType("PICKUP");
+
+ request.setBizModel(model);
+ return alipaySdkUtil.execute(request);
+ }
+
+ @Override
+ public String getData(AlipayOpenAppDeliveryTemplateQueryResponse response) {
+ return response.getBody();
+ }
+
+ @Override
+ public String getApiName() {
+ return "alipay.open.app.delivery.template.query";
+ }
+ });
+ }
+
+
private AlipayOpenAppItemCreateModel getAlipayOpenAppItemCreateModel(RentRuleItem rentRuleItem) throws AlipayApiException {
AlipayOpenAppItemCreateModel model = new AlipayOpenAppItemCreateModel();
From 85132eb752c62478a39946d9786dd8f2cb4ae0c8 Mon Sep 17 00:00:00 2001
From: eric <465889110@qq.com>
Date: Mon, 1 Sep 2025 23:16:51 +0800
Subject: [PATCH 7/7] =?UTF-8?q?=E5=88=9B=E5=BB=BA=E6=A8=A1=E6=9D=BF?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../java/com/sczx/pay/alipay/service/impl/ItemServiceImpl.java | 2 --
1 file changed, 2 deletions(-)
diff --git a/src/main/java/com/sczx/pay/alipay/service/impl/ItemServiceImpl.java b/src/main/java/com/sczx/pay/alipay/service/impl/ItemServiceImpl.java
index a6e7f03..ae83f03 100644
--- a/src/main/java/com/sczx/pay/alipay/service/impl/ItemServiceImpl.java
+++ b/src/main/java/com/sczx/pay/alipay/service/impl/ItemServiceImpl.java
@@ -168,8 +168,6 @@ public class ItemServiceImpl implements ItemService {
model.setDeliveryType("PICKUP");
model.setDeliveryName("电动车租赁自提履约");
- // 设置履约信息ID
- model.setDeliveryId("20250901000800000001");
// 设置履约属性
List attrs = new ArrayList();