商品品类
This commit is contained in:
		
							
								
								
									
										130
									
								
								src/main/java/com/sczx/pay/alipay/controller/ItemController.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										130
									
								
								src/main/java/com/sczx/pay/alipay/controller/ItemController.java
									
									
									
									
									
										Normal file
									
								
							| @ -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<List<AppxCategoryVO>> 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<AlipayOpenAppItemTemplateQueryResponse> 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<String> saleCreate(@RequestBody ItemCreateRequest request) { | ||||
|         return itemService.createSaleItem(request); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 租赁类(实物)商品创建 | ||||
|      */ | ||||
|     @ApiOperation(value = "租赁类(实物)商品创建") | ||||
|     @ApiOperationSupport(order = 4) | ||||
|     @PostMapping(value = "/rent/create") | ||||
|     public OpenResponse<String> rentCreate(@RequestBody ItemCreateRequest request) { | ||||
|         return itemService.createRentItem(request); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 付费充值/兑换类(虚拟)商品创建 | ||||
|      */ | ||||
|     @ApiOperation(value = "付费充值/兑换类(虚拟)商品创建", notes = "电影/演出/体育赛事票务类商品") | ||||
|     @ApiOperationSupport(order = 5) | ||||
|     @PostMapping(value = "/virtual/create") | ||||
|     public OpenResponse<String> virtualCreate(@RequestBody ItemCreateRequest request) { | ||||
|         return itemService.createVirtualItem(request); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 售卖类(实物)商品更新 | ||||
|      */ | ||||
|     @ApiOperation(value = "商品更新") | ||||
|     @ApiOperationSupport(order = 6) | ||||
|     @PostMapping(value = "/update") | ||||
|     public OpenResponse<String> update(@RequestBody ItemCreateRequest request) { | ||||
|         return itemService.updateItem(request); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 商品详情查询 | ||||
|      */ | ||||
|     @ApiOperation(value = "商品详情查询") | ||||
|     @ApiOperationSupport(order = 7) | ||||
|     @GetMapping(value = "/query") | ||||
|     public OpenResponse<AlipayOpenAppItemQueryResponse> 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<AlipayOpenAppItemListQueryResponse> 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); | ||||
|     } | ||||
| } | ||||
| @ -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<String> createImageDirectory(ImageDirectoryRequest createRequest); | ||||
|  | ||||
|     /** | ||||
|      * 修改图片空间目录 | ||||
|      */ | ||||
|     OpenResponse<Void> updateImageDirectory(ImageDirectoryRequest updateRequest); | ||||
|  | ||||
|     /** | ||||
|      * 分页查询图片空间目录 | ||||
|      */ | ||||
|     OpenResponse<AlipayMarketingImagedirectoryListQueryResponse> queryImageDirectoryList(Long pageNum, Long pageSize, ImageDirectoryRequest queryRequest); | ||||
|  | ||||
|     /** | ||||
|      * 修改图片信息 | ||||
|      */ | ||||
|     OpenResponse<Void> updateImage(String imageIndexId, String fileName, String imageDirectoryId); | ||||
|  | ||||
|     /** | ||||
|      * 分页查询图片 | ||||
|      */ | ||||
|     OpenResponse<AlipayMarketingImageListQueryResponse> queryImageList(Long pageNum, Long pageSize, String imageIndexId, String fileName, String imageDirectoryId); | ||||
|  | ||||
|     /** | ||||
|      * 删除图片 | ||||
|      */ | ||||
|     OpenResponse<Void> deleteImage(List<String> imageIndexIdList); | ||||
| } | ||||
							
								
								
									
										60
									
								
								src/main/java/com/sczx/pay/alipay/service/ItemService.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										60
									
								
								src/main/java/com/sczx/pay/alipay/service/ItemService.java
									
									
									
									
									
										Normal file
									
								
							| @ -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<List<AppxCategoryVO>> getCategories(String itemType, String catStatus); | ||||
