feat:付款码支付
This commit is contained in:
1 parent
92c5c630bb
commit
4f50cc2952
53 files changed
+630
-2298
No files matched your search
+5
-1
@@ -14,7 +14,9 @@ import java.util.Arrays;
|
||||
@Getter
|
||||
public enum HardXfjTypeEnum {
|
||||
|
||||
QRCODE_PAY("10", "二维码支付"),
|
||||
QRCODE_PAY("10", "钱包二维码支付"),
|
||||
WECHAT_QRCODE_PAY("11", "微信二维码支付"),
|
||||
ALI_QRCODE_PAY("12", "支付宝二维码支付"),
|
||||
CARD_PAY("20", "饭卡支付"),
|
||||
;
|
||||
private final String type;
|
||||
@@ -28,6 +30,8 @@ public enum HardXfjTypeEnum {
|
||||
public static HardPayTypeEnum getHardPayType(HardXfjTypeEnum type) {
|
||||
return switch (type) {
|
||||
case QRCODE_PAY -> HardPayTypeEnum.WALLET_QR_CODE;
|
||||
case WECHAT_QRCODE_PAY -> HardPayTypeEnum.WECHANT_SELF_QR_CODE_PAY;
|
||||
case ALI_QRCODE_PAY -> HardPayTypeEnum.ALI_SELF_QR_CODE_PAY;
|
||||
case CARD_PAY -> HardPayTypeEnum.WALLET_CARD;
|
||||
};
|
||||
}
|
||||
|
||||
+11
@@ -1,6 +1,7 @@
|
||||
package com.bsd.pjcloud.hard.api.dto.order.xfj;
|
||||
|
||||
import com.bsd.pjcloud.hard.api.constant.xfj.HardXfjTypeEnum;
|
||||
import com.bsd.pjcloud.thirdparty.constant.miniplatform.AppPlusPlatformTypeEnum;
|
||||
import com.bsd.pjcloud.wallet.api.constant.WalletTypeEnum;
|
||||
import lombok.Data;
|
||||
|
||||
@@ -37,4 +38,14 @@ public class HardXfjFastCreateOrderDto {
|
||||
*/
|
||||
private HardXfjTypeEnum xfjPayType;
|
||||
|
||||
/**
|
||||
* 终端支付类型
|
||||
*/
|
||||
private AppPlusPlatformTypeEnum platformType;
|
||||
|
||||
/**
|
||||
* 付款码支付code
|
||||
*/
|
||||
private String devicePayCode;
|
||||
|
||||
}
|
||||
-21
@@ -1,21 +0,0 @@
|
||||
package com.bsd.pjcloud.hard.api.dto.wechat;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* 撤销订单入参
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class WechantReverseDto {
|
||||
|
||||
private Long orderId;
|
||||
|
||||
private String wechantOrderId;
|
||||
|
||||
}
|
||||
-34
@@ -1,34 +0,0 @@
|
||||
package com.bsd.pjcloud.hard.api.dto.wechat;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class WechatMicropayDto {
|
||||
|
||||
/**
|
||||
* 商户id
|
||||
*/
|
||||
private Long merId;
|
||||
|
||||
/**
|
||||
* 订单id
|
||||
*/
|
||||
private Long orderId;
|
||||
|
||||
/**
|
||||
* 支付金额(分)
|
||||
*/
|
||||
private Integer price;
|
||||
|
||||
/**
|
||||
* 微信付款码code
|
||||
*/
|
||||
private String wechatQrCode;
|
||||
|
||||
}
|
||||
-21
@@ -1,21 +0,0 @@
|
||||
package com.bsd.pjcloud.hard.api.dto.wechat;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 查询订单入参
|
||||
*/
|
||||
@Data
|
||||
public class WechatQueryDto {
|
||||
|
||||
/**
|
||||
* 微信订单号
|
||||
*/
|
||||
private String wechantOrderId;
|
||||
|
||||
/**
|
||||
* 商户订单号
|
||||
*/
|
||||
private String orderId;
|
||||
|
||||
}
|
||||
-27
@@ -1,27 +0,0 @@
|
||||
package com.bsd.pjcloud.hard.api.dto.wechat;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* 退款入参
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class WechatRefundDto {
|
||||
|
||||
private Long orderId;
|
||||
|
||||
private String wechantOrderId;
|
||||
|
||||
private Long refundId;
|
||||
|
||||
private Integer orderPrice;
|
||||
|
||||
private Integer refundPrice;
|
||||
|
||||
}
|
||||
-17
@@ -1,17 +0,0 @@
|
||||
package com.bsd.pjcloud.hard.api.dto.wechat;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 微信退款查询入参
|
||||
*/
|
||||
@Data
|
||||
public class WechatRefundQueryDto {
|
||||
|
||||
/**
|
||||
* 退款id
|
||||
*/
|
||||
private String refundId;
|
||||
|
||||
|
||||
}
|
||||
-30
@@ -1,30 +0,0 @@
|
||||
package com.bsd.pjcloud.hard.api.vo.wechat;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 微信退款回调加密的返回参数
|
||||
*/
|
||||
@Data
|
||||
public class WechantRefunCallbackSoureVo {
|
||||
|
||||
/**
|
||||
* 公众账号ID
|
||||
*/
|
||||
private String appid;
|
||||
|
||||
/**
|
||||
* 退款的商户号
|
||||
*/
|
||||
private String mch_id;
|
||||
|
||||
/**
|
||||
* 随机字符串
|
||||
*/
|
||||
private String nonce_str;
|
||||
|
||||
/**
|
||||
* 加密信息
|
||||
*/
|
||||
private String req_info;
|
||||
}
|
||||
-77
@@ -1,77 +0,0 @@
|
||||
package com.bsd.pjcloud.hard.api.vo.wechat;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 微信退款回调返回参数
|
||||
*/
|
||||
@Data
|
||||
public class WechantRefunCallbackVo {
|
||||
|
||||
public static final String SUCCESS_CODE = "SUCCESS";
|
||||
|
||||
/**
|
||||
* 微信订单号
|
||||
*/
|
||||
private String transaction_id;
|
||||
|
||||
/**
|
||||
* 商户订单号
|
||||
*/
|
||||
private String out_trade_no;
|
||||
|
||||
/**
|
||||
* 微信退款单号
|
||||
*/
|
||||
private String refund_id;
|
||||
|
||||
/**
|
||||
* 商户退款单号
|
||||
*/
|
||||
private String out_refund_no;
|
||||
|
||||
/**
|
||||
* 订单金额
|
||||
*/
|
||||
private String total_fee;
|
||||
|
||||
/**
|
||||
* 应结订单金额
|
||||
*/
|
||||
private String settlement_total_fee;
|
||||
|
||||
/**
|
||||
* 申请退款金额
|
||||
*/
|
||||
private String refund_fee;
|
||||
|
||||
/**
|
||||
* 退款金额
|
||||
*/
|
||||
private String settlement_refund_fee;
|
||||
|
||||
/**
|
||||
* 退款状态
|
||||
*/
|
||||
private String refund_status;
|
||||
|
||||
public boolean isAllSuccess() {
|
||||
return ObjectUtil.equals(refund_status, SUCCESS_CODE);
|
||||
}
|
||||
|
||||
public static String wechantError() {
|
||||
return "<xml>" +
|
||||
"<return_code><![CDATA[FAIL]]></return_code>" +
|
||||
"<return_msg><![CDATA[FAIL]]></return_msg>" +
|
||||
"</xml>";
|
||||
}
|
||||
|
||||
public static String wechantSuccess() {
|
||||
return "<xml>" +
|
||||
" <return_code><![CDATA[SUCCESS]]></return_code>" +
|
||||
" <return_msg><![CDATA[OK]]></return_msg>\n" +
|
||||
"</xml>";
|
||||
}
|
||||
|
||||
}
|
||||
-44
@@ -1,44 +0,0 @@
|
||||
package com.bsd.pjcloud.hard.api.vo.wechat;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 撤销订单返回
|
||||
*/
|
||||
@Data
|
||||
public class WechantReverseVo {
|
||||
public static final String SUCCESS = "SUCCESS";
|
||||
|
||||
private String return_code;
|
||||
|
||||
private String return_msg;
|
||||
|
||||
private String appid;
|
||||
|
||||
private String mch_id;
|
||||
|
||||
private String nonce_str;
|
||||
|
||||
private String sign;
|
||||
|
||||
private String result_code;
|
||||
|
||||
private String err_code;
|
||||
|
||||
private String err_code_des;
|
||||
|
||||
private String recall;
|
||||
|
||||
public boolean isHttpSucess() {
|
||||
return ObjectUtil.equals(WechatMicropayVo.SUCCESS, return_code);
|
||||
}
|
||||
|
||||
public boolean isPaySucess() {
|
||||
return ObjectUtil.equals(WechatMicropayVo.SUCCESS, result_code);
|
||||
}
|
||||
|
||||
public boolean isAllSuccess() {
|
||||
return isHttpSucess() && isPaySucess();
|
||||
}
|
||||
}
|
||||
-43
@@ -1,43 +0,0 @@
|
||||
package com.bsd.pjcloud.hard.api.vo.wechat;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class WechatMicropayVo {
|
||||
|
||||
public static final String SUCCESS = "SUCCESS";
|
||||
|
||||
private String return_code;
|
||||
|
||||
private String return_msg;
|
||||
|
||||
private String appid;
|
||||
|
||||
private String mch_id;
|
||||
|
||||
private String device_info;
|
||||
|
||||
private String nonce_str;
|
||||
|
||||
private String sign;
|
||||
|
||||
private String result_code;
|
||||
|
||||
private String err_code;
|
||||
|
||||
private String err_code_des;
|
||||
|
||||
public boolean isHttpSucess() {
|
||||
return ObjectUtil.equals(WechatMicropayVo.SUCCESS, return_code);
|
||||
}
|
||||
|
||||
public boolean isPaySucess() {
|
||||
return ObjectUtil.equals(WechatMicropayVo.SUCCESS, result_code);
|
||||
}
|
||||
|
||||
public boolean isAllSuccess(){
|
||||
return isHttpSucess() && isPaySucess();
|
||||
}
|
||||
|
||||
}
|
||||
-125
@@ -1,125 +0,0 @@
|
||||
package com.bsd.pjcloud.hard.api.vo.wechat;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 查询订单返回
|
||||
*/
|
||||
@Data
|
||||
public class WechatQueryVo {
|
||||
public static final String SUCCESS = "SUCCESS";
|
||||
|
||||
private String return_code;
|
||||
|
||||
private String return_msg;
|
||||
|
||||
private String appid;
|
||||
|
||||
private String mch_id;
|
||||
|
||||
private String nonce_str;
|
||||
|
||||
private String sign;
|
||||
|
||||
private String result_code;
|
||||
|
||||
private String err_code;
|
||||
|
||||
private String err_code_des;
|
||||
|
||||
private String device_info;
|
||||
|
||||
/**
|
||||
* 用户标识
|
||||
*/
|
||||
private String openid;
|
||||
|
||||
/**
|
||||
* 是否关注公众账号
|
||||
*/
|
||||
private String is_subscribe;
|
||||
|
||||
/**
|
||||
* 交易类型
|
||||
*/
|
||||
private String trade_type;
|
||||
|
||||
/**
|
||||
* 交易状态
|
||||
*/
|
||||
private String trade_state;
|
||||
|
||||
/**
|
||||
* 付款银行
|
||||
*/
|
||||
private String bank_type;
|
||||
|
||||
/**
|
||||
* 标价金额
|
||||
*/
|
||||
private String total_fee;
|
||||
|
||||
/**
|
||||
* 应结订单金额
|
||||
*/
|
||||
private String settlement_total_fee;
|
||||
|
||||
/**
|
||||
* 标价币种
|
||||
*/
|
||||
private String fee_type;
|
||||
|
||||
/**
|
||||
* 现金支付金额
|
||||
*/
|
||||
private String cash_fee;
|
||||
|
||||
/**
|
||||
* 现金支付币种
|
||||
*/
|
||||
private String cash_fee_type;
|
||||
|
||||
/**
|
||||
* 代金券金额
|
||||
*/
|
||||
private String coupon_fee;
|
||||
|
||||
/**
|
||||
* 代金券使用数量
|
||||
*/
|
||||
private String coupon_count;
|
||||
|
||||
/**
|
||||
* 微信支付订单号
|
||||
*/
|
||||
private String transaction_id;
|
||||
|
||||
/**
|
||||
* 商户订单号
|
||||
*/
|
||||
private String out_trade_no;
|
||||
|
||||
/**
|
||||
* 附加数据
|
||||
*/
|
||||
private String attach;
|
||||
|
||||
/**
|
||||
* 支付完成时间
|
||||
*/
|
||||
private String time_end;
|
||||
|
||||
/**
|
||||
* 交易状态描述
|
||||
*/
|
||||
private String trade_state_desc;
|
||||
|
||||
public boolean isHttpSucess() {
|
||||
return ObjectUtil.equals(WechatMicropayVo.SUCCESS, return_code);
|
||||
}
|
||||
|
||||
public boolean isPaySucess() {
|
||||
return ObjectUtil.equals(WechatMicropayVo.SUCCESS, result_code);
|
||||
}
|
||||
}
|
||||
-102
@@ -1,102 +0,0 @@
|
||||
package com.bsd.pjcloud.hard.api.vo.wechat;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 退款返回
|
||||
*/
|
||||
@Data
|
||||
public class WechatRefundQueryVo {
|
||||
|
||||
public static final String SUCCESS = "SUCCESS";
|
||||
|
||||
/**
|
||||
* 业务结果
|
||||
*/
|
||||
private String result_code;
|
||||
|
||||
/**
|
||||
* 错误码
|
||||
*/
|
||||
private String err_code;
|
||||
|
||||
/**
|
||||
* 错误描述
|
||||
*/
|
||||
private String err_code_des;
|
||||
|
||||
/**
|
||||
* 公众账号ID
|
||||
*/
|
||||
private String appid;
|
||||
|
||||
/**
|
||||
* 商户号
|
||||
*/
|
||||
private String mch_id;
|
||||
|
||||
/**
|
||||
* 随机字符串
|
||||
*/
|
||||
private String nonce_str;
|
||||
|
||||
/**
|
||||
* 签名
|
||||
*/
|
||||
private String sign;
|
||||
|
||||
/**
|
||||
* 订单总退款次数
|
||||
*/
|
||||
private Long total_refund_count;
|
||||
|
||||
/**
|
||||
* 微信订单号
|
||||
*/
|
||||
private String transaction_id;
|
||||
|
||||
/**
|
||||
* 商户订单号
|
||||
*/
|
||||
private String out_trade_no;
|
||||
|
||||
/**
|
||||
* 订单金额
|
||||
*/
|
||||
private Long total_fee;
|
||||
|
||||
/**
|
||||
* 应结订单金额
|
||||
*/
|
||||
private Long settlement_total_fee;
|
||||
|
||||
/**
|
||||
* 货币种类
|
||||
*/
|
||||
private String fee_type;
|
||||
|
||||
/**
|
||||
* 现金支付金额
|
||||
*/
|
||||
private Long cash_fee;
|
||||
|
||||
/**
|
||||
* 退款笔数
|
||||
*/
|
||||
private Long refund_count;
|
||||
|
||||
/**
|
||||
* 退款总金额
|
||||
*/
|
||||
private Long refund_fee;
|
||||
|
||||
public boolean isHttpSucess() {
|
||||
return ObjectUtil.equals(WechatMicropayVo.SUCCESS, err_code);
|
||||
}
|
||||
|
||||
public boolean isPaySucess() {
|
||||
return ObjectUtil.equals(WechatMicropayVo.SUCCESS, result_code);
|
||||
}
|
||||
|
||||
}
|
||||
-84
@@ -1,84 +0,0 @@
|
||||
package com.bsd.pjcloud.hard.api.vo.wechat;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 退款返回
|
||||
*/
|
||||
@Data
|
||||
public class WechatRefundVo {
|
||||
|
||||
public static final String SUCCESS = "SUCCESS";
|
||||
|
||||
private String return_code;
|
||||
|
||||
private String return_msg;
|
||||
|
||||
private String result_code;
|
||||
|
||||
private String err_code;
|
||||
|
||||
private String err_code_des;
|
||||
|
||||
private String appid;
|
||||
|
||||
private String mch_id;
|
||||
|
||||
private String nonce_str;
|
||||
|
||||
|
||||
private String sign;
|
||||
|
||||
/**
|
||||
* 微信支付订单号
|
||||
*/
|
||||
private String transaction_id;
|
||||
|
||||
/**
|
||||
* 商户订单号
|
||||
*/
|
||||
private String out_trade_no;
|
||||
|
||||
/**
|
||||
* 商户退款单号
|
||||
*/
|
||||
private String out_refund_no;
|
||||
|
||||
/**
|
||||
* 微信退款单号
|
||||
*/
|
||||
private String refund_id;
|
||||
|
||||
/**
|
||||
* 退款金额
|
||||
*/
|
||||
private String refund_fee;
|
||||
|
||||
/**
|
||||
* 应结退款金额
|
||||
*/
|
||||
private String settlement_refund_fee;
|
||||
|
||||
/**
|
||||
* 标价金额
|
||||
*/
|
||||
private String total_fee;
|
||||
|
||||
/**
|
||||
* 应结订单金额
|
||||
*/
|
||||
private String settlement_total_fee;
|
||||
|
||||
public boolean isHttpSucess() {
|
||||
return ObjectUtil.equals(WechatMicropayVo.SUCCESS, return_code);
|
||||
}
|
||||
|
||||
public boolean isPaySucess() {
|
||||
return ObjectUtil.equals(WechatMicropayVo.SUCCESS, result_code);
|
||||
}
|
||||
|
||||
public boolean isAllSuccess() {
|
||||
return isHttpSucess() && isPaySucess();
|
||||
}
|
||||
}
|
||||
-122
@@ -1,122 +0,0 @@
|
||||
package com.bsd.pjcloud.hard.controller;
|
||||
|
||||
import cn.hutool.core.util.ArrayUtil;
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
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.hard.api.dto.HardThirdMiPayDto;
|
||||
import com.bsd.pjcloud.hard.api.entity.HardThirdMiOrderEntity;
|
||||
import com.bsd.pjcloud.hard.service.HardThirdMiOrderService;
|
||||
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;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* 硬件商品免密订单
|
||||
*/
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
@RequestMapping("/hard-third-mi-order")
|
||||
@Tag(description = "hardThirdMiOrder", name = "硬件商品免密订单管理")
|
||||
@SecurityRequirement(name = HttpHeaders.AUTHORIZATION)
|
||||
public class HardThirdMiOrderController {
|
||||
|
||||
private final HardThirdMiOrderService hardThirdMiOrderService;
|
||||
|
||||
/**
|
||||
* 刷新订单
|
||||
*/
|
||||
@Operation(summary = "刷新订单", description = "刷新订单")
|
||||
@GetMapping("/refresh")
|
||||
public R refresh(@RequestParam("id") Long id) {
|
||||
hardThirdMiOrderService.refresh(id);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 支付订单
|
||||
*/
|
||||
@Operation(summary = "支付订单", description = "支付订单")
|
||||
@PostMapping("/admin-pay")
|
||||
public R adminPay(@RequestBody HardThirdMiPayDto dto) {
|
||||
hardThirdMiOrderService.adminPay(dto);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 分页查询
|
||||
*/
|
||||
@Operation(summary = "分页查询", description = "分页查询")
|
||||
@GetMapping("/page")
|
||||
@PreAuthorize("@pms.hasPermission('thirdmi_hardThirdMiOrder_view')")
|
||||
public R getHardThirdMiOrderPage(@ParameterObject Page page, @ParameterObject HardThirdMiOrderEntity hardThirdMiOrder) {
|
||||
LambdaQueryWrapper<HardThirdMiOrderEntity> wrapper = Wrappers.lambdaQuery();
|
||||
return R.ok(hardThirdMiOrderService.page(page, wrapper));
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过id查询硬件商品免密订单
|
||||
*/
|
||||
@Operation(summary = "通过id查询", description = "通过id查询")
|
||||
@GetMapping("/{id}")
|
||||
@PreAuthorize("@pms.hasPermission('thirdmi_hardThirdMiOrder_view')")
|
||||
public R getById(@PathVariable("id") Long id) {
|
||||
return R.ok(hardThirdMiOrderService.getById(id));
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增硬件商品免密订单
|
||||
*/
|
||||
@Operation(summary = "新增硬件商品免密订单", description = "新增硬件商品免密订单")
|
||||
@SysLog("新增硬件商品免密订单")
|
||||
@PostMapping
|
||||
@PreAuthorize("@pms.hasPermission('thirdmi_hardThirdMiOrder_add')")
|
||||
public R save(@RequestBody HardThirdMiOrderEntity hardThirdMiOrder) {
|
||||
return R.ok(hardThirdMiOrderService.save(hardThirdMiOrder));
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改硬件商品免密订单
|
||||
*/
|
||||
@Operation(summary = "修改硬件商品免密订单", description = "修改硬件商品免密订单")
|
||||
@SysLog("修改硬件商品免密订单")
|
||||
@PutMapping
|
||||
@PreAuthorize("@pms.hasPermission('thirdmi_hardThirdMiOrder_edit')")
|
||||
public R updateById(@RequestBody HardThirdMiOrderEntity hardThirdMiOrder) {
|
||||
return R.ok(hardThirdMiOrderService.updateById(hardThirdMiOrder));
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过id删除硬件商品免密订单
|
||||
*/
|
||||
@Operation(summary = "通过id删除硬件商品免密订单", description = "通过id删除硬件商品免密订单")
|
||||
@SysLog("通过id删除硬件商品免密订单")
|
||||
@DeleteMapping
|
||||
@PreAuthorize("@pms.hasPermission('thirdmi_hardThirdMiOrder_del')")
|
||||
public R removeById(@RequestBody Long[] ids) {
|
||||
return R.ok(hardThirdMiOrderService.removeBatchByIds(CollUtil.toList(ids)));
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出excel 表格
|
||||
*/
|
||||
@ResponseExcel
|
||||
@GetMapping("/export")
|
||||
@PreAuthorize("@pms.hasPermission('thirdmi_hardThirdMiOrder_export')")
|
||||
public List<HardThirdMiOrderEntity> export(HardThirdMiOrderEntity hardThirdMiOrder, Long[] ids) {
|
||||
return hardThirdMiOrderService.list(Wrappers.lambdaQuery(hardThirdMiOrder).in(ArrayUtil.isNotEmpty(ids), HardThirdMiOrderEntity::getId, ids));
|
||||
}
|
||||
}
|
||||
-47
@@ -1,47 +0,0 @@
|
||||
package com.bsd.pjcloud.hard.controller.ali;
|
||||
|
||||
import com.bsd.pjcloud.common.security.annotation.Inner;
|
||||
import com.bsd.pjcloud.hard.service.AlipayService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.http.HttpEntity;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestHeader;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
@RequestMapping("/hard-ali-pay")
|
||||
@Tag(description = "hard-ali-pay", name = "支付宝相关")
|
||||
@SecurityRequirement(name = HttpHeaders.AUTHORIZATION)
|
||||
@Validated
|
||||
public class AliPayController {
|
||||
|
||||
private final AlipayService aliPayService;
|
||||
|
||||
/* ************************************* start callback start ************************************* */
|
||||
|
||||
@Inner(value = false)
|
||||
@PostMapping("/callback")
|
||||
@Operation(summary = "支付宝回调")
|
||||
public String refundCallback(HttpServletRequest request) {
|
||||
Map<String, String[]> parameterMap = request.getParameterMap();
|
||||
Map<String, String> params = new HashMap<>();
|
||||
for (Map.Entry<String, String[]> entry : parameterMap.entrySet()) {
|
||||
params.put(entry.getKey(), entry.getValue()[0]);
|
||||
}
|
||||
return aliPayService.refundCallback(params);
|
||||
}
|
||||
|
||||
/* ************************************* end callback end ************************************* */
|
||||
|
||||
}
|
||||
-40
@@ -1,40 +0,0 @@
|
||||
package com.bsd.pjcloud.hard.controller.wechant;
|
||||
|
||||
import com.bsd.pjcloud.common.security.annotation.Inner;
|
||||
import com.bsd.pjcloud.hard.service.WechatPayService;
|
||||
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.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestHeader;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
@RequestMapping("/hard-wechant-pay")
|
||||
@Tag(description = "hard-wechant", name = "微信相关")
|
||||
@SecurityRequirement(name = HttpHeaders.AUTHORIZATION)
|
||||
@Validated
|
||||
public class WechantPayController {
|
||||
|
||||
private final WechatPayService wechatPayService;
|
||||
|
||||
/* ************************************* start callback start ************************************* */
|
||||
|
||||
@Inner(value = false)
|
||||
@PostMapping("/callback/refund")
|
||||
@Operation(summary = "微信退款回调")
|
||||
public String refundCallback(HttpEntity<String> httpEntity, @RequestHeader Map<String, String> headers) {
|
||||
return wechatPayService.refundCallback(httpEntity, headers);
|
||||
}
|
||||
|
||||
/* ************************************* end callback end ************************************* */
|
||||
|
||||
}
|
||||
-42
@@ -1,42 +0,0 @@
|
||||
package com.bsd.pjcloud.hard.service;
|
||||
|
||||
|
||||
import com.alipay.api.response.*;
|
||||
import com.bsd.pjcloud.hard.api.dto.ali.*;
|
||||
import org.springframework.http.HttpEntity;
|
||||
import org.springframework.web.bind.annotation.RequestHeader;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public interface AlipayService {
|
||||
|
||||
/**
|
||||
* 付款码支付
|
||||
*/
|
||||
AlipayTradePayResponse micropay(AliMicropayDto dto);
|
||||
|
||||
/**
|
||||
* 查询订单
|
||||
*/
|
||||
AlipayTradeQueryResponse query(AliQueryDto dto);
|
||||
|
||||
/**
|
||||
* 撤销订单
|
||||
*/
|
||||
AlipayTradeCancelResponse reverse(AliReverseDto dto);
|
||||
|
||||
/**
|
||||
* 申请退款
|
||||
*/
|
||||
AlipayTradeRefundResponse refund(AliRefundDto dto);
|
||||
|
||||
/**
|
||||
* 查询退款
|
||||
*/
|
||||
AlipayTradeFastpayRefundQueryResponse refundQuery(AliRefundQueryDto dto);
|
||||
|
||||
/**
|
||||
* 退款回调
|
||||
*/
|
||||
String refundCallback(Map<String, String> params);
|
||||
}
|
||||
-6
@@ -11,7 +11,6 @@ import com.bsd.pjcloud.hard.api.entity.order.HardAfterSaleEntity;
|
||||
import com.bsd.pjcloud.hard.api.entity.order.HardAfterSaleLogEntity;
|
||||
import com.bsd.pjcloud.hard.api.vo.order.HardAfterSaleVo;
|
||||
import com.bsd.pjcloud.hard.api.vo.order.HardOrderVo;
|
||||
import com.bsd.pjcloud.hard.api.vo.wechat.WechantRefunCallbackVo;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -45,11 +44,6 @@ public interface HardAfterSaleService extends IService<HardAfterSaleEntity> {
|
||||
|
||||
void refund(Long afterSaleId, String prefixStr);
|
||||
|
||||
/**
|
||||
* 微信退款回调通知
|
||||
*/
|
||||
boolean wechatRefundCallback(WechantRefunCallbackVo decrypt);
|
||||
|
||||
/**
|
||||
* 同意售后
|
||||
*/
|
||||
|
||||
-24
@@ -1,24 +0,0 @@
|
||||
package com.bsd.pjcloud.hard.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.bsd.pjcloud.hard.api.dto.HardThirdMiPayDto;
|
||||
import com.bsd.pjcloud.hard.api.entity.HardThirdMiOrderEntity;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
|
||||
public interface HardThirdMiOrderService extends IService<HardThirdMiOrderEntity> {
|
||||
|
||||
/**
|
||||
* 刷新订单
|
||||
*/
|
||||
void refresh(Long id);
|
||||
|
||||
/**
|
||||
* 后台支付
|
||||
*/
|
||||
void adminPay(HardThirdMiPayDto dto);
|
||||
|
||||
/**
|
||||
* 根据授权id查询授权订单
|
||||
*/
|
||||
HardThirdMiOrderEntity getByAuthId(Long authId);
|
||||
}
|
||||
-50
@@ -1,50 +0,0 @@
|
||||
package com.bsd.pjcloud.hard.service;
|
||||
|
||||
|
||||
import com.alipay.api.response.*;
|
||||
import com.bsd.pjcloud.common.core.constant.enums.UserTypeEnum;
|
||||
import com.bsd.pjcloud.hard.api.entity.HardThirdMiOrderEntity;
|
||||
|
||||
public interface MiniAlipayService {
|
||||
|
||||
/**
|
||||
* 获取智能柜小程序二维码
|
||||
*/
|
||||
String getDoorMiniQrCode(String hardDoorId, String cabinetNo);
|
||||
|
||||
/**
|
||||
* 免密授权
|
||||
*/
|
||||
String miDynamicSign(Long userId, UserTypeEnum userType, Long authId);
|
||||
|
||||
/**
|
||||
* 查询免密授权
|
||||
*/
|
||||
ZhimaCreditPayafteruseCreditagreementQueryResponse miDynamicQueySign(Long authId);
|
||||
|
||||
/**
|
||||
* 免密服务下单
|
||||
*/
|
||||
ZhimaCreditPayafteruseCreditbizorderOrderResponse miDynamicOrder(Long authId, Long orderId, Long flowId);
|
||||
|
||||
/**
|
||||
* 创建支付宝免密订单
|
||||
*/
|
||||
AlipayTradeCreateResponse miCreateOrder(String openId, Long authId, Long userId, UserTypeEnum userType);
|
||||
|
||||
/**
|
||||
* 查询支付宝免密订单
|
||||
*/
|
||||
ZhimaCreditPayafteruseCreditbizorderQueryResponse miQueryOrder(String alipayOrderNo, Long authId);
|
||||
|
||||
/**
|
||||
* 支付宝免密扣款
|
||||
*/
|
||||
boolean miPay(HardThirdMiOrderEntity thirdOrder, int totalPrice);
|
||||
|
||||
/**
|
||||
* 支付宝免密(取消/退款)
|
||||
*/
|
||||
AlipayTradeRefundResponse miCancelOrRefund(String authId, String refundId, int price);
|
||||
|
||||
}
|
||||
-45
@@ -1,45 +0,0 @@
|
||||
package com.bsd.pjcloud.hard.service;
|
||||
|
||||
|
||||
import com.bsd.pjcloud.hard.api.dto.wechat.*;
|
||||
import com.bsd.pjcloud.hard.api.vo.wechat.*;
|
||||
import org.springframework.http.HttpEntity;
|
||||
import org.springframework.web.bind.annotation.RequestHeader;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 微信支付
|
||||
*/
|
||||
public interface WechatPayService {
|
||||
|
||||
/**
|
||||
* 付款码支付
|
||||
*/
|
||||
WechatMicropayVo micropay(WechatMicropayDto dto);
|
||||
|
||||
/**
|
||||
* 查询订单
|
||||
*/
|
||||
WechatQueryVo query(WechatQueryDto dto);
|
||||
|
||||
/**
|
||||
* 撤销订单
|
||||
*/
|
||||
WechantReverseVo reverse(WechantReverseDto dto);
|
||||
|
||||
/**
|
||||
* 申请退款
|
||||
*/
|
||||
WechatRefundVo refund(WechatRefundDto dto);
|
||||
|
||||
/**
|
||||
* 查询退款
|
||||
*/
|
||||
WechatRefundQueryVo refundQuery(WechatRefundQueryDto dto);
|
||||
|
||||
/**
|
||||
* 退款回调
|
||||
*/
|
||||
String refundCallback(HttpEntity<String> httpEntity, @RequestHeader Map<String, String> headers);
|
||||
}
|
||||
+5
-17
@@ -56,8 +56,6 @@ public class HardAuthServiceImpl extends ServiceImpl<HardAuthMapper, HardAuthEnt
|
||||
private final HardDoorManagerService hardDoorManagerService;
|
||||
private final HardDoorFlowService hardDoorFlowService;
|
||||
private final HardOrderService hardOrderService;
|
||||
private final MiniAlipayService miniAlipayService;
|
||||
private final HardThirdMiOrderService hardThirdMiOrderService;
|
||||
|
||||
private final HardManagerMapper hardManagerMapper;
|
||||
|
||||
@@ -151,11 +149,11 @@ public class HardAuthServiceImpl extends ServiceImpl<HardAuthMapper, HardAuthEnt
|
||||
HardAppCreateThirdDoorOrderVo res = new HardAppCreateThirdDoorOrderVo();
|
||||
|
||||
// AlipayTradeCreateResponse alipayRes = miniAlipayService.miCreateOrder(appUser.getOpenid(), authEntity.getId(), dto.getUserId(), dto.getUserType());
|
||||
AlipayTradeCreateResponse alipayRes = miniAlipayService.miCreateOrder(appUser.getOpenid(), authEntity.getId(), dto.getUserId(), dto.getUserType());
|
||||
if (ObjectUtil.isEmpty(alipayRes)) {
|
||||
throw new RuntimeException("创建支付宝免密订单失败");
|
||||
}
|
||||
res.setAlipayOrderStr(alipayRes.getTradeNo());
|
||||
// AlipayTradeCreateResponse alipayRes = miniAlipayService.miCreateOrder(appUser.getOpenid(), authEntity.getId(), dto.getUserId(), dto.getUserType());
|
||||
// if (ObjectUtil.isEmpty(alipayRes)) {
|
||||
// throw new RuntimeException("创建支付宝免密订单失败");
|
||||
// }
|
||||
// res.setAlipayOrderStr(alipayRes.getTradeNo());
|
||||
return res;
|
||||
}
|
||||
|
||||
@@ -170,18 +168,8 @@ public class HardAuthServiceImpl extends ServiceImpl<HardAuthMapper, HardAuthEnt
|
||||
// 查询设备信息
|
||||
HardDoorManagerVo hardDoorDetail = hardDoorManagerService.getByHardId(authEntity.getHardId());
|
||||
if (ObjectUtil.isEmpty(hardDoorDetail)) throw new RuntimeException("设备信息不存在");
|
||||
HardThirdMiOrderEntity thirdMiOrder = hardThirdMiOrderService.getByAuthId(dto.getAuthId());
|
||||
if (ObjectUtil.isEmpty(thirdMiOrder)) throw new RuntimeException("第三方免密订单不存在");
|
||||
|
||||
if (ObjectUtil.equals(dto.getUserType(), UserTypeEnum.TOC.getStatus())) {
|
||||
// 微信免密支付
|
||||
if (ObjectUtil.equals(thirdMiOrder.getBizType(), HardThirdMiTypeEnum.MI_WECHAT.getType())) {
|
||||
|
||||
}
|
||||
// 支付宝-芝麻先享
|
||||
if (ObjectUtil.equals(thirdMiOrder.getBizType(), HardThirdMiTypeEnum.MI_ALIPAY.getType())) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
HardAuthEntity updateObj = HardAuthEntity.builder().id(dto.getAuthId()).authStatus(YesNoEnum.YES.getCode()).authTime(LocalDateTime.now()).build();
|
||||
|
||||
-21
@@ -79,8 +79,6 @@ public class HardDoorFlowServiceImpl extends ServiceImpl<HardDoorFlowMapper, Har
|
||||
private final HardOrderService hardOrderService;
|
||||
@Lazy
|
||||
private final HardAuthService hardAuthService;
|
||||
private final HardThirdMiOrderService hardThirdMiOrderService;
|
||||
private final MiniAlipayService miniAlipayService;
|
||||
|
||||
private final HardManagerMapper hardManagerMapper;
|
||||
private final HardThirdMiOrderMapper hardThirdMiOrderMapper;
|
||||
@@ -259,26 +257,7 @@ public class HardDoorFlowServiceImpl extends ServiceImpl<HardDoorFlowMapper, Har
|
||||
Long orderId = hardOrderService.createHardDoorOrder(flowDetail.getUserId(), userType, flowDetail.getHardId());
|
||||
updateObj.setOrderId(orderId);
|
||||
if (ObjectUtil.equals(flowDetail.getUserType(), UserTypeEnum.TOC.getStatus())) {
|
||||
// 更新`hard_third_mi_order`表
|
||||
HardThirdMiOrderEntity thirdOrder = hardThirdMiOrderService.getByAuthId(flowDetail.getAuthId());
|
||||
if (ObjectUtil.isEmpty(thirdOrder)) {
|
||||
log.error("|{}|disposeLocakCallback创建第三方免密支付错误,原因:未查询到第三方免密支付记录authId|{}|", TAG, flowDetail.getAuthId());
|
||||
} else {
|
||||
HardThirdMiOrderEntity updateMiOrderObj = new HardThirdMiOrderEntity();
|
||||
updateMiOrderObj.setId(thirdOrder.getId());
|
||||
updateMiOrderObj.setOrderId(orderId);
|
||||
updateMiOrderObj.setFlowId(flowDetail.getId());
|
||||
updateMiOrderObj.setOutOrderNo(String.valueOf(orderId));
|
||||
hardThirdMiOrderMapper.updateById(updateMiOrderObj);
|
||||
// 微信免密支付
|
||||
if (ObjectUtil.equals(thirdOrder.getBizType(), HardThirdMiTypeEnum.MI_WECHAT.getType())) {
|
||||
|
||||
}
|
||||
// 支付宝-芝麻先享
|
||||
if (ObjectUtil.equals(thirdOrder.getBizType(), HardThirdMiTypeEnum.MI_ALIPAY.getType())) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
baseMapper.updateById(updateObj);
|
||||
|
||||
-114
@@ -1,114 +0,0 @@
|
||||
package com.bsd.pjcloud.hard.service.impl;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.alipay.api.response.ZhimaCreditPayafteruseCreditbizorderQueryResponse;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.bsd.pjcloud.hard.api.constant.HardThirdMiStatusEnum;
|
||||
import com.bsd.pjcloud.hard.api.constant.HardThirdMiTypeEnum;
|
||||
import com.bsd.pjcloud.hard.api.dto.HardThirdMiPayDto;
|
||||
import com.bsd.pjcloud.hard.api.entity.HardThirdMiOrderEntity;
|
||||
import com.bsd.pjcloud.hard.mapper.HardThirdMiOrderMapper;
|
||||
import com.bsd.pjcloud.hard.service.HardThirdMiOrderService;
|
||||
import com.bsd.pjcloud.hard.service.MiniAlipayService;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/**
|
||||
* 硬件商品免密订单
|
||||
*/
|
||||
@Service
|
||||
@AllArgsConstructor
|
||||
public class HardThirdMiOrderServiceImpl extends ServiceImpl<HardThirdMiOrderMapper, HardThirdMiOrderEntity> implements HardThirdMiOrderService {
|
||||
|
||||
private final MiniAlipayService miniAlipayService;
|
||||
|
||||
/**
|
||||
* 刷新订单
|
||||
*/
|
||||
@Override
|
||||
public void refresh(Long id) {
|
||||
HardThirdMiOrderEntity order = baseMapper.selectById(id);
|
||||
if (ObjectUtil.isEmpty(order)) {
|
||||
throw new RuntimeException("订单不存在");
|
||||
}
|
||||
// 微信免密支付
|
||||
if (ObjectUtil.equals(order.getBizType(), HardThirdMiTypeEnum.MI_WECHAT.getType())) {
|
||||
|
||||
return;
|
||||
}
|
||||
// 支付宝-芝麻先享
|
||||
if (ObjectUtil.equals(order.getBizType(), HardThirdMiTypeEnum.MI_ALIPAY.getType())) {
|
||||
ZhimaCreditPayafteruseCreditbizorderQueryResponse res = miniAlipayService.miQueryOrder(null, order.getAuthId());
|
||||
if (ObjectUtil.isEmpty(res)) {
|
||||
throw new RuntimeException("支付宝-芝麻先享,未查询到此订单");
|
||||
}
|
||||
HardThirdMiOrderEntity updateObj = new HardThirdMiOrderEntity();
|
||||
updateObj.setId(order.getId());
|
||||
// 押金
|
||||
updateObj.setDepositPrice(new BigDecimal(res.getTotalAmount()).multiply(BigDecimal.valueOf(100)).intValue());
|
||||
// 扣款金额
|
||||
if (ObjectUtil.isNotEmpty(res.getTotalCreditPayAmount())) {
|
||||
updateObj.setPayPrice(new BigDecimal(res.getTotalCreditPayAmount()).multiply(BigDecimal.valueOf(100)).intValue());
|
||||
}
|
||||
// 订单状态
|
||||
if (ObjectUtil.isNotEmpty(res.getOrderStatus())) {
|
||||
String orderStatus = res.getOrderStatus();
|
||||
switch (orderStatus) {
|
||||
// 下单状态
|
||||
case "INIT":
|
||||
updateObj.setOrderStatus(HardThirdMiStatusEnum.CREATE_ORDER.getType());
|
||||
break;
|
||||
// 订单取消或者交易全额退款
|
||||
case "TRADE_CLOSED":
|
||||
updateObj.setOrderStatus(HardThirdMiStatusEnum.REFUND.getType());
|
||||
break;
|
||||
// 扣款成功状态
|
||||
case "TRADE_FINISHED":
|
||||
updateObj.setOrderStatus(HardThirdMiStatusEnum.PAY.getType());
|
||||
break;
|
||||
}
|
||||
}
|
||||
baseMapper.updateById(updateObj);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 后台支付
|
||||
*/
|
||||
@Override
|
||||
public void adminPay(HardThirdMiPayDto dto) {
|
||||
HardThirdMiOrderEntity order = baseMapper.selectById(dto.getId());
|
||||
if (ObjectUtil.isEmpty(order)) {
|
||||
throw new RuntimeException("订单不存在");
|
||||
}
|
||||
// 微信免密支付
|
||||
if (ObjectUtil.equals(order.getBizType(), HardThirdMiTypeEnum.MI_WECHAT.getType())) {
|
||||
|
||||
refresh(dto.getId());
|
||||
return;
|
||||
}
|
||||
// 支付宝-芝麻先享
|
||||
if (ObjectUtil.equals(order.getBizType(), HardThirdMiTypeEnum.MI_ALIPAY.getType())) {
|
||||
if (ObjectUtil.isEmpty(order.getOrderId())) {
|
||||
throw new RuntimeException("支付宝-芝麻先享,此订单未创建");
|
||||
}
|
||||
miniAlipayService.miPay(order, 10);
|
||||
refresh(dto.getId());
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据授权id查询授权订单
|
||||
*/
|
||||
@Override
|
||||
public HardThirdMiOrderEntity getByAuthId(Long authId) {
|
||||
return baseMapper.selectOne(new LambdaQueryWrapper<HardThirdMiOrderEntity>()
|
||||
.eq(HardThirdMiOrderEntity::getAuthId, authId)
|
||||
);
|
||||
}
|
||||
}
|
||||
-206
@@ -1,206 +0,0 @@
|
||||
package com.bsd.pjcloud.hard.service.impl.ali;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.alipay.api.AlipayClient;
|
||||
import com.alipay.api.AlipayConfig;
|
||||
import com.alipay.api.DefaultAlipayClient;
|
||||
import com.alipay.api.domain.*;
|
||||
import com.alipay.api.internal.util.AlipaySignature;
|
||||
import com.alipay.api.request.*;
|
||||
import com.alipay.api.response.*;
|
||||
import com.bsd.pjcloud.hard.api.dto.ali.*;
|
||||
import com.bsd.pjcloud.hard.config.AlipayConf;
|
||||
import com.bsd.pjcloud.hard.service.AlipayService;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 支付宝支付
|
||||
*/
|
||||
@Service
|
||||
@AllArgsConstructor
|
||||
@Slf4j
|
||||
public class AlipayServiceImpl implements AlipayService {
|
||||
|
||||
private final AlipayConf conf;
|
||||
|
||||
static private AlipayClient client = null;
|
||||
|
||||
private void initClient() {
|
||||
AlipayConfig alipayConfig = new AlipayConfig();
|
||||
alipayConfig.setServerUrl("https://openapi.alipay.com/gateway.do");
|
||||
alipayConfig.setAppId(conf.getAppId());
|
||||
alipayConfig.setPrivateKey(conf.getPrivateKey());
|
||||
alipayConfig.setFormat("json");
|
||||
alipayConfig.setCharset("UTF-8");
|
||||
alipayConfig.setAlipayPublicKey(conf.getAlipayPublicKey());
|
||||
alipayConfig.setSignType("RSA2");
|
||||
try {
|
||||
AlipayServiceImpl.client = new DefaultAlipayClient(alipayConfig);
|
||||
} catch (Exception e) {
|
||||
log.error("初始化支付宝客户端异常", e);
|
||||
}
|
||||
}
|
||||
|
||||
private AlipayClient getClient() {
|
||||
if (ObjectUtil.isEmpty(AlipayServiceImpl.client)) initClient();
|
||||
return AlipayServiceImpl.client;
|
||||
}
|
||||
|
||||
/**
|
||||
* 付款码支付
|
||||
*/
|
||||
public AlipayTradePayResponse micropay(AliMicropayDto dto) {
|
||||
AlipayClient alipayClient = getClient();
|
||||
AlipayTradePayRequest request = new AlipayTradePayRequest();
|
||||
AlipayTradePayModel model = new AlipayTradePayModel();
|
||||
BigDecimal payPrice = BigDecimal.valueOf(dto.getPrice()).divide(BigDecimal.valueOf(100), 2, RoundingMode.HALF_UP);
|
||||
// 订单号
|
||||
model.setOutTradeNo(String.valueOf(dto.getOrderId()));
|
||||
// 支付金额单位元
|
||||
model.setTotalAmount(payPrice.toString());
|
||||
// 订单标题
|
||||
model.setSubject(dto.getSubject());
|
||||
// 支付授权码
|
||||
model.setAuthCode(dto.getAuthCode());
|
||||
// 支付场景
|
||||
model.setScene("bar_code");
|
||||
request.setBizModel(model);
|
||||
request.setNotifyUrl(conf.getCallbackUrl());
|
||||
try {
|
||||
AlipayTradePayResponse response = alipayClient.execute(request);
|
||||
String body = response.getBody();
|
||||
log.debug("申请退款,json|{}", body);
|
||||
return response;
|
||||
} catch (Exception e) {
|
||||
log.error("支付宝支付异常", e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询订单
|
||||
*/
|
||||
@Override
|
||||
public AlipayTradeQueryResponse query(AliQueryDto dto) {
|
||||
AlipayClient alipayClient = getClient();
|
||||
AlipayTradeQueryRequest request = new AlipayTradeQueryRequest();
|
||||
AlipayTradeQueryModel model = new AlipayTradeQueryModel();
|
||||
// 订单号
|
||||
model.setOutTradeNo(dto.getOrderId());
|
||||
// 支付宝订单号
|
||||
model.setTradeNo(dto.getAliOrderId());
|
||||
request.setBizModel(model);
|
||||
try {
|
||||
AlipayTradeQueryResponse response = alipayClient.execute(request);
|
||||
String body = response.getBody();
|
||||
log.debug("查询订单,json|{}", body);
|
||||
return response;
|
||||
} catch (Exception e) {
|
||||
log.error("查询订单异常", e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 撤销订单
|
||||
*/
|
||||
@Override
|
||||
public AlipayTradeCancelResponse reverse(AliReverseDto dto) {
|
||||
AlipayClient alipayClient = getClient();
|
||||
AlipayTradeCancelRequest request = new AlipayTradeCancelRequest();
|
||||
AlipayTradeCancelModel model = new AlipayTradeCancelModel();
|
||||
// 订单号
|
||||
model.setOutTradeNo(String.valueOf(dto.getOrderId()));
|
||||
// 支付宝订单号
|
||||
model.setTradeNo(dto.getAliOrderId());
|
||||
request.setBizModel(model);
|
||||
try {
|
||||
AlipayTradeCancelResponse response = alipayClient.execute(request);
|
||||
String body = response.getBody();
|
||||
log.debug("撤销订单,json|{}", body);
|
||||
return response;
|
||||
} catch (Exception e) {
|
||||
log.error("撤销订单", e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 申请退款
|
||||
*/
|
||||
@Override
|
||||
public AlipayTradeRefundResponse refund(AliRefundDto dto) {
|
||||
AlipayClient alipayClient = getClient();
|
||||
AlipayTradeRefundRequest request = new AlipayTradeRefundRequest();
|
||||
AlipayTradeRefundModel model = new AlipayTradeRefundModel();
|
||||
BigDecimal refundPrice = BigDecimal.valueOf(dto.getRefundPrice()).divide(BigDecimal.valueOf(100), 2, RoundingMode.HALF_UP);
|
||||
// 退款金额(元)
|
||||
model.setRefundAmount(String.valueOf(refundPrice));
|
||||
// 订单号
|
||||
model.setOutTradeNo(String.valueOf(dto.getOrderId()));
|
||||
// 支付宝订单id
|
||||
model.setTradeNo(dto.getAliOrderId());
|
||||
// 退款单号
|
||||
model.setOutRequestNo(String.valueOf(dto.getRefundId()));
|
||||
request.setBizModel(model);
|
||||
request.setNotifyUrl(conf.getCallbackUrl());
|
||||
try {
|
||||
AlipayTradeRefundResponse response = alipayClient.execute(request);
|
||||
String body = response.getBody();
|
||||
log.debug("申请退款,json|{}", body);
|
||||
return response;
|
||||
} catch (Exception e) {
|
||||
log.error("申请退款", e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询退款
|
||||
*/
|
||||
@Override
|
||||
public AlipayTradeFastpayRefundQueryResponse refundQuery(AliRefundQueryDto dto) {
|
||||
AlipayClient alipayClient = getClient();
|
||||
AlipayTradeFastpayRefundQueryRequest request = new AlipayTradeFastpayRefundQueryRequest();
|
||||
AlipayTradeFastpayRefundQueryModel model = new AlipayTradeFastpayRefundQueryModel();
|
||||
// 退款单号
|
||||
model.setOutRequestNo(String.valueOf(dto.getRefundId()));
|
||||
request.setBizModel(model);
|
||||
request.setNotifyUrl(conf.getCallbackUrl());
|
||||
try {
|
||||
AlipayTradeFastpayRefundQueryResponse response = alipayClient.execute(request);
|
||||
String body = response.getBody();
|
||||
log.debug("查询退款,json|{}", body);
|
||||
return response;
|
||||
} catch (Exception e) {
|
||||
log.error("查询退款", e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 退款回调
|
||||
*/
|
||||
@Override
|
||||
public String refundCallback(Map<String, String> params) {
|
||||
if (ObjectUtil.isEmpty(params)) return "fail";
|
||||
try {
|
||||
boolean checkSignature = AlipaySignature.rsaCheckV1(params, conf.getAlipayPublicKey(), "UTF-8", "RSA2");
|
||||
if (!checkSignature) {
|
||||
log.error("支付宝回调校验失败");
|
||||
return "fail";
|
||||
}
|
||||
log.debug("支付宝回调参数:{}", params);
|
||||
return "success";
|
||||
} catch (Exception e) {
|
||||
log.error("退款回调", e);
|
||||
return "fail";
|
||||
}
|
||||
}
|
||||
}
|
||||
-411
@@ -1,411 +0,0 @@
|
||||
package com.bsd.pjcloud.hard.service.impl.ali;
|
||||
|
||||
import cn.hutool.core.date.DatePattern;
|
||||
import cn.hutool.core.date.LocalDateTimeUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.json.JSONArray;
|
||||
import cn.hutool.json.JSONObject;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.alipay.api.AlipayClient;
|
||||
import com.alipay.api.AlipayConfig;
|
||||
import com.alipay.api.DefaultAlipayClient;
|
||||
import com.alipay.api.domain.*;
|
||||
import com.alipay.api.request.*;
|
||||
import com.alipay.api.response.*;
|
||||
import com.bsd.pjcloud.common.core.constant.enums.UserTypeEnum;
|
||||
import com.bsd.pjcloud.hard.api.constant.HardThirdMiStatusEnum;
|
||||
import com.bsd.pjcloud.hard.api.constant.HardThirdMiTypeEnum;
|
||||
import com.bsd.pjcloud.hard.api.entity.HardThirdMiOrderEntity;
|
||||
import com.bsd.pjcloud.hard.config.MiniAlipayConf;
|
||||
import com.bsd.pjcloud.hard.mapper.HardThirdMiOrderMapper;
|
||||
import com.bsd.pjcloud.hard.service.HardThirdMiOrderService;
|
||||
import com.bsd.pjcloud.hard.service.MiniAlipayService;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 支付宝小程序支付
|
||||
*/
|
||||
@Service
|
||||
@AllArgsConstructor
|
||||
@Slf4j
|
||||
public class MiniAlipayServiceImpl implements MiniAlipayService {
|
||||
|
||||
private final HardThirdMiOrderMapper hardThirdMiOrderMapper;
|
||||
|
||||
private final MiniAlipayConf conf;
|
||||
|
||||
static private AlipayClient client = null;
|
||||
|
||||
private void initClient() {
|
||||
AlipayConfig alipayConfig = new AlipayConfig();
|
||||
alipayConfig.setServerUrl("https://openapi.alipay.com/gateway.do");
|
||||
alipayConfig.setAppId(conf.getAppId());
|
||||
alipayConfig.setPrivateKey(conf.getPrivateKey());
|
||||
alipayConfig.setFormat("json");
|
||||
alipayConfig.setCharset("UTF-8");
|
||||
alipayConfig.setAlipayPublicKey(conf.getAlipayPublicKey());
|
||||
alipayConfig.setSignType("RSA2");
|
||||
try {
|
||||
MiniAlipayServiceImpl.client = new DefaultAlipayClient(alipayConfig);
|
||||
} catch (Exception e) {
|
||||
log.error("初始化支付宝客户端异常", e);
|
||||
}
|
||||
}
|
||||
|
||||
private AlipayClient getClient() {
|
||||
if (ObjectUtil.isEmpty(MiniAlipayServiceImpl.client)) initClient();
|
||||
return MiniAlipayServiceImpl.client;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取智能柜小程序二维码
|
||||
*/
|
||||
@Override
|
||||
public String getDoorMiniQrCode(String hardDoorId, String cabinetNo) {
|
||||
AlipayOpenAppQrcodeCreateRequest request = new AlipayOpenAppQrcodeCreateRequest();
|
||||
AlipayOpenAppQrcodeCreateModel model = new AlipayOpenAppQrcodeCreateModel();
|
||||
model.setUrlParam("pages/tabbar/login");
|
||||
model.setQueryParam(String.format("action=scan&path=%s&hardDoorId=%s&cabinetNo=%s", "pages/tabbar/login", hardDoorId, cabinetNo));
|
||||
model.setDescribe("支付宝智能柜二维码");
|
||||
request.setBizModel(model);
|
||||
try {
|
||||
AlipayOpenAppQrcodeCreateResponse response = getClient().execute(request);
|
||||
if (!response.isSuccess()) {
|
||||
log.error("|获取小程序二维码|失败,json|{}", response.getBody());
|
||||
return null;
|
||||
}
|
||||
return response.getQrCodeUrlCircleBlue();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
log.error("|获取小程序二维码|异常", e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 免密授权
|
||||
*/
|
||||
@Override
|
||||
public String miDynamicSign(Long userId, UserTypeEnum userType, Long authId) {
|
||||
HardThirdMiOrderEntity thirdOrder = new HardThirdMiOrderEntity();
|
||||
thirdOrder.setBizType(HardThirdMiTypeEnum.MI_ALIPAY.getType());
|
||||
thirdOrder.setAuthId(authId);
|
||||
thirdOrder.setUserId(userId);
|
||||
thirdOrder.setUserType(userType.getStatus());
|
||||
thirdOrder.setCreateOrderTime(LocalDateTime.now());
|
||||
thirdOrder.setOrderStatus(HardThirdMiStatusEnum.CREATE_ORDER.getType());
|
||||
|
||||
ZhimaCreditPayafteruseCreditagreementSignRequest request = new ZhimaCreditPayafteruseCreditagreementSignRequest();
|
||||
ZhimaCreditPayafteruseCreditagreementSignModel model = new ZhimaCreditPayafteruseCreditagreementSignModel();
|
||||
// 设置芝麻信用服务ID
|
||||
model.setZmServiceId(conf.getZmServiceId());
|
||||
// 设置芝麻外部类目
|
||||
model.setCategoryId("credit_pay_after_use");
|
||||
model.setOutAgreementNo(String.valueOf(authId));
|
||||
request.setBizModel(model);
|
||||
try {
|
||||
ZhimaCreditPayafteruseCreditagreementSignResponse response = getClient().sdkExecute(request);
|
||||
if (!response.isSuccess()) {
|
||||
log.error("|免密授权|失败,json|{}", response.getBody());
|
||||
return null;
|
||||
}
|
||||
return response.getBody();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
log.error("|免密授权|异常", e);
|
||||
return null;
|
||||
} finally {
|
||||
hardThirdMiOrderMapper.insert(thirdOrder);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询面密授权
|
||||
*/
|
||||
@Override
|
||||
public ZhimaCreditPayafteruseCreditagreementQueryResponse miDynamicQueySign(Long authId) {
|
||||
HardThirdMiOrderEntity thirdMiOrder = hardThirdMiOrderMapper.getByAuthId(authId);
|
||||
if (ObjectUtil.isEmpty(thirdMiOrder)) {
|
||||
log.error("|查询面密授权|订单不存在,authId|{}", authId);
|
||||
return null;
|
||||
}
|
||||
HardThirdMiOrderEntity updateObj = new HardThirdMiOrderEntity();
|
||||
updateObj.setId(thirdMiOrder.getId());
|
||||
|
||||
ZhimaCreditPayafteruseCreditagreementQueryRequest request = new ZhimaCreditPayafteruseCreditagreementQueryRequest();
|
||||
ZhimaCreditPayafteruseCreditagreementQueryModel model = new ZhimaCreditPayafteruseCreditagreementQueryModel();
|
||||
model.setOutAgreementNo(String.valueOf(authId));
|
||||
request.setBizModel(model);
|
||||
try {
|
||||
ZhimaCreditPayafteruseCreditagreementQueryResponse response = getClient().execute(request);
|
||||
if (!response.isSuccess()) {
|
||||
log.error("|查询面密授权|失败,json|{}", response.getBody());
|
||||
return null;
|
||||
}
|
||||
updateObj.setOrgSignJson(JSONUtil.toJsonStr(response));
|
||||
return response;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
log.error("|查询面密授权|异常", e);
|
||||
return null;
|
||||
} finally {
|
||||
if (ObjectUtil.isNotEmpty(updateObj.getOrgSignJson())) {
|
||||
hardThirdMiOrderMapper.updateById(updateObj);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 免密服务下单
|
||||
*/
|
||||
@Override
|
||||
public ZhimaCreditPayafteruseCreditbizorderOrderResponse miDynamicOrder(Long authId, Long orderId, Long flowId) {
|
||||
HardThirdMiOrderEntity thirdMiOrder = hardThirdMiOrderMapper.getByAuthId(authId);
|
||||
if (ObjectUtil.isEmpty(thirdMiOrder)) {
|
||||
log.error("|免密服务下单|订单不存在,authId|{}", authId);
|
||||
return null;
|
||||
}
|
||||
ZhimaCreditPayafteruseCreditagreementQueryResponse signObj = JSONUtil.toBean(thirdMiOrder.getOrgSignJson(), ZhimaCreditPayafteruseCreditagreementQueryResponse.class);
|
||||
if (ObjectUtil.isEmpty(signObj)) {
|
||||
log.error("|免密服务下单|signObj为空,授权错误,authId|{}", authId);
|
||||
return null;
|
||||
}
|
||||
HardThirdMiOrderEntity updateObj = new HardThirdMiOrderEntity();
|
||||
updateObj.setId(thirdMiOrder.getId());
|
||||
updateObj.setOrderId(orderId);
|
||||
updateObj.setFlowId(flowId);
|
||||
updateObj.setOutOrderNo(String.valueOf(orderId));
|
||||
|
||||
ZhimaCreditPayafteruseCreditbizorderOrderRequest request = new ZhimaCreditPayafteruseCreditbizorderOrderRequest();
|
||||
ZhimaCreditPayafteruseCreditbizorderOrderModel model = new ZhimaCreditPayafteruseCreditbizorderOrderModel();
|
||||
// 设置商户外部订单号
|
||||
model.setOutOrderNo(String.valueOf(orderId));
|
||||
// 设置芝麻开通协议号
|
||||
model.setCreditAgreementId(signObj.getCreditAgreementId());
|
||||
// 设置芝麻外部类目
|
||||
model.setCategoryId("credit_pay_after_use");
|
||||
// 设置芝麻产品代码
|
||||
model.setProductCode("CREDIT_PAY_AFTER_USE");
|
||||
// 设置订单标题
|
||||
model.setSubject("浦江智能柜芝麻先享");
|
||||
// 设置订单描述
|
||||
model.setBody("浦江智能柜芝麻先享");
|
||||
request.setBizModel(model);
|
||||
try {
|
||||
ZhimaCreditPayafteruseCreditbizorderOrderResponse response = getClient().execute(request);
|
||||
if (!response.isSuccess()) {
|
||||
log.error("|免密服务下单|失败,json|{}", response.getBody());
|
||||
return null;
|
||||
}
|
||||
updateObj.setThirdOrderNo(response.getCreditBizOrderId());
|
||||
updateObj.setOrgOrderJson(JSONUtil.toJsonStr(response));
|
||||
|
||||
// 一般是芝麻信用评估不通过、未开通等
|
||||
if (List.of("ZHIMA_CHECK_NO_PASS", "ZHIMA_EVALUATE_NO_PASS", "CREDIT_AGREEMENT_INVALID").contains(response.getCode())) {
|
||||
miDynamicCreate(authId, orderId);
|
||||
}
|
||||
|
||||
response.getCode();
|
||||
return response;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
log.error("|免密服务下单|异常", e);
|
||||
return null;
|
||||
} finally {
|
||||
hardThirdMiOrderMapper.updateById(updateObj);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建免密服务订单(风险评估)
|
||||
*/
|
||||
private ZhimaCreditPayafteruseCreditbizorderCreateResponse miDynamicCreate(Long authId, Long orderId) {
|
||||
ZhimaCreditPayafteruseCreditbizorderCreateRequest request = new ZhimaCreditPayafteruseCreditbizorderCreateRequest();
|
||||
ZhimaCreditPayafteruseCreditbizorderCreateModel model = new ZhimaCreditPayafteruseCreditbizorderCreateModel();
|
||||
// 设置商户外部订单号
|
||||
model.setOutOrderNo(String.valueOf(orderId));
|
||||
model.setZmServiceId(conf.getZmServiceId());
|
||||
model.setAmountType("RISK_AMOUNT");
|
||||
model.setCategoryId("credit_pay_after_use");
|
||||
model.setSubject("浦江智能柜芝麻先享");
|
||||
model.setBody("浦江智能柜芝麻先享");
|
||||
request.setBizModel(model);
|
||||
try {
|
||||
ZhimaCreditPayafteruseCreditbizorderCreateResponse response = getClient().sdkExecute(request);
|
||||
if (!response.isSuccess()) {
|
||||
log.error("|创建免密服务订单(风险评估)|失败,json|{}", response.getBody());
|
||||
return null;
|
||||
}
|
||||
return response;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
log.error("|创建免密服务订单(风险评估)|异常", e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建支付宝免密订单
|
||||
*/
|
||||
@Override
|
||||
public AlipayTradeCreateResponse miCreateOrder(String openId, Long authId, Long userId, UserTypeEnum userType) {
|
||||
HardThirdMiOrderEntity thirdOrder = new HardThirdMiOrderEntity();
|
||||
thirdOrder.setBizType(HardThirdMiTypeEnum.MI_ALIPAY.getType());
|
||||
thirdOrder.setAuthId(authId);
|
||||
thirdOrder.setUserId(userId);
|
||||
thirdOrder.setUserType(userType.getStatus());
|
||||
thirdOrder.setCreateOrderTime(LocalDateTime.now());
|
||||
thirdOrder.setOrderStatus(HardThirdMiStatusEnum.CREATE_ORDER.getType());
|
||||
AlipayTradeCreateRequest request = new AlipayTradeCreateRequest();
|
||||
try {
|
||||
JSONObject bizContent = new JSONObject();
|
||||
// 设置商户订单号
|
||||
bizContent.putOnce("out_trade_no", String.valueOf(authId));
|
||||
// 设置订单标题
|
||||
bizContent.putOnce("subject", "浦江智能柜芝麻先享");
|
||||
// 设置订单附加信息
|
||||
bizContent.putOnce("body", "浦江智能柜芝麻先享");
|
||||
// 设置订单金额
|
||||
bizContent.putOnce("total_amount", 0.01);
|
||||
// 固定
|
||||
bizContent.putOnce("product_code", "JSAPI_PAY");
|
||||
// 用户登录id
|
||||
bizContent.putOnce("buyer_open_id", openId);
|
||||
bizContent.putOnce("op_buyer_open_id", openId);
|
||||
bizContent.putOnce("op_app_id", conf.getAppId());
|
||||
// 订单超时时间(1天)
|
||||
bizContent.putOnce("time_expire", LocalDateTimeUtil.format(LocalDateTime.now().plusDays(1), DatePattern.NORM_DATETIME_FORMATTER));
|
||||
JSONObject extraParam = new JSONObject();
|
||||
extraParam.putOnce("zmServiceId", conf.getZmServiceId());
|
||||
extraParam.putOnce("creditTradeScene", "CREDIT_PAY");
|
||||
bizContent.putOnce("extend_params", extraParam);
|
||||
request.setBizContent(bizContent.toString());
|
||||
AlipayTradeCreateResponse response = getClient().execute(request);
|
||||
if (!response.isSuccess()) {
|
||||
log.error("|创建支付宝订单|失败,json|{}", response.getBody());
|
||||
return null;
|
||||
}
|
||||
log.info("|创建支付宝订单|成功,json|{}", response.getBody());
|
||||
thirdOrder.setOutOrderNo(String.valueOf(authId));
|
||||
thirdOrder.setThirdOrderNo(response.getTradeNo());
|
||||
return response;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
log.error("|创建支付宝订单|意外的错误", e);
|
||||
return null;
|
||||
} finally {
|
||||
hardThirdMiOrderMapper.insert(thirdOrder);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询支付宝免密订单
|
||||
*/
|
||||
@Override
|
||||
public ZhimaCreditPayafteruseCreditbizorderQueryResponse miQueryOrder(String alipayOrderNo, Long authId) {
|
||||
ZhimaCreditPayafteruseCreditbizorderQueryRequest request = new ZhimaCreditPayafteruseCreditbizorderQueryRequest();
|
||||
ZhimaCreditPayafteruseCreditbizorderQueryModel model = new ZhimaCreditPayafteruseCreditbizorderQueryModel();
|
||||
if (ObjectUtil.isNotEmpty(alipayOrderNo)) {
|
||||
model.setCreditBizOrderId(alipayOrderNo);
|
||||
}
|
||||
if (ObjectUtil.isNotEmpty(authId)) {
|
||||
model.setOutOrderNo(String.valueOf(authId));
|
||||
}
|
||||
request.setBizModel(model);
|
||||
try {
|
||||
ZhimaCreditPayafteruseCreditbizorderQueryResponse response = getClient().execute(request);
|
||||
if (!response.isSuccess()) {
|
||||
log.error("|查询支付宝免密订单|失败,json|{}", response.getBody());
|
||||
return null;
|
||||
}
|
||||
log.info("|查询支付宝免密订单|成功,json|{}", response.getBody());
|
||||
return response;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
log.error("|查询支付宝免密订单|意外的错误", e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 支付宝免密扣款
|
||||
*/
|
||||
@Override
|
||||
public boolean miPay(HardThirdMiOrderEntity thirdOrder, int totalPrice) {
|
||||
HardThirdMiOrderEntity updateObj = new HardThirdMiOrderEntity();
|
||||
updateObj.setId(thirdOrder.getId());
|
||||
updateObj.setPayOrderTime(LocalDateTime.now());
|
||||
updateObj.setOrderPrice(totalPrice);
|
||||
updateObj.setPayPrice(totalPrice);
|
||||
|
||||
AlipayTradeOrderPayRequest request = new AlipayTradeOrderPayRequest();
|
||||
AlipayTradeOrderPayModel model = new AlipayTradeOrderPayModel();
|
||||
model.setOutRequestNo(String.valueOf(thirdOrder.getOrderId()));
|
||||
model.setTradeNo(thirdOrder.getOutOrderNo());
|
||||
model.setFulfillmentAmount(new BigDecimal(totalPrice).divide(BigDecimal.valueOf(100), 2, RoundingMode.HALF_UP).toString());
|
||||
model.setOrderPayMode("CREDIT_FULFILLMENT_ZM");
|
||||
try {
|
||||
request.setBizModel(model);
|
||||
AlipayTradeOrderPayResponse response = getClient().execute(request);
|
||||
if (!response.isSuccess()) {
|
||||
log.error("|支付宝免密扣款|失败,json|{}", response.getBody());
|
||||
return false;
|
||||
}
|
||||
log.info("|支付宝免密扣款|成功,json|{}", response.getBody());
|
||||
if (ObjectUtil.equals(response.getCode(), "10000")) {
|
||||
updateObj.setOrderStatus(HardThirdMiStatusEnum.PAY.getType());
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
log.error("|支付宝免密扣款|异常", e);
|
||||
return false;
|
||||
} finally {
|
||||
if (ObjectUtil.isNotEmpty(updateObj.getOrderStatus())) {
|
||||
hardThirdMiOrderMapper.updateById(updateObj);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 支付宝免密(取消/退款)
|
||||
*/
|
||||
@Override
|
||||
public AlipayTradeRefundResponse miCancelOrRefund(String authId, String refundId, int price) {
|
||||
AlipayTradeRefundRequest request = new AlipayTradeRefundRequest();
|
||||
JSONObject bizContent = new JSONObject();
|
||||
|
||||
// 订单总金额
|
||||
bizContent.putOnce("refund_amount", new BigDecimal(price).divide(BigDecimal.valueOf(100), 2, RoundingMode.HALF_UP));
|
||||
// 商家订单唯一号
|
||||
bizContent.putOnce("out_trade_no", authId);
|
||||
bizContent.putOnce("out_request_no", refundId);
|
||||
//扩展参数
|
||||
JSONObject extendParam = new JSONObject();
|
||||
extendParam.putOnce("is_fulfilled", "true");
|
||||
bizContent.putOnce("extend_params", extendParam);
|
||||
try {
|
||||
request.setBizContent(bizContent.toString());
|
||||
AlipayTradeRefundResponse response = getClient().execute(request);
|
||||
if (!response.isSuccess()) {
|
||||
log.error("|支付宝免密(取消/退款)|失败,json|{}", response.getBody());
|
||||
return null;
|
||||
}
|
||||
log.info("|支付宝免密(取消/退款)|成功,json|{}", response.getBody());
|
||||
return response;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
log.error("|支付宝免密(取消/退款)|异常", e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+4
-6
@@ -16,7 +16,6 @@ import com.bsd.pjcloud.hard.api.vo.manager.HardDoorCabinetCodeVo;
|
||||
import com.bsd.pjcloud.hard.api.vo.manager.HardDoorCabinetVo;
|
||||
import com.bsd.pjcloud.hard.mapper.manager.HardDoorCabinetMapper;
|
||||
import com.bsd.pjcloud.hard.service.HardDoorCabinetService;
|
||||
import com.bsd.pjcloud.hard.service.MiniAlipayService;
|
||||
import com.bsd.pjcloud.thirdparty.vo.door.DoorStatusVo;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -41,7 +40,6 @@ public class HardDoorCabinetServiceImpl extends ServiceImpl<HardDoorCabinetMappe
|
||||
|
||||
private static final String TAG = "智能柜货柜";
|
||||
|
||||
private final MiniAlipayService miniAlipayService;
|
||||
|
||||
private final RemoteFileService remoteFileService;
|
||||
|
||||
@@ -109,10 +107,10 @@ public class HardDoorCabinetServiceImpl extends ServiceImpl<HardDoorCabinetMappe
|
||||
updateObj.setQrCode(qrCode);
|
||||
updateObj.setUrlQrCode(urlQrCode);
|
||||
// 刷新支付宝二维码
|
||||
String doorMiniQrCode = miniAlipayService.getDoorMiniQrCode(String.valueOf(cabinetDetail.getHardDoorId()), String.valueOf(cabinetDetail.getCabinetNo()));
|
||||
if (ObjectUtil.isNotEmpty(doorMiniQrCode)) {
|
||||
updateObj.setUrlAlipayQrCode(doorMiniQrCode);
|
||||
}
|
||||
// String doorMiniQrCode = miniAlipayService.getDoorMiniQrCode(String.valueOf(cabinetDetail.getHardDoorId()), String.valueOf(cabinetDetail.getCabinetNo()));
|
||||
// if (ObjectUtil.isNotEmpty(doorMiniQrCode)) {
|
||||
// updateObj.setUrlAlipayQrCode(doorMiniQrCode);
|
||||
// }
|
||||
// 刷新微信小程序
|
||||
baseMapper.updateById(updateObj);
|
||||
}
|
||||
|
||||
+6
-65
@@ -31,17 +31,13 @@ import com.bsd.pjcloud.hard.api.constant.refund.HardSaleStatusEnum;
|
||||
import com.bsd.pjcloud.hard.api.constant.refund.HardSaleTypeEnum;
|
||||
import com.bsd.pjcloud.hard.api.dto.ali.AliRefundDto;
|
||||
import com.bsd.pjcloud.hard.api.dto.order.*;
|
||||
import com.bsd.pjcloud.hard.api.dto.wechat.WechatRefundDto;
|
||||
import com.bsd.pjcloud.hard.api.entity.order.*;
|
||||
import com.bsd.pjcloud.hard.api.utils.HardUtil;
|
||||
import com.bsd.pjcloud.hard.api.vo.order.HardAfterSaleVo;
|
||||
import com.bsd.pjcloud.hard.api.vo.order.HardCarVo;
|
||||
import com.bsd.pjcloud.hard.api.vo.order.HardOrderVo;
|
||||
import com.bsd.pjcloud.hard.api.vo.wechat.WechantRefunCallbackVo;
|
||||
import com.bsd.pjcloud.hard.api.vo.wechat.WechatRefundVo;
|
||||
import com.bsd.pjcloud.hard.mapper.order.HardAfterSaleLogMapper;
|
||||
import com.bsd.pjcloud.hard.mapper.order.HardAfterSaleMapper;
|
||||
import com.bsd.pjcloud.hard.mapper.order.HardCarMapper;
|
||||
import com.bsd.pjcloud.hard.mapper.order.HardOrderMapper;
|
||||
import com.bsd.pjcloud.hard.service.*;
|
||||
import com.bsd.pjcloud.wallet.api.dto.recharge.WalletRechargeRefundDto;
|
||||
@@ -72,8 +68,6 @@ public class HardAfterSaleServiceImpl extends ServiceImpl<HardAfterSaleMapper, H
|
||||
|
||||
private final HardAfterSaleLogMapper hardAfterSaleLogMapper;
|
||||
private final HardOrderService hardOrderService;
|
||||
private final WechatPayService wechatPayService;
|
||||
private final AlipayService alipayService;
|
||||
|
||||
private final HardOrderMapper hardOrderMapper;
|
||||
|
||||
@@ -263,67 +257,14 @@ public class HardAfterSaleServiceImpl extends ServiceImpl<HardAfterSaleMapper, H
|
||||
.refundTime(LocalDateTime.now())
|
||||
.build();
|
||||
hardOrderService.updateById(updateObj);
|
||||
} else if (isWeChatPay) {
|
||||
WechatRefundDto refundDto = WechatRefundDto.builder().orderId(order.getId()).refundId(afterSale.getId()).orderPrice(refundPrice).refundPrice(refundPrice).build();
|
||||
WechatRefundVo refundVo = wechatPayService.refund(refundDto);
|
||||
if (ObjectUtil.isEmpty(refundVo)) {
|
||||
throw new RuntimeException("微信退款错误");
|
||||
}
|
||||
if (!refundVo.isAllSuccess()) {
|
||||
throw new RuntimeException(refundVo.getErr_code_des());
|
||||
}
|
||||
} else if (isAliPay) {
|
||||
AliRefundDto refundDto = AliRefundDto.builder().orderId(order.getId()).refundId(afterSale.getId()).refundPrice(refundPrice).build();
|
||||
AlipayTradeRefundResponse refundVo = alipayService.refund(refundDto);
|
||||
if (ObjectUtil.isEmpty(refundVo) || !refundVo.isSuccess()) {
|
||||
throw new RuntimeException("支付宝退款错误");
|
||||
}
|
||||
// 售后成功
|
||||
HardOrderEntity updateObj = HardOrderEntity.builder()
|
||||
.id(order.getId())
|
||||
.orderStatus(HardOrderStatusEnum.REFUND.getType())
|
||||
.refundStatus(HardRefundStatusEnum.SUCCESS.getStatus())
|
||||
.payRefundId(order.getId())
|
||||
.refundPrice(order.getPayPrice())
|
||||
.refundTime(LocalDateTime.now())
|
||||
.build();
|
||||
hardOrderService.updateById(updateObj);
|
||||
}
|
||||
}
|
||||
// 微信支付退款
|
||||
else if (isWeChatPay) {
|
||||
|
||||
}
|
||||
// 支付宝退款
|
||||
else if (isAliPay) {
|
||||
|
||||
/**
|
||||
* 微信退款回调通知
|
||||
*/
|
||||
@Override
|
||||
public boolean wechatRefundCallback(WechantRefunCallbackVo decrypt) {
|
||||
try {
|
||||
Long orderId = Long.valueOf(decrypt.getOut_trade_no());
|
||||
Long refunId = Long.valueOf(decrypt.getOut_refund_no());
|
||||
// 查询订单
|
||||
HardOrderEntity order = hardOrderService.getById(orderId);
|
||||
if (ObjectUtil.isEmpty(order)) {
|
||||
log.error("微信退款回调通知,订单不存在orderId:{}", orderId);
|
||||
return false;
|
||||
}
|
||||
// 查询售后单
|
||||
HardAfterSaleEntity afterSale = baseMapper.selectById(refunId);
|
||||
if (ObjectUtil.isEmpty(afterSale)) {
|
||||
log.error("微信退款回调通知,售后单不存在refunId:{}", refunId);
|
||||
return false;
|
||||
}
|
||||
HardOrderEntity updateObj = HardOrderEntity.builder()
|
||||
.id(order.getId())
|
||||
.orderStatus(HardOrderStatusEnum.REFUND.getType())
|
||||
.refundStatus(HardRefundStatusEnum.SUCCESS.getStatus())
|
||||
.payRefundId(orderId)
|
||||
.refundPrice(Integer.valueOf(decrypt.getRefund_fee()))
|
||||
.refundTime(LocalDateTime.now())
|
||||
.build();
|
||||
hardOrderService.updateById(updateObj);
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
log.error("微信退款回调通知失败", e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+58
-46
@@ -59,8 +59,6 @@ import com.bsd.pjcloud.hard.api.dto.order.app.HardAppTakeOutApptDto;
|
||||
import com.bsd.pjcloud.hard.api.dto.order.remote.HardUpdateTakeOutStatusDto;
|
||||
import com.bsd.pjcloud.hard.api.dto.order.xfj.HardXfjFastCreateOrderDto;
|
||||
import com.bsd.pjcloud.hard.api.dto.spu.DeductionSpuStockDto;
|
||||
import com.bsd.pjcloud.hard.api.dto.wechat.WechantReverseDto;
|
||||
import com.bsd.pjcloud.hard.api.dto.wechat.WechatMicropayDto;
|
||||
import com.bsd.pjcloud.hard.api.entity.HardApptEntity;
|
||||
import com.bsd.pjcloud.hard.api.entity.HardThirdMiOrderEntity;
|
||||
import com.bsd.pjcloud.hard.api.entity.manager.HardManagerEntity;
|
||||
@@ -73,7 +71,6 @@ import com.bsd.pjcloud.hard.api.vo.order.HardCarVo;
|
||||
import com.bsd.pjcloud.hard.api.vo.order.HardCreateHardQrCodeScanOrderVo;
|
||||
import com.bsd.pjcloud.hard.api.vo.order.HardOrderVo;
|
||||
import com.bsd.pjcloud.hard.util.MchJobTimeUtils;
|
||||
import com.bsd.pjcloud.hard.api.vo.wechat.WechatMicropayVo;
|
||||
import com.bsd.pjcloud.hard.mapper.HardThirdMiOrderMapper;
|
||||
import com.bsd.pjcloud.hard.mapper.manager.HardManagerMapper;
|
||||
import com.bsd.pjcloud.hard.mapper.order.HardOrderMapper;
|
||||
@@ -84,6 +81,10 @@ import com.bsd.pjcloud.supermarket.api.feign.RemoteSupermarketSpuService;
|
||||
import com.bsd.pjcloud.supermarket.dto.MallProductStockChangeDTO;
|
||||
import com.bsd.pjcloud.supermarket.dto.SkuStockChangeDTO;
|
||||
import com.bsd.pjcloud.supermarket.dto.SupermarketSpuUpdateStockReqDTO;
|
||||
import com.bsd.pjcloud.thirdparty.api.feign.RemoterThirdAppPlusPayService;
|
||||
import com.bsd.pjcloud.thirdparty.constant.miniplatform.AppPlusPlatformTypeEnum;
|
||||
import com.bsd.pjcloud.thirdparty.constant.pay.ThirdPayOrderBizTypeEnum;
|
||||
import com.bsd.pjcloud.thirdparty.dto.appplus.ThirdMicropayDto;
|
||||
import com.bsd.pjcloud.thirdparty.dto.ks.KsRecognitionCallbackDto;
|
||||
import com.bsd.pjcloud.wallet.api.constant.WalletBizEnum;
|
||||
import com.bsd.pjcloud.wallet.api.constant.WalletCodeBizEnum;
|
||||
@@ -146,9 +147,6 @@ public class HardOrderServiceImpl extends ServiceImpl<HardOrderMapper, HardOrder
|
||||
private final HardBroadcastService hardBroadcastService;
|
||||
private final HardSpuService hardSpuService;
|
||||
private final HardApptService hardApptService;
|
||||
private final WechatPayService wechatPayService;
|
||||
private final AlipayService alipayService;
|
||||
private final MiniAlipayService miniAlipayService;
|
||||
private final HardOrderAddressService hardOrderAddressService;
|
||||
private final HardTakeOutApptService hardTakeOutApptService;
|
||||
|
||||
@@ -162,6 +160,7 @@ public class HardOrderServiceImpl extends ServiceImpl<HardOrderMapper, HardOrder
|
||||
private final RemoteUserService userService;
|
||||
private final RemoteDeptService deptService;
|
||||
private final RemoteMchRuleJoinService mchRuleJoinService;
|
||||
private final RemoterThirdAppPlusPayService thirdAppPlusPayService;
|
||||
|
||||
private final RemoteOnlineCanteenSpuService onlineCanteenSpuService;
|
||||
private final RemoteSupermarketSpuService supermarketSpuService;
|
||||
@@ -373,32 +372,11 @@ public class HardOrderServiceImpl extends ServiceImpl<HardOrderMapper, HardOrder
|
||||
}
|
||||
// 微信支付
|
||||
if (isWeChatPay) {
|
||||
WechatMicropayDto wechatPayDto = WechatMicropayDto.builder().merId(orderObj.getMerchantId()).orderId(orderObj.getId()).price(payPrice).wechatQrCode(String.valueOf(dto.getOrderSourceTypeId())).build();
|
||||
WechatMicropayVo wechatPayVo = wechatPayService.micropay(wechatPayDto);
|
||||
if (ObjectUtil.isEmpty(wechatPayVo)) {
|
||||
throw new RuntimeException("微信支付失败");
|
||||
}
|
||||
boolean wehcantPaySuccess = wechatPayVo.isAllSuccess();
|
||||
if (!wehcantPaySuccess) {
|
||||
// 如果微信支付订单返回不明确(不是支付成功)直接撤销支付
|
||||
wechatPayService.reverse(WechantReverseDto.builder().orderId(orderObj.getId()).build());
|
||||
throw new RuntimeException(wechatPayVo.getErr_code_des());
|
||||
} else {
|
||||
getSelf().orderSuccess(orderObj, Boolean.TRUE);
|
||||
}
|
||||
|
||||
}
|
||||
// 支付宝支付
|
||||
if (isAliPay) {
|
||||
AliMicropayDto wechatPayDto = AliMicropayDto.builder().merId(orderObj.getMerchantId()).orderId(orderObj.getId()).price(payPrice).subject(subject).authCode(String.valueOf(dto.getOrderSourceTypeId())).build();
|
||||
AlipayTradePayResponse micropay = alipayService.micropay(wechatPayDto);
|
||||
if (ObjectUtil.isEmpty(micropay) || !micropay.isSuccess()) {
|
||||
// 如果支付宝支付订单返回不明确(不是支付成功)直接撤销支付
|
||||
alipayService.reverse(AliReverseDto.builder().orderId(orderObj.getId()).build());
|
||||
throw new RuntimeException(micropay.getSubMsg());
|
||||
} else {
|
||||
orderObj.setOrderNo(micropay.getTradeNo());
|
||||
getSelf().orderSuccess(orderObj, Boolean.TRUE);
|
||||
}
|
||||
|
||||
}
|
||||
// 发送mq消息
|
||||
getSelf().createOrderAfterSendMqMsg(orderObj.getId(), userDetail);
|
||||
@@ -1012,19 +990,25 @@ public class HardOrderServiceImpl extends ServiceImpl<HardOrderMapper, HardOrder
|
||||
}
|
||||
}
|
||||
// 查询用户
|
||||
UserInfo userDetail = userService.getInnerByUserId(dto.getUserId()).getData();
|
||||
if (ObjectUtil.isEmpty(userDetail)) {
|
||||
throw new RuntimeException("用户不存在不存在");
|
||||
UserInfo userDetail = null;
|
||||
if (ObjectUtil.equals(dto.getPlatformType(), AppPlusPlatformTypeEnum.ZAX_APP_WALLET)) {
|
||||
userService.getInnerByUserId(dto.getUserId()).getData();
|
||||
if (ObjectUtil.isEmpty(userDetail)) {
|
||||
throw new RuntimeException("用户不存在不存在");
|
||||
}
|
||||
}
|
||||
// 钱包
|
||||
WalletManageEntity wallet = remoteWalletService.getWallet(dto.getUserId(), dto.getWalletType()).getData();
|
||||
if (ObjectUtil.isEmpty(wallet)) {
|
||||
throw new RuntimeException("用户钱包不存在");
|
||||
}
|
||||
Integer balance = wallet.getBalance();
|
||||
int totalPrice = dto.getPrice();
|
||||
if (balance < totalPrice) {
|
||||
throw new RuntimeException("钱包余额不足");
|
||||
WalletManageEntity wallet = null;
|
||||
if (ObjectUtil.isNotEmpty(dto.getWalletType())) {
|
||||
wallet = remoteWalletService.getWallet(dto.getUserId(), dto.getWalletType()).getData();
|
||||
if (ObjectUtil.isEmpty(wallet)) {
|
||||
throw new RuntimeException("用户钱包不存在");
|
||||
}
|
||||
Integer balance = wallet.getBalance();
|
||||
int totalPrice = dto.getPrice();
|
||||
if (balance < totalPrice) {
|
||||
throw new RuntimeException("钱包余额不足");
|
||||
}
|
||||
}
|
||||
String subject = "未知商品x?";
|
||||
HardPayTypeEnum hardPayType = HardXfjTypeEnum.getHardPayType(dto.getXfjPayType());
|
||||
@@ -1035,7 +1019,6 @@ public class HardOrderServiceImpl extends ServiceImpl<HardOrderMapper, HardOrder
|
||||
HardOrderEntity orderObj = HardOrderEntity.builder()
|
||||
.userId(dto.getUserId())
|
||||
.orderNo(dto.getOrderNo())
|
||||
.userDeptId(userDetail.getSysUser().getDeptId())
|
||||
.merchantId(mch.getId())
|
||||
.merchantType(mch.getTypes())
|
||||
.merchantDeptId(mch.getDeptId())
|
||||
@@ -1046,16 +1029,44 @@ public class HardOrderServiceImpl extends ServiceImpl<HardOrderMapper, HardOrder
|
||||
.orderType(HardOrderTypeEnum.XFJ.getType())
|
||||
.payType(hardPayType.getType())
|
||||
.orderSourceTypeId(null)
|
||||
.totalPrice(totalPrice)
|
||||
.totalPrice(dto.getPrice())
|
||||
.extraPrice(0)
|
||||
.payPrice(totalPrice)
|
||||
.payPrice(dto.getPrice())
|
||||
.isOfflineOrder(YesNoEnum.NO.getCode())
|
||||
.productDesc(subject)
|
||||
.build();
|
||||
orderObj.setWalletId(wallet.getId());
|
||||
if (ObjectUtil.isNotEmpty(wallet)) {
|
||||
orderObj.setWalletId(wallet.getId());
|
||||
}
|
||||
if (ObjectUtil.isNotEmpty(userDetail)) {
|
||||
orderObj.setUserDeptId(userDetail.getSysUser().getDeptId());
|
||||
} else {
|
||||
orderObj.setUserId(-1L);
|
||||
}
|
||||
baseMapper.insert(orderObj);
|
||||
// 钱包扣款
|
||||
getSelf().fastReduceBalance(orderObj);
|
||||
if (ObjectUtil.equals(dto.getPlatformType(), AppPlusPlatformTypeEnum.ZAX_APP_WALLET)) {
|
||||
getSelf().fastReduceBalance(orderObj);
|
||||
}
|
||||
// 微信、支付宝付款码支付
|
||||
else if (ObjectUtil.equals(dto.getPlatformType(), AppPlusPlatformTypeEnum.WECHAT) || ObjectUtil.equals(dto.getPlatformType(), AppPlusPlatformTypeEnum.ALI_PAY)) {
|
||||
ThirdMicropayDto remoterDto = new ThirdMicropayDto();
|
||||
remoterDto.setBizType(ThirdPayOrderBizTypeEnum.YXFJ_PAY);
|
||||
remoterDto.setBizId(String.valueOf(orderObj.getId()));
|
||||
remoterDto.setMiniPlatformType(dto.getPlatformType());
|
||||
remoterDto.setAmount(dto.getPrice());
|
||||
remoterDto.setUserId(dto.getUserId());
|
||||
remoterDto.setMchId(hard.getMerchantId());
|
||||
remoterDto.setDevicePayCode(dto.getDevicePayCode());
|
||||
R<String> micropayR = thirdAppPlusPayService.remoterMicropay(remoterDto);
|
||||
if (!micropayR.isOk()) {
|
||||
throw new RuntimeException("支付失败:" + micropayR.getMsg());
|
||||
}
|
||||
if (ObjectUtil.isEmpty(micropayR.getData())) {
|
||||
throw new RuntimeException("支付失败,未查询到订单号");
|
||||
}
|
||||
getSelf().orderSuccess(orderObj, Boolean.TRUE);
|
||||
}
|
||||
return orderObj.getId();
|
||||
}
|
||||
|
||||
@@ -1254,7 +1265,8 @@ public class HardOrderServiceImpl extends ServiceImpl<HardOrderMapper, HardOrder
|
||||
if (ObjectUtil.isEmpty(thirdOrder)) {
|
||||
log.error("|{}|智能柜订单结算,第三方免密订单不存在orderId|{}|", TAG, orderObj.getId());
|
||||
} else {
|
||||
boolean isPay = miniAlipayService.miPay(thirdOrder, totalPrice);
|
||||
boolean isPay = false;
|
||||
// miniAlipayService.miPay(thirdOrder, totalPrice);
|
||||
if (isPay) {
|
||||
// 更新订单状态
|
||||
getSelf().orderSuccess(dto, false);
|
||||
|
||||
-377
@@ -1,377 +0,0 @@
|
||||
package com.bsd.pjcloud.hard.service.impl.wechat;
|
||||
|
||||
|
||||
import cn.hutool.core.codec.Base64;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.RandomUtil;
|
||||
import cn.hutool.core.util.XmlUtil;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.bsd.pjcloud.hard.api.dto.wechat.*;
|
||||
import com.bsd.pjcloud.hard.api.vo.wechat.*;
|
||||
import com.bsd.pjcloud.hard.config.WechatPay;
|
||||
import com.bsd.pjcloud.hard.service.HardAfterSaleService;
|
||||
import com.bsd.pjcloud.hard.service.WechatPayService;
|
||||
import com.bsd.pjcloud.hard.utils.constant.WechantPayConstant;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.codec.digest.DigestUtils;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.http.HttpEntity;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.crypto.Cipher;
|
||||
import javax.crypto.spec.SecretKeySpec;
|
||||
import javax.net.ssl.*;
|
||||
import java.io.FileInputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.KeyStore;
|
||||
import java.security.SecureRandom;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
/**
|
||||
* 微信支付
|
||||
*/
|
||||
@Service
|
||||
@AllArgsConstructor
|
||||
@Slf4j
|
||||
public class WechatPayServiceImpl implements WechatPayService {
|
||||
|
||||
private final WechatPay wechatPay;
|
||||
|
||||
@Lazy
|
||||
private final HardAfterSaleService hardAfterSaleService;
|
||||
|
||||
/**
|
||||
* 生成微信支付签名
|
||||
*/
|
||||
public String generateSign(Map<String, Object> params) {
|
||||
String apiKey = wechatPay.getApiV2Key();
|
||||
Map<String, String> filtered = new TreeMap<>();
|
||||
for (Map.Entry<String, Object> entry : params.entrySet()) {
|
||||
if (ObjectUtil.isEmpty(entry.getValue()) || ObjectUtil.equals("sign", entry.getKey())) {
|
||||
continue;
|
||||
}
|
||||
filtered.put(entry.getKey(), String.valueOf(entry.getValue()));
|
||||
}
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (Map.Entry<String, String> entry : filtered.entrySet()) {
|
||||
sb.append(entry.getKey()).append("=").append(entry.getValue()).append("&");
|
||||
}
|
||||
sb.append("key=").append(apiKey);
|
||||
try {
|
||||
String sign = DigestUtils.md5Hex(String.valueOf(sb));
|
||||
return sign.toUpperCase();
|
||||
} catch (Exception e) {
|
||||
log.error("微信支付签名生成失败", e);
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
private WechantPayConstant.Api initApi(WechantPayConstant.Api api) {
|
||||
api.setBaseUrl(wechatPay.getBaseUrl());
|
||||
return api;
|
||||
}
|
||||
|
||||
private String getNonceStr() {
|
||||
int length = 32;
|
||||
return RandomUtil.randomString(length);
|
||||
}
|
||||
|
||||
private SSLSocketFactory createSSLSocketFactory() throws Exception {
|
||||
KeyStore keyStore = KeyStore.getInstance("PKCS12");
|
||||
FileInputStream certStream = new FileInputStream(wechatPay.getMerchantSerialPath());
|
||||
keyStore.load(certStream, wechatPay.getMerchantId().toCharArray());
|
||||
certStream.close();
|
||||
// 创建KeyManagerFactory
|
||||
KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
|
||||
keyManagerFactory.init(keyStore, wechatPay.getMerchantId().toCharArray());
|
||||
// 创建TrustManagerFactory(信任所有证书)
|
||||
TrustManager[] trustManagers = new TrustManager[]{
|
||||
new X509TrustManager() {
|
||||
public java.security.cert.X509Certificate[] getAcceptedIssuers() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void checkClientTrusted(java.security.cert.X509Certificate[] certs, String authType) {
|
||||
}
|
||||
|
||||
public void checkServerTrusted(java.security.cert.X509Certificate[] certs, String authType) {
|
||||
}
|
||||
}
|
||||
};
|
||||
// 创建SSLContext
|
||||
SSLContext sslContext = SSLContext.getInstance("TLS");
|
||||
sslContext.init(keyManagerFactory.getKeyManagers(), trustManagers, new SecureRandom());
|
||||
return sslContext.getSocketFactory();
|
||||
}
|
||||
|
||||
/**
|
||||
* 解密回调信息解密
|
||||
*/
|
||||
private WechantRefunCallbackVo decrypt(String xml) {
|
||||
try {
|
||||
WechantRefunCallbackSoureVo vo = JSONUtil.toBean(JSONUtil.toJsonStr(XmlUtil.xmlToMap(xml)), WechantRefunCallbackSoureVo.class);
|
||||
String reqInfo = vo.getReq_info();
|
||||
// 1 对加密串A做base64解码,得到加密串B
|
||||
byte[] encryptedBytes = Base64.decode(reqInfo);
|
||||
// 2 对商户key做md5,得到32位小写key
|
||||
String md5Key = DigestUtils.md5Hex(wechatPay.getApiV2Key()).toLowerCase();
|
||||
// 3. AES-256-ECB 解密
|
||||
SecretKeySpec secretKey = new SecretKeySpec(md5Key.getBytes(StandardCharsets.UTF_8), "AES");
|
||||
Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
|
||||
cipher.init(Cipher.DECRYPT_MODE, secretKey);
|
||||
byte[] decryptedBytes = cipher.doFinal(encryptedBytes);
|
||||
String json = new String(decryptedBytes, StandardCharsets.UTF_8);
|
||||
WechantRefunCallbackVo entity = JSONUtil.toBean(JSONUtil.toJsonStr(XmlUtil.xmlToMap(json)), WechantRefunCallbackVo.class);
|
||||
log.debug("解密回调信息,json|{}", JSONUtil.toJsonStr(entity));
|
||||
return entity;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
log.error("解密回调信息解密异常", e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 付款码支付
|
||||
*/
|
||||
@Override
|
||||
public WechatMicropayVo micropay(WechatMicropayDto dto) {
|
||||
try {
|
||||
Map<String, Object> params = new HashMap<>();
|
||||
// 公众账号ID
|
||||
params.put("appid", wechatPay.getAppId());
|
||||
// 商户号
|
||||
params.put("mch_id", wechatPay.getMerchantId());
|
||||
// 设备号-终端设备号(商户自定义,如门店编号)
|
||||
params.put("device_info", dto.getMerId());
|
||||
// 随机字符串
|
||||
params.put("nonce_str", getNonceStr());
|
||||
// 签名
|
||||
params.put("sign", "");
|
||||
// 签名类型
|
||||
params.put("sign_type", "MD5");
|
||||
// 商品描述
|
||||
params.put("body", "小铺故事超市-超市");
|
||||
// 商户单号
|
||||
params.put("out_trade_no", dto.getOrderId());
|
||||
// 订单金额(分)
|
||||
params.put("total_fee", dto.getPrice());
|
||||
// 终端IP
|
||||
params.put("spbill_create_ip", wechatPay.getSpbillCreateIp());
|
||||
// 付款码
|
||||
params.put("auth_code", dto.getWechatQrCode());
|
||||
// 生成签名
|
||||
params.put("sign", generateSign(params));
|
||||
WechantPayConstant.Api api = initApi(WechantPayConstant.APY);
|
||||
String res = api.getHttpRequest().body(XmlUtil.mapToXmlStr(params)).execute().body();
|
||||
log.debug("付款码支付,json,xml|{}", res);
|
||||
if (ObjectUtil.isEmpty(res)) {
|
||||
log.error("付款码支付,res为空");
|
||||
return null;
|
||||
}
|
||||
WechatMicropayVo vo = JSONUtil.toBean(JSONUtil.toJsonStr(XmlUtil.xmlToMap(res)), WechatMicropayVo.class);
|
||||
log.debug("付款码支付,json,res|{}", JSONUtil.toJsonStr(vo));
|
||||
if (!vo.isHttpSucess()) {
|
||||
return null;
|
||||
}
|
||||
return vo;
|
||||
} catch (Exception e) {
|
||||
log.error("付款码支付,异常", e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询订单
|
||||
*/
|
||||
@Override
|
||||
public WechatQueryVo query(WechatQueryDto dto) {
|
||||
try {
|
||||
Map<String, Object> params = new HashMap<>();
|
||||
// 公众账号ID
|
||||
params.put("appid", wechatPay.getAppId());
|
||||
// 商户号
|
||||
params.put("mch_id", wechatPay.getMerchantId());
|
||||
// 微信订单号
|
||||
params.put("transaction_id", dto.getWechantOrderId());
|
||||
// 商户订单号
|
||||
params.put("out_trade_no", dto.getOrderId());
|
||||
// 随机字符串
|
||||
params.put("nonce_str", getNonceStr());
|
||||
// 签名
|
||||
params.put("sign", "");
|
||||
// 签名类型
|
||||
params.put("sign_type", "MD5");
|
||||
// 生成签名
|
||||
params.put("sign", generateSign(params));
|
||||
WechantPayConstant.Api api = initApi(WechantPayConstant.QUERY);
|
||||
String res = api.getHttpRequest().body(XmlUtil.mapToXmlStr(params)).execute().body();
|
||||
log.debug("查询订单,json,xml|{}", res);
|
||||
if (ObjectUtil.isEmpty(res)) {
|
||||
log.error("查询订单,res为空");
|
||||
return null;
|
||||
}
|
||||
WechatQueryVo vo = JSONUtil.toBean(JSONUtil.toJsonStr(XmlUtil.xmlToMap(res)), WechatQueryVo.class);
|
||||
log.debug("查询订单,json,res|{}", JSONUtil.toJsonStr(vo));
|
||||
if (!vo.isHttpSucess()) {
|
||||
return null;
|
||||
}
|
||||
return vo;
|
||||
} catch (Exception e) {
|
||||
log.error("查询订单,异常", e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 撤销订单
|
||||
*/
|
||||
@Override
|
||||
public WechantReverseVo reverse(WechantReverseDto dto) {
|
||||
try {
|
||||
Map<String, Object> params = new HashMap<>();
|
||||
// 公众账号ID
|
||||
params.put("appid", wechatPay.getAppId());
|
||||
// 商户号
|
||||
params.put("mch_id", wechatPay.getMerchantId());
|
||||
// 微信订单号
|
||||
params.put("transaction_id", dto.getWechantOrderId());
|
||||
// 商户订单号
|
||||
params.put("out_trade_no", dto.getOrderId());
|
||||
// 随机字符串
|
||||
params.put("nonce_str", getNonceStr());
|
||||
// 签名
|
||||
params.put("sign", "");
|
||||
// 签名类型
|
||||
params.put("sign_type", "MD5");
|
||||
// 生成签名
|
||||
params.put("sign", generateSign(params));
|
||||
WechantPayConstant.Api api = initApi(WechantPayConstant.REVERSE);
|
||||
api.setSslSocketFactory(createSSLSocketFactory());
|
||||
String res = api.getHttpRequest().body(XmlUtil.mapToXmlStr(params)).execute().body();
|
||||
log.debug("撤销订单,json,xml|{}", res);
|
||||
if (ObjectUtil.isEmpty(res)) {
|
||||
log.error("撤销订单,res为空");
|
||||
return null;
|
||||
}
|
||||
WechantReverseVo vo = JSONUtil.toBean(JSONUtil.toJsonStr(XmlUtil.xmlToMap(res)), WechantReverseVo.class);
|
||||
log.debug("撤销订单,json,res|{}", JSONUtil.toJsonStr(vo));
|
||||
if (!vo.isHttpSucess()) {
|
||||
return null;
|
||||
}
|
||||
return vo;
|
||||
} catch (Exception e) {
|
||||
log.error("撤销订单,异常", e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 申请退款
|
||||
*/
|
||||
@Override
|
||||
public WechatRefundVo refund(WechatRefundDto dto) {
|
||||
try {
|
||||
Map<String, Object> params = new HashMap<>();
|
||||
// 公众账号ID
|
||||
params.put("appid", wechatPay.getAppId());
|
||||
// 商户号
|
||||
params.put("mch_id", wechatPay.getMerchantId());
|
||||
// 随机字符串
|
||||
params.put("nonce_str", getNonceStr());
|
||||
// 签名
|
||||
params.put("sign", "");
|
||||
// 签名类型
|
||||
params.put("sign_type", "MD5");
|
||||
// 微信支付订单号
|
||||
params.put("transaction_id", dto.getWechantOrderId());
|
||||
// 商户订单号
|
||||
params.put("out_trade_no", dto.getOrderId());
|
||||
// 商户退款单号
|
||||
params.put("out_refund_no", dto.getRefundId());
|
||||
// 订单金额
|
||||
params.put("total_fee", dto.getOrderPrice());
|
||||
// 退款金额
|
||||
params.put("refund_fee", dto.getRefundPrice());
|
||||
// 退款结果通知url
|
||||
params.put("notify_url", wechatPay.getRefundCallbackUrl());
|
||||
// 生成签名
|
||||
params.put("sign", generateSign(params));
|
||||
WechantPayConstant.Api api = initApi(WechantPayConstant.REFUND);
|
||||
api.setSslSocketFactory(createSSLSocketFactory());
|
||||
String res = api.getHttpRequest().body(XmlUtil.mapToXmlStr(params)).execute().body();
|
||||
log.debug("申请退款,json,xml|{}", res);
|
||||
if (ObjectUtil.isEmpty(res)) {
|
||||
log.error("申请退款,res为空");
|
||||
return null;
|
||||
}
|
||||
WechatRefundVo vo = JSONUtil.toBean(JSONUtil.toJsonStr(XmlUtil.xmlToMap(res)), WechatRefundVo.class);
|
||||
log.debug("申请退款,json,res|{}", JSONUtil.toJsonStr(vo));
|
||||
if (!vo.isHttpSucess()) {
|
||||
return null;
|
||||
}
|
||||
return vo;
|
||||
} catch (Exception e) {
|
||||
log.error("申请退款,异常", e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询退款
|
||||
*/
|
||||
@Override
|
||||
public WechatRefundQueryVo refundQuery(WechatRefundQueryDto dto) {
|
||||
try {
|
||||
Map<String, Object> params = new HashMap<>();
|
||||
// 公众账号ID
|
||||
params.put("appid", wechatPay.getAppId());
|
||||
// 商户号
|
||||
params.put("mch_id", wechatPay.getMerchantId());
|
||||
// 随机字符串
|
||||
params.put("nonce_str", getNonceStr());
|
||||
// 签名
|
||||
params.put("sign", "");
|
||||
// 签名类型
|
||||
params.put("sign_type", "MD5");
|
||||
// 签名类型
|
||||
params.put("out_refund_no", dto.getRefundId());
|
||||
// 生成签名
|
||||
params.put("sign", generateSign(params));
|
||||
WechantPayConstant.Api api = initApi(WechantPayConstant.REFUND_QUERY);
|
||||
String res = api.getHttpRequest().body(XmlUtil.mapToXmlStr(params)).execute().body();
|
||||
log.debug("查询退款,json,xml|{}", res);
|
||||
if (ObjectUtil.isEmpty(res)) {
|
||||
log.error("查询退款,res为空");
|
||||
return null;
|
||||
}
|
||||
WechatRefundQueryVo vo = JSONUtil.toBean(JSONUtil.toJsonStr(XmlUtil.xmlToMap(res)), WechatRefundQueryVo.class);
|
||||
log.debug("查询退款,json,res|{}", JSONUtil.toJsonStr(vo));
|
||||
if (!vo.isHttpSucess()) {
|
||||
return null;
|
||||
}
|
||||
return vo;
|
||||
} catch (Exception e) {
|
||||
log.error("查询退款,异常", e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 退款回调
|
||||
*/
|
||||
@Override
|
||||
public String refundCallback(HttpEntity<String> httpEntity, Map<String, String> headers) {
|
||||
String body = httpEntity.getBody();
|
||||
WechantRefunCallbackVo decrypt = decrypt(body);
|
||||
if (ObjectUtil.isEmpty(decrypt)) {
|
||||
// 告诉微信错误
|
||||
return WechantRefunCallbackVo.wechantError();
|
||||
}
|
||||
boolean isSuccess = hardAfterSaleService.wechatRefundCallback(decrypt);
|
||||
return isSuccess ? WechantRefunCallbackVo.wechantSuccess() : WechantRefunCallbackVo.wechantError();
|
||||
}
|
||||
}
|
||||
+50
-9
@@ -24,6 +24,7 @@ import com.bsd.pjcloud.hard.api.vo.order.HardOrderVo;
|
||||
import com.bsd.pjcloud.hard.api.vo.xfj.*;
|
||||
import com.bsd.pjcloud.hard.mapper.order.HardOrderMapper;
|
||||
import com.bsd.pjcloud.hard.service.*;
|
||||
import com.bsd.pjcloud.thirdparty.constant.miniplatform.AppPlusPlatformTypeEnum;
|
||||
import com.bsd.pjcloud.wallet.api.constant.WalletTypeEnum;
|
||||
import com.bsd.pjcloud.wallet.api.dto.WalletRemoteOpenCardListDto;
|
||||
import com.bsd.pjcloud.wallet.api.entity.WalletActiveEntity;
|
||||
@@ -46,6 +47,7 @@ import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Validated
|
||||
@@ -546,22 +548,41 @@ public class HardXfjServiceImpl implements HardXfjService {
|
||||
}
|
||||
// 扣费
|
||||
if (ObjectUtil.equals(dto.getMode(), "0")) {
|
||||
// 传过来的是`短码`需要解析一下
|
||||
WalletCodeUseEntity data = remoteCodeUseService.getInfoByShortCode(dto.getQR()).getData();
|
||||
if (ObjectUtil.isEmpty(data)) {
|
||||
result.setStatus(XfjBaseVo.STATUS_FAIL);
|
||||
result.setMsg("二维码错误");
|
||||
return result;
|
||||
// `QR`有三种可能性1、微信、支付宝、短码
|
||||
AppPlusPlatformTypeEnum platformType = judgeQrCode(dto.getQR());
|
||||
if (ObjectUtil.isEmpty(platformType)) {
|
||||
throw new RuntimeException("二维码解析错误");
|
||||
}
|
||||
Long userId = null;
|
||||
WalletTypeEnum walletType = null;
|
||||
HardXfjTypeEnum xfjPayType = HardXfjTypeEnum.QRCODE_PAY;
|
||||
if (ObjectUtil.equals(platformType, AppPlusPlatformTypeEnum.ZAX_APP_WALLET)) {
|
||||
walletType = WalletTypeEnum.EAT;
|
||||
// 传过来的是`短码`需要解析一下
|
||||
WalletCodeUseEntity data = remoteCodeUseService.getInfoByShortCode(dto.getQR()).getData();
|
||||
if (ObjectUtil.isEmpty(data)) {
|
||||
result.setStatus(XfjBaseVo.STATUS_FAIL);
|
||||
result.setMsg("二维码错误");
|
||||
return result;
|
||||
}
|
||||
userId = data.getUserId();
|
||||
} else if (ObjectUtil.equals(platformType, AppPlusPlatformTypeEnum.WECHAT)) {
|
||||
xfjPayType = HardXfjTypeEnum.WECHAT_QRCODE_PAY;
|
||||
} else if (ObjectUtil.equals(platformType, AppPlusPlatformTypeEnum.ALI_PAY)) {
|
||||
xfjPayType = HardXfjTypeEnum.ALI_QRCODE_PAY;
|
||||
}
|
||||
|
||||
// 解析金额
|
||||
int price = BigDecimal.valueOf(Double.valueOf(dto.getAmount())).multiply(BigDecimal.valueOf(100)).setScale(2, RoundingMode.HALF_UP).intValue();
|
||||
|
||||
HardXfjFastCreateOrderDto payDto = new HardXfjFastCreateOrderDto();
|
||||
payDto.setUserId(data.getUserId());
|
||||
payDto.setUserId(userId);
|
||||
payDto.setHardId(entity.getId());
|
||||
payDto.setPrice(price);
|
||||
payDto.setWalletType(WalletTypeEnum.EAT);
|
||||
payDto.setXfjPayType(HardXfjTypeEnum.QRCODE_PAY);
|
||||
payDto.setWalletType(walletType);
|
||||
payDto.setXfjPayType(xfjPayType);
|
||||
payDto.setPlatformType(platformType);
|
||||
payDto.setDevicePayCode(dto.getQR());
|
||||
Long orderId = hardOrderService.xfjFastCreateOrder(payDto);
|
||||
result.setQrorder(String.valueOf(orderId));
|
||||
return result;
|
||||
@@ -792,4 +813,24 @@ public class HardXfjServiceImpl implements HardXfjService {
|
||||
return String.format("%s|%s|%s", serialNumber, carNumber, operationType);
|
||||
}
|
||||
|
||||
private AppPlusPlatformTypeEnum judgeQrCode(String qrCode) {
|
||||
String qrCodePrefix = qrCode.substring(0, 2);
|
||||
int qrCodeLength = qrCode.length();
|
||||
|
||||
// 支付宝`qrCode`18位纯数字,前缀以"25"到"29"或者 "30"开头
|
||||
if (qrCodeLength == 18 && Pattern.compile("^(2[5-9]|30)").matcher(qrCode).find()) {
|
||||
return AppPlusPlatformTypeEnum.ALI_PAY;
|
||||
}
|
||||
// 微信`qrCode`18位纯数字,前缀以10、11、12、13、14、15开头
|
||||
else if (qrCodeLength == 18 && List.of("10", "11", "12", "13", "14", "15").contains(qrCodePrefix)) {
|
||||
return AppPlusPlatformTypeEnum.WECHAT;
|
||||
}
|
||||
// 钱包二维码
|
||||
else if (qrCodeLength == 32) {
|
||||
return AppPlusPlatformTypeEnum.ZAX_APP_WALLET;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+9
-1
@@ -3,6 +3,7 @@ package com.bsd.pjcloud.thirdparty.api.feign;
|
||||
import com.bsd.pjcloud.common.core.constant.ServiceNameConstants;
|
||||
import com.bsd.pjcloud.common.core.util.R;
|
||||
import com.bsd.pjcloud.common.feign.annotation.NoToken;
|
||||
import com.bsd.pjcloud.thirdparty.dto.appplus.ThirdMicropayDto;
|
||||
import com.bsd.pjcloud.wallet.api.entity.mch.MchManageEntity;
|
||||
import com.bsd.pjcloud.wallet.api.vo.MchManageVo;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
@@ -17,7 +18,14 @@ public interface RemoterThirdAppPlusPayService {
|
||||
* 编辑商户的回调
|
||||
*/
|
||||
@NoToken
|
||||
@PostMapping("/remoter/change-mch")
|
||||
@PostMapping("/pay-remoter/change-mch")
|
||||
R<Boolean> remoterChangeMch(@RequestBody MchManageVo dto);
|
||||
|
||||
/**
|
||||
* 付款码支付
|
||||
*/
|
||||
@NoToken
|
||||
@PostMapping("/pay-remoter/micropay")
|
||||
R<String> remoterMicropay(@RequestBody ThirdMicropayDto dto);
|
||||
|
||||
}
|
||||
+1
@@ -15,6 +15,7 @@ public enum AppPlusPlatformTypeEnum {
|
||||
|
||||
WECHAT("10", "微信"),
|
||||
ALI_PAY("20", "支付宝"),
|
||||
ZAX_APP_WALLET("30", "资安信-钱包"),
|
||||
;
|
||||
|
||||
private final String type;
|
||||
|
||||
+2
-1
@@ -13,7 +13,8 @@ import java.util.Arrays;
|
||||
@Getter
|
||||
public enum ThirdPayOrderBizTypeEnum {
|
||||
|
||||
MINI_APP_WALLET_RECHARGE("10", "小程序用户钱包充值"),
|
||||
MINI_APP_RECHARGE("10", "小程序用户钱包充值"),
|
||||
YXFJ_PAY("20", "云消费机付款码支付"),
|
||||
;
|
||||
|
||||
private final String type;
|
||||
|
||||
+55
@@ -0,0 +1,55 @@
|
||||
package com.bsd.pjcloud.thirdparty.dto.appplus;
|
||||
|
||||
import com.bsd.pjcloud.thirdparty.constant.miniplatform.AppPlusPlatformTypeEnum;
|
||||
import com.bsd.pjcloud.thirdparty.constant.pay.ThirdPayOrderBizTypeEnum;
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class ThirdMicropayDto {
|
||||
|
||||
/**
|
||||
* 充值业务类型
|
||||
*/
|
||||
@NotNull(message = "充值业务类型不能为空")
|
||||
private ThirdPayOrderBizTypeEnum bizType;
|
||||
|
||||
/**
|
||||
* 充值业务id
|
||||
*/
|
||||
@NotEmpty(message = "充值业务id不能为空")
|
||||
private String bizId;
|
||||
|
||||
/**
|
||||
* 平台
|
||||
*/
|
||||
@NotNull(message = "小程序平台标识不能为空")
|
||||
private AppPlusPlatformTypeEnum miniPlatformType;
|
||||
|
||||
/**
|
||||
* 金额(分)
|
||||
*/
|
||||
private Integer amount;
|
||||
|
||||
/**
|
||||
* 用户id
|
||||
*/
|
||||
private Long userId;
|
||||
|
||||
/**
|
||||
* 用户商户id
|
||||
*/
|
||||
private Long mchId;
|
||||
|
||||
/**
|
||||
* 用户唯一标识
|
||||
*/
|
||||
private String openId;
|
||||
|
||||
/**
|
||||
* 付款码支付code
|
||||
*/
|
||||
private String devicePayCode;
|
||||
|
||||
}
|
||||
+1
-1
@@ -22,7 +22,7 @@ public class ThirdMiniAppPayDto {
|
||||
private String bizId;
|
||||
|
||||
/**
|
||||
* 小程序平台
|
||||
* 平台
|
||||
*/
|
||||
@NotNull(message = "小程序平台标识不能为空")
|
||||
private AppPlusPlatformTypeEnum miniPlatformType;
|
||||
|
||||
+5
@@ -46,4 +46,9 @@ public class ThirdAppPlusPayDto {
|
||||
*/
|
||||
private Integer amount;
|
||||
|
||||
/**
|
||||
* 付款码支付code
|
||||
*/
|
||||
private String devicePayCode;
|
||||
|
||||
}
|
||||
@@ -43,6 +43,13 @@
|
||||
<version>1.1.3</version>
|
||||
</dependency>
|
||||
|
||||
<!--微信支付v2(微信付款码支付只支持v2)-->
|
||||
<dependency>
|
||||
<groupId>com.github.binarywang</groupId>
|
||||
<artifactId>weixin-java-pay</artifactId>
|
||||
<version>4.8.0</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.bsd</groupId>
|
||||
<artifactId>pjcloud-upms-api</artifactId>
|
||||
|
||||
+19
@@ -86,8 +86,27 @@ public class AppPlusPayConfig {
|
||||
*/
|
||||
private String baseUrl;
|
||||
|
||||
/**
|
||||
* 微信支付v2配置
|
||||
*/
|
||||
private WechatV2Config v2Config;
|
||||
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class WechatV2Config {
|
||||
|
||||
/**
|
||||
* 商户密钥
|
||||
*/
|
||||
private String mchKey;
|
||||
|
||||
/**
|
||||
* apiclient_cert.p12证书路径
|
||||
*/
|
||||
private String keyPath;
|
||||
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class AliPayConfig {
|
||||
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
package com.bsd.pjcloud.thirdparty.config.initconfig;
|
||||
|
||||
import com.bsd.pjcloud.thirdparty.config.AppPlusPayConfig;
|
||||
import com.github.binarywang.wxpay.config.WxPayConfig;
|
||||
import com.github.binarywang.wxpay.service.BusinessOperationTransferService;
|
||||
import com.github.binarywang.wxpay.service.WxPayService;
|
||||
import com.github.binarywang.wxpay.service.impl.WxPayServiceImpl;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Slf4j
|
||||
@Configuration
|
||||
public class WechatV2Configuration {
|
||||
|
||||
private final AppPlusPayConfig properties;
|
||||
|
||||
@Autowired
|
||||
public WechatV2Configuration(AppPlusPayConfig properties) {
|
||||
this.properties = properties;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public WxPayService wxPayService() {
|
||||
AppPlusPayConfig.WechatConfig wechatConfig = properties.getWechatConfig();
|
||||
|
||||
WxPayConfig wxPayConfig = new WxPayConfig();
|
||||
wxPayConfig.setAppId(wechatConfig.getAppPlatformAppId());
|
||||
wxPayConfig.setMchId(wechatConfig.getMerchantId());
|
||||
wxPayConfig.setMchKey(wechatConfig.getV2Config().getMchKey());
|
||||
wxPayConfig.setKeyPath(wechatConfig.getV2Config().getKeyPath());
|
||||
|
||||
// 初始化服务
|
||||
WxPayService wxPayService = new WxPayServiceImpl();
|
||||
wxPayService.setConfig(wxPayConfig);
|
||||
return wxPayService;
|
||||
}
|
||||
|
||||
}
|
||||
+3
-7
@@ -7,14 +7,9 @@ import cn.binarywang.wx.miniapp.config.impl.WxMaDefaultConfigImpl;
|
||||
import com.bsd.pjcloud.thirdparty.config.AppPlusPayConfig;
|
||||
import com.wechat.pay.java.core.Config;
|
||||
import com.wechat.pay.java.core.RSAAutoCertificateConfig;
|
||||
import com.wechat.pay.java.core.RSAPublicKeyConfig;
|
||||
import com.wechat.pay.java.core.notification.NotificationConfig;
|
||||
import com.wechat.pay.java.core.notification.NotificationParser;
|
||||
import com.wechat.pay.java.core.notification.RSAPublicKeyNotificationConfig;
|
||||
import com.wechat.pay.java.service.partnerpayments.app.AppService;
|
||||
import com.wechat.pay.java.service.partnerpayments.app.AppServiceExtension;
|
||||
import com.wechat.pay.java.service.partnerpayments.jsapi.JsapiServiceExtension;
|
||||
import com.wechat.pay.java.service.partnerpayments.nativepay.NativePayService;
|
||||
import com.wechat.pay.java.service.profitsharing.ProfitsharingService;
|
||||
import com.wechat.pay.java.service.refund.RefundService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -24,12 +19,12 @@ import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Slf4j
|
||||
@Configuration
|
||||
public class WechatConfiguration {
|
||||
public class WechatV3Configuration {
|
||||
|
||||
private final AppPlusPayConfig properties;
|
||||
|
||||
@Autowired
|
||||
public WechatConfiguration(AppPlusPayConfig properties) {
|
||||
public WechatV3Configuration(AppPlusPayConfig properties) {
|
||||
this.properties = properties;
|
||||
}
|
||||
|
||||
@@ -72,6 +67,7 @@ public class WechatConfiguration {
|
||||
return new NotificationParser(config);
|
||||
}
|
||||
|
||||
// 退款
|
||||
@Bean
|
||||
public RefundService refundService() {
|
||||
AppPlusPayConfig.WechatConfig wechatConfig = properties.getWechatConfig();
|
||||
+19
-5
@@ -5,7 +5,9 @@ import cn.hutool.json.JSONUtil;
|
||||
import com.bsd.pjcloud.common.core.util.R;
|
||||
import com.bsd.pjcloud.common.security.annotation.Inner;
|
||||
import com.bsd.pjcloud.thirdparty.constant.miniplatform.AppPlusPlatformPayType;
|
||||
import com.bsd.pjcloud.thirdparty.dto.appplus.ThirdMicropayDto;
|
||||
import com.bsd.pjcloud.thirdparty.dto.appplus.pay.wechat.ThirdMiniWechatRefundDto;
|
||||
import com.bsd.pjcloud.thirdparty.service.ThirdAppPlusService;
|
||||
import com.bsd.pjcloud.thirdparty.service.ThirdAppPlusWechatFzService;
|
||||
import com.bsd.pjcloud.thirdparty.vo.appplus.pay.ThirdMiniAppPayVo;
|
||||
import com.bsd.pjcloud.wallet.api.dto.WalletManageDto;
|
||||
@@ -28,14 +30,26 @@ import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
@RequestMapping("/remoter")
|
||||
@Tag(description = "remoter", name = "小程序支付")
|
||||
@RequestMapping("/pay-remoter")
|
||||
@Tag(description = "remoter", name = "支付")
|
||||
@SecurityRequirement(name = HttpHeaders.AUTHORIZATION)
|
||||
public class ThirdAppPlusController {
|
||||
|
||||
private final ThirdAppPlusWechatFzService appPlusWechatFzService;
|
||||
private final ThirdAppPlusWechatFzService thirdAppPlusWechatFzService;
|
||||
private final ThirdAppPlusService thirdAppPlusService;
|
||||
|
||||
@Operation(summary = "支付退款")
|
||||
/* ************************************* start 远程调用 start ************************************* */
|
||||
|
||||
@Operation(summary = "付款码支付")
|
||||
@PostMapping("/micropay")
|
||||
@Inner
|
||||
public R<String> remoterMicropay(@RequestBody ThirdMicropayDto dto) {
|
||||
return R.ok(thirdAppPlusService.micropay(dto));
|
||||
}
|
||||
|
||||
/* ************************************* end 远程调用 end ************************************* */
|
||||
|
||||
@Operation(summary = "商户改动")
|
||||
@PostMapping("/change-mch")
|
||||
@Inner
|
||||
public R<Boolean> remoterChangeMch(@RequestBody MchManageVo dto) {
|
||||
@@ -46,7 +60,7 @@ public class ThirdAppPlusController {
|
||||
if (ObjectUtil.equals(v.getPlatformType(), AppPlusPlatformPayType.WECHAT.getType())) {
|
||||
MchPaySettingEntity.WechatPaySetting jsonSetting = JSONUtil.toBean(v.getSettingJson(), MchPaySettingEntity.WechatPaySetting.class);
|
||||
if (ObjectUtil.isNotEmpty(jsonSetting)) {
|
||||
appPlusWechatFzService.addReceiver(jsonSetting.getSubMchid());
|
||||
thirdAppPlusWechatFzService.addReceiver(jsonSetting.getSubMchid());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+6
@@ -1,5 +1,6 @@
|
||||
package com.bsd.pjcloud.thirdparty.service;
|
||||
|
||||
import com.bsd.pjcloud.thirdparty.dto.appplus.ThirdMicropayDto;
|
||||
import com.bsd.pjcloud.thirdparty.dto.appplus.ThirdMiniAppGetUniqueDto;
|
||||
import com.bsd.pjcloud.thirdparty.dto.appplus.ThirdMiniAppOAth2LoginDto;
|
||||
import com.bsd.pjcloud.thirdparty.dto.appplus.ThirdMiniAppPayDto;
|
||||
@@ -33,6 +34,11 @@ public interface ThirdAppPlusService {
|
||||
*/
|
||||
ThirdMiniAppPayVo miniPay(Long userId, ThirdMiniAppPayDto dto);
|
||||
|
||||
/**
|
||||
* 付款码支付
|
||||
*/
|
||||
String micropay(ThirdMicropayDto dto );
|
||||
|
||||
/**
|
||||
* 小程序退款
|
||||
*/
|
||||
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
package com.bsd.pjcloud.thirdparty.service;
|
||||
|
||||
|
||||
import com.bsd.pjcloud.thirdparty.dto.appplus.pay.wechat.ThirdAppPlusPayDto;
|
||||
import com.bsd.pjcloud.thirdparty.entity.pay.ThirdPayOrderEntity;
|
||||
import com.bsd.pjcloud.wallet.api.vo.mch.MchPaySettingVo;
|
||||
import com.github.binarywang.wxpay.bean.result.WxPayMicropayResult;
|
||||
|
||||
/**
|
||||
* 微信付款码支付(只支持v2,所以单独写一个服务)
|
||||
*/
|
||||
public interface ThirdAppPlusWechatMicropayService {
|
||||
|
||||
/**
|
||||
* 付款码支付
|
||||
*/
|
||||
WxPayMicropayResult micropay(ThirdAppPlusPayDto dto, MchPaySettingVo setting);
|
||||
|
||||
/**
|
||||
* 撤销订单
|
||||
*/
|
||||
Object reverse(ThirdPayOrderEntity payOrder);
|
||||
|
||||
}
|
||||
+83
-5
@@ -4,7 +4,6 @@ import cn.binarywang.wx.miniapp.bean.WxMaPhoneNumberInfo;
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.RandomUtil;
|
||||
import cn.hutool.core.util.XmlUtil;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.alipay.api.internal.util.AlipaySignature;
|
||||
import com.alipay.api.response.AlipayTradeQueryResponse;
|
||||
@@ -16,7 +15,6 @@ import com.bsd.pjcloud.app.api.constant.AppUserTypeEnum;
|
||||
import com.bsd.pjcloud.app.api.dto.AppAdminSyncDto;
|
||||
import com.bsd.pjcloud.app.api.dto.AppUserInfo;
|
||||
import com.bsd.pjcloud.app.api.feign.RemoteAppUserService;
|
||||
import com.bsd.pjcloud.common.core.constant.enums.MerchantTypeEnum;
|
||||
import com.bsd.pjcloud.common.core.constant.enums.YesNoEnum;
|
||||
import com.bsd.pjcloud.thirdparty.config.AppPlusPayConfig;
|
||||
import com.bsd.pjcloud.thirdparty.constant.miniplatform.AppPlusPlatformLoginErrorEnum;
|
||||
@@ -24,6 +22,7 @@ import com.bsd.pjcloud.thirdparty.constant.miniplatform.AppPlusPlatformPayType;
|
||||
import com.bsd.pjcloud.thirdparty.constant.miniplatform.AppPlusPlatformTypeEnum;
|
||||
import com.bsd.pjcloud.thirdparty.constant.pay.ThirdPayOrderBizTypeEnum;
|
||||
import com.bsd.pjcloud.thirdparty.constant.pay.ThirdPayOrderStatusEnum;
|
||||
import com.bsd.pjcloud.thirdparty.dto.appplus.ThirdMicropayDto;
|
||||
import com.bsd.pjcloud.thirdparty.dto.appplus.ThirdMiniAppGetUniqueDto;
|
||||
import com.bsd.pjcloud.thirdparty.dto.appplus.ThirdMiniAppOAth2LoginDto;
|
||||
import com.bsd.pjcloud.thirdparty.dto.appplus.ThirdMiniAppPayDto;
|
||||
@@ -44,6 +43,7 @@ import com.bsd.pjcloud.wallet.api.feign.RemoteMchService;
|
||||
import com.bsd.pjcloud.wallet.api.feign.RemoteWalletRechargePackageService;
|
||||
import com.bsd.pjcloud.wallet.api.vo.MchManageVo;
|
||||
import com.bsd.pjcloud.wallet.api.vo.mch.MchPaySettingVo;
|
||||
import com.github.binarywang.wxpay.bean.result.WxPayMicropayResult;
|
||||
import com.wechat.pay.java.service.partnerpayments.app.model.Transaction;
|
||||
import com.wechat.pay.java.service.refund.model.RefundNotification;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
@@ -70,6 +70,7 @@ public class ThirdAppPlusServiceImpl implements ThirdAppPlusService {
|
||||
|
||||
private final AppPlusPayConfig appPlusPayConfig;
|
||||
private final ThirdAppPlusWechatService thirdMiniAppWechatService;
|
||||
private final ThirdAppPlusWechatMicropayService thirdAppPlusWechatMicropayService;
|
||||
private final ThirdAppPlusAliPayService thirdMiniAppAliPayService;
|
||||
private final ThirdPayLogService thirdPayLogService;
|
||||
private final ThirdPayOrderService thirdPayOrderService;
|
||||
@@ -193,7 +194,7 @@ public class ThirdAppPlusServiceImpl implements ThirdAppPlusService {
|
||||
|
||||
List<MchPaySettingVo> paySettingList = mchManage.getPaySettingList();
|
||||
|
||||
if (ObjectUtil.equals(dto.getBizType(), ThirdPayOrderBizTypeEnum.MINI_APP_WALLET_RECHARGE)) {
|
||||
if (ObjectUtil.equals(dto.getBizType(), ThirdPayOrderBizTypeEnum.MINI_APP_RECHARGE)) {
|
||||
|
||||
Long bizId = null;
|
||||
try {
|
||||
@@ -251,8 +252,8 @@ public class ThirdAppPlusServiceImpl implements ThirdAppPlusService {
|
||||
if (ObjectUtil.isEmpty(paySetting)) {
|
||||
throw new RuntimeException("商户未配置微信支付参数");
|
||||
}
|
||||
MchPaySettingEntity.AliPaySetting wechatPaySetting = JSONUtil.toBean(paySetting.getSettingJson(), MchPaySettingEntity.AliPaySetting.class);
|
||||
appPlusPayDto.setSubMchid(wechatPaySetting.getSubMchid());
|
||||
MchPaySettingEntity.AliPaySetting aliPaySetting = JSONUtil.toBean(paySetting.getSettingJson(), MchPaySettingEntity.AliPaySetting.class);
|
||||
appPlusPayDto.setSubMchid(aliPaySetting.getSubMchid());
|
||||
|
||||
String orderStr = thirdMiniAppAliPayService.appPay(appPlusPayDto, paySetting);
|
||||
if (ObjectUtil.isEmpty(orderStr)) {
|
||||
@@ -272,6 +273,83 @@ public class ThirdAppPlusServiceImpl implements ThirdAppPlusService {
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 付款码支付
|
||||
*/
|
||||
@Override
|
||||
public String micropay(ThirdMicropayDto dto) {
|
||||
MchManageVo mchManage = null;
|
||||
// 查询用户属于的商户
|
||||
if (ObjectUtil.equals(dto.getMiniPlatformType(), AppPlusPlatformTypeEnum.ZAX_APP_WALLET)) {
|
||||
UserInfo userInfo = remoteUserService.getByUserId(dto.getUserId()).getData();
|
||||
if (ObjectUtil.isEmpty(userInfo)) {
|
||||
throw new RuntimeException("用户不存在");
|
||||
}
|
||||
mchManage = remoteMchService.getViewsCanteenMchByDeptId(userInfo.getSysUser().getDeptId()).getData();
|
||||
} else {
|
||||
mchManage = remoteMchService.getById(dto.getMchId()).getData();
|
||||
}
|
||||
if (ObjectUtil.isEmpty(mchManage)) {
|
||||
throw new RuntimeException("用户不属于任何食堂");
|
||||
}
|
||||
if (ObjectUtil.isEmpty(mchManage.getPaySettingList())) {
|
||||
throw new RuntimeException("商户未配置支付参数");
|
||||
}
|
||||
|
||||
List<MchPaySettingVo> paySettingList = mchManage.getPaySettingList();
|
||||
if (ObjectUtil.equals(dto.getBizType(), ThirdPayOrderBizTypeEnum.YXFJ_PAY)) {
|
||||
|
||||
}
|
||||
// 不支持的类型
|
||||
else {
|
||||
throw new RuntimeException("不支持的支付类型");
|
||||
}
|
||||
|
||||
ThirdAppPlusPayDto appPlusPayDto = new ThirdAppPlusPayDto();
|
||||
// 当前时间戳+10位随机字符串
|
||||
String outTradeNo = LocalDateTime.now().atZone(ZoneId.systemDefault()).toInstant().toEpochMilli() + RandomUtil.randomString(10);
|
||||
appPlusPayDto.setOutTradeNo(outTradeNo);
|
||||
appPlusPayDto.setBizId(dto.getBizId());
|
||||
appPlusPayDto.setBizType(dto.getBizType());
|
||||
appPlusPayDto.setUserId(dto.getUserId());
|
||||
appPlusPayDto.setOpenid(dto.getOpenId());
|
||||
appPlusPayDto.setAmount(dto.getAmount());
|
||||
appPlusPayDto.setMchId(mchManage.getId());
|
||||
appPlusPayDto.setDevicePayCode(dto.getDevicePayCode());
|
||||
if (ObjectUtil.isEmpty(appPlusPayDto.getUserId())) {
|
||||
appPlusPayDto.setUserId(-1L);
|
||||
}
|
||||
|
||||
// 微信
|
||||
if (ObjectUtil.equals(dto.getMiniPlatformType().getType(), AppPlusPlatformTypeEnum.WECHAT.getType())) {
|
||||
MchPaySettingVo paySetting = paySettingList.stream().filter(item -> ObjectUtil.equals(item.getPlatformType(), AppPlusPlatformPayType.WECHAT.getType())).findFirst().orElse(null);
|
||||
if (ObjectUtil.isEmpty(paySetting) || ObjectUtil.isEmpty(paySetting.getSettingJson())) {
|
||||
throw new RuntimeException("商户未配置微信支付参数");
|
||||
}
|
||||
MchPaySettingEntity.WechatPaySetting wechatPaySetting = JSONUtil.toBean(paySetting.getSettingJson(), MchPaySettingEntity.WechatPaySetting.class);
|
||||
appPlusPayDto.setSubMchid(wechatPaySetting.getSubMchid());
|
||||
|
||||
WxPayMicropayResult micropay = thirdAppPlusWechatMicropayService.micropay(appPlusPayDto, paySetting);
|
||||
if (ObjectUtil.isNotEmpty(micropay)) {
|
||||
return micropay.getOutTradeNo();
|
||||
}
|
||||
}
|
||||
// 支付宝
|
||||
else if (ObjectUtil.equals(dto.getMiniPlatformType().getType(), AppPlusPlatformTypeEnum.ALI_PAY.getType())) {
|
||||
MchPaySettingVo paySetting = paySettingList.stream().filter(item -> ObjectUtil.equals(item.getPlatformType(), AppPlusPlatformPayType.ALI_PAY.getType())).findFirst().orElse(null);
|
||||
if (ObjectUtil.isEmpty(paySetting)) {
|
||||
throw new RuntimeException("商户未配置微信支付参数");
|
||||
}
|
||||
MchPaySettingEntity.AliPaySetting aliPaySetting = JSONUtil.toBean(paySetting.getSettingJson(), MchPaySettingEntity.AliPaySetting.class);
|
||||
appPlusPayDto.setSubMchid(aliPaySetting.getSubMchid());
|
||||
}
|
||||
// 不支持的支付类型
|
||||
else {
|
||||
throw new RuntimeException("不支持的支付类型");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 小程序退款
|
||||
*/
|
||||
|
||||
+163
@@ -0,0 +1,163 @@
|
||||
package com.bsd.pjcloud.thirdparty.service.impl.appplus;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.RandomUtil;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.bsd.pjcloud.common.core.constant.enums.YesNoEnum;
|
||||
import com.bsd.pjcloud.thirdparty.config.AppPlusPayConfig;
|
||||
import com.bsd.pjcloud.thirdparty.constant.miniplatform.AppPlusPlatformTypeEnum;
|
||||
import com.bsd.pjcloud.thirdparty.constant.pay.ThirdPayOrderStatusEnum;
|
||||
import com.bsd.pjcloud.thirdparty.dto.appplus.pay.wechat.ThirdAppPlusPayDto;
|
||||
import com.bsd.pjcloud.thirdparty.entity.pay.ThirdPayOrderEntity;
|
||||
import com.bsd.pjcloud.thirdparty.service.ThirdAppPlusWechatMicropayService;
|
||||
import com.bsd.pjcloud.thirdparty.service.ThirdPayOrderService;
|
||||
import com.bsd.pjcloud.thirdparty.service.impl.appplus.fz.lifecycle.ThirdAppPlusWechatFzLifecycle;
|
||||
import com.bsd.pjcloud.thirdparty.utils.pay.PayForUtil;
|
||||
import com.bsd.pjcloud.wallet.api.entity.mch.MchPaySettingEntity;
|
||||
import com.bsd.pjcloud.wallet.api.vo.mch.MchPaySettingVo;
|
||||
import com.github.binarywang.wxpay.bean.request.WxPayMicropayRequest;
|
||||
import com.github.binarywang.wxpay.bean.request.WxPayOrderReverseRequest;
|
||||
import com.github.binarywang.wxpay.bean.result.WxPayMicropayResult;
|
||||
import com.github.binarywang.wxpay.bean.result.WxPayOrderReverseResult;
|
||||
import com.github.binarywang.wxpay.service.WxPayService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
/**
|
||||
* 微信付款码支付(只支持v2,所以单独写一个服务)
|
||||
*/
|
||||
@Service
|
||||
@Validated
|
||||
@Slf4j
|
||||
@RequiredArgsConstructor
|
||||
public class ThirdAppPlusWechatMicropayServiceImpl implements ThirdAppPlusWechatMicropayService {
|
||||
|
||||
private final String TAG = "维修付款码支付";
|
||||
|
||||
private final AppPlusPayConfig appPlusPayConfig;
|
||||
|
||||
private final ThirdPayOrderService thirdPayOrderService;
|
||||
|
||||
private final WxPayService wxPayService;
|
||||
|
||||
private final ThirdAppPlusWechatFzLifecycle appPlusWechatFzLifecycle;
|
||||
|
||||
private static final ExecutorService executorService = Executors.newFixedThreadPool(10);
|
||||
|
||||
/**
|
||||
* 付款码支付
|
||||
*/
|
||||
@Override
|
||||
public WxPayMicropayResult micropay(ThirdAppPlusPayDto dto, MchPaySettingVo setting) {
|
||||
AppPlusPayConfig.WechatConfig wechatConfig = appPlusPayConfig.getWechatConfig();
|
||||
|
||||
ThirdPayOrderEntity payOrder = new ThirdPayOrderEntity();
|
||||
payOrder.setPayPlatformType(AppPlusPlatformTypeEnum.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());
|
||||
payOrder.setPayNo(dto.getOutTradeNo());
|
||||
payOrder.setMchId(dto.getMchId());
|
||||
payOrder.setMchPaySettingJson(JSONUtil.toJsonStr(setting));
|
||||
payOrder.setEnableFz(YesNoEnum.YES.getCode());
|
||||
payOrder.setIsBizCallback(YesNoEnum.YES.getCode());
|
||||
|
||||
WxPayMicropayRequest request = new WxPayMicropayRequest();
|
||||
request.setAppid(wechatConfig.getAppPlatformAppId());
|
||||
request.setMchId(wechatConfig.getMerchantId());
|
||||
request.setSubMchId(dto.getSubMchid());
|
||||
request.setNonceStr(RandomUtil.randomString(32));
|
||||
request.setSign("");
|
||||
request.setBody("资安信-付款码支付");
|
||||
request.setOutTradeNo(dto.getOutTradeNo());
|
||||
request.setTotalFee(dto.getAmount());
|
||||
request.setSpbillCreateIp(PayForUtil.localIp());
|
||||
request.setAuthCode(dto.getDevicePayCode());
|
||||
request.setProfitSharing("Y");
|
||||
|
||||
try {
|
||||
payOrder.setPayRep(JSONUtil.toJsonStr(request));
|
||||
|
||||
WxPayMicropayResult res = wxPayService.micropay(request);
|
||||
payOrder.setPayTime(LocalDateTime.now());
|
||||
payOrder.setPayRes(JSONUtil.toJsonStr(res));
|
||||
|
||||
if (ObjectUtil.equals(res.getResultCode(), "SUCCESS") && ObjectUtil.equals(res.getReturnCode(), "SUCCESS")) {
|
||||
payOrder.setStatus(ThirdPayOrderStatusEnum.PAY_SUCCESS.getType());
|
||||
payOrder.setThirdPayNo(res.getTransactionId());
|
||||
}
|
||||
// 如果支付失败了就撤销订单
|
||||
else {
|
||||
payOrder.setStatus(ThirdPayOrderStatusEnum.PAY_FAILED.getType());
|
||||
reverse(payOrder);
|
||||
}
|
||||
return res;
|
||||
} catch (Exception e) {
|
||||
payOrder.setStatus(ThirdPayOrderStatusEnum.PAY_FAILED.getType());
|
||||
e.printStackTrace();
|
||||
log.error("|{}|付款码支付,意外的错误,异常:{}", TAG, e.getMessage(), e);
|
||||
return null;
|
||||
} finally {
|
||||
thirdPayOrderService.save(payOrder);
|
||||
// 订单支付成功
|
||||
CompletableFuture.runAsync(() -> {
|
||||
try {
|
||||
if (ObjectUtil.notEqual(payOrder.getStatus(), ThirdPayOrderStatusEnum.PAY_SUCCESS.getType())) {
|
||||
return;
|
||||
}
|
||||
Thread.sleep(30000);
|
||||
appPlusWechatFzLifecycle.orderPaySuccess(thirdPayOrderService.getById(payOrder.getId()));
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
log.error("|{}|延迟调用orderPaySuccess被中断", TAG, e);
|
||||
} catch (Exception e) {
|
||||
log.error("|{}|延迟调用orderPaySuccess异常", TAG, e);
|
||||
}
|
||||
}, executorService);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 撤销订单
|
||||
*/
|
||||
@Override
|
||||
public Object reverse(ThirdPayOrderEntity payOrder) {
|
||||
AppPlusPayConfig.WechatConfig wechatConfig = appPlusPayConfig.getWechatConfig();
|
||||
|
||||
if (ObjectUtil.isEmpty(payOrder.getMchPaySettingJson())) {
|
||||
throw new RuntimeException("支付配置不存在");
|
||||
}
|
||||
MchPaySettingEntity wechatPaySettingEntity = JSONUtil.toBean(payOrder.getMchPaySettingJson(), MchPaySettingEntity.class);
|
||||
MchPaySettingEntity.WechatPaySetting wechatPaySetting = JSONUtil.toBean(wechatPaySettingEntity.getSettingJson(), MchPaySettingEntity.WechatPaySetting.class);
|
||||
|
||||
WxPayOrderReverseRequest request = new WxPayOrderReverseRequest();
|
||||
request.setAppid(wechatConfig.getAppPlatformAppId());
|
||||
request.setMchId(wechatConfig.getMerchantId());
|
||||
request.setSubMchId(wechatPaySetting.getSubMchid());
|
||||
request.setTransactionId(payOrder.getThirdPayNo());
|
||||
request.setNonceStr(RandomUtil.randomString(32));
|
||||
request.setSign("");
|
||||
try {
|
||||
WxPayOrderReverseResult result = wxPayService.reverseOrder(request);
|
||||
if (ObjectUtil.notEqual(result.getResultCode(), "SUCCESS")) {
|
||||
throw new RuntimeException("撤销订单失败res:" + JSONUtil.toJsonStr(result));
|
||||
}
|
||||
return result;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
log.error("|{}|撤销订单,意外的错误,异常:{}", TAG, e.getMessage(), e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+4
-1
@@ -27,6 +27,7 @@ import com.wechat.pay.java.core.notification.RequestParam;
|
||||
import com.wechat.pay.java.service.partnerpayments.app.AppServiceExtension;
|
||||
import com.wechat.pay.java.service.partnerpayments.app.model.*;
|
||||
import com.wechat.pay.java.service.partnerpayments.app.model.Amount;
|
||||
import com.wechat.pay.java.service.partnerpayments.nativepay.NativePayService;
|
||||
import com.wechat.pay.java.service.profitsharing.ProfitsharingService;
|
||||
import com.wechat.pay.java.service.refund.RefundService;
|
||||
import com.wechat.pay.java.service.refund.model.*;
|
||||
@@ -67,7 +68,7 @@ public class ThirdAppPlusWechatServiceImpl implements ThirdAppPlusWechatService
|
||||
private final AppServiceExtension appServiceExtension;
|
||||
private final RefundService refundService;
|
||||
private final NotificationParser notificationParser;
|
||||
private final ProfitsharingService profitsharingService;
|
||||
|
||||
private final ThirdAppPlusWechatFzLifecycle appPlusWechatFzLifecycle;
|
||||
|
||||
private static final ExecutorService executorService = Executors.newFixedThreadPool(10);
|
||||
@@ -190,6 +191,8 @@ public class ThirdAppPlusWechatServiceImpl implements ThirdAppPlusWechatService
|
||||
@Override
|
||||
public ThirdMiniWechantReverseVo reverse(ThirdMiniWechantReverseDto dto) {
|
||||
AppPlusPayConfig.WechatConfig wechatConfig = appPlusPayConfig.getWechatConfig();
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -56,7 +56,7 @@ public class ThirdAppPlusWechatFzServiceImpl implements ThirdAppPlusWechatFzServ
|
||||
throw new RuntimeException("支付配置不存在");
|
||||
}
|
||||
// 总金额小毛直接返回(不分账)
|
||||
if (orderEntity.getPrice() < 10) {
|
||||
if (orderEntity.getPrice() <= 10) {
|
||||
log.info("|{}|订单金额太小,无需分账,订单号:{}", TAG, orderEntity.getPayNo());
|
||||
return null;
|
||||
}
|
||||
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
package com.bsd.pjcloud.thirdparty.utils.pay;
|
||||
|
||||
import java.net.*;
|
||||
import java.util.Enumeration;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public class PayForUtil {
|
||||
|
||||
/**
|
||||
* 获取本机ip
|
||||
*/
|
||||
public static String localIp() {
|
||||
String ip = null;
|
||||
Enumeration allNetInterfaces;
|
||||
try {
|
||||
allNetInterfaces = NetworkInterface.getNetworkInterfaces();
|
||||
while (allNetInterfaces.hasMoreElements()) {
|
||||
NetworkInterface netInterface = (NetworkInterface) allNetInterfaces.nextElement();
|
||||
List<InterfaceAddress> InterfaceAddress = netInterface.getInterfaceAddresses();
|
||||
for (InterfaceAddress add : InterfaceAddress) {
|
||||
InetAddress Ip = add.getAddress();
|
||||
if (Ip != null && Ip instanceof Inet4Address) {
|
||||
ip = Ip.getHostAddress();
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (SocketException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return ip;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -123,6 +123,9 @@ ad:
|
||||
# refund-callback-url: /third/third-app-pay/app/refund-callback
|
||||
# spbill-create-ip: 59.202.170.152
|
||||
# base-url: https://api.mch.weixin.qq.com
|
||||
# v2-config:
|
||||
# mch-key: f0f5fd485bac7f377af6f5ca97636dd4
|
||||
# key-path: /Users/dengzhangchen/Desktop/backups/pay/zax_wx_pt_v2/apiclient_cert.p12
|
||||
# ali-pay-config:
|
||||
# app-id: 2021006152609558
|
||||
# app-private-key: MIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQC24MPW2yRAhwvsggYizILPI1ip10LFRrLKrwnstP3C0CmsxGsJFzmw3iA0jT3ruaAEB/fM4UpJKFQG8JCUui3+eMqEi0d39GSBD9puMh4Vc5tVPqPdBTmiN3T4ut3857HPRq58d/9CnGF7AldNuVv6gPNrGBideEoAuBV5iTfrmlv7gVStO4ieEYJnkcLjutD0uzZ24j2HsWQHg0x/qioH9odFBizNsnTH3Uvd3RnK3n9rZXgxsNnhTEEw+lu32w+xzHC/1ob3k2alE6Kn+w4Rljr7T9mcv9eQPqaMa5Slu+ulpDbZe5guMv3WWI0QwNU2x0gfWqN36RtZwgC5AUmzAgMBAAECggEAXhGpyyg4MpUE1ihf3aCTHNeSsPKQXwepykZVdZP4ADCxbzQt1qRCwa7QpBePJWT7YXdzyMiOPKlo55Tw2gAWzpH1ok4+ef6VgCnWct6GyQQJf8TT50nbxox+N79vlrrbpMI32MCk5e+o2OxwWgOhw253R7xCVSXd8xa9vSGPSTngyskNIoXXujIg6bf0CfYClMD1c8jWAA3Y9ZlM2RcxFP16RvGRvDvgDomF1/oEB8aIP1BswXpmFbWVlmYMB/5pS1P90fzJ+w74pqRObH90kYJgoQ0k+5NUD3q8xv61Wu7+mCfGrlxgYEmNp+O3rT0DMRaQhG3qCB/FJM/xa7cNyQKBgQD+u0f363GIE6penUGlxH+Ww2wtR7aTrYVf4TQMpjPNGjoh+jx4VAIwA0Uxq3diA4+l03DbSGZkFiQaSK8txWpXqe2R6o/5+Y+/MCVzRLDsBRl8TB2EPtFUmhzRSS4rWzEZzpzRh7qHT+ycxxuJNo66WOIgqs4Tx2Mp0TinufmedQKBgQC3yeN5qa+eaUORoWfBbuRB1XxuVneU+i5/1D9Md7heTzM9NzJYN8LAB6y/VsQQsLJO0p0fVKkjKbJSY/qyB0o7AXlr7dZhbzfCLN0yaWdUzpyy/nbO1Z4jzZEXGMNfqi2N41fuVBucVXpUcU3NDf0oFkwdtGVTz5WCUq3y4gCShwKBgQCN25wjq+Go51K8qBTUDQ8E1cXbnZFGwp6BG7hRxwkYEqAHJgUg+Z/SPy/8jkHIurT3oz25UKN833uxi4LLGaK0OTTNSvRtQJbV4Skp/ToN5nUf7H+PkzAeTkj4ICnvCTTZ618XrN+q1U6urI9gJZrsme0sRhLHnwVRV2uWtJIXtQKBgQCCOy3UXRgTkRWPESc7Wv+lYsh8SwsLZsgiTlzYK5FaSpbNTtp+xmxatFWFc88U4JBI6FbsB4qeXwJ7/Vp8YkwIScAnaW3atvt0vWO0QBo3bvx8nXHEmHwpdJXWHvb6R9Vl0G3TdIfoHG3FflAZ+Eql6D7hYZ3XaKXRphKao+ix6wKBgQC6aYF2ldJcX4cxvkm1Cuz96jvKt5qx7IhH3CkH+qEVnnYZRrcMbwcO4agwWpvgp/tTKgYV2DzEuXF5aNbBoKXAXG5FOT+etPlutnkt+/n2vsRiafeMMnBFvWqZ48XgREqi/ehHCMcZdsDpudxX0VAAwtvBYJsQfes6XyMYsC6gbA==
|
||||
|
||||
+10
@@ -63,6 +63,16 @@ public class MchPaySettingServiceImpl extends ServiceImpl<MchPaySettingMapper, M
|
||||
throw new RuntimeException("改支付类型已经设置,请直接修改");
|
||||
}
|
||||
baseMapper.insert(dto);
|
||||
CompletableFuture.runAsync(() -> {
|
||||
try {
|
||||
MchManageVo mchManage = mchManageService.join(dto.getMchId());
|
||||
if (ObjectUtil.isNotEmpty(mchManage)) {
|
||||
thirdAppPlusPayService.remoterChangeMch(mchManage);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("编辑商户的回调异常:{}", e.getMessage());
|
||||
}
|
||||
});
|
||||
return dto.getId();
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -42,7 +42,7 @@ public class WalletRechargePackageServiceImpl extends ServiceImpl<WalletRecharge
|
||||
@Override
|
||||
public Boolean remotePaySuccess(WalletRechargePaySuccess dto) {
|
||||
// 小程序用户钱包充值
|
||||
if (ObjectUtil.equals(dto.getBizType(), ThirdPayOrderBizTypeEnum.MINI_APP_WALLET_RECHARGE.getType())) {
|
||||
if (ObjectUtil.equals(dto.getBizType(), ThirdPayOrderBizTypeEnum.MINI_APP_RECHARGE.getType())) {
|
||||
// 查询充值套餐
|
||||
WalletRechargePackageEntity rechargePackage = baseMapper.selectById(dto.getBizId());
|
||||
if (ObjectUtil.isEmpty(rechargePackage)) {
|
||||
@@ -78,7 +78,7 @@ public class WalletRechargePackageServiceImpl extends ServiceImpl<WalletRecharge
|
||||
@Override
|
||||
public Boolean remoteRefundSuccess(WalletRechargeRefundSuccess dto) {
|
||||
// 小程序用户钱包充值
|
||||
if (ObjectUtil.equals(dto.getBizType(), ThirdPayOrderBizTypeEnum.MINI_APP_WALLET_RECHARGE.getType())) {
|
||||
if (ObjectUtil.equals(dto.getBizType(), ThirdPayOrderBizTypeEnum.MINI_APP_RECHARGE.getType())) {
|
||||
// 查询充值套餐
|
||||
WalletRechargePackageEntity rechargePackage = baseMapper.selectById(dto.getBizId());
|
||||
if (ObjectUtil.isEmpty(rechargePackage)) {
|
||||
|
||||
Reference in new issue
Block a user