新增:无感登录接口
This commit is contained in:
@@ -51,6 +51,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
|
||||
"/api/parseToken/*",
|
||||
"/api/login-alipay/*",
|
||||
"/api/wx-login/loginByMpWxPhone",
|
||||
"/api/wx-login/loginByOpenId",
|
||||
"/api/system/wx-native-pay/**",
|
||||
"/api/system/wx-pay/**",
|
||||
"/api/wxWorkQrConnect",
|
||||
|
||||
@@ -2,18 +2,22 @@ package com.gxwebsoft.common.system.controller;
|
||||
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.lang.Validator;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.RandomUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.http.HttpRequest;
|
||||
import cn.hutool.http.HttpUtil;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.gxwebsoft.common.core.config.ConfigProperties;
|
||||
import com.gxwebsoft.common.core.exception.BusinessException;
|
||||
import com.gxwebsoft.common.core.security.JwtSubject;
|
||||
import com.gxwebsoft.common.core.security.JwtUtil;
|
||||
import com.gxwebsoft.common.core.utils.CommonUtil;
|
||||
import com.gxwebsoft.common.core.utils.JSONUtil;
|
||||
import com.gxwebsoft.common.core.utils.RedisUtil;
|
||||
import com.gxwebsoft.common.core.web.ApiResult;
|
||||
import com.gxwebsoft.common.core.web.BaseController;
|
||||
import com.gxwebsoft.common.system.entity.*;
|
||||
@@ -54,6 +58,8 @@ public class WxLoginController extends BaseController {
|
||||
@Resource
|
||||
private RoleService roleService;
|
||||
@Resource
|
||||
private RedisUtil redisUtil;
|
||||
@Resource
|
||||
private ConfigProperties config;
|
||||
|
||||
public WxLoginController(StringRedisTemplate redisTemplate) {
|
||||
@@ -352,6 +358,41 @@ public class WxLoginController extends BaseController {
|
||||
}
|
||||
|
||||
|
||||
@ApiOperation("openid无感登录")
|
||||
@PostMapping("/loginByOpenId")
|
||||
public ApiResult<?> loginByOpenId(@RequestBody Mp mp) {
|
||||
System.out.println("mp = " + mp);
|
||||
String key1 = "AppId:".concat(mp.getTenantId().toString());
|
||||
String key2 = "AppSecret:".concat(mp.getTenantId().toString());
|
||||
String AppId = redisUtil.get(key1);
|
||||
String AppSecret = redisUtil.get(key2);
|
||||
|
||||
// 请求微信接口获取openid
|
||||
String apiUrl = "https://api.weixin.qq.com/sns/jscode2session";
|
||||
final HashMap<String, Object> map = new HashMap<>();
|
||||
map.put("appid",AppId);
|
||||
map.put("secret",AppSecret);
|
||||
map.put("js_code",mp.getCode());
|
||||
map.put("grant_type","authorization_code");
|
||||
final String response = HttpUtil.get(apiUrl,map);
|
||||
final JSONObject jsonObject = JSONObject.parseObject(response);
|
||||
String openid = jsonObject.getString("openid");
|
||||
String sessionKey = jsonObject.getString("session_key");
|
||||
String unionid = jsonObject.getString("unionid");
|
||||
System.out.println("openid = " + openid);
|
||||
|
||||
if (StrUtil.isNotBlank(openid)) {
|
||||
User user = userService.getOne(new LambdaQueryWrapper<User>().eq(User::getOpenid, openid).last("limit 1"));
|
||||
if (ObjectUtil.isEmpty(user)) {
|
||||
// 注册新用户
|
||||
final UserParam param = new UserParam();
|
||||
addUser(param);
|
||||
user = userService.getOne(new LambdaQueryWrapper<User>().eq(User::getOpenid, openid));
|
||||
}
|
||||
return success("登录成功", user);
|
||||
}
|
||||
return fail("登录失败",openid);
|
||||
}
|
||||
|
||||
/**
|
||||
* 文件上传位置(服务器)
|
||||
|
||||
100
src/main/java/com/gxwebsoft/common/system/entity/Mp.java
Normal file
100
src/main/java/com/gxwebsoft/common/system/entity/Mp.java
Normal file
@@ -0,0 +1,100 @@
|
||||
package com.gxwebsoft.common.system.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 小程序信息
|
||||
*
|
||||
* @author 科技小王子
|
||||
* @since 2024-07-21 23:03:05
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@ApiModel(value = "Mp对象", description = "小程序信息")
|
||||
@TableName("cms_mp")
|
||||
public class Mp implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@ApiModelProperty(value = "ID")
|
||||
@TableId(value = "mp_id", type = IdType.AUTO)
|
||||
private Integer mpId;
|
||||
|
||||
@ApiModelProperty(value = "是否主账号")
|
||||
private Integer type;
|
||||
|
||||
@ApiModelProperty(value = "小程序ID")
|
||||
private String appId;
|
||||
|
||||
@ApiModelProperty(value = "小程序密钥")
|
||||
private String appSecret;
|
||||
|
||||
@ApiModelProperty(value = "小程序名称")
|
||||
private String mpName;
|
||||
|
||||
@ApiModelProperty(value = "小程序简称")
|
||||
private String shortName;
|
||||
|
||||
@ApiModelProperty(value = "头像")
|
||||
private String avatar;
|
||||
|
||||
@ApiModelProperty(value = "小程序码")
|
||||
private String mpQrcode;
|
||||
|
||||
@ApiModelProperty(value = "微信认证")
|
||||
private Integer authentication;
|
||||
|
||||
@ApiModelProperty(value = "主体信息")
|
||||
private String companyName;
|
||||
|
||||
@ApiModelProperty(value = "小程序备案")
|
||||
private String icpNo;
|
||||
|
||||
@ApiModelProperty(value = "登录邮箱")
|
||||
private String email;
|
||||
|
||||
@ApiModelProperty(value = "登录密码")
|
||||
private String password;
|
||||
|
||||
@ApiModelProperty(value = "原始ID")
|
||||
private String ghId;
|
||||
|
||||
@ApiModelProperty(value = "入口页面")
|
||||
private String mainPath;
|
||||
|
||||
@ApiModelProperty(value = "过期时间")
|
||||
private Date expirationTime;
|
||||
|
||||
@ApiModelProperty(value = "排序(数字越小越靠前)")
|
||||
private Integer sortNumber;
|
||||
|
||||
@ApiModelProperty(value = "介绍")
|
||||
private String comments;
|
||||
|
||||
@ApiModelProperty(value = "用户ID")
|
||||
private Integer userId;
|
||||
|
||||
@ApiModelProperty(value = "状态, 0正常, 1冻结")
|
||||
private Integer status;
|
||||
|
||||
@ApiModelProperty(value = "是否删除, 0否, 1是")
|
||||
@TableLogic
|
||||
private Integer deleted;
|
||||
|
||||
@ApiModelProperty(value = "租户id")
|
||||
private Integer tenantId;
|
||||
|
||||
@ApiModelProperty(value = "注册时间")
|
||||
private Date createTime;
|
||||
|
||||
@ApiModelProperty(value = "登录凭证")
|
||||
@TableField(exist = false)
|
||||
private String code;
|
||||
|
||||
}
|
||||
@@ -103,6 +103,9 @@
|
||||
<if test="param.recommend != null">
|
||||
AND a.recommend = #{param.recommend}
|
||||
</if>
|
||||
<if test="param.gradeId != null">
|
||||
AND a.grade_id = #{param.gradeId}
|
||||
</if>
|
||||
<if test="param.isAdmin != null">
|
||||
AND a.is_admin = #{param.isAdmin}
|
||||
</if>
|
||||
|
||||
Reference in New Issue
Block a user