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 state = ShareCodeUtils.idToCode(SecurityUtils.getUserId()); // 防止CSRF攻击
String encodedRedirectUri = URLEncoder.encode(bindUrl, "UTF-8"); String encodedRedirectUri = URLEncoder.encode(bindUrl, "UTF-8");
// 线上 String authUrl = String.format(aliConfig.getOauthUrl(),appId, scope, encodedRedirectUri, state);
// 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
);
// QrCodeUtil.generate(authUrl, 300, 300, "png", response.getOutputStream()); // QrCodeUtil.generate(authUrl, 300, 300, "png", response.getOutputStream());
return R.ok(authUrl, "成功"); return R.ok(authUrl, "成功");

View File

@ -156,11 +156,15 @@ mall:
# alipayCertPath: D:\workspace\mochuang\mcwl-ai\mcwl-admin\src\main\resources\cert\dev\alipayPublicCert.crt # 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 # 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 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: huawei:
obs: obs:

View File

@ -148,6 +148,10 @@ mall:
gatewayUrl: https://openapi.alipay.com/gateway.do gatewayUrl: https://openapi.alipay.com/gateway.do
# 绑定回调 # 绑定回调
bindUrl: https://36072a51.r27.cpolar.top/ali/pay/callback 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: huawei:
obs: obs:

View File

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

View File

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

View File

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