|  | ||||
|     /** | ||||
|      * 查询普通商品模板信息 | ||||
|      */ | ||||
|     OpenResponse<AlipayOpenAppItemTemplateQueryResponse> queryTemplate(String categoryId, String itemType); | ||||
|  | ||||
|     /** | ||||
|      * 创建售卖类(实物)商品 | ||||
|      */ | ||||
|     OpenResponse<String> createSaleItem(ItemCreateRequest param); | ||||
|  | ||||
|     /** | ||||
|      * 创建租赁类(实物)商品 | ||||
|      */ | ||||
|     OpenResponse<String> createRentItem(ItemCreateRequest param); | ||||
|  | ||||
|     /** | ||||
|      * 创建付费充值/兑换类(虚拟)商品 | ||||
|      */ | ||||
|     OpenResponse<String> createVirtualItem(ItemCreateRequest param); | ||||
|  | ||||
|     /** | ||||
|      * 修改售卖类(实物)商品 | ||||
|      */ | ||||
|     OpenResponse<String> updateItem(ItemCreateRequest param); | ||||
|  | ||||
|     /** | ||||
|      * 查询商品详情 | ||||
|      */ | ||||
|     OpenResponse<AlipayOpenAppItemQueryResponse> queryItemDetail(String itemId, String outItemId, long needEditSpu); | ||||
|  | ||||
|     /** | ||||
|      * 分页查询商品列表 | ||||
|      */ | ||||
|     OpenResponse<AlipayOpenAppItemListQueryResponse> queryItemList(String itemId, String outItemId, long pageNum, long pageSize); | ||||
| } | ||||
| @ -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<String> createImageDirectory(ImageDirectoryRequest createRequest) { | ||||
|         return AlipayApiTemplate.execute(new AlipayApiCallback<String, AlipayMarketingImagedirectoryCreateResponse>() { | ||||
|             @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<Void> updateImageDirectory(ImageDirectoryRequest updateRequest) { | ||||
|         return AlipayApiTemplate.execute(new AlipayApiCallback<Void, AlipayMarketingImagedirectoryModifyResponse>() { | ||||
|             @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<AlipayMarketingImagedirectoryListQueryResponse> queryImageDirectoryList(Long pageNum, Long pageSize, ImageDirectoryRequest queryRequest) { | ||||
|         return AlipayApiTemplate.execute(new AlipayApiCallback<AlipayMarketingImagedirectoryListQueryResponse, AlipayMarketingImagedirectoryListQueryResponse>() { | ||||
|             @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<Void> updateImage(String imageIndexId, String fileName, String imageDirectoryId) { | ||||
|         return AlipayApiTemplate.execute(new AlipayApiCallback<Void, AlipayMarketingImageModifyResponse>() { | ||||
|             @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<AlipayMarketingImageListQueryResponse> queryImageList(Long pageNum, Long pageSize, String imageIndexId, String fileName, String imageDirectoryId) { | ||||
|         return AlipayApiTemplate.execute(new AlipayApiCallback<AlipayMarketingImageListQueryResponse, AlipayMarketingImageListQueryResponse>() { | ||||
|             @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<Void> deleteImage(List<String> imageIndexIdList) { | ||||
|         return AlipayApiTemplate.execute(new AlipayApiCallback<Void, AlipayMarketingImageDeleteResponse>() { | ||||
|             @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"; | ||||
|             } | ||||
|         }); | ||||
|     } | ||||
| } | ||||
| @ -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<List<AppxCategoryVO>> getCategories(String itemType, String catStatus) { | ||||
|         return AlipayApiTemplate.execute(new AlipayApiCallback<List<AppxCategoryVO>, 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<AppxCategoryVO> getData(AlipayOpenAppItemAllcategoryQueryResponse response) { | ||||
|                 List<CategoryAndParentVO> cats = response.getCats(); | ||||
|                 if (CollectionUtils.isEmpty(cats)) { | ||||
|                     return null; | ||||
|                 } | ||||
|                 List<AppxCategoryVO> childs = new ArrayList<>(); | ||||
|                 for (CategoryAndParentVO cat : cats) { | ||||
|                     if (CollectionUtils.isEmpty(cat.getCatAndParent())) { | ||||
|                         continue; | ||||
|                     } | ||||
|                     // 获取叶子节点(cat_status不为空的是叶子结点) | ||||
|                     Optional<AppxCategoryVO> 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<AlipayOpenAppItemTemplateQueryResponse> queryTemplate(String categoryId, String itemType) { | ||||
|         return AlipayApiTemplate.execute(new AlipayApiCallback<AlipayOpenAppItemTemplateQueryResponse, AlipayOpenAppItemTemplateQueryResponse>() { | ||||
|             @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<String> createSaleItem(ItemCreateRequest param) { | ||||
|         return AlipayApiTemplate.execute(new AlipayApiCallback<String, AlipayOpenAppItemCreateResponse>() { | ||||
|  | ||||
|             @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<String> createRentItem(ItemCreateRequest param) { | ||||
|         return AlipayApiTemplate.execute(new AlipayApiCallback<String, AlipayOpenAppItemCreateResponse>() { | ||||
|  | ||||
|             @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<String> createVirtualItem(ItemCreateRequest param) { | ||||
|         return AlipayApiTemplate.execute(new AlipayApiCallback<String, AlipayOpenAppItemCreateResponse>() { | ||||
|  | ||||
|             @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<String> updateItem(ItemCreateRequest param) { | ||||
|         return AlipayApiTemplate.execute(new AlipayApiCallback<String, AlipayOpenAppItemModifyResponse>() { | ||||
|  | ||||
|             @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<AlipayOpenAppItemQueryResponse> queryItemDetail(String itemId, String outItemId, long needEditSpu) { | ||||
|         return AlipayApiTemplate.execute(new AlipayApiCallback<AlipayOpenAppItemQueryResponse, AlipayOpenAppItemQueryResponse>() { | ||||
|             @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<AlipayOpenAppItemListQueryResponse> queryItemList(String itemId, String outItemId, long pageNum, long pageSize) { | ||||
|         return AlipayApiTemplate.execute(new AlipayApiCallback<AlipayOpenAppItemListQueryResponse, AlipayOpenAppItemListQueryResponse>() { | ||||
|             @Override | ||||
|             public AlipayOpenAppItemListQueryResponse process() throws AlipayApiException { | ||||
|                 // 构造请求参数以调用接口 | ||||
|                 AlipayOpenAppItemListQueryRequest request = new AlipayOpenAppItemListQueryRequest(); | ||||
|                 AlipayOpenAppItemListQueryModel model = new AlipayOpenAppItemListQueryModel(); | ||||
|  | ||||
|                 if (!StringUtils.isEmpty(outItemId)) { | ||||
|                     // 设置商家侧id列表 | ||||
|                     List<String> outItemIdList = new ArrayList<>(); | ||||
|                     outItemIdList.add(outItemId); | ||||
|                     model.setOutItemIdList(outItemIdList); | ||||
|                 } | ||||
|  | ||||
|                 if (!StringUtils.isEmpty(itemId)) { | ||||
|                     // 设置平台侧商品id列表 | ||||
|                     List<String> 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<String> 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<AttributeVO> getTemplateItemAttrs(String categoryId, String itemType) throws AlipayApiException { | ||||
|         OpenResponse<AlipayOpenAppItemTemplateQueryResponse> 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<AppItemAttrVO> getItemAttrs(ItemCreateRequest param, List<String> imageList, String itemType) throws AlipayApiException { | ||||
|         List<AttributeVO> attributes = getTemplateItemAttrs(param.getCategoryId(), itemType); | ||||
|         if (CollectionUtils.isEmpty(attributes)) { | ||||
|             return null; | ||||
|         } | ||||
|         List<AppItemAttrVO> 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; | ||||
|     } | ||||
| } | ||||
| @ -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 <tt>imageDirectoryName</tt>. | ||||
|      * | ||||
|      * @return property value of imageDirectoryName | ||||
|      */ | ||||
|     public String getImageDirectoryName() { | ||||
|         return imageDirectoryName; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Setter method for property <tt>imageDirectoryName</tt>. | ||||
|      * | ||||
|      * @param imageDirectoryName value to be assigned to property imageDirectoryName | ||||
|      */ | ||||
|     public void setImageDirectoryName(String imageDirectoryName) { | ||||
|         this.imageDirectoryName = imageDirectoryName; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Getter method for property <tt>parentDirectoryId</tt>. | ||||
|      * | ||||
|      * @return property value of parentDirectoryId | ||||
|      */ | ||||
|     public String getParentDirectoryId() { | ||||
|         return parentDirectoryId; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Setter method for property <tt>parentDirectoryId</tt>. | ||||
|      * | ||||
|      * @param parentDirectoryId value to be assigned to property parentDirectoryId | ||||
|      */ | ||||
|     public void setParentDirectoryId(String parentDirectoryId) { | ||||
|         this.parentDirectoryId = parentDirectoryId; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Getter method for property <tt>imageDirectoryId</tt>. | ||||
|      * | ||||
|      * @return property value of imageDirectoryId | ||||
|      */ | ||||
|     public String getImageDirectoryId() { | ||||
|         return imageDirectoryId; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Setter method for property <tt>imageDirectoryId</tt>. | ||||
|      * | ||||
|      * @param imageDirectoryId value to be assigned to property imageDirectoryId | ||||
|      */ | ||||
|     public void setImageDirectoryId(String imageDirectoryId) { | ||||
|         this.imageDirectoryId = imageDirectoryId; | ||||
|     } | ||||
| } | ||||
							
								
								
									
										164
									
								
								src/main/java/com/sczx/pay/alipay/vo/ItemCreateRequest.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										164
									
								
								src/main/java/com/sczx/pay/alipay/vo/ItemCreateRequest.java
									
									
									
									
									
										Normal file
									
								
							| @ -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<String> shopIds; | ||||
|  | ||||
|     /** | ||||
|      * Getter method for property <tt>categoryId</tt>. | ||||
|      * | ||||
|      * @return property value of categoryId | ||||
|      */ | ||||
|     public String getCategoryId() { | ||||
|         return categoryId; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Setter method for property <tt>categoryId</tt>. | ||||
|      * | ||||
|      * @param categoryId value to be assigned to property categoryId | ||||
|      */ | ||||
|     public void setCategoryId(String categoryId) { | ||||
|         this.categoryId = categoryId; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Getter method for property <tt>productName</tt>. | ||||
|      * | ||||
|      * @return property value of productName | ||||
|      */ | ||||
|     public String getProductName() { | ||||
|         return productName; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Setter method for property <tt>productName</tt>. | ||||
|      * | ||||
|      * @param productName value to be assigned to property productName | ||||
|      */ | ||||
|     public void setProductName(String productName) { | ||||
|         this.productName = productName; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Getter method for property <tt>outItemId</tt>. | ||||
|      * | ||||
|      * @return property value of outItemId | ||||
|      */ | ||||
|     public String getOutItemId() { | ||||
|         return outItemId; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Setter method for property <tt>outItemId</tt>. | ||||
|      * | ||||
|      * @param outItemId value to be assigned to property outItemId | ||||
|      */ | ||||
|     public void setOutItemId(String outItemId) { | ||||
|         this.outItemId = outItemId; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Getter method for property <tt>merchantName</tt>. | ||||
|      * | ||||
|      * @return property value of merchantName | ||||
|      */ | ||||
|     public String getMerchantName() { | ||||
|         return merchantName; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Setter method for property <tt>merchantName</tt>. | ||||
|      * | ||||
|      * @param merchantName value to be assigned to property merchantName | ||||
|      */ | ||||
|     public void setMerchantName(String merchantName) { | ||||
|         this.merchantName = merchantName; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Getter method for property <tt>deliveryId</tt>. | ||||
|      * | ||||
|      * @return property value of deliveryId | ||||
|      */ | ||||
|     public String getDeliveryId() { | ||||
|         return deliveryId; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Setter method for property <tt>deliveryId</tt>. | ||||
|      * | ||||
|      * @param deliveryId value to be assigned to property deliveryId | ||||
|      */ | ||||
|     public void setDeliveryId(String deliveryId) { | ||||
|         this.deliveryId = deliveryId; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Getter method for property <tt>shopIds</tt>. | ||||
|      * | ||||
|      * @return property value of shopIds | ||||
|      */ | ||||
|     public List<String> getShopIds() { | ||||
|         return shopIds; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Setter method for property <tt>shopIds</tt>. | ||||
|      * | ||||
|      * @param shopIds value to be assigned to property shopIds | ||||
|      */ | ||||
|     public void setShopIds(List<String> shopIds) { | ||||
|         this.shopIds = shopIds; | ||||
|     } | ||||
| } | ||||
							
								
								
									
										136
									
								
								src/main/java/com/sczx/pay/alipay/vo/OpenResponse.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										136
									
								
								src/main/java/com/sczx/pay/alipay/vo/OpenResponse.java
									
									
									
									
									
										Normal file
									
								
							| @ -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<E extends Object> 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 <tt>code</tt>. | ||||
|      * | ||||
|      * @return property value of code | ||||
|      */ | ||||
|     public String getCode() { | ||||
|         return code; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Setter method for property <tt>code</tt>. | ||||
|      * | ||||
|      * @param code value to be assigned to property code | ||||
|      */ | ||||
|     public void setCode(String code) { | ||||
|         this.code = code; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Getter method for property <tt>msg</tt>. | ||||
|      * | ||||
|      * @return property value of msg | ||||
|      */ | ||||
|     public String getMsg() { | ||||
|         return msg; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Setter method for property <tt>msg</tt>. | ||||
|      * | ||||
|      * @param msg value to be assigned to property msg | ||||
|      */ | ||||
|     public void setMsg(String msg) { | ||||
|         this.msg = msg; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Getter method for property <tt>subCode</tt>. | ||||
|      * | ||||
|      * @return property value of subCode | ||||
|      */ | ||||
|     public String getSubCode() { | ||||
|         return subCode; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Setter method for property <tt>subCode</tt>. | ||||
|      * | ||||
|      * @param subCode value to be assigned to property subCode | ||||
|      */ | ||||
|     public void setSubCode(String subCode) { | ||||
|         this.subCode = subCode; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Getter method for property <tt>subMsg</tt>. | ||||
|      * | ||||
|      * @return property value of subMsg | ||||
|      */ | ||||
|     public String getSubMsg() { | ||||
|         return subMsg; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Setter method for property <tt>subMsg</tt>. | ||||
|      * | ||||
|      * @param subMsg value to be assigned to property subMsg | ||||
|      */ | ||||
|     public void setSubMsg(String subMsg) { | ||||
|         this.subMsg = subMsg; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Getter method for property <tt>data</tt>. | ||||
|      * | ||||
|      * @return property value of data | ||||
|      */ | ||||
|     public E getData() { | ||||
|         return data; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Setter method for property <tt>data</tt>. | ||||
|      * | ||||
|      * @param data value to be assigned to property data | ||||
|      */ | ||||
|     public void setData(E data) { | ||||
|         this.data = data; | ||||
|     } | ||||
| } | ||||
							
								
								
									
										21
									
								
								src/main/java/com/sczx/pay/utils/AlipayApiCallback.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										21
									
								
								src/main/java/com/sczx/pay/utils/AlipayApiCallback.java
									
									
									
									
									
										Normal file
									
								
							| @ -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<T, R extends AlipayResponse> { | ||||
|  | ||||
|     R process() throws AlipayApiException; | ||||
|  | ||||
|     T getData(R response); | ||||
|  | ||||
|     String getApiName(); | ||||
| } | ||||
							
								
								
									
										50
									
								
								src/main/java/com/sczx/pay/utils/AlipayApiTemplate.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										50
									
								
								src/main/java/com/sczx/pay/utils/AlipayApiTemplate.java
									
									
									
									
									
										Normal file
									
								
							| @ -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 <T, R extends AlipayResponse> OpenResponse<T> execute(AlipayApiCallback<T, R> callback) { | ||||
|         try { | ||||
|             //执行 | ||||
|             R response = callback.process(); | ||||
|             OpenResponse<T> 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<T> response = new OpenResponse<>(); | ||||
|             response.setCode("SYSTEM_ERROR"); | ||||
|             response.setMsg("系统错误"); | ||||
|             response.setSubMsg(e.getMessage()); | ||||
|             return response; | ||||
|         } | ||||
|     } | ||||
| } | ||||
							
								
								
									
										242
									
								
								src/main/java/com/sczx/pay/utils/AlipaySdkUtil.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										242
									
								
								src/main/java/com/sczx/pay/utils/AlipaySdkUtil.java
									
									
									
									
									
										Normal file
									
								
							| @ -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 extends AlipayResponse> T execute(AlipayRequest<T> 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<String, String> headers = new HashMap<>(); | ||||
|         headers.put("alipay-sdk-demo", "app-item-0.0.1"); | ||||
|         alipayConfig.setCustomHeaders(headers); | ||||
|  | ||||
|  | ||||
|  | ||||
|         return alipayConfig; | ||||
|  | ||||
|     } | ||||
|  | ||||
|  | ||||
|  | ||||
|     /** | ||||
|      * Getter method for property <tt>pid</tt>. | ||||
|      * | ||||
|      * @return property value of pid | ||||
|      */ | ||||
|     public String getPid() { | ||||
|         return pid; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Setter method for property <tt>pid</tt>. | ||||
|      * | ||||
|      * @param pid value to be assigned to property pid | ||||
|      */ | ||||
|     public void setPid(String pid) { | ||||
|         this.pid = pid; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Getter method for property <tt>appId</tt>. | ||||
|      * | ||||
|      * @return property value of appId | ||||
|      */ | ||||
|     public String getAppId() { | ||||
|         return appId; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Setter method for property <tt>appId</tt>. | ||||
|      * | ||||
|      * @param appId value to be assigned to property appId | ||||
|      */ | ||||
|     public void setAppId(String appId) { | ||||
|         this.appId = appId; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Getter method for property <tt>openid</tt>. | ||||
|      * | ||||
|      * @return property value of openid | ||||
|      */ | ||||
|     public String getOpenid() { | ||||
|         return openid; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Setter method for property <tt>openid</tt>. | ||||
|      * | ||||
|      * @param openid value to be assigned to property openid | ||||
|      */ | ||||
|     public void setOpenid(String openid) { | ||||
|         this.openid = openid; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Getter method for property <tt>userid</tt>. | ||||
|      * | ||||
|      * @return property value of userid | ||||
|      */ | ||||
|     public String getUserid() { | ||||
|         return userid; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Setter method for property <tt>userid</tt>. | ||||
|      * | ||||
|      * @param userid value to be assigned to property userid | ||||
|      */ | ||||
|     public void setUserid(String userid) { | ||||
|         this.userid = userid; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Getter method for property <tt>useOpenId</tt>. | ||||
|      * | ||||
|      * @return property value of useOpenId | ||||
|      */ | ||||
|     public boolean isUseOpenId() { | ||||
|         return useOpenId; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Setter method for property <tt>useOpenId</tt>. | ||||
|      * | ||||
|      * @param useOpenId value to be assigned to property useOpenId | ||||
|      */ | ||||
|     public void setUseOpenId(boolean useOpenId) { | ||||
|         this.useOpenId = useOpenId; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Getter method for property <tt>isIsv</tt>. | ||||
|      * | ||||
|      * @return property value of isIsv | ||||
|      */ | ||||
|     public boolean isv() { | ||||
|         return isIsv; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Setter method for property <tt>isIsv</tt>. | ||||
|      * | ||||
|      * @param isv value to be assigned to property isIsv | ||||
|      */ | ||||
|     public void setIsv(boolean isv) { | ||||
|         isIsv = isv; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Getter method for property <tt>appAuthToken</tt>. | ||||
|      * | ||||
|      * @return property value of appAuthToken | ||||
|      */ | ||||
|     public String getAppAuthToken() { | ||||
|         return appAuthToken; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Setter method for property <tt>appAuthToken</tt>. | ||||
|      * | ||||
|      * @param appAuthToken value to be assigned to property appAuthToken | ||||
|      */ | ||||
|     public void setAppAuthToken(String appAuthToken) { | ||||
|         this.appAuthToken = appAuthToken; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Getter method for property <tt>privateKey</tt>. | ||||
|      * | ||||
|      * @return property value of privateKey | ||||
|      */ | ||||
|     public String getPrivateKey() { | ||||
|         return privateKey; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Setter method for property <tt>privateKey</tt>. | ||||
|      * | ||||
|      * @param privateKey value to be assigned to property privateKey | ||||
|      */ | ||||
|     public void setPrivateKey(String privateKey) { | ||||
|         this.privateKey = privateKey; | ||||
|     } | ||||
|  | ||||
|  | ||||
| } | ||||
		Reference in New Issue
	
	Block a user