feat:免密支付

This commit is contained in:
dzc committed 2025-12-25 13:27:25 +08:00
1 parent bbeef4536a
commit 0a2ec15518
9 files changed
+329 -184

No files matched your search

@@ -0,0 +1,27 @@
package com.bsd.pjcloud.app.api.constant;
import cn.hutool.core.util.ObjectUtil;
import lombok.AllArgsConstructor;
import lombok.Getter;
import java.util.Arrays;
/**
* app用户类型
*/
@AllArgsConstructor
@Getter
public enum AppUserTypeEnum {
MINI_WECHAT("10", "微信小程序用户"),
MINI_ALIPAY("20", "支付宝小程序用户"),
;
private final String type;
private final String description;
public static AppUserTypeEnum valueOfByType(String type) {
if (ObjectUtil.isEmpty(type)) return null;
return Arrays.stream(values()).filter(v -> ObjectUtil.equals(type, v.getType())).findFirst().get();
}
}
@@ -40,122 +40,134 @@ import java.time.LocalDateTime;
@Schema(description = "app用户表")
public class AppUser extends Model<AppUser> {
private static final long serialVersionUID = 1L;
private static final long serialVersionUID = 1L;
/**
* userId
*/
@TableId(type = IdType.ASSIGN_ID)
@Schema(description = "userId")
private Long userId;
/**
* userId
*/
@TableId(type = IdType.ASSIGN_ID)
@Schema(description = "userId")
private Long userId;
/**
* 用户名
*/
@Schema(description = "用户名")
private String username;
/**
* 用户类型
*/
@Schema(description = "用户类型")
private String userType;
/**
* 密码
*/
@Schema(description = "密码")
private String password;
/**
* 用户名
*/
@Schema(description = "用户名")
private String username;
/**
* 随机盐
*/
@JsonIgnore
@Schema(description = "随机盐")
private String salt;
/**
* 密码
*/
@Schema(description = "密码")
private String password;
/**
* 手机号
*/
@Schema(description = "手机号")
private String phone;
/**
* 随机盐
*/
@JsonIgnore
@Schema(description = "随机盐")
private String salt;
/**
* 头像
*/
@Schema(description = "头像")
private String avatar;
/**
* 手机号
*/
@Schema(description = "手机号")
private String phone;
/**
* 昵称
*/
@Schema(description = "拓展字段:昵称")
private String nickname;
/**
* 头像
*/
@Schema(description = "头像")
private String avatar;
/**
* 姓名
*/
@Schema(description = "拓展字段:姓名")
private String name;
/**
* 昵称
*/
@Schema(description = "拓展字段:昵称")
private String nickname;
/**
* 邮箱
*/
@Schema(description = "拓展字段:邮箱")
private String email;
/**
* 姓名
*/
@Schema(description = "拓展字段:姓名")
private String name;
/**
* 创建人
*/
@Schema(description = "创建人")
@TableField(fill = FieldFill.INSERT)
private String createBy;
/**
* 邮箱
*/
@Schema(description = "拓展字段:邮箱")
private String email;
/**
* 修改人
*/
@Schema(description = "修改人")
@TableField(fill = FieldFill.UPDATE)
private String updateBy;
/**
* 第三方登录扩展字段
*/
@Schema(description = "第三方登录扩展字段")
private String loginExtJson;
/**
* 创建时间
*/
@Schema(description = "创建时间")
@TableField(fill = FieldFill.INSERT)
private LocalDateTime createTime;
/**
* 创建人
*/
@Schema(description = "创建人")
@TableField(fill = FieldFill.INSERT)
private String createBy;
/**
* 修改时间
*/
@Schema(description = "修改时间")
@TableField(fill = FieldFill.UPDATE)
private LocalDateTime updateTime;
/**
* 修改人
*/
@Schema(description = "修改人")
@TableField(fill = FieldFill.UPDATE)
private String updateBy;
/**
* 删除标记
*/
@Schema(description = "删除标记,1:已删除,0:正常")
@TableField(fill = FieldFill.INSERT)
@TableLogic
private String delFlag;
/**
* 创建时间
*/
@Schema(description = "创建时间")
@TableField(fill = FieldFill.INSERT)
private LocalDateTime createTime;
/**
* 所属租户
*/
@Schema(description = "所属租户", hidden = true)
private Long tenantId;
/**
* 修改时间
*/
@Schema(description = "修改时间")
@TableField(fill = FieldFill.UPDATE)
private LocalDateTime updateTime;
/**
* 最后一次密码修改时间
*/
@Schema(description = "最后一次密码修改时间")
private LocalDateTime lastModifiedTime;
/**
* 删除标记
*/
@Schema(description = "删除标记,1:已删除,0:正常")
@TableField(fill = FieldFill.INSERT)
@TableLogic
private String delFlag;
/**
* 锁定标记
*/
@Schema(description = "锁定标记")
private String lockFlag;
/**
* 所属租户
*/
@Schema(description = "所属租户", hidden = true)
private Long tenantId;
/**
* 微信小程序登录openId
*/
@Schema(description = "微信小程序登录openId")
private String wxOpenid;
/**
* 最后一次密码修改时间
*/
@Schema(description = "最后一次密码修改时间")
private LocalDateTime lastModifiedTime;
/**
* 锁定标记
*/
@Schema(description = "锁定标记")
private String lockFlag;
/**
* openId
*/
@Schema(description = "openId")
private String openid;
}
@@ -27,32 +27,27 @@ import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
/**
* @author pjcloud
* @date 2018/6/22
*/
@FeignClient(contextId = "remoteAppUserService", value = ServiceNameConstants.APP_SERVER)
public interface RemoteAppUserService {
/**
* 通过用户名查询用户、角色信息
* @param username 用户名
* @param from 调用标志
* @return R
*/
@NoToken
@GetMapping("/appuser/info/{username}")
R<AppUserInfo> info(@PathVariable("username") String username);
/**
* 通过用户名查询用户、角色信息
*/
@NoToken
@GetMapping("/appuser/info/{username}")
R<AppUserInfo> info(@PathVariable("username") String username);
/**
* 通过社交账号或手机号查询用户、角色信息
* @param inStr appid@code
* @param from 调用标志
* @return
*/
@NoToken
@GetMapping("/appsocial/info/{inStr}")
R<AppUserInfo> social(@PathVariable("inStr") String inStr);
@NoToken
@GetMapping("/appuser/infoByUserId/{userId}")
R<AppUserInfo> infoByUserId(@PathVariable("userId") Long userId);
/**
* 通过社交账号或手机号查询用户、角色信息
*/
@NoToken
@GetMapping("/appsocial/info/{inStr}")
R<AppUserInfo> social(@PathVariable("inStr") String inStr);
}
@@ -81,6 +81,8 @@ public class AppUserController {
/* ************************************* end app end ************************************* */
/* ************************************* start 远程调用 start ************************************* */
@Inner
@GetMapping("/info/{username}")
public R info(@PathVariable String username) {
@@ -95,6 +97,19 @@ public class AppUserController {
return R.ok(appUserService.findUserInfo(user));
}
@Inner
@GetMapping("/infoByUserId/{userId}")
public R<AppUserInfo> infoByUserId(@PathVariable Long userId) {
AppUser user = appUserService.getOne(Wrappers.<AppUser>query()
.lambda()
.eq(AppUser::getUserId, userId)
);
if (user == null) return R.failed();
return R.ok(appUserService.findUserInfo(user));
}
/* ************************************* end 远程调用 end ************************************* */
/**
* 分页查询
*/
@@ -1,12 +1,14 @@
package com.bsd.pjcloud.app.handler;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.json.JSONUtil;
import com.alipay.api.AlipayClient;
import com.alipay.api.AlipayConfig;
import com.alipay.api.DefaultAlipayClient;
import com.alipay.api.request.AlipaySystemOauthTokenRequest;
import com.alipay.api.response.AlipaySystemOauthTokenResponse;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.bsd.pjcloud.app.api.constant.AppUserTypeEnum;
import com.bsd.pjcloud.app.api.dto.AppUserInfo;
import com.bsd.pjcloud.app.api.entity.AppUser;
import com.bsd.pjcloud.app.config.MiniAlipayConf;
@@ -106,18 +108,22 @@ public class MiniAlipayLoginHandler extends AbstractLoginHandler {
*/
@Override
public AppUserInfo info(String openId) {
AppUser user = appUserService.getOne(Wrappers.<AppUser>query().lambda().eq(AppUser::getWxOpenid, openId));
AppUser user = appUserService.getOne(Wrappers.<AppUser>query().lambda().eq(AppUser::getOpenid, openId));
if (ObjectUtil.isEmpty(user)) {
log.info("支付宝小程序openId:{},创建新的用户", openId);
String name = "支付宝游客-" + openId;
AppUser appUser = new AppUser();
appUser.setWxOpenid(openId);
appUser.setOpenid(openId);
appUser.setUserType(AppUserTypeEnum.MINI_ALIPAY.getType());
appUser.setUsername(name);
appUser.setName(name);
appUser.setCreateBy(openId);
appUser.setUpdateBy(openId);
appUserService.saveOrUpdate(appUser);
return appUserService.findUserInfo(user);
}
if (ObjectUtil.isEmpty(user.getLoginExtJson())) {
}
return appUserService.findUserInfo(user);
}
@@ -127,7 +133,7 @@ public class MiniAlipayLoginHandler extends AbstractLoginHandler {
*/
@Override
public Boolean bind(AppUser user, String identify) {
user.setWxOpenid(identify);
user.setOpenid(identify);
appUserService.updateById(user);
return true;
}
@@ -82,13 +82,13 @@ public class MiniWechatLoginHandler extends AbstractLoginHandler {
*/
@Override
public AppUserInfo info(String openId) {
AppUser user = appUserService.getOne(Wrappers.<AppUser>query().lambda().eq(AppUser::getWxOpenid, openId));
AppUser user = appUserService.getOne(Wrappers.<AppUser>query().lambda().eq(AppUser::getOpenid, openId));
// 未注册用户自动注册
if (Objects.isNull(user)) {
log.info("微信小程序未绑定:{},创建新的用户", openId);
AppUser appUser = new AppUser();
appUser.setWxOpenid(openId);
appUser.setOpenid(openId);
appUser.setUsername(openId);
appUser.setCreateBy(openId);
appUser.setUpdateBy(openId);
@@ -111,7 +111,7 @@ public class MiniWechatLoginHandler extends AbstractLoginHandler {
*/
@Override
public Boolean bind(AppUser user, String identify) {
user.setWxOpenid(identify);
user.setOpenid(identify);
appUserService.updateById(user);
return true;
}