feat(pay): 添加支付宝绑定状态查询

master
yang 2025-03-07 16:15:48 +08:00
parent 1a56de7de0
commit 32a50b8394
4 changed files with 50 additions and 5 deletions

View File

@ -32,6 +32,7 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid; import javax.validation.Valid;
import javax.validation.constraints.Min; import javax.validation.constraints.Min;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull; import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern; import javax.validation.constraints.Pattern;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
@ -84,6 +85,7 @@ public class AliPayController extends BaseController {
*/ */
@ApiOperation(value = "支付宝绑定") @ApiOperation(value = "支付宝绑定")
@GetMapping("/generateQrCode") @GetMapping("/generateQrCode")
@ResponseBody
public R<String> generateQrCode(HttpServletResponse response) throws Exception { public R<String> generateQrCode(HttpServletResponse response) throws Exception {
String scope = "auth_user"; // 需要获取用户信息 String scope = "auth_user"; // 需要获取用户信息
String appId = aliConfig.getAppId(); String appId = aliConfig.getAppId();
@ -99,6 +101,16 @@ public class AliPayController extends BaseController {
return R.ok("成功", authUrl); return R.ok("成功", authUrl);
} }
/**
*
*/
@GetMapping("/queryBindStatus")
@ApiOperation(value = "支付宝绑定状态查询")
public R<Object> queryTradeStatus() throws Exception {
return aliPayService.queryBindStatus();
}
/** /**
* *
* *

View File

@ -143,11 +143,11 @@ mall:
alipayCertPath: cert/dev/alipayPublicCert.crt alipayCertPath: cert/dev/alipayPublicCert.crt
# 沙箱支付宝根证书路径 # 沙箱支付宝根证书路径
alipayRootCertPath: cert/dev/alipayRootCert.crt alipayRootCertPath: cert/dev/alipayRootCert.crt
notifyUrl: https://53a65908.r27.cpolar.top/ali/pay/notify notifyUrl: https://1e312ae8.r27.cpolar.top/ali/pay/notify
# 沙箱支付宝网关 # 沙箱支付宝网关
gatewayUrl: https://openapi-sandbox.dl.alipaydev.com/gateway.do gatewayUrl: https://openapi-sandbox.dl.alipaydev.com/gateway.do
# 绑定回调 # 绑定回调
bindUrl: https://4b0ca615.r27.cpolar.top/ali/pay/callback bindUrl: https://1e312ae8.r27.cpolar.top/ali/pay/callback
huawei: huawei:
obs: obs:

View File

@ -22,4 +22,6 @@ public interface AliPayService {
R<Object> queryTradeStatus(String outTradeNo) throws Exception; R<Object> queryTradeStatus(String outTradeNo) throws Exception;
PayVo walletPay(Double amount) throws Exception; PayVo walletPay(Double amount) throws Exception;
R<Object> queryBindStatus();
} }

View File

@ -25,6 +25,7 @@ import com.alipay.easysdk.kernel.Config;
import com.alipay.easysdk.payment.common.models.AlipayTradeCancelResponse; import com.alipay.easysdk.payment.common.models.AlipayTradeCancelResponse;
import com.alipay.easysdk.payment.common.models.AlipayTradeQueryResponse; import com.alipay.easysdk.payment.common.models.AlipayTradeQueryResponse;
import com.alipay.easysdk.payment.facetoface.models.AlipayTradePrecreateResponse; import com.alipay.easysdk.payment.facetoface.models.AlipayTradePrecreateResponse;
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.mcwl.common.JSONUtils; import com.mcwl.common.JSONUtils;
import com.mcwl.common.core.domain.AjaxResult; import com.mcwl.common.core.domain.AjaxResult;
import com.mcwl.common.core.domain.R; import com.mcwl.common.core.domain.R;
@ -287,6 +288,33 @@ public class AliPayServiceImpl implements AliPayService {
return payVo; return payVo;
} }
/**
*
*
* @return 01
*/
@Override
public R<Object> queryBindStatus() {
// 查询redis中支付宝绑定状态
String bindStatus = redisCache.getCacheObject("alipay:bind:user:status:" + SecurityUtils.getUserId());
if (Objects.nonNull(bindStatus)) {
return R.ok(bindStatus);
}
SysUserPayAccount sysUserPayAccount = sysUserPayAccountService.lambdaQuery()
.eq(SysUserPayAccount::getUserId, SecurityUtils.getUserId())
.one();
if (Objects.isNull(sysUserPayAccount)) {
redisCache.setCacheObject("alipay:bind:user:status:", 0, 4, TimeUnit.SECONDS);
return R.ok(0);
}
redisCache.setCacheObject("alipay:bind:user:status:", 1, 4, TimeUnit.SECONDS);
return R.ok(1);
}
/** /**
* *
* *
@ -459,12 +487,15 @@ public class AliPayServiceImpl implements AliPayService {
userPayAccount.setOpenId(openId); userPayAccount.setOpenId(openId);
userPayAccount.setType(0); userPayAccount.setType(0);
sysUserPayAccountService.save(userPayAccount); sysUserPayAccountService.save(userPayAccount);
redisCache.setCacheObject("alipay:bind:user:status:", 1, 4, TimeUnit.SECONDS);
return "success"; return "success";
} else { } else {
System.out.println("绑定失败:" + response.getSubMsg()); System.out.println("绑定失败:" + response.getSubMsg());
redisCache.setCacheObject("alipay:bind:user:status:", 0, 4, TimeUnit.SECONDS);
return "fail"; return "fail";
} }
} catch (AlipayApiException e) { } catch (AlipayApiException e) {
redisCache.setCacheObject("alipay:bind:user:status:", 0, 4, TimeUnit.SECONDS);
return "fail"; return "fail";
} }
@ -545,13 +576,13 @@ public class AliPayServiceImpl implements AliPayService {
// 设置应用公钥证书路径(线上) // 设置应用公钥证书路径(线上)
// config.setAppCertPath(getClass().getResource("/cert/appCertPublicKey.crt").getPath()); // config.setAppCertPath(getClass().getResource("/cert/appCertPublicKey.crt").getPath());
// 设置应用公钥证书路径(沙箱) // 设置应用公钥证书路径(沙箱)
config.setAppCertPath(ResourceUtils.getFile("classpath:"+aliConfig.getAppCertPath()).getAbsolutePath()); config.setAppCertPath(ResourceUtils.getFile("classpath:" + aliConfig.getAppCertPath()).getAbsolutePath());
// 设置支付宝公钥证书路径 // 设置支付宝公钥证书路径
config.setAlipayPublicCertPath(ResourceUtils.getFile("classpath:"+aliConfig.getAlipayCertPath()).getAbsolutePath()); config.setAlipayPublicCertPath(ResourceUtils.getFile("classpath:" + aliConfig.getAlipayCertPath()).getAbsolutePath());
// 设置支付宝根证书路径 // 设置支付宝根证书路径
config.setRootCertPath(ResourceUtils.getFile("classpath:"+aliConfig.getAlipayRootCertPath()).getAbsolutePath()); config.setRootCertPath(ResourceUtils.getFile("classpath:" + aliConfig.getAlipayRootCertPath()).getAbsolutePath());
// 设置字符编码格式 // 设置字符编码格式
config.setCharset("UTF-8"); config.setCharset("UTF-8");