This commit is contained in:
2025-09-02 00:11:42 +08:00
17 changed files with 2343 additions and 1 deletions

15
pom.xml
View File

@ -186,7 +186,22 @@
<artifactId>wechatpay-java</artifactId>
<version>0.2.14</version>
</dependency>
<dependency>
<groupId>com.alipay.sdk</groupId>
<artifactId>alipay-sdk-java</artifactId>
<version>4.39.79.ALL</version>
</dependency>
<dependency>
<groupId>com.alipay.sdk</groupId>
<artifactId>alipay-sdk-java-v3</artifactId>
<version>2.9.0.ALL</version>
</dependency>
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>knife4j-spring-boot-starter</artifactId>
<version>2.0.2</version>
</dependency>
<!-- Apache Commons Codec -->
<dependency>
<groupId>commons-codec</groupId>

View File

@ -0,0 +1,105 @@
/**
* 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.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;
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 = "普通商品模块")
@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 = 4)
@PostMapping(value = "/rent/create")
public OpenResponse<String> rentCreate(@RequestBody RentRuleItem request) {
return itemService.createRentItem(request);
}
/**
* 租赁类(实物)履约模板创建
*/
@ApiOperation(value = "租赁类(实物)履约模板创建")
@ApiOperationSupport(order = 4)
@PostMapping(value = "/template/create")
public OpenResponse<String> templateCreate() {
return itemService.syncDeliveryInfo();
}
/**
* 租赁类(实物)履约模板创建
*/
@ApiOperation(value = "租赁类(实物)履约模板创建")
@ApiOperationSupport(order = 4)
@PostMapping(value = "/delivery/query")
public OpenResponse<String> deliveryQuery() {
return itemService.deliveryInfoQuery();
}
@ApiOperation(value = "租赁类(实物)履约模板创建")
@ApiOperationSupport(order = 4)
@PostMapping(value = "/deliverytemplate/query")
public OpenResponse<String> deliveryTemplateQuery() {
return itemService.deliveryTemplateQuery();
}
}

View File

@ -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:1800kb以内", 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<String> imageList;
// SKU信息
@ApiModelProperty(value = "SKU数组")
private List<RentSkuRequest> skus;
// 商品属性
@ApiModelProperty(value = "商品属性")
private List<ItemAttrRequest> 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<String> getImageList() {
return imageList;
}
public void setImageList(List<String> imageList) {
this.imageList = imageList;
}
public List<RentSkuRequest> getSkus() {
return skus;
}
public void setSkus(List<RentSkuRequest> skus) {
this.skus = skus;
}
public List<ItemAttrRequest> getAttrs() {
return attrs;
}
public void setAttrs(List<ItemAttrRequest> 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<SkuAttrRequest> 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<SkuAttrRequest> getSkuAttrs() {
return skuAttrs;
}
public void setSkuAttrs(List<SkuAttrRequest> 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;
}
}
}

View File

@ -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;
}
}

View File

@ -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);
}

View File

@ -0,0 +1,46 @@
/**
* 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.po.RentRuleItem;
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> createRentItem(RentRuleItem param);
/**
* 根据业务属性写死自提履约信息
*/
OpenResponse<String> syncDeliveryInfo();
OpenResponse<String> deliveryInfoQuery();
OpenResponse<String> deliveryTemplateQuery();
}

View File

