feat(payment): 支持支付宝多种身份类型绑定

master
yang 2025-03-31 13:30:15 +08:00
parent 0d29d79af6
commit 196ba38b15
8 changed files with 29 additions and 21 deletions

View File

@ -93,16 +93,7 @@ public class AliPayController extends BaseController {
String state = ShareCodeUtils.idToCode(SecurityUtils.getUserId()); // 防止CSRF攻击
String encodedRedirectUri = URLEncoder.encode(bindUrl, "UTF-8");
// 线上
// String authUrl = String.format(
// "https://openauth.alipay.com/oauth2/publicAppAuthorize.htm?app_id=%s&scope=%s&redirect_uri=%s&state=%s",
// appId, scope, encodedRedirectUri, state
// );
// 沙箱
String authUrl = String.format(
"https://openauth-sandbox.dl.alipaydev.com/oauth2/publicAppAuthorize.htm?app_id=%s&scope=%s&redirect_uri=%s&state=%s",
appId, scope, encodedRedirectUri, state
);
String authUrl = String.format(aliConfig.getOauthUrl(),appId, scope, encodedRedirectUri, state);
// QrCodeUtil.generate(authUrl, 300, 300, "png", response.getOutputStream());
return R.ok(authUrl, "成功");
@ -168,7 +159,7 @@ public class AliPayController extends BaseController {
if ("member".equalsIgnoreCase(type)) {
if (!Optional.ofNullable(orderTradeDto.getProductId()).isPresent()) {
return R.fail(HttpStatus.SHOW_ERROR_MSG,"商品id不能为空");
return R.fail(HttpStatus.SHOW_ERROR_MSG, "商品id不能为空");
}
payVo = aliPayService.memberPay(orderTradeDto);
// QrCodeUtil.generate(payVo.getUrl(), 300, 300, "png", response.getOutputStream());
@ -178,12 +169,12 @@ public class AliPayController extends BaseController {
} else if ("wallet".equalsIgnoreCase(type)) {
// 充值金额只能是整数
if (orderTradeDto.getAmount() % 1 != 0) {
return R.fail(HttpStatus.SHOW_ERROR_MSG,"充值金额只能是整数");
return R.fail(HttpStatus.SHOW_ERROR_MSG, "充值金额只能是整数");
}
payVo = aliPayService.walletPay(orderTradeDto.getAmount());
// QrCodeUtil.generate(payVo.getUrl(), 300, 300, "png", response.getOutputStream());
} else {
return R.fail(HttpStatus.SHOW_ERROR_MSG,"订单类型错误");
return R.fail(HttpStatus.SHOW_ERROR_MSG, "订单类型错误");
}
return R.ok(payVo);
@ -207,12 +198,12 @@ public class AliPayController extends BaseController {
.one();
if (Objects.isNull(sysUserPayAccount)) {
return R.fail(HttpStatus.SHOW_ERROR_MSG,"请先绑定支付宝");
return R.fail(HttpStatus.SHOW_ERROR_MSG, "请先绑定支付宝");
}
if (Double.parseDouble(amount) < 0.1) {
return R.fail(HttpStatus.SHOW_ERROR_MSG,"提现金额最小为0.1");
return R.fail(HttpStatus.SHOW_ERROR_MSG, "提现金额最小为0.1");
}
return aliPayService.fetch(amount);

View File

@ -156,11 +156,15 @@ mall:
# alipayCertPath: D:\workspace\mochuang\mcwl-ai\mcwl-admin\src\main\resources\cert\dev\alipayPublicCert.crt
# # 沙箱支付宝根证书路径
# alipayRootCertPath: D:\workspace\mochuang\mcwl-ai\mcwl-admin\src\main\resources\cert\dev\alipayRootCert.crt
notifyUrl: http://113.45.190.154:8080/ali/pay/notify
notifyUrl: https://4e3c963e.r27.cpolar.top/ali/pay/notify
# 沙箱支付宝网关
gatewayUrl: https://openapi-sandbox.dl.alipaydev.com/gateway.do
# 绑定回调
bindUrl: http://113.45.190.154:8080/ali/pay/callback
bindUrl: https://4e3c963e.r27.cpolar.top/ali/pay/callback
# 参与方的标识类型,目前支持如下类型: 1、ALIPAY_USER_ID 支付宝的会员ID 2、ALIPAY_LOGON_ID支付宝登录号支持邮箱和手机号格式 3、ALIPAY_OPEN_ID支付宝openid
identityType: ALIPAY_USER_ID
# 授权url
oauthUrl: https://openauth-sandbox.dl.alipaydev.com/oauth2/publicAppAuthorize.htm?app_id=%s&scope=%s&redirect_uri=%s&state=%s
huawei:
obs:

View File

@ -148,6 +148,10 @@ mall:
gatewayUrl: https://openapi.alipay.com/gateway.do
# 绑定回调
bindUrl: https://36072a51.r27.cpolar.top/ali/pay/callback
# 参与方的标识类型,目前支持如下类型: 1、ALIPAY_USER_ID 支付宝的会员ID 2、ALIPAY_LOGON_ID支付宝登录号支持邮箱和手机号格式 3、ALIPAY_OPEN_ID支付宝openid
identityType: ALIPAY_OPEN_ID
# 授权url
oauthUrl: https://openauth.alipay.com/oauth2/publicAppAuthorize.htm?app_id=%s&scope=%s&redirect_uri=%s&state=%s
huawei:
obs:

View File

@ -30,4 +30,8 @@ public class AliConfig {
private String gatewayUrl;
@Value("${mall.mgt.aliPayConfig.notifyUrl}")
private String notifyUrl;
@Value("${mall.mgt.aliPayConfig.identityType}")
private String identityType;
@Value("${mall.mgt.aliPayConfig.oauthUrl}")
private String oauthUrl;
}

View File

@ -3,6 +3,7 @@ package com.mcwl.pay.service.impl;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.lang.UUID;
import cn.hutool.core.util.StrUtil;
import cn.hutool.extra.mail.MailUtil;
import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSONObject;
@ -47,6 +48,7 @@ import com.mcwl.system.service.ISysUserPayAccountService;
import com.mcwl.system.service.ISysUserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
@ -324,9 +326,8 @@ public class AliPayServiceImpl implements AliPayService {
// 收款方信息
Participant payeeInfo = new Participant();
// 线上环境
payeeInfo.setIdentity(sysUserPayAccount.getOpenId());
payeeInfo.setIdentityType("ALIPAY_OPEN_ID");
payeeInfo.setIdentityType(aliConfig.getIdentityType());
model.setPayeeInfo(payeeInfo);
request.setBizModel(model);
@ -440,6 +441,7 @@ public class AliPayServiceImpl implements AliPayService {
if (response.isSuccess()) {
// 支付宝用户唯一ID
String openId = response.getOpenId();
String uid = response.getUserId();
// 判断是否已经绑定过
SysUserPayAccount sysUserPayAccount = sysUserPayAccountService.lambdaQuery()
.eq(SysUserPayAccount::getUserId, userId)
@ -450,12 +452,12 @@ public class AliPayServiceImpl implements AliPayService {
// 已经绑定过,直接返回
return "success";
}
System.out.println("绑定成功openId" + openId);
System.out.println("绑定成功openId/uid" + openId);
// 将openId与当前商城用户绑定保存到数据库
SysUserPayAccount userPayAccount = new SysUserPayAccount();
userPayAccount.setUserId(userId);
userPayAccount.setAppId(aliConfig.getAppId());
userPayAccount.setOpenId(openId);
userPayAccount.setOpenId(StrUtil.isEmpty(openId) ? uid : openId);
userPayAccount.setType(0);
sysUserPayAccountService.save(userPayAccount);
redisCache.setCacheObject("alipay:bind:user:status:" + userId, "1", 4, TimeUnit.SECONDS);

View File

@ -61,6 +61,7 @@
sys_user u ON mil.user_id = u.user_id
WHERE
mil.user_id = #{userId}
and mil.del_flag = '0' and mi.del_flag = '0' and u.del_flag = '0'
ORDER BY
<choose>
<when test="orderByColumn == 'create_time'">

View File

@ -132,6 +132,7 @@
ON ml.user_id = u.user_id
WHERE
ml.user_id = #{userId}
and ml.del_flag = '0' and m.del_flag = '0' and u.del_flag = '0'
ORDER BY
<choose>
<when test="orderByColumn == 'create_time'">

View File

@ -88,6 +88,7 @@
ON wfl.user_id = u.user_id
WHERE
wfl.user_id = #{userId}
and wfl.del_flag = '0' and wf.del_flag = '0' and u.del_flag = '0'
ORDER BY
<choose>
<when test="orderByColumn == 'create_time'">