|
@@ -21,6 +21,7 @@ import lombok.AllArgsConstructor;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springblade.common.constant.CommonConstant;
|
|
|
+import org.springblade.common.utils.CommonUtil;
|
|
|
import org.springblade.common.utils.NotifyUtils;
|
|
|
import org.springblade.core.log.annotation.ApiLog;
|
|
|
import org.springblade.core.log.exception.ServiceException;
|
|
@@ -57,16 +58,13 @@ public class AliPay01Controller {
|
|
|
private static final Logger log = LoggerFactory.getLogger(AliPay01Controller.class);
|
|
|
|
|
|
//预授权
|
|
|
- private static final String NOTIFY_URL = "https://wine.gzzzyd.com/api/v1/aliPay/sdk/auth_notify_url";
|
|
|
+ private static final String NOTIFY_URL = "/api/v1/aliPay/sdk/auth_notify_url";
|
|
|
|
|
|
//抢购
|
|
|
- private static final String TRADE_URL = "https://wine.gzzzyd.com/api/v1/aliPay/sdk/trade_notify_url";
|
|
|
+ private static final String TRADE_URL = "/api/v1/aliPay/sdk/trade_notify_url";
|
|
|
|
|
|
//购买
|
|
|
- //private static final String TRADE_URL = "https://wine.gzzzyd.com/api/v1/aliPay/sdk/order_notify_url";
|
|
|
-
|
|
|
- //平台支付宝账号
|
|
|
- private static final String ALIPAY_PID = "2088341967443472";
|
|
|
+ //private static final String TRADE_URL = "/api/v1/aliPay/sdk/order_notify_url";
|
|
|
|
|
|
@Autowired
|
|
|
private AlipayClient client;//支付宝请求sdk客户端
|
|
@@ -106,18 +104,18 @@ public class AliPay01Controller {
|
|
|
}
|
|
|
}
|
|
|
if("aliPay".equals(payFor)){
|
|
|
- JSONObject data = new JSONObject();
|
|
|
- data.put("out_trade_no", outTradeNo); //商户订单号
|
|
|
- //产品码, APP支付 QUICK_MSECURITY_PAY, PC支付 FAST_INSTANT_TRADE_PAY, 移动H5支付 QUICK_WAP_PAY
|
|
|
- data.put("product_code", "QUICK_MSECURITY_PAY");
|
|
|
- data.put("total_amount", "0.1"); //订单金额
|
|
|
- data.put("subject", "中宏酒业"); //订单标题
|
|
|
- //APP支付
|
|
|
- AlipayTradeAppPayRequest request = new AlipayTradeAppPayRequest();
|
|
|
- request.setNotifyUrl(TRADE_URL); //异步通知地址
|
|
|
- request.setBizContent(data.toJSONString()); //业务参数
|
|
|
- //APP支付
|
|
|
try {
|
|
|
+ JSONObject data = new JSONObject();
|
|
|
+ data.put("out_trade_no", outTradeNo); //商户订单号
|
|
|
+ //产品码, APP支付 QUICK_MSECURITY_PAY, PC支付 FAST_INSTANT_TRADE_PAY, 移动H5支付 QUICK_WAP_PAY
|
|
|
+ data.put("product_code", "QUICK_MSECURITY_PAY");
|
|
|
+ data.put("total_amount", "0.1"); //订单金额
|
|
|
+ data.put("subject", "中宏酒业"); //订单标题
|
|
|
+ //APP支付
|
|
|
+ AlipayTradeAppPayRequest request = new AlipayTradeAppPayRequest();
|
|
|
+ request.setNotifyUrl(properties.getDomain() + TRADE_URL); //异步通知地址
|
|
|
+ request.setBizContent(data.toJSONString()); //业务参数
|
|
|
+ //APP支付
|
|
|
AlipayTradeAppPayResponse response = client.sdkExecute(request);
|
|
|
if (response.isSuccess()){
|
|
|
return R.data(response.getBody());
|
|
@@ -131,7 +129,7 @@ public class AliPay01Controller {
|
|
|
return R.fail("该支付方式暂不支持!");
|
|
|
}
|
|
|
|
|
|
- @ApiLog("发起支付-预授权")
|
|
|
+ @ApiLog("绑定订单-预授权")
|
|
|
@PostMapping("/pay_002")
|
|
|
@ApiOperation(value = "统一收单交易支付接口", notes = "预授权")
|
|
|
@ApiOperationSupport(order = 2)
|
|
@@ -168,11 +166,11 @@ public class AliPay01Controller {
|
|
|
}else{
|
|
|
data.put("auth_confirm_mode", "NOT_COMPLETE");//不解冻
|
|
|
}
|
|
|
- data.put("seller_id", ALIPAY_PID); //收款方
|
|
|
+ data.put("seller_id", properties.getPayeeUserId()); //收款方
|
|
|
data.put("buyer_id", query.getAlipayUserId()); //买家ID //2088012801069195
|
|
|
//APP支付
|
|
|
AlipayTradePayRequest request = new AlipayTradePayRequest();
|
|
|
- request.setNotifyUrl(TRADE_URL); //异步通知地址
|
|
|
+ request.setNotifyUrl(properties.getDomain() + TRADE_URL); //异步通知地址
|
|
|
request.setBizContent(data.toJSONString()); //业务参数
|
|
|
//APP支付
|
|
|
try {
|
|
@@ -187,7 +185,10 @@ public class AliPay01Controller {
|
|
|
if (response.isSuccess()){
|
|
|
return R.data(response.getBody());
|
|
|
}else{
|
|
|
- throw new ServiceException("支付失败!");
|
|
|
+ orderGrantService.remove(Wrappers.<OrderGrant>lambdaQuery()
|
|
|
+ .eq(OrderGrant::getId,orderGrant.getId())
|
|
|
+ .eq(OrderGrant::getStatus, 0));
|
|
|
+ logger.info("订单绑定失败","删除预授权数据");
|
|
|
}
|
|
|
} catch (AlipayApiException e) {
|
|
|
e.printStackTrace();
|
|
@@ -195,9 +196,9 @@ public class AliPay01Controller {
|
|
|
return R.fail("发起支付失败!");
|
|
|
}
|
|
|
|
|
|
- @ApiLog("线上资金授权冻结接口")
|
|
|
+ @ApiLog("发起支付宝预授权")
|
|
|
@PostMapping("/pay_003")
|
|
|
- @ApiOperation(value = "线上资金授权冻结接口", notes = "支付请求")
|
|
|
+ @ApiOperation(value = "线上资金授权冻结接口-调用支付宝预授权", notes = "支付请求")
|
|
|
@ApiOperationSupport(order = 3)
|
|
|
public R<String> pay003(@ApiParam(value = "用户号", required = true) @RequestParam Long userId,
|
|
|
@ApiParam(value = "批次ID", required = true) @RequestParam Long batNo,
|
|
@@ -205,22 +206,21 @@ public class AliPay01Controller {
|
|
|
@ApiParam(value = "数量", required = true) @RequestParam Integer num) throws AlipayApiException {
|
|
|
//1.通过批次号查询金额
|
|
|
JSONObject data = new JSONObject();
|
|
|
- String orderNo = PayKit.generateStr();
|
|
|
+ String orderNo = CommonUtil.genTimeID();
|
|
|
data.put("out_order_no", orderNo);
|
|
|
data.put("out_request_no", orderNo);
|
|
|
data.put("order_title","预授权冻结");
|
|
|
data.put("amount", NumberUtil.mul(price, num));
|
|
|
data.put("product_code","PRE_AUTH_ONLINE"); //销售产品码。支付宝预授权产品固定为 PRE_AUTH_ONLINE
|
|
|
- data.put("payee_user_id", ALIPAY_PID);
|
|
|
+ data.put("payee_user_id", properties.getPayeeUserId());
|
|
|
data.put("timeout_express","30m");
|
|
|
//APP支付
|
|
|
AlipayFundAuthOrderAppFreezeRequest request = new AlipayFundAuthOrderAppFreezeRequest();
|
|
|
- request.setNotifyUrl(NOTIFY_URL); //异步通知地址
|
|
|
+ request.setNotifyUrl(properties.getDomain() + NOTIFY_URL); //异步通知地址
|
|
|
request.setBizContent(data.toJSONString()); //业务参数
|
|
|
//APP支付
|
|
|
AlipayFundAuthOrderAppFreezeResponse response = client.sdkExecute(request);
|
|
|
if(response.isSuccess()){
|
|
|
- //新增数据
|
|
|
//查询数据如果已经预授权的
|
|
|
String dataDate = DateUtil.format(DateUtil.now(), DateUtil.PATTERN_DATE);
|
|
|
OrderGrant grant = new OrderGrant();
|
|
@@ -269,8 +269,6 @@ public class AliPay01Controller {
|
|
|
return R.fail("授权失败!");
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
@ApiLog("抢购打款-测试")
|
|
|
@PostMapping("/pay_005")
|
|
|
@ApiOperation(value = "单笔转账到支付宝账户", notes = "单笔转账到支付宝账户")
|
|
@@ -317,6 +315,35 @@ public class AliPay01Controller {
|
|
|
return R.fail("打款失败!");
|
|
|
}
|
|
|
|
|
|
+ @ApiLog("资金解冻")
|
|
|
+ @GetMapping("/pay_unfreeze")
|
|
|
+ @ApiOperation(value = "资金授权解冻", notes = "支付请求")
|
|
|
+ @ApiOperationSupport(order = 3)
|
|
|
+ public R payUnfreeze(@ApiParam(value = "支付宝资金授权订单号", required = true) @RequestParam String authNo,
|
|
|
+ @ApiParam(value = "解冻金额", required = true) @RequestParam Double amount) throws AlipayApiException {
|
|
|
+ AlipayFundAuthOrderUnfreezeRequest request = new AlipayFundAuthOrderUnfreezeRequest();
|
|
|
+ JSONObject bizContent = new JSONObject();
|
|
|
+ bizContent.put("auth_no",authNo);
|
|
|
+ bizContent.put("out_request_no","outRequestNo123");
|
|
|
+ bizContent.put("amount",amount);
|
|
|
+ bizContent.put("remark","解冻资金");
|
|
|
+ JSONObject extraParam = new JSONObject();
|
|
|
+ JSONObject unfreezeBizInfo = new JSONObject();
|
|
|
+ unfreezeBizInfo.put("bizComplete",true);
|
|
|
+ extraParam.put("unfreezeBizInfo",unfreezeBizInfo);
|
|
|
+ bizContent.put("extra_param",extraParam);
|
|
|
+ // 设置整体请求参数
|
|
|
+ request.setBizContent(bizContent.toString());
|
|
|
+ // 使用execute方法发起请求
|
|
|
+ AlipayFundAuthOrderUnfreezeResponse response = client.execute(request);
|
|
|
+ if(response.isSuccess()){
|
|
|
+ logger.info("解冻资金成功",response.getBody());
|
|
|
+ return R.fail("解冻资金成功!");
|
|
|
+ }
|
|
|
+ logger.info("解冻资金失败",response.getBody());
|
|
|
+ return R.fail("解冻资金失败!");
|
|
|
+ }
|
|
|
+
|
|
|
@GetMapping("/getAlipay_sign")
|
|
|
@ApiOperation(value = "获取签名", notes = "获取签名")
|
|
|
@ApiOperationSupport(order = 97)
|
|
@@ -330,12 +357,13 @@ public class AliPay01Controller {
|
|
|
"&product_id=APP_FAST_LOGIN" +
|
|
|
"&scope=kuaijie" +
|
|
|
"&sign_type=RSA2" +
|
|
|
- "&target_id=" + PayKit.generateStr();
|
|
|
+ "&target_id=" + CommonUtil.genTimeID();
|
|
|
String sign = AlipaySignature.rsaSign(content, properties.getPrivateKey(),"utf-8","RSA2");
|
|
|
String urlencoder = URLEncoder.encode(sign,"UTF-8");
|
|
|
return R.data(content + "&sign=" + urlencoder);
|
|
|
}
|
|
|
|
|
|
+ @ApiLog("获取支付宝用户信息")
|
|
|
@GetMapping("/setAlipay_userInfo")
|
|
|
@ApiOperation(value = "设置用户信息", notes = "设置用户信息")
|
|
|
@ApiOperationSupport(order = 97)
|
|
@@ -352,6 +380,7 @@ public class AliPay01Controller {
|
|
|
return R.status(param.updateById());
|
|
|
}
|
|
|
|
|
|
+ @ApiLog("预授回调")
|
|
|
@RequestMapping(value = "/auth_notify_url", method = {RequestMethod.GET, RequestMethod.POST})
|
|
|
@ApiOperation(value = "异步通知相应-预授回调", notes = "异步通知相应")
|
|
|
@ApiOperationSupport(order = 99)
|
|
@@ -393,6 +422,7 @@ public class AliPay01Controller {
|
|
|
return "success";
|
|
|
}
|
|
|
|
|
|
+ @ApiLog("购买进货回调")
|
|
|
@RequestMapping(value = "/trade_notify_url", method = {RequestMethod.GET, RequestMethod.POST})
|
|
|
@ApiOperation(value = "异步通知相应-购买进货回调", notes = "异步通知相应")
|
|
|
@ApiOperationSupport(order = 100)
|
|
@@ -452,6 +482,7 @@ public class AliPay01Controller {
|
|
|
User u = userService.getById(user.getUserId());
|
|
|
if (u != null && u.getRealName() != null){
|
|
|
//向寄售人打款
|
|
|
+ log.info(errMsg + "-向寄售人打款");
|
|
|
transfer(user.getAlipayUserId(),u.getRealName(), Double.toString(query.getPrice()));
|
|
|
}else{
|
|
|
log.info(errMsg + "-修改失败");
|
|
@@ -493,7 +524,7 @@ public class AliPay01Controller {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
AlipayFundTransUniTransferModel model = new AlipayFundTransUniTransferModel();
|
|
|
- model.setOutBizNo(PayKit.generateStr());
|
|
|
+ model.setOutBizNo(CommonUtil.genTimeID());
|
|
|
model.setRemark("寄售订单打款");
|
|
|
model.setBusinessParams("{\"payer_show_name_use_alias\":\"true\"}");
|
|
|
model.setBizScene("DIRECT_TRANSFER");
|