diff --git a/pigx-auth/src/main/java/com/pig4cloud/pigx/auth/service/PigxUserDetailsServiceImpl.java b/pigx-auth/src/main/java/com/pig4cloud/pigx/auth/service/PigxUserDetailsServiceImpl.java index 80a458c07..4da2fc605 100644 --- a/pigx-auth/src/main/java/com/pig4cloud/pigx/auth/service/PigxUserDetailsServiceImpl.java +++ b/pigx-auth/src/main/java/com/pig4cloud/pigx/auth/service/PigxUserDetailsServiceImpl.java @@ -21,7 +21,6 @@ package com.pig4cloud.pigx.auth.service; import cn.hutool.core.util.ArrayUtil; import cn.hutool.core.util.StrUtil; -import cn.hutool.json.JSONUtil; import com.pig4cloud.pigx.admin.api.dto.UserInfo; import com.pig4cloud.pigx.admin.api.entity.SysUser; import com.pig4cloud.pigx.admin.api.feign.RemoteUserService; @@ -29,7 +28,6 @@ import com.pig4cloud.pigx.common.core.constant.CommonConstant; import com.pig4cloud.pigx.common.core.constant.SecurityConstants; import com.pig4cloud.pigx.common.core.constant.enums.EnumLoginType; import com.pig4cloud.pigx.common.core.util.R; -import com.pig4cloud.pigx.common.security.social.WxSocialConfig; import com.pig4cloud.pigx.common.security.util.PigxUserDetailsService; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -39,7 +37,6 @@ import org.springframework.security.core.userdetails.User; import org.springframework.security.core.userdetails.UserDetails; import org.springframework.security.core.userdetails.UsernameNotFoundException; import org.springframework.stereotype.Service; -import org.springframework.web.client.RestTemplate; import java.util.Arrays; import java.util.Collection; @@ -55,12 +52,7 @@ import java.util.Set; @Service @AllArgsConstructor public class PigxUserDetailsServiceImpl implements PigxUserDetailsService { - private static final String WX_AUTHORIZATION_CODE_URL = "https://api.weixin.qq.com/sns/oauth2/access_token" + - "?appid=%s&secret=%s&code=%s&grant_type=authorization_code"; - private static final String REGEX = "@"; - private final RestTemplate restTemplate; private final RemoteUserService remoteUserService; - private final WxSocialConfig wxSocialConfig; /** * 用户密码登录 @@ -85,25 +77,7 @@ public class PigxUserDetailsServiceImpl implements PigxUserDetailsService { */ @Override public UserDetails loadUserBySocial(String inStr) throws UsernameNotFoundException { - String[] codeStr = inStr.split(REGEX); - String type = codeStr[0]; - String code = codeStr[1]; - - R userInfo = null; - if (EnumLoginType.WECHAT.getType().equals(type)) { - String url = String.format(WX_AUTHORIZATION_CODE_URL - , wxSocialConfig.getAppid(), wxSocialConfig.getSecret(), code); - String result = restTemplate.getForObject(url, String.class); - log.debug("微信响应报文:{}", result); - - Object obj = JSONUtil.parseObj(result).get("openid"); - if (obj != null) { - userInfo = remoteUserService.social(EnumLoginType.WECHAT.getType(), obj.toString()); - } - - } - - return getUserDetails(userInfo); + return getUserDetails(remoteUserService.social(inStr)); } /** diff --git a/pigx-common/pigx-common-core/src/main/java/com/pig4cloud/pigx/common/core/constant/SecurityConstants.java b/pigx-common/pigx-common-core/src/main/java/com/pig4cloud/pigx/common/core/constant/SecurityConstants.java index 7fd7c2906..a923ac523 100644 --- a/pigx-common/pigx-common-core/src/main/java/com/pig4cloud/pigx/common/core/constant/SecurityConstants.java +++ b/pigx-common/pigx-common-core/src/main/java/com/pig4cloud/pigx/common/core/constant/SecurityConstants.java @@ -78,4 +78,10 @@ public interface SecurityConstants { * 手机号登录URL */ String MOBILE_TOKEN_URL = "/mobile/token"; + + /** + * 微信获取OPENID + */ + String WX_AUTHORIZATION_CODE_URL = "https://api.weixin.qq.com/sns/oauth2/access_token" + + "?appid=%s&secret=%s&code=%s&grant_type=authorization_code"; } diff --git a/pigx-config/src/main/resources/config/pigx-auth-dev.yml b/pigx-config/src/main/resources/config/pigx-auth-dev.yml index ad424766e..0c0a5346a 100644 --- a/pigx-config/src/main/resources/config/pigx-auth-dev.yml +++ b/pigx-config/src/main/resources/config/pigx-auth-dev.yml @@ -5,16 +5,4 @@ spring: driver-class-name: com.mysql.jdbc.Driver username: root password: root - url: jdbc:mysql://mysql:3306/pigx?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false - -# 社交登录配置新 -social: - wx: - appid: wxd1678d3f83b1d83a - secret: 6ddb043f94da5d2172926abe8533504f - -# 社交登录配置新 -social: - wx: - appid: wxd1678d3f83b1d83a - secret: 6ddb043f94da5d2172926abe8533504f + url: jdbc:mysql://114.116.45.246:13306/pigx?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false diff --git a/pigx-upms/pigx-upms-api/src/main/java/com/pig4cloud/pigx/admin/api/entity/SysSocialDetails.java b/pigx-upms/pigx-upms-api/src/main/java/com/pig4cloud/pigx/admin/api/entity/SysSocialDetails.java new file mode 100755 index 000000000..cf0996c70 --- /dev/null +++ b/pigx-upms/pigx-upms-api/src/main/java/com/pig4cloud/pigx/admin/api/entity/SysSocialDetails.java @@ -0,0 +1,87 @@ +/* + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + */ + +package com.pig4cloud.pigx.admin.api.entity; + +import com.baomidou.mybatisplus.activerecord.Model; +import com.baomidou.mybatisplus.annotations.TableId; +import com.baomidou.mybatisplus.annotations.TableLogic; +import com.baomidou.mybatisplus.annotations.TableName; +import lombok.Data; +import lombok.EqualsAndHashCode; + import java.io.Serializable; +import java.time.LocalDateTime; + +/** + * 系统社交登录账号表 + * + * @author pigx code generator + * @date 2018-08-16 21:30:41 + */ +@Data +@EqualsAndHashCode(callSuper = true) +@TableName("sys_social_details") +public class SysSocialDetails extends Model { + private static final long serialVersionUID = 1L; + + /** + * 主鍵 + */ + @TableId + private Integer id; + /** + * 类型 + */ + private String type; + /** + * 描述 + */ + private String remark; + /** + * appid + */ + private String appId; + /** + * app_secret + */ + private String appSecret; + /** + * 回调地址 + */ + private String redirectUrl; + /** + * 创建时间 + */ + private LocalDateTime createTime; + /** + * 更新时间 + */ + private LocalDateTime updateTime; + /** + * 删除标记 + */ + @TableLogic + private String delFlag; + + /** + * 主键值 + */ + @Override + protected Serializable pkVal() { + return this.id; + } +} diff --git a/pigx-upms/pigx-upms-api/src/main/java/com/pig4cloud/pigx/admin/api/feign/RemoteUserService.java b/pigx-upms/pigx-upms-api/src/main/java/com/pig4cloud/pigx/admin/api/feign/RemoteUserService.java index 4fa0c51d4..bcf806353 100644 --- a/pigx-upms/pigx-upms-api/src/main/java/com/pig4cloud/pigx/admin/api/feign/RemoteUserService.java +++ b/pigx-upms/pigx-upms-api/src/main/java/com/pig4cloud/pigx/admin/api/feign/RemoteUserService.java @@ -48,11 +48,9 @@ public interface RemoteUserService { /** * 通过社交账号查询用户、角色信息 * - * @param type 社交账号类型 (QQ/WX) - * @param openid 账号 + * @param inStr appid@code * @return */ - @GetMapping("/user/social/{type}/{openid}") - R social(@PathVariable("type") String type - , @PathVariable("openid") String openid); + @GetMapping("/social/info/{inStr}") + R social(@PathVariable("inStr") String inStr); } diff --git a/pigx-upms/pigx-upms-api/src/main/java/com/pig4cloud/pigx/admin/api/feign/fallback/RemoteUserServiceFallbackImpl.java b/pigx-upms/pigx-upms-api/src/main/java/com/pig4cloud/pigx/admin/api/feign/fallback/RemoteUserServiceFallbackImpl.java index 49039463c..7f501bca0 100644 --- a/pigx-upms/pigx-upms-api/src/main/java/com/pig4cloud/pigx/admin/api/feign/fallback/RemoteUserServiceFallbackImpl.java +++ b/pigx-upms/pigx-upms-api/src/main/java/com/pig4cloud/pigx/admin/api/feign/fallback/RemoteUserServiceFallbackImpl.java @@ -48,14 +48,12 @@ public class RemoteUserServiceFallbackImpl implements RemoteUserService { /** * 通过社交账号查询用户、角色信息 * - * @param type 社交账号类型 (QQ/WX) - * @param openid 账号 + * @param inStr appid@code * @return */ @Override - public R social(String type, String openid) { - log.error("feign 查询用户信息失败:{}", openid); + public R social(String inStr) { + log.error("feign 查询用户信息失败:{}", inStr); return null; } - } diff --git a/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/config/ResourceServerConfigurer.java b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/config/ResourceServerConfigurer.java index 8668ed0a7..20925f5c3 100644 --- a/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/config/ResourceServerConfigurer.java +++ b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/config/ResourceServerConfigurer.java @@ -46,7 +46,7 @@ public class ResourceServerConfigurer extends ResourceServerConfigurerAdapter { http.authorizeRequests() .antMatchers("/actuator/**" , "/user/info/*" - , "/user/social/**" + , "/social/info/**" , "/log/**" , "/v2/api-docs").permitAll() .anyRequest().authenticated() diff --git a/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/controller/SysSocialDetailsController.java b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/controller/SysSocialDetailsController.java new file mode 100755 index 000000000..06f3a5e5d --- /dev/null +++ b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/controller/SysSocialDetailsController.java @@ -0,0 +1,132 @@ +/* + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + */ + +package com.pig4cloud.pigx.admin.controller; + +import com.baomidou.mybatisplus.mapper.EntityWrapper; +import com.baomidou.mybatisplus.plugins.Page; +import com.pig4cloud.pigx.admin.api.dto.UserInfo; +import com.pig4cloud.pigx.admin.api.entity.SysSocialDetails; +import com.pig4cloud.pigx.admin.service.SysSocialDetailsService; +import com.pig4cloud.pigx.admin.service.SysUserService; +import com.pig4cloud.pigx.common.core.util.Query; +import com.pig4cloud.pigx.common.core.util.R; +import lombok.AllArgsConstructor; +import org.springframework.web.bind.annotation.*; + +import java.util.Arrays; +import java.util.Map; + + +/** + * 系统社交登录账号表 + * + * @author pigx code generator + * @date 2018-08-16 21:30:41 + */ +@RestController +@RequestMapping("/social") +@AllArgsConstructor +public class SysSocialDetailsController { + private final SysUserService sysUserService; + private final SysSocialDetailsService sysSocialDetailsService; + + + /** + * 列表 + * + * @param params + * @return + */ + @GetMapping("/page") + public Page page(@RequestParam Map params) { + return sysSocialDetailsService.selectPage(new Query<>(params), new EntityWrapper<>()); + } + + + /** + * 信息 + * + * @param id + * @return R + */ + @GetMapping("/{id}") + public R info(@PathVariable("id") Integer id) { + SysSocialDetails sysSocialDetails = sysSocialDetailsService.selectById(id); + return new R<>(sysSocialDetails); + } + + /** + * 保存 + * + * @param sysSocialDetails + * @return R + */ + @PostMapping + public R save(@RequestBody SysSocialDetails sysSocialDetails) { + sysSocialDetailsService.insert(sysSocialDetails); + return new R<>(Boolean.TRUE); + } + + /** + * 修改 + * + * @param sysSocialDetails + * @return R + */ + @PutMapping + public R update(@RequestBody SysSocialDetails sysSocialDetails) { + sysSocialDetailsService.updateById(sysSocialDetails); + return new R<>(Boolean.TRUE); + } + + /** + * 删除 + * + * @param ids + * @return R + */ + @DeleteMapping + public R delete(@RequestBody Integer[] ids) { + sysSocialDetailsService.deleteBatchIds(Arrays.asList(ids)); + return new R<>(Boolean.TRUE); + } + + /** + * 通过社交账号查询用户、角色信息 + * + * @param inStr appid@code + * @return + */ + @GetMapping("/info/{inStr}") + public R social(@PathVariable String inStr) { + Map result = sysSocialDetailsService.findOpenId(inStr); + return new R<>(sysUserService.findUserInfo(result.get("type"), result.get("openId"))); + } + + /** + * 绑定社交账号 + * + * @param state 类型 + * @param code code + * @return + */ + @PostMapping("/bind") + public R bind(String state, String code) { + return new R<>(sysSocialDetailsService.bindSocial(state, code)); + } +} diff --git a/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/controller/UserController.java b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/controller/UserController.java index b427af97f..ed3e42509 100644 --- a/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/controller/UserController.java +++ b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/controller/UserController.java @@ -79,30 +79,6 @@ public class UserController { return new R<>(userService.findUserInfo(EnumLoginType.PWD.getType(), username)); } - /** - * 通过社交账号查询用户、角色信息 - * - * @param type 社交账号类型 (QQ/WX) - * @param openid 账号 - * @return - */ - @GetMapping("/social/{type}/{openid}") - public R social(@PathVariable String type, @PathVariable String openid) { - return new R<>(userService.findUserInfo(type, openid)); - } - - /** - * 绑定社交账号 - * - * @param state 类型 - * @param code code - * @return - */ - @PostMapping("/social/bind") - public R bind(String state, String code) { - return new R<>(userService.bindSocial(state, code)); - } - /** * 通过ID查询当前用户信息 * diff --git a/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/mapper/SysSocialDetailsMapper.java b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/mapper/SysSocialDetailsMapper.java new file mode 100755 index 000000000..b18f2da09 --- /dev/null +++ b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/mapper/SysSocialDetailsMapper.java @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + */ + +package com.pig4cloud.pigx.admin.mapper; + +import com.baomidou.mybatisplus.mapper.BaseMapper; +import com.pig4cloud.pigx.admin.api.entity.SysSocialDetails; +import org.apache.ibatis.annotations.Mapper; + +/** + * 系统社交登录账号表 + * + * @author pigx code generator + * @date 2018-08-16 21:30:41 + */ +@Mapper +public interface SysSocialDetailsMapper extends BaseMapper { + +} diff --git a/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/SysSocialDetailsService.java b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/SysSocialDetailsService.java new file mode 100755 index 000000000..f6b1d8a67 --- /dev/null +++ b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/SysSocialDetailsService.java @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + */ + +package com.pig4cloud.pigx.admin.service; + +import com.baomidou.mybatisplus.service.IService; +import com.pig4cloud.pigx.admin.api.entity.SysSocialDetails; + +import java.util.Map; + +/** + * 系统社交登录账号表 + * + * @author pigx code generator + * @date 2018-08-16 21:30:41 + */ +public interface SysSocialDetailsService extends IService { + + /** + * 绑定社交账号 + * + * @param state 类型 + * @param code code + * @return + */ + Boolean bindSocial(String state, String code); + + /** + * 通过客户端信息查询openId + * + * @param inStr appid @ code + * @return + */ + Map findOpenId(String inStr); +} + diff --git a/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/SysUserService.java b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/SysUserService.java index 3a325a66b..384ef2fd9 100644 --- a/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/SysUserService.java +++ b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/SysUserService.java @@ -83,13 +83,4 @@ public interface SysUserService extends IService { * @return 用户信息 */ UserVO selectUserVoById(Integer id); - - /** - * 绑定社交账号 - * - * @param state 类型 - * @param code code - * @return - */ - Boolean bindSocial(String state, String code); } diff --git a/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/impl/SysSocialDetailsServiceImpl.java b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/impl/SysSocialDetailsServiceImpl.java new file mode 100755 index 000000000..80f09ecd2 --- /dev/null +++ b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/impl/SysSocialDetailsServiceImpl.java @@ -0,0 +1,118 @@ +/* + * Copyright (c) 2018-2025, lengleng All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the pig4cloud.com developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: lengleng (wangiegie@gmail.com) + */ + +package com.pig4cloud.pigx.admin.service.impl; + +import cn.hutool.json.JSONUtil; +import com.baomidou.mybatisplus.service.impl.ServiceImpl; +import com.pig4cloud.pigx.admin.api.entity.SysSocialDetails; +import com.pig4cloud.pigx.admin.api.entity.SysUser; +import com.pig4cloud.pigx.admin.mapper.SysSocialDetailsMapper; +import com.pig4cloud.pigx.admin.mapper.SysUserMapper; +import com.pig4cloud.pigx.admin.service.SysSocialDetailsService; +import com.pig4cloud.pigx.common.core.constant.SecurityConstants; +import com.pig4cloud.pigx.common.core.constant.enums.EnumLoginType; +import com.pig4cloud.pigx.common.security.util.SecurityUtils; +import lombok.AllArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.cache.CacheManager; +import org.springframework.stereotype.Service; +import org.springframework.web.client.RestTemplate; + +import java.util.HashMap; +import java.util.Map; + +/** + * @author lengleng + * @date 2018年08月16日 + */ +@Slf4j +@AllArgsConstructor +@Service("sysSocialDetailsService") +public class SysSocialDetailsServiceImpl extends ServiceImpl implements SysSocialDetailsService { + private final CacheManager cacheManager; + private final RestTemplate restTemplate; + private final SysUserMapper sysUserMapper; + + /** + * 通过客户端信息查询openId + * + * @param inStr appid @ code + * @return + */ + @Override + public Map findOpenId(String inStr) { + String[] inStrs = inStr.split("@"); + return getOpenId(inStrs[0], inStrs[1]); + } + + /** + * 绑定社交账号 + * + * @param appId appId + * @param code code + * @return + */ + @Override + public Boolean bindSocial(String appId, String code) { + Map result = getOpenId(appId, code); + + SysUser condition = new SysUser(); + condition.setUsername(SecurityUtils.getUser()); + SysUser sysUser = sysUserMapper.selectOne(condition); + sysUser.setWxOpenid(result.get("openId")); + + sysUserMapper.updateAllColumnById(sysUser); + //更新緩存 + cacheManager.getCache("user_details").evict(result.get("openId")); + return Boolean.TRUE; + } + + /** + * 通过appid 、code 获得openID + * + * @param appId + * @param code + * @return + */ + private Map getOpenId(String appId, String code) { + SysSocialDetails condition = new SysSocialDetails(); + condition.setAppId(appId); + SysSocialDetails socialDetails = this.baseMapper.selectOne(condition); + + String openId = null; + //微信登录 + if (EnumLoginType.WECHAT.getType().equals(socialDetails.getType())) { + String url = String.format(SecurityConstants.WX_AUTHORIZATION_CODE_URL + , socialDetails.getAppId(), socialDetails.getAppSecret(), code); + String result = restTemplate.getForObject(url, String.class); + log.debug("微信响应报文:{}", result); + + Object obj = JSONUtil.parseObj(result).get("openid"); + if (obj == null) { + return null; + } + openId = obj.toString(); + } + + Map result = new HashMap<>(2); + result.put("type", socialDetails.getType()); + result.put("openId", openId); + return result; + } + +} diff --git a/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/impl/SysUserServiceImpl.java b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/impl/SysUserServiceImpl.java index c91d20948..fcd37e757 100644 --- a/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/impl/SysUserServiceImpl.java +++ b/pigx-upms/pigx-upms-biz/src/main/java/com/pig4cloud/pigx/admin/service/impl/SysUserServiceImpl.java @@ -41,6 +41,7 @@ import com.pig4cloud.pigx.admin.service.SysUserService; import com.pig4cloud.pigx.common.core.constant.enums.EnumLoginType; import com.pig4cloud.pigx.common.core.util.Query; import com.pig4cloud.pigx.common.core.util.R; +import com.pig4cloud.pigx.common.security.social.WxSocialConfig; import com.pig4cloud.pigx.common.security.util.SecurityUtils; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -69,12 +70,8 @@ import java.util.Set; @AllArgsConstructor public class SysUserServiceImpl extends ServiceImpl implements SysUserService { private static final PasswordEncoder ENCODER = new BCryptPasswordEncoder(); - private static final String WX_AUTHORIZATION_CODE_URL = "https://api.weixin.qq.com/sns/oauth2/access_token" + - "?appid=%s&secret=%s&code=%s&grant_type=authorization_code"; private final SysMenuService sysMenuService; private final SysUserMapper sysUserMapper; - private final CacheManager cacheManager; - private final RestTemplate restTemplate; private final SysRoleService sysRoleService; private final SysUserRoleService sysUserRoleService; @@ -127,34 +124,6 @@ public class SysUserServiceImpl extends ServiceImpl impl return userInfo; } - /** - * 绑定社交账号 - * - * @param state 类型 - * @param code code - * @return - */ - @Override - public Boolean bindSocial(String state, String code) { - String result = restTemplate.getForObject(WX_AUTHORIZATION_CODE_URL, String.class); - log.debug("微信响应报文:{}", result); - - Object obj = JSONUtil.parseObj(result).get("openid"); - if (obj == null) { - return Boolean.FALSE; - } - - SysUser condition = new SysUser(); - condition.setUsername(SecurityUtils.getUser()); - SysUser sysUser = this.selectOne(new EntityWrapper<>(condition)); - sysUser.setWxOpenid(obj.toString()); - sysUserMapper.updateAllColumnById(sysUser); - - //更新緩存 - cacheManager.getCache("user_details").evict(sysUser.getUsername()); - return Boolean.TRUE; - } - @Override public Page selectWithRolePage(Query query) { Object username = query.getCondition().get("username"); diff --git a/pigx-upms/pigx-upms-biz/src/main/resources/mapper/SysSocialDetailsMapper.xml b/pigx-upms/pigx-upms-biz/src/main/resources/mapper/SysSocialDetailsMapper.xml new file mode 100755 index 000000000..cae986a26 --- /dev/null +++ b/pigx-upms/pigx-upms-biz/src/main/resources/mapper/SysSocialDetailsMapper.xml @@ -0,0 +1,37 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/pigx-visual/pigx-codegen/src/main/resources/template/Controller.java.vm b/pigx-visual/pigx-codegen/src/main/resources/template/Controller.java.vm index 39417495a..cdf8e78d3 100755 --- a/pigx-visual/pigx-codegen/src/main/resources/template/Controller.java.vm +++ b/pigx-visual/pigx-codegen/src/main/resources/template/Controller.java.vm @@ -46,8 +46,7 @@ public class ${className}Controller { @GetMapping("/{${pk.lowerAttrName}}") public R info(@PathVariable("${pk.lowerAttrName}") ${pk.attrType} ${pk.lowerAttrName}){ ${className} ${classname} = ${classname}Service.selectById(${pk.lowerAttrName}); - - return new R<>(${classname}); + return new R<>(${classname}); } /** @@ -55,11 +54,10 @@ public class ${className}Controller { * @param ${classname} * @return R */ - @PostMapping("/save") + @PostMapping public R save(@RequestBody ${className} ${classname}){ ${classname}Service.insert(${classname}); - - return new R<>(Boolean.TRUE); + return new R<>(Boolean.TRUE); } /** @@ -67,10 +65,9 @@ public class ${className}Controller { * @param ${classname} * @return R */ - @PutMapping("/update") + @PutMapping public R update(@RequestBody ${className} ${classname}){ ${classname}Service.updateById(${classname}); - return new R<>(Boolean.TRUE); } @@ -79,10 +76,9 @@ public class ${className}Controller { * @param ${pk.lowerAttrName}s * @return R */ - @DeleteMapping("/delete") + @DeleteMapping public R delete(@RequestBody ${pk.attrType}[] ${pk.lowerAttrName}s){ ${classname}Service.deleteBatchIds(Arrays.asList(${pk.lowerAttrName}s)); - return new R<>(Boolean.TRUE); } diff --git a/pigx-visual/pigx-codegen/src/main/resources/template/crud.js.vm b/pigx-visual/pigx-codegen/src/main/resources/template/crud.js.vm index 09d28226b..e4baf3f55 100644 --- a/pigx-visual/pigx-codegen/src/main/resources/template/crud.js.vm +++ b/pigx-visual/pigx-codegen/src/main/resources/template/crud.js.vm @@ -16,16 +16,16 @@ */ export const tableOption = { - "border": true, - "index": true, - "stripe": true, - "menuAlign": "center", - "align": "center", - "editBtn": false, - "delBtn": false, - "addBtn": false, - "dic": [], - "column": [ + 'border': true, + 'index': true, + 'stripe': true, + 'menuAlign': "center", + 'align': "center", + 'editBtn': false, + 'delBtn': false, + 'addBtn': false, + 'dic': [], + 'column': [ #foreach ($column in $columns) { label: '$column.comments', diff --git a/pigx-visual/pigx-codegen/src/main/resources/template/index.vue.vm b/pigx-visual/pigx-codegen/src/main/resources/template/index.vue.vm index 11129d7b4..9848914f0 100755 --- a/pigx-visual/pigx-codegen/src/main/resources/template/index.vue.vm +++ b/pigx-visual/pigx-codegen/src/main/resources/template/index.vue.vm @@ -70,6 +70,10 @@ currentPage: 1, // 当前页数 pageSize: 20 // 每页显示多少条 }, + listQuery: { + page: 1, + limit: 20 + }, tableLoading: false, tableOption: tableOption } @@ -84,21 +88,20 @@ methods: { getList() { this.tableLoading = true - fetchList({ - page: this.page.currentPage, - limit: this.page.pageSize - }).then(response => { + fetchList(this.listQuery).then(response => { this.tableData = response.data.records - this.page.total = response.data.total - this.tableLoading = false + this.page.total = response.data.total + this.tableLoading = false }) }, currentChange(val) { this.page.currentPage = val + this.listQuery.page = val this.getList() }, sizeChange(val) { this.page.pageSize = val + this.listQuery.limit = val this.getList() }, /**