@ -0,0 +1,324 @@
/**
* 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.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Base64;
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 {
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);
}
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";
}
});
}
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();
}
}
}

View File

@ -0,0 +1,429 @@
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.po.RentRuleItem;
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.math.BigDecimal;
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> createRentItem(RentRuleItem 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> syncDeliveryInfo() {
return AlipayApiTemplate.execute(new AlipayApiCallback<String, AlipayOpenAppDeliveryInfoSyncResponse>() {
@Override
public AlipayOpenAppDeliveryInfoSyncResponse process() throws AlipayApiException {
// 构造请求参数以调用接口
AlipayOpenAppDeliveryInfoSyncRequest request = new AlipayOpenAppDeliveryInfoSyncRequest();
AlipayOpenAppDeliveryInfoSyncModel model = new AlipayOpenAppDeliveryInfoSyncModel();
// 设置履约类型
model.setDeliveryType("PICKUP");
model.setDeliveryName("电动车租赁自提履约");
// 设置履约属性
List<AppItemAttrVO> attrs = new ArrayList<AppItemAttrVO>();
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(AlipayOpenAppDeliveryInfoSyncResponse response) {
return response.getDeliveryId();
}
@Override
public String getApiName() {
return "alipay.open.app.delivery.info.sync";
}
});
}
@Override
public OpenResponse<String> deliveryInfoQuery() {
return AlipayApiTemplate.execute(new AlipayApiCallback<String, AlipayOpenAppDeliveryInfoQueryResponse>() {
@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";
}
});
}
@Override
public OpenResponse<String> deliveryTemplateQuery() {
return AlipayApiTemplate.execute(new AlipayApiCallback<String, AlipayOpenAppDeliveryTemplateQueryResponse>() {
@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();
// 设置商家侧商品ID
model.setOutItemId(rentRuleItem.getOutItemId());
// 设置商品名称由品牌、型号、电池规格、租赁类型、套餐名称拼接
String title = rentRuleItem.getBrandName() + rentRuleItem.getModelName() +"_"+ rentRuleItem.getCategoryName() + "_" +rentRuleItem.getRentalDays()+ rentRuleItem.getDictLabel()+rentRuleItem.getRuleName();
// 设置商品名称
model.setTitle(title);
// 设置导购描述
model.setDesc(title);
// 设置商品主图
model.setHeadImg(imageUploadService.uploadAndReturnId(rentRuleItem.getImage(), "ITEM_HEAD_IMG"));
// 设置商品图片的文件id列表
List<String> 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解析失败");
// }
// 设置类目ID
model.setCategoryId("C001684401");
// 设置商品售价
Long rentalPriceInCents = rentRuleItem.getRentalPrice().multiply(new BigDecimal(100)).setScale(0, java.math.RoundingMode.HALF_UP).longValue();
model.setSalePrice(rentalPriceInCents);
// 设置商品原价
model.setOriginalPrice(rentalPriceInCents);
// 设置库存
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(RentRuleItem param, List<String> imageList, String itemType) throws AlipayApiException {
List<AttributeVO> attributes = getTemplateItemAttrs("C001684401", 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;
}
}

View File

@ -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;
}
}

View 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;
}
}

View 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;
}
}

View File

@ -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<RentRuleItem> 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<RentRuleItem> list);
}

View 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();
}

View 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;
}
}
}

View 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;
// 商户IDalipay.pid
@Value("${alipay.pid}")
private String pid;
// 是否使用OpenIdalipay.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;
}
}

View File

@ -76,3 +76,16 @@ ali:
alipayRootCertPath: /root/cert/alipayRootCert.crt
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: false
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

View File

@ -0,0 +1,123 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.sczx.pay.mapper.RentRuleItemMapper">
<!-- 结果映射 -->
<resultMap id="BaseResultMap" type="com.sczx.pay.alipay.po.RentRuleItem">
<id property="id" column="id"/>
<result property="outItemId" column="out_item_id"/>
<result property="aliItemId" column="ali_item_id"/>
<result property="brandName" column="brand_name"/>
<result property="modelName" column="model_name"/>
<result property="categoryName" column="category_name"/>
<result property="dictLabel" column="dict_label"/>
<result property="ruleName" column="rule_name"/>
<result property="image" column="image"/>
<result property="batteryRuleId" column="battery_rule_id"/>
<result property="carRuleId" column="car_rule_id"/>
<result property="carModelId" column="car_model_id"/>
<result property="brandId" column="brand_id"/>
</resultMap>
<!-- 字段列表 -->
<sql id="Base_Column_List">
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
</sql>
<!-- 查询所有 -->
<select id="selectAll" resultMap="BaseResultMap">
SELECT <include refid="Base_Column_List"/>
FROM zc_rent_rule_item
</select>
<!-- 根据ID查询 -->
<select id="selectById" parameterType="Long" resultMap="BaseResultMap">
SELECT <include refid="Base_Column_List"/>
FROM zc_rent_rule_item
WHERE id = #{id}
</select>
<!-- 插入 -->
<insert id="insert" parameterType="com.sczx.pay.alipay.po.RentRuleItem">
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>
<!-- 批量插入 -->
<insert id="insertBatch">
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
<foreach collection="list" item="item" separator=",">
(
#{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}
)
</foreach>
</insert>
<!-- 更新 -->
<update id="update" parameterType="com.sczx.pay.alipay.po.RentRuleItem">
UPDATE zc_rent_rule_item
<set>
<if test="outItemId != null and outItemId != ''">out_item_id = #{outItemId},</if>
<if test="aliItemId != null and aliItemId != ''">ali_item_id = #{aliItemId},</if>
<if test="brandName != null and brandName != ''">brand_name = #{brandName},</if>
<if test="modelName != null and modelName != ''">model_name = #{modelName},</if>
<if test="categoryName != null and categoryName != ''">category_name = #{categoryName},</if>
<if test="dictLabel != null and dictLabel != ''">dict_label = #{dictLabel},</if>
<if test="ruleName != null and ruleName != ''">rule_name = #{ruleName},</if>
<if test="image != null">image = #{image},</if>
<if test="batteryRuleId != null">battery_rule_id = #{batteryRuleId},</if>
<if test="carRuleId != null">car_rule_id = #{carRuleId},</if>
<if test="carModelId != null">car_model_id = #{carModelId},</if>
<if test="brandId != null">brand_id = #{brandId},</if>
</set>
WHERE id = #{id}
</update>
<!-- 根据ID删除 -->
<delete id="deleteById" parameterType="Long">
DELETE FROM zc_rent_rule_item WHERE id = #{id}
</delete>
</mapper>