|
|
@ -2,10 +2,26 @@ package cc.yunxi.controller;
|
|
|
|
|
|
|
|
|
|
|
|
import cc.yunxi.common.domain.CommonResult;
|
|
|
|
import cc.yunxi.common.domain.CommonResult;
|
|
|
|
import cc.yunxi.common.exception.BadRequestException;
|
|
|
|
import cc.yunxi.common.exception.BadRequestException;
|
|
|
|
|
|
|
|
import cc.yunxi.common.exception.BizIllegalException;
|
|
|
|
|
|
|
|
import cc.yunxi.config.props.WxPayV3Properties;
|
|
|
|
import cc.yunxi.domain.query.TestQuery;
|
|
|
|
import cc.yunxi.domain.query.TestQuery;
|
|
|
|
import cc.yunxi.enums.UserTypeEnum;
|
|
|
|
import cc.yunxi.enums.UserTypeEnum;
|
|
|
|
import cc.yunxi.service.ITestService;
|
|
|
|
import cc.yunxi.service.ITestService;
|
|
|
|
|
|
|
|
import cn.hutool.core.date.DatePattern;
|
|
|
|
|
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
|
|
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
|
|
|
|
|
import cn.hutool.json.JSONUtil;
|
|
|
|
import cn.hutool.log.Log;
|
|
|
|
import cn.hutool.log.Log;
|
|
|
|
|
|
|
|
import com.ijpay.core.IJPayHttpResponse;
|
|
|
|
|
|
|
|
import com.ijpay.core.enums.RequestMethodEnum;
|
|
|
|
|
|
|
|
import com.ijpay.core.kit.PayKit;
|
|
|
|
|
|
|
|
import com.ijpay.core.kit.WxPayKit;
|
|
|
|
|
|
|
|
import com.ijpay.wxpay.WxPayApi;
|
|
|
|
|
|
|
|
import com.ijpay.wxpay.enums.WxDomainEnum;
|
|
|
|
|
|
|
|
import com.ijpay.wxpay.enums.v3.TransferApiEnum;
|
|
|
|
|
|
|
|
import com.ijpay.wxpay.model.TransferModel;
|
|
|
|
|
|
|
|
import com.ijpay.wxpay.model.v3.BatchTransferModel;
|
|
|
|
|
|
|
|
import com.ijpay.wxpay.model.v3.TransferDetailInput;
|
|
|
|
import io.swagger.annotations.Api;
|
|
|
|
import io.swagger.annotations.Api;
|
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
@ -14,6 +30,9 @@ import org.springframework.scheduling.annotation.Async;
|
|
|
|
import org.springframework.util.concurrent.ListenableFuture;
|
|
|
|
import org.springframework.util.concurrent.ListenableFuture;
|
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
|
|
|
import java.security.cert.X509Certificate;
|
|
|
|
|
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.concurrent.ExecutionException;
|
|
|
|
import java.util.concurrent.ExecutionException;
|
|
|
|
|
|
|
|
|
|
|
|
@Api(tags = "测试接口")
|
|
|
|
@Api(tags = "测试接口")
|
|
|
@ -25,6 +44,9 @@ public class TestController {
|
|
|
|
|
|
|
|
|
|
|
|
private final ITestService testService;
|
|
|
|
private final ITestService testService;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
|
|
|
|
private WxPayV3Properties wxPayV3Properties;
|
|
|
|
|
|
|
|
|
|
|
|
@ApiOperation("测试接口成功")
|
|
|
|
@ApiOperation("测试接口成功")
|
|
|
|
@GetMapping("/test01")
|
|
|
|
@GetMapping("/test01")
|
|
|
|
public CommonResult<String> success() {
|
|
|
|
public CommonResult<String> success() {
|
|
|
@ -71,4 +93,64 @@ public class TestController {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return CommonResult.success("数据处理完成");
|
|
|
|
return CommonResult.success("数据处理完成");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ApiOperation("微信提现测试")
|
|
|
|
|
|
|
|
@GetMapping("/wxcash")
|
|
|
|
|
|
|
|
public CommonResult<String> wxCash(@RequestParam("openid") String openid) throws Exception {
|
|
|
|
|
|
|
|
// String openId = "oYkV86-mE9DakrcP5us474KscefQ";
|
|
|
|
|
|
|
|
BatchTransferModel batchTransferModel = new BatchTransferModel()
|
|
|
|
|
|
|
|
.setAppid(wxPayV3Properties.getAppId())
|
|
|
|
|
|
|
|
.setOut_batch_no(PayKit.generateStr())
|
|
|
|
|
|
|
|
.setBatch_name("测试商户转账到零钱")
|
|
|
|
|
|
|
|
.setBatch_remark("测试商户转账到零钱")
|
|
|
|
|
|
|
|
.setTotal_amount(1)
|
|
|
|
|
|
|
|
.setTotal_num(1)
|
|
|
|
|
|
|
|
.setTransfer_detail_list(Collections.singletonList(
|
|
|
|
|
|
|
|
new TransferDetailInput()
|
|
|
|
|
|
|
|
.setOut_detail_no(PayKit.generateStr())
|
|
|
|
|
|
|
|
.setTransfer_amount(1)
|
|
|
|
|
|
|
|
.setTransfer_remark("测试商户转账到零钱")
|
|
|
|
|
|
|
|
.setOpenid(openid)));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
log.info("发起商家转账请求参数 {}", JSONUtil.toJsonStr(batchTransferModel));
|
|
|
|
|
|
|
|
// 删除
|
|
|
|
|
|
|
|
IJPayHttpResponse response = WxPayApi.v3(
|
|
|
|
|
|
|
|
RequestMethodEnum.POST,
|
|
|
|
|
|
|
|
WxDomainEnum.CHINA.toString(),
|
|
|
|
|
|
|
|
TransferApiEnum.TRANSFER_BATCHES.toString(),
|
|
|
|
|
|
|
|
wxPayV3Properties.getMchId(),
|
|
|
|
|
|
|
|
getSerialNumber(),
|
|
|
|
|
|
|
|
null,
|
|
|
|
|
|
|
|
wxPayV3Properties.getKeyPath(),
|
|
|
|
|
|
|
|
JSONUtil.toJsonStr(batchTransferModel)
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
log.info("发起商家转账响应 {}", response);
|
|
|
|
|
|
|
|
// 根据证书序列号查询对应的证书来验证签名结果
|
|
|
|
|
|
|
|
// boolean verifySignature = WxPayKit.verifySignature(response, wxPayV3Properties.getPlatformCertPath());
|
|
|
|
|
|
|
|
// log.info("verifySignature: {}", verifySignature);
|
|
|
|
|
|
|
|
// if (response.getStatus() == OK && verifySignature) {
|
|
|
|
|
|
|
|
// return response.getBody();
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
if (response.getStatus() != 200) {
|
|
|
|
|
|
|
|
log.warn("提现失败: {}", response.getBody());
|
|
|
|
|
|
|
|
throw new BizIllegalException("提现失败");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return CommonResult.success(response.getBody());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 商户API证书序列号
|
|
|
|
|
|
|
|
private String getSerialNumber() {
|
|
|
|
|
|
|
|
// 获取证书序列号
|
|
|
|
|
|
|
|
X509Certificate certificate = PayKit.getCertificate(wxPayV3Properties.getCertPath());
|
|
|
|
|
|
|
|
if (certificate == null) {
|
|
|
|
|
|
|
|
throw new BizIllegalException("商户证书序列号获取失败!");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
String serialNo = certificate.getSerialNumber().toString(16).toUpperCase();
|
|
|
|
|
|
|
|
// 提前两天检查证书是否有效
|
|
|
|
|
|
|
|
boolean isValid = PayKit.checkCertificateIsValid(certificate, wxPayV3Properties.getMchId(), -2);
|
|
|
|
|
|
|
|
log.info("证书是否可用 {} 证书有效期为 {}", isValid, DateUtil.format(certificate.getNotAfter(), DatePattern.NORM_DATETIME_PATTERN));
|
|
|
|
|
|
|
|
return serialNo;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|