feat:额外收费
This commit is contained in:
1 parent
54a431891a
commit
33ff7edc2e
46 files changed
+955
-26
No files matched your search
+27
@@ -0,0 +1,27 @@
|
||||
package com.bsd.pjcloud.thirdparty.constant.pay;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* 第三方支付业务类型
|
||||
*/
|
||||
@AllArgsConstructor
|
||||
@Getter
|
||||
public enum ThirdPayOrderBizTypeEnum {
|
||||
|
||||
MINI_APP_WALLET_RECHARGE("10", "小程序用户钱包充值"),
|
||||
;
|
||||
|
||||
private final String type;
|
||||
private final String description;
|
||||
|
||||
public static ThirdPayOrderBizTypeEnum valueOfByType(String type) {
|
||||
if (ObjectUtil.isEmpty(type)) return null;
|
||||
return Arrays.stream(values()).filter(v -> ObjectUtil.equals(type, v.getType())).findFirst().get();
|
||||
}
|
||||
|
||||
}
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
package com.bsd.pjcloud.thirdparty.constant.pay;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* 第三方支付订单状态
|
||||
*/
|
||||
@AllArgsConstructor
|
||||
@Getter
|
||||
public enum ThirdPayOrderStatusEnum {
|
||||
PAY_UNPAID("10", "未支付"),
|
||||
PAY_SUCCESS("20", "支付成功"),
|
||||
PAY_FAILED("30", "已经支付"),
|
||||
|
||||
REFUNDING("100", "退款中"),
|
||||
REFUND_SUCCESS("200", "退款成功"),
|
||||
REFUND_FAILED("300", "退款失败"),
|
||||
;
|
||||
|
||||
private final String type;
|
||||
private final String description;
|
||||
|
||||
public static ThirdPayOrderStatusEnum valueOfByType(String type) {
|
||||
if (ObjectUtil.isEmpty(type)) return null;
|
||||
return Arrays.stream(values()).filter(v -> ObjectUtil.equals(type, v.getType())).findFirst().get();
|
||||
}
|
||||
|
||||
}
|
||||
+14
-1
@@ -1,6 +1,7 @@
|
||||
package com.bsd.pjcloud.thirdparty.dto.oathmini;
|
||||
|
||||
import com.bsd.pjcloud.thirdparty.constant.miniplatform.MiniPlatformTypeEnum;
|
||||
import com.bsd.pjcloud.thirdparty.constant.pay.ThirdPayOrderBizTypeEnum;
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
@@ -8,6 +9,19 @@ import lombok.Data;
|
||||
@Data
|
||||
public class ThirdMiniAppPayDto {
|
||||
|
||||
/**
|
||||
* 充值业务类型
|
||||
*/
|
||||
@NotNull(message = "充值业务类型不能为空")
|
||||
private ThirdPayOrderBizTypeEnum bizType;
|
||||
|
||||
/**
|
||||
* 充值业务id
|
||||
*/
|
||||
@NotEmpty(message = "充值业务id不能为空")
|
||||
private String bizId;
|
||||
|
||||
|
||||
/**
|
||||
* 小程序平台
|
||||
*/
|
||||
@@ -17,7 +31,6 @@ public class ThirdMiniAppPayDto {
|
||||
/**
|
||||
* 金额(分)
|
||||
*/
|
||||
@NotNull(message = "金额(分)不能为空")
|
||||
private Integer amount;
|
||||
|
||||
/**
|
||||
|
||||
+16
@@ -1,5 +1,6 @@
|
||||
package com.bsd.pjcloud.thirdparty.dto.oathmini.pay.wechat;
|
||||
|
||||
import com.bsd.pjcloud.thirdparty.constant.pay.ThirdPayOrderBizTypeEnum;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
@@ -8,11 +9,26 @@ import lombok.Data;
|
||||
@Data
|
||||
public class ThirdMiniJsapiPayDto {
|
||||
|
||||
/**
|
||||
* 充值业务类型
|
||||
*/
|
||||
private ThirdPayOrderBizTypeEnum bizType;
|
||||
|
||||
/**
|
||||
* 充值业务id
|
||||
*/
|
||||
private String bizId;
|
||||
|
||||
/**
|
||||
* 商户订单号
|
||||
*/
|
||||
private String outTradeNo;
|
||||
|
||||
/**
|
||||
* 用户id
|
||||
*/
|
||||
private Long userId;
|
||||
|
||||
/**
|
||||
* 用户标识
|
||||
*/
|
||||
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
package com.bsd.pjcloud.thirdparty.dto.pay;
|
||||
|
||||
import com.bsd.pjcloud.thirdparty.entity.pay.ThirdPayOrderEntity;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class ThirdPayOrderDto extends ThirdPayOrderEntity {
|
||||
|
||||
}
|
||||
Vendored
Executable
+155
@@ -0,0 +1,155 @@
|
||||
package com.bsd.pjcloud.thirdparty.entity.pay;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
import com.baomidou.mybatisplus.extension.activerecord.Model;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import com.bsd.pjcloud.common.core.util.TenantTable;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 第三方支付订单
|
||||
*/
|
||||
@Data
|
||||
@TenantTable
|
||||
@TableName("third_pay_order")
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Schema(description = "第三方支付订单")
|
||||
public class ThirdPayOrderEntity extends Model<ThirdPayOrderEntity> {
|
||||
|
||||
|
||||
/**
|
||||
* 主键
|
||||
*/
|
||||
@TableId(type = IdType.ASSIGN_ID)
|
||||
@Schema(description = "主键")
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 支付平台类型
|
||||
*/
|
||||
@Schema(description = "支付平台类型")
|
||||
private String payPlatformType;
|
||||
|
||||
/**
|
||||
* 支付类型
|
||||
*/
|
||||
@Schema(description = "支付类型")
|
||||
private String bizType;
|
||||
|
||||
/**
|
||||
* 支付相关id
|
||||
*/
|
||||
@Schema(description = "支付相关id")
|
||||
private String bizId;
|
||||
|
||||
/**
|
||||
* 用户id
|
||||
*/
|
||||
@Schema(description = "用户id")
|
||||
private Long userId;
|
||||
|
||||
/**
|
||||
* 用户code
|
||||
*/
|
||||
@Schema(description = "用户code")
|
||||
private String userCode;
|
||||
|
||||
/**
|
||||
* 支付金额(分)
|
||||
*/
|
||||
@Schema(description = "支付金额(分)")
|
||||
private Integer price;
|
||||
|
||||
/**
|
||||
* 支付状态
|
||||
*/
|
||||
@Schema(description = "支付状态")
|
||||
private String status;
|
||||
|
||||
/**
|
||||
* 支付订单号
|
||||
*/
|
||||
@Schema(description = "支付订单号")
|
||||
private String payNo;
|
||||
|
||||
/**
|
||||
* 支付时间
|
||||
*/
|
||||
@Schema(description = "支付时间")
|
||||
private LocalDateTime payTime;
|
||||
|
||||
/**
|
||||
* 支付返回
|
||||
*/
|
||||
@Schema(description = "支付返回")
|
||||
private String payRes;
|
||||
|
||||
/**
|
||||
* 退款订单号
|
||||
*/
|
||||
@Schema(description = "退款订单号")
|
||||
private String refundNo;
|
||||
|
||||
/**
|
||||
* 退款时间
|
||||
*/
|
||||
@Schema(description = "退款时间")
|
||||
private LocalDateTime refundTime;
|
||||
|
||||
/**
|
||||
* 退款返回
|
||||
*/
|
||||
@Schema(description = "退款返回")
|
||||
private String refundRes;
|
||||
|
||||
/**
|
||||
* 订单过期时间
|
||||
*/
|
||||
@Schema(description = "订单过期时间")
|
||||
private LocalDateTime expireTime;
|
||||
|
||||
/**
|
||||
* 创建人
|
||||
*/
|
||||
@TableField(fill = FieldFill.INSERT)
|
||||
@Schema(description = "创建人")
|
||||
private String createBy;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
@TableField(fill = FieldFill.INSERT)
|
||||
@Schema(description = "创建时间")
|
||||
private LocalDateTime createTime;
|
||||
|
||||
/**
|
||||
* 更新人
|
||||
*/
|
||||
@TableField(fill = FieldFill.INSERT_UPDATE)
|
||||
@Schema(description = "更新人")
|
||||
private String updateBy;
|
||||
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
@TableField(fill = FieldFill.INSERT_UPDATE)
|
||||
@Schema(description = "更新时间")
|
||||
private LocalDateTime updateTime;
|
||||
|
||||
/**
|
||||
* 删除时间
|
||||
*/
|
||||
@TableLogic
|
||||
@TableField(fill = FieldFill.INSERT)
|
||||
@Schema(description = "删除时间")
|
||||
private String delFlag;
|
||||
|
||||
/**
|
||||
* tenantId
|
||||
*/
|
||||
@Schema(description = "tenantId")
|
||||
private Long tenantId;
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
package com.bsd.pjcloud.thirdparty.vo.oathmini.pay;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
@Data
|
||||
public class ThirdMiniAppPayVo {
|
||||
|
||||
private HashMap<String, Object> miniAppPayParams;
|
||||
|
||||
}
|
||||
+4
@@ -3,6 +3,8 @@ package com.bsd.pjcloud.thirdparty.vo.oathmini.pay.wechat;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
/**
|
||||
* JSAPI/小程序下单
|
||||
*/
|
||||
@@ -37,6 +39,8 @@ public class ThirdMiniJsapiPayVo {
|
||||
|
||||
private String code_url;
|
||||
|
||||
private HashMap<String, Object> miniAppPayParams;
|
||||
|
||||
public boolean isHttpSucess() {
|
||||
return ObjectUtil.equals(ThirdMiniWechatQueryVo.SUCCESS, return_code);
|
||||
}
|
||||
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
package com.bsd.pjcloud.thirdparty.vo.pay;
|
||||
|
||||
import com.bsd.pjcloud.thirdparty.entity.pay.ThirdPayOrderEntity;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class ThirdPayOrderVo extends ThirdPayOrderEntity {
|
||||
|
||||
}
|
||||
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
+5
@@ -46,6 +46,11 @@ public class MiniAppConfig {
|
||||
*/
|
||||
private String apiV2Key;
|
||||
|
||||
/**
|
||||
* 支付成功的回调
|
||||
*/
|
||||
private String payCallbackUrl;
|
||||
|
||||
/**
|
||||
* 退款回调地址
|
||||
*/
|
||||
|
||||
+23
-6
@@ -7,15 +7,17 @@ import com.bsd.pjcloud.common.security.util.SecurityUtils;
|
||||
import com.bsd.pjcloud.thirdparty.dto.oathmini.ThirdMiniAppPayDto;
|
||||
import com.bsd.pjcloud.thirdparty.service.ThirdMiniAppService;
|
||||
import com.bsd.pjcloud.thirdparty.vo.oathmini.ThirdMinAppOAth2LoginVo;
|
||||
import com.bsd.pjcloud.thirdparty.vo.oathmini.pay.ThirdMiniAppPayVo;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.http.HttpEntity;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
@@ -28,10 +30,25 @@ public class ThirdMinAppPayCotroller {
|
||||
|
||||
@Operation(summary = "小程序支付")
|
||||
@PostMapping("/app/pay")
|
||||
@Inner(value = false)
|
||||
public R<String> miniPay(@RequestBody ThirdMiniAppPayDto dto) {
|
||||
public R<ThirdMiniAppPayVo> miniPay(@Validated @RequestBody ThirdMiniAppPayDto dto) {
|
||||
PjcloudUser user = SecurityUtils.getUser();
|
||||
return R.ok(thirdMiniAppService.miniPay(user.getId(), dto));
|
||||
}
|
||||
|
||||
@Operation(summary = "小程序支付回调")
|
||||
@PostMapping("/app/pay-callback")
|
||||
@Inner(value = false)
|
||||
public R<String> miniPayCallback(HttpEntity<String> httpEntity, @RequestHeader Map<String, String> headers) {
|
||||
String body = httpEntity.getBody();
|
||||
return R.ok(thirdMiniAppService.miniPayCallback(body, headers));
|
||||
}
|
||||
|
||||
@Operation(summary = "小程序退款回调")
|
||||
@PostMapping("/app/refund-callback")
|
||||
@Inner(value = false)
|
||||
public R<String> miniRefundCallback(HttpEntity<String> httpEntity, @RequestHeader Map<String, String> headers) {
|
||||
String body = httpEntity.getBody();
|
||||
return R.ok(thirdMiniAppService.miniRefundCallback(body, headers));
|
||||
}
|
||||
|
||||
}
|
||||
Vendored
Executable
+100
@@ -0,0 +1,100 @@
|
||||
package com.bsd.pjcloud.thirdparty.controller.pay;
|
||||
|
||||
import cn.hutool.core.util.ArrayUtil;
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.bsd.pjcloud.common.core.util.R;
|
||||
import com.bsd.pjcloud.common.log.annotation.SysLog;
|
||||
import com.bsd.pjcloud.thirdparty.dto.pay.ThirdPayOrderDto;
|
||||
import com.bsd.pjcloud.thirdparty.entity.pay.ThirdPayOrderEntity;
|
||||
import com.bsd.pjcloud.thirdparty.service.ThirdPayOrderService;
|
||||
import com.bsd.pjcloud.thirdparty.vo.pay.ThirdPayOrderVo;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import com.bsd.pjcloud.common.excel.annotation.ResponseExcel;
|
||||
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
|
||||
import org.springdoc.core.annotations.ParameterObject;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 第三方支付订单
|
||||
*/
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
@RequestMapping("/third-pay-order")
|
||||
@Tag(description = "third-pay-order", name = "第三方支付订单管理")
|
||||
@SecurityRequirement(name = HttpHeaders.AUTHORIZATION)
|
||||
public class ThirdPayOrderController {
|
||||
|
||||
private final ThirdPayOrderService thirdPayOrderService;
|
||||
|
||||
/**
|
||||
* 分页查询
|
||||
*/
|
||||
@Operation(summary = "分页查询", description = "分页查询")
|
||||
@GetMapping("/page")
|
||||
@PreAuthorize("@pms.hasPermission('third_thirdPayOrder_view')")
|
||||
public R<Page<ThirdPayOrderVo>> getThirdPayOrderPage(@ParameterObject Page page, @ParameterObject ThirdPayOrderDto dto) {
|
||||
return R.ok(thirdPayOrderService.scopePage(page, dto, null));
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过id查询第三方支付订单
|
||||
*/
|
||||
@Operation(summary = "通过id查询", description = "通过id查询")
|
||||
@GetMapping("/{id}")
|
||||
@PreAuthorize("@pms.hasPermission('third_thirdPayOrder_view')")
|
||||
public R getById(@PathVariable("id") Long id) {
|
||||
return R.ok(thirdPayOrderService.getById(id));
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增第三方支付订单
|
||||
*/
|
||||
@Operation(summary = "新增第三方支付订单", description = "新增第三方支付订单")
|
||||
@SysLog("新增第三方支付订单")
|
||||
@PostMapping
|
||||
@PreAuthorize("@pms.hasPermission('third_thirdPayOrder_add')")
|
||||
public R save(@RequestBody ThirdPayOrderEntity thirdPayOrder) {
|
||||
return R.ok(thirdPayOrderService.save(thirdPayOrder));
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改第三方支付订单
|
||||
*/
|
||||
@Operation(summary = "修改第三方支付订单", description = "修改第三方支付订单")
|
||||
@SysLog("修改第三方支付订单")
|
||||
@PutMapping
|
||||
@PreAuthorize("@pms.hasPermission('third_thirdPayOrder_edit')")
|
||||
public R updateById(@RequestBody ThirdPayOrderEntity thirdPayOrder) {
|
||||
return R.ok(thirdPayOrderService.updateById(thirdPayOrder));
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过id删除第三方支付订单
|
||||
*/
|
||||
@Operation(summary = "通过id删除第三方支付订单", description = "通过id删除第三方支付订单")
|
||||
@SysLog("通过id删除第三方支付订单")
|
||||
@DeleteMapping
|
||||
@PreAuthorize("@pms.hasPermission('third_thirdPayOrder_del')")
|
||||
public R removeById(@RequestBody Long[] ids) {
|
||||
return R.ok(thirdPayOrderService.removeBatchByIds(CollUtil.toList(ids)));
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出excel 表格
|
||||
*/
|
||||
@ResponseExcel
|
||||
@GetMapping("/export")
|
||||
@PreAuthorize("@pms.hasPermission('third_thirdPayOrder_export')")
|
||||
public List<ThirdPayOrderEntity> export(ThirdPayOrderEntity thirdPayOrder, Long[] ids) {
|
||||
return thirdPayOrderService.list(Wrappers.lambdaQuery(thirdPayOrder).in(ArrayUtil.isNotEmpty(ids), ThirdPayOrderEntity::getId, ids));
|
||||
}
|
||||
|
||||
}
|
||||
Vendored
Executable
+17
@@ -0,0 +1,17 @@
|
||||
package com.bsd.pjcloud.thirdparty.mapper.pay;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.bsd.pjcloud.common.data.datascope.DataScope;
|
||||
import com.bsd.pjcloud.common.data.datascope.PjcloudBaseMapper;
|
||||
import com.bsd.pjcloud.thirdparty.dto.pay.ThirdPayOrderDto;
|
||||
import com.bsd.pjcloud.thirdparty.entity.pay.ThirdPayOrderEntity;
|
||||
import com.bsd.pjcloud.thirdparty.vo.pay.ThirdPayOrderVo;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
@Mapper
|
||||
public interface ThirdPayOrderMapper extends PjcloudBaseMapper<ThirdPayOrderEntity> {
|
||||
|
||||
Page<ThirdPayOrderVo> scopePage(Page page, @Param("dto") ThirdPayOrderDto dto, DataScope dataScope);
|
||||
|
||||
}
|
||||
+14
-1
@@ -4,6 +4,9 @@ import com.bsd.pjcloud.thirdparty.dto.oathmini.ThirdMiniAppGetUniqueDto;
|
||||
import com.bsd.pjcloud.thirdparty.dto.oathmini.ThirdMiniAppOAth2LoginDto;
|
||||
import com.bsd.pjcloud.thirdparty.dto.oathmini.ThirdMiniAppPayDto;
|
||||
import com.bsd.pjcloud.thirdparty.vo.oathmini.ThirdMinAppOAth2LoginVo;
|
||||
import com.bsd.pjcloud.thirdparty.vo.oathmini.pay.ThirdMiniAppPayVo;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public interface ThirdMiniAppService {
|
||||
|
||||
@@ -20,5 +23,15 @@ public interface ThirdMiniAppService {
|
||||
/**
|
||||
* 小程序支付
|
||||
*/
|
||||
String miniPay(Long userId, ThirdMiniAppPayDto dto);
|
||||
ThirdMiniAppPayVo miniPay(Long userId, ThirdMiniAppPayDto dto);
|
||||
|
||||
/**
|
||||
* 小程序支付回调
|
||||
*/
|
||||
String miniPayCallback(String body, Map<String, String> headers);
|
||||
|
||||
/**
|
||||
* 小程序退款回调
|
||||
*/
|
||||
String miniRefundCallback(String body, Map<String, String> headers);
|
||||
}
|
||||
Vendored
Executable
+14
@@ -0,0 +1,14 @@
|
||||
package com.bsd.pjcloud.thirdparty.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.bsd.pjcloud.common.data.datascope.DataScope;
|
||||
import com.bsd.pjcloud.thirdparty.dto.pay.ThirdPayOrderDto;
|
||||
import com.bsd.pjcloud.thirdparty.entity.pay.ThirdPayOrderEntity;
|
||||
import com.bsd.pjcloud.thirdparty.vo.pay.ThirdPayOrderVo;
|
||||
|
||||
public interface ThirdPayOrderService extends IService<ThirdPayOrderEntity> {
|
||||
|
||||
Page<ThirdPayOrderVo> scopePage(Page page, ThirdPayOrderDto dto, DataScope dataScope);
|
||||
|
||||
}
|
||||
+65
-5
@@ -2,6 +2,7 @@ package com.bsd.pjcloud.thirdparty.service.impl.miniapp;
|
||||
|
||||
import cn.binarywang.wx.miniapp.bean.WxMaPhoneNumberInfo;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.RandomUtil;
|
||||
import com.bsd.pjcloud.admin.api.dto.UserInfo;
|
||||
import com.bsd.pjcloud.admin.api.dto.UserTokenDTO;
|
||||
import com.bsd.pjcloud.admin.api.feign.RemoteTokenService;
|
||||
@@ -12,6 +13,7 @@ import com.bsd.pjcloud.app.api.dto.AppUserInfo;
|
||||
import com.bsd.pjcloud.app.api.feign.RemoteAppUserService;
|
||||
import com.bsd.pjcloud.thirdparty.constant.miniplatform.MiniPlatformLoginErrorEnum;
|
||||
import com.bsd.pjcloud.thirdparty.constant.miniplatform.MiniPlatformTypeEnum;
|
||||
import com.bsd.pjcloud.thirdparty.constant.pay.ThirdPayOrderBizTypeEnum;
|
||||
import com.bsd.pjcloud.thirdparty.dto.oathmini.ThirdMiniAppGetUniqueDto;
|
||||
import com.bsd.pjcloud.thirdparty.dto.oathmini.ThirdMiniAppOAth2LoginDto;
|
||||
import com.bsd.pjcloud.thirdparty.dto.oathmini.ThirdMiniAppPayDto;
|
||||
@@ -22,13 +24,19 @@ import com.bsd.pjcloud.thirdparty.service.ThirdMiniAppService;
|
||||
import com.bsd.pjcloud.thirdparty.service.ThirdMiniAppWechatService;
|
||||
import com.bsd.pjcloud.thirdparty.service.ThirdPayLogService;
|
||||
import com.bsd.pjcloud.thirdparty.vo.oathmini.ThirdMinAppOAth2LoginVo;
|
||||
import com.bsd.pjcloud.thirdparty.vo.oathmini.pay.ThirdMiniAppPayVo;
|
||||
import com.bsd.pjcloud.thirdparty.vo.oathmini.pay.wechat.ThirdMiniJsapiPayVo;
|
||||
import com.bsd.pjcloud.wallet.api.entity.recharge.WalletRechargePackageEntity;
|
||||
import com.bsd.pjcloud.wallet.api.feign.RemoteWalletRechargePackageService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import javax.net.ssl.*;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.util.Date;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
@@ -47,6 +55,7 @@ public class ThirdMiniAppServiceImpl implements ThirdMiniAppService {
|
||||
private final RemoteUserService remoteUserService;
|
||||
private final RemoteTokenService remoteTokenService;
|
||||
private final RemoteAppUserService remoteAppUserService;
|
||||
private final RemoteWalletRechargePackageService remoteWalletRechargePackageService;
|
||||
|
||||
/**
|
||||
* 小程序登录
|
||||
@@ -122,26 +131,77 @@ public class ThirdMiniAppServiceImpl implements ThirdMiniAppService {
|
||||
* 小程序支付
|
||||
*/
|
||||
@Override
|
||||
public String miniPay(Long userId, ThirdMiniAppPayDto dto) {
|
||||
ThirdPayLogEntity log = new ThirdPayLogEntity();
|
||||
public ThirdMiniAppPayVo miniPay(Long userId, ThirdMiniAppPayDto dto) {
|
||||
ThirdMiniAppPayVo result = new ThirdMiniAppPayVo();
|
||||
|
||||
if (ObjectUtil.equals(dto.getBizType(), ThirdPayOrderBizTypeEnum.MINI_APP_WALLET_RECHARGE)) {
|
||||
Long bizId = null;
|
||||
try {
|
||||
bizId = Long.valueOf(dto.getBizId());
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("充值业务id解析错误");
|
||||
}
|
||||
// 查询充值配置
|
||||
WalletRechargePackageEntity walletPackage = remoteWalletRechargePackageService.remoteGetById(bizId).getData();
|
||||
if (ObjectUtil.isEmpty(walletPackage)) {
|
||||
throw new RuntimeException("错误的充值配置");
|
||||
}
|
||||
int price = walletPackage.getPayPrice() + walletPackage.getBonusPrice();
|
||||
if (price <= 0) {
|
||||
throw new RuntimeException("错误的充值配置");
|
||||
}
|
||||
dto.setAmount(price);
|
||||
}
|
||||
// 不支持的类型
|
||||
else {
|
||||
throw new RuntimeException("不支持的支付类型");
|
||||
}
|
||||
try {
|
||||
// 微信小程序
|
||||
if (ObjectUtil.equals(dto.getMiniPlatformType().getType(), MiniPlatformTypeEnum.WECHAT.getType())) {
|
||||
ThirdMiniJsapiPayDto wechatPayDto = new ThirdMiniJsapiPayDto();
|
||||
wechatPayDto.setOutTradeNo("");
|
||||
// 当前时间戳+10位随机字符串
|
||||
String outTradeNo = LocalDateTime.now().atZone(ZoneId.systemDefault()).toInstant().toEpochMilli() + RandomUtil.randomString(10);
|
||||
wechatPayDto.setOutTradeNo(outTradeNo);
|
||||
wechatPayDto.setBizId(dto.getBizId());
|
||||
wechatPayDto.setBizType(dto.getBizType());
|
||||
wechatPayDto.setUserId(userId);
|
||||
wechatPayDto.setOpenid(dto.getOpenId());
|
||||
wechatPayDto.setAmount(dto.getAmount());
|
||||
ThirdMiniJsapiPayVo thirdMiniJsapiPayVo = thirdMiniAppWechatService.jsapiPay(wechatPayDto);
|
||||
if (ObjectUtil.isEmpty(thirdMiniJsapiPayVo)) {
|
||||
throw new RuntimeException("创建微信支付错误");
|
||||
}
|
||||
result.setMiniAppPayParams(thirdMiniJsapiPayVo.getMiniAppPayParams());
|
||||
}
|
||||
// 支付宝
|
||||
else if (ObjectUtil.equals(dto.getMiniPlatformType().getType(), MiniPlatformTypeEnum.ALI_PAY.getType())) {
|
||||
|
||||
}
|
||||
// 不支持的支付类型
|
||||
else {
|
||||
throw new RuntimeException("不支持的支付类型");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
|
||||
} finally {
|
||||
thirdPayLogService.save(log);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 小程序支付回调
|
||||
*/
|
||||
@Override
|
||||
public String miniPayCallback(String body, Map<String, String> headers) {
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* 小程序退款回调
|
||||
*/
|
||||
@Override
|
||||
public String miniRefundCallback(String body, Map<String, String> headers) {
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
+40
@@ -9,8 +9,12 @@ import cn.hutool.core.util.RandomUtil;
|
||||
import cn.hutool.core.util.XmlUtil;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.bsd.pjcloud.thirdparty.config.MiniAppConfig;
|
||||
import com.bsd.pjcloud.thirdparty.constant.miniplatform.MiniPlatformTypeEnum;
|
||||
import com.bsd.pjcloud.thirdparty.constant.pay.ThirdPayOrderStatusEnum;
|
||||
import com.bsd.pjcloud.thirdparty.dto.oathmini.pay.wechat.*;
|
||||
import com.bsd.pjcloud.thirdparty.entity.pay.ThirdPayOrderEntity;
|
||||
import com.bsd.pjcloud.thirdparty.service.ThirdMiniAppWechatService;
|
||||
import com.bsd.pjcloud.thirdparty.service.ThirdPayOrderService;
|
||||
import com.bsd.pjcloud.thirdparty.utils.miniapp.pay.wechat.ThirdMiniWechantPayConstant;
|
||||
import com.bsd.pjcloud.thirdparty.vo.oathmini.pay.wechat.*;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
@@ -27,6 +31,7 @@ import java.io.FileInputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.KeyStore;
|
||||
import java.security.SecureRandom;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
@@ -45,6 +50,7 @@ public class ThirdMiniAppWechatServiceImpl implements ThirdMiniAppWechatService
|
||||
private final MiniAppConfig miniAppConfig;
|
||||
|
||||
private final WxMaService wxMaService;
|
||||
private final ThirdPayOrderService thirdPayOrderService;
|
||||
|
||||
|
||||
/**
|
||||
@@ -53,6 +59,15 @@ public class ThirdMiniAppWechatServiceImpl implements ThirdMiniAppWechatService
|
||||
@Override
|
||||
public ThirdMiniJsapiPayVo jsapiPay(ThirdMiniJsapiPayDto dto) {
|
||||
MiniAppConfig.WechatConfig wechatConfig = miniAppConfig.getWechatConfig();
|
||||
|
||||
ThirdPayOrderEntity payOrder = new ThirdPayOrderEntity();
|
||||
payOrder.setPayPlatformType(MiniPlatformTypeEnum.WECHAT.getType());
|
||||
payOrder.setBizId(dto.getBizId());
|
||||
payOrder.setBizType(dto.getBizType().getType());
|
||||
payOrder.setUserId(dto.getUserId());
|
||||
payOrder.setUserCode(dto.getOpenid());
|
||||
payOrder.setPrice(dto.getAmount());
|
||||
payOrder.setStatus(ThirdPayOrderStatusEnum.PAY_UNPAID.getType());
|
||||
try {
|
||||
Map<String, Object> params = new HashMap<>();
|
||||
// 公众账号ID
|
||||
@@ -93,10 +108,35 @@ public class ThirdMiniAppWechatServiceImpl implements ThirdMiniAppWechatService
|
||||
if (!vo.isHttpSucess()) {
|
||||
return null;
|
||||
}
|
||||
payOrder.setPayTime(LocalDateTime.now());
|
||||
payOrder.setPayRes(res);
|
||||
// 生成小程序 paySign
|
||||
String nonceStr = RandomUtil.randomString(32);
|
||||
long timeStamp = System.currentTimeMillis() / 1000;
|
||||
String payPackage = "prepay_id=" + vo.getPrepay_id();
|
||||
String signType = "MD5";
|
||||
|
||||
String payStr = "appId=" + wechatConfig.getAppId() + "&";
|
||||
payStr += "nonceStr=" + nonceStr + "&";
|
||||
payStr += "package=" + payPackage + "&";
|
||||
payStr += "signType=" + signType + "&";
|
||||
payStr += "timeStamp=" + timeStamp + "&";
|
||||
payStr += "key=" + wechatConfig.getApiV2Key();
|
||||
String paySign = DigestUtils.md5Hex(payStr);
|
||||
|
||||
HashMap<String, Object> miniAppPayParams = new HashMap<>();
|
||||
miniAppPayParams.put("timeStamp", timeStamp);
|
||||
miniAppPayParams.put("nonceStr", nonceStr);
|
||||
miniAppPayParams.put("package", payPackage);
|
||||
miniAppPayParams.put("signType", signType);
|
||||
miniAppPayParams.put("paySign", paySign);
|
||||
vo.setMiniAppPayParams(miniAppPayParams);
|
||||
return vo;
|
||||
} catch (Exception e) {
|
||||
log.error("|{}|JSAPI/小程序下单,异常", TAG, e);
|
||||
return null;
|
||||
} finally {
|
||||
thirdPayOrderService.save(payOrder);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Vendored
Executable
+24
@@ -0,0 +1,24 @@
|
||||
package com.bsd.pjcloud.thirdparty.service.impl.pay;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.bsd.pjcloud.common.data.datascope.DataScope;
|
||||
import com.bsd.pjcloud.thirdparty.dto.pay.ThirdPayOrderDto;
|
||||
import com.bsd.pjcloud.thirdparty.entity.pay.ThirdPayOrderEntity;
|
||||
import com.bsd.pjcloud.thirdparty.mapper.pay.ThirdPayOrderMapper;
|
||||
import com.bsd.pjcloud.thirdparty.service.ThirdPayOrderService;
|
||||
import com.bsd.pjcloud.thirdparty.vo.pay.ThirdPayOrderVo;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* 第三方支付订单
|
||||
*/
|
||||
@Service
|
||||
public class ThirdPayOrderServiceImpl extends ServiceImpl<ThirdPayOrderMapper, ThirdPayOrderEntity> implements ThirdPayOrderService {
|
||||
|
||||
@Override
|
||||
public Page<ThirdPayOrderVo> scopePage(Page page, ThirdPayOrderDto dto, DataScope dataScope) {
|
||||
return baseMapper.scopePage(page, dto, dataScope);
|
||||
}
|
||||
|
||||
}
|
||||
+3
-2
@@ -181,8 +181,9 @@ mini-platform:
|
||||
app-secret: a6b0d036b229117595687a7c1705d332
|
||||
merchant-id: 1106210589
|
||||
api-v2-key: qr0w9WkAu6GG3uuxPjDT7bcdIVoBr0rw
|
||||
merchant-serial-path: /Users/dengzhangchen/Desktop/backups/pay/cert/apiclient_cert.p12
|
||||
refund-callback-url: https://rj4jv5rwqs.by.takin.cc/hard/hard-wechant-pay/callback/refund
|
||||
merchant-serial-path: /Users/dengzhangchen/Desktop/backups/pay/third_cert/apiclient_cert.p12
|
||||
pay-callback-url: https://rj4jv5rwqs.by.takin.cc/third/third-mini-app-pay/app/pay-callback
|
||||
refund-callback-url: https://rj4jv5rwqs.by.takin.cc/hard/hard-wechant-pay/app/refund-callback
|
||||
spbill-create-ip: 59.202.170.152
|
||||
base-url: https://api.mch.weixin.qq.com
|
||||
ali-pay-config:
|
||||
|
||||
Vendored
Executable
+46
@@ -0,0 +1,46 @@
|
||||
<?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.bsd.pjcloud.thirdparty.mapper.pay.ThirdPayOrderMapper">
|
||||
|
||||
<sql id="selectA">
|
||||
select a.id,
|
||||
a.pay_platform_type,
|
||||
a.biz_type,
|
||||
a.biz_id,
|
||||
a.user_id,
|
||||
a.user_code,
|
||||
a.price,
|
||||
a.status,
|
||||
a.pay_no,
|
||||
a.pay_time,
|
||||
a.pay_res,
|
||||
a.refund_no,
|
||||
a.refund_time,
|
||||
a.refund_res,
|
||||
a.expire_time,
|
||||
a.create_time,
|
||||
a.update_time,
|
||||
a.create_by,
|
||||
a.update_by,
|
||||
a.del_flag,
|
||||
a.tenant_id
|
||||
</sql>
|
||||
|
||||
<sql id="whereA">
|
||||
a.del_flag = '0'
|
||||
<if test="dto.id != null">
|
||||
|
||||
</if>
|
||||
</sql>
|
||||
|
||||
<select id="scopePage" resultType="com.bsd.pjcloud.thirdparty.vo.pay.ThirdPayOrderVo">
|
||||
<include refid="selectA"/>
|
||||
from third_pay_order a
|
||||
<where>
|
||||
<include refid="whereA"/>
|
||||
</where>
|
||||
order by a.create_time desc, a.id desc
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
Reference in new issue
Block a user