Compare commits

...

2 Commits

Author SHA1 Message Date
姜玉琦 ea52f8e363 Merge branch 'dev_xd' of http://62.234.3.186:3000/jiangyq/YZProjectCloud into dev_xd 2024-10-13 15:40:39 +08:00
姜玉琦 4e2416fee1 提交代码 2024-10-13 15:40:28 +08:00
28 changed files with 1067 additions and 127 deletions

View File

@ -20,9 +20,6 @@ import java.util.Map;
public interface RemoteProService
{
@GetMapping("/wxCallBack/maLogin/{code}")
public R<Map<String,Object>> maLogin(@PathVariable("code") String code, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);
/**
*
*

View File

@ -1,5 +1,6 @@
package com.yanzhu.system.api;
import com.yanzhu.system.api.domain.SysUserUniopen;
import com.yanzhu.system.api.model.LoginUser;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.*;
@ -20,6 +21,24 @@ import java.util.Map;
@FeignClient(contextId = "remoteUserService", value = ServiceNameConstants.SYSTEM_SERVICE, fallbackFactory = RemoteUserFallbackFactory.class)
public interface RemoteUserService
{
/**
*
* @param code
* @param source
* @return
*/
@GetMapping("/sysUserUniopen/getMaOpenId/{code}")
public R<Map<String,Object>> getMaOpenId(@PathVariable("code") String code, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);
/**
*
* @param maOpenId id
* @param source
* @return
*/
@GetMapping("/sysUserUniopen/findByMaOpenId/{maOpenId}")
public R<SysUserUniopen> findByMaOpenId(@PathVariable("maOpenId") String maOpenId, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);
/**
*
*

View File

@ -0,0 +1,121 @@
package com.yanzhu.system.api.domain;
import com.yanzhu.common.core.annotation.Excel;
import com.yanzhu.common.core.web.domain.BaseEntity;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
/**
* sys_user_uniopen
*
* @author JiangYuQi
* @date 2024-10-13
*/
public class SysUserUniopen extends BaseEntity
{
private static final long serialVersionUID = 1L;
/** 主键 */
private Long id;
/** 用户主键 */
@Excel(name = "用户主键")
private Long userId;
/** 用户账号 */
@Excel(name = "用户账号")
private String userName;
/** 用户昵称 */
@Excel(name = "用户昵称")
private String userNick;
/** 唯一关联id */
@Excel(name = "唯一关联id")
private String unionid;
/** 小程序授权id */
@Excel(name = "小程序授权id")
private String maOpenId;
/** 公众号授权id */
@Excel(name = "公众号授权id")
private String mpOpenId;
public void setId(Long id)
{
this.id = id;
}
public Long getId()
{
return id;
}
public void setUserId(Long userId)
{
this.userId = userId;
}
public Long getUserId()
{
return userId;
}
public void setUserName(String userName)
{
this.userName = userName;
}
public String getUserName()
{
return userName;
}
public void setUserNick(String userNick)
{
this.userNick = userNick;
}
public String getUserNick()
{
return userNick;
}
public void setUnionid(String unionid)
{
this.unionid = unionid;
}
public String getUnionid()
{
return unionid;
}
public void setMaOpenId(String maOpenId)
{
this.maOpenId = maOpenId;
}
public String getMaOpenId()
{
return maOpenId;
}
public void setMpOpenId(String mpOpenId)
{
this.mpOpenId = mpOpenId;
}
public String getMpOpenId()
{
return mpOpenId;
}
@Override
public String toString() {
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
.append("id", getId())
.append("userId", getUserId())
.append("userName", getUserName())
.append("userNick", getUserNick())
.append("unionid", getUnionid())
.append("maOpenId", getMaOpenId())
.append("mpOpenId", getMpOpenId())
.toString();
}
}

View File

@ -26,12 +26,6 @@ public class RemoteProFallbackFactory implements FallbackFactory<RemoteProServic
log.error("项目服务调用失败:{}", throwable.getMessage());
return new RemoteProService()
{
@Override
public R<Map<String,Object>> maLogin(String code, String source)
{
return R.fail("小程序登录失败:" + throwable.getMessage());
}
@Override
public R<Map<String,Object>> info(Long id, String source)
{

View File

@ -1,6 +1,7 @@
package com.yanzhu.system.api.factory;
import com.yanzhu.system.api.RemoteUserService;
import com.yanzhu.system.api.domain.SysUserUniopen;
import com.yanzhu.system.api.model.LoginUser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -28,6 +29,18 @@ public class RemoteUserFallbackFactory implements FallbackFactory<RemoteUserServ
log.error("用户服务调用失败:{}", throwable.getMessage());
return new RemoteUserService()
{
@Override
public R<Map<String,Object>> getMaOpenId(String code, String source)
{
return R.fail("获取小程序授权失败:" + throwable.getMessage());
}
@Override
public R<SysUserUniopen> findByMaOpenId(String maOpenId, String source)
{
return R.fail("查询小程序授权失败:" + throwable.getMessage());
}
@Override
public R<LoginUser> getUserInfo(String username, String source)
{

View File

@ -2,7 +2,8 @@ package com.yanzhu.auth.controller;
import com.yanzhu.auth.form.LoginBody;
import com.yanzhu.auth.form.RegisterBody;
import com.yanzhu.auth.form.WxLoginBody;
import com.yanzhu.auth.form.WxMaLoginBody;
import com.yanzhu.auth.form.WxMaOpenIdBody;
import com.yanzhu.auth.service.SysLoginService;
import com.yanzhu.common.core.constant.SecurityConstants;
import com.yanzhu.common.core.domain.R;
@ -20,6 +21,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import java.util.Map;
import java.util.Objects;
@ -57,16 +59,29 @@ public class TokenController
return R.ok(tokenService.createToken(userInfo));
}
/**
*
* @param body
* @return
*/
@PostMapping("getMaOpenId")
public R<?> getMaOpenId(@RequestBody @Valid WxMaOpenIdBody body)
{
String maOpenId = sysLoginService.getMaOpenId(body.getCode());
// 获取授权openId
return R.ok(maOpenId);
}
/**
*
* @param form
* @param body
* @return
*/
@PostMapping("maLogin")
public R<?> maLogin(@RequestBody WxLoginBody form)
public R<?> maLogin(@RequestBody @Valid WxMaLoginBody body)
{
// 用户登录
Map<String,Object> result = sysLoginService.maLogin(form.getCode(), form.getAppId());
Map<String,Object> result = sysLoginService.maLogin(body);
// 获取登录token
return R.ok(result);
}

View File

@ -1,35 +0,0 @@
package com.yanzhu.auth.form;
/**
*
*
* @author ruoyi
*/
public class WxLoginBody {
/**
*
*/
private String code;
/**
*
*/
private String appId;
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public String getAppId() {
return appId;
}
public void setAppId(String appId) {
this.appId = appId;
}
}

View File

@ -0,0 +1,40 @@
package com.yanzhu.auth.form;
import io.swagger.annotations.ApiModel;
import lombok.Data;
import javax.validation.constraints.NotBlank;
/**
*
*
* @author ruoyi
*/
@Data
@ApiModel(description = "微信小程序登录对象")
public class WxMaLoginBody {
/**
*
*/
private Long proId;
/**
*
*/
@NotBlank(message = "授权编号不能为空")
private String openId;
/**
*
*/
@NotBlank(message = "加密代码不能为空")
private String encryptedData;
/**
*
*/
@NotBlank(message = "加密方式不能为空")
private String iv;
}

View File

@ -0,0 +1,21 @@
package com.yanzhu.auth.form;
import io.swagger.annotations.ApiModel;
import lombok.Data;
import javax.validation.constraints.NotBlank;
/**
*
*/
@Data
@ApiModel(description = "微信小程序授权对象")
public class WxMaOpenIdBody {
/**
*
*/
@NotBlank(message = "授权码不能为空")
private String code;
}

View File

@ -1,6 +1,8 @@
package com.yanzhu.auth.service;
import com.yanzhu.auth.form.WxMaLoginBody;
import com.yanzhu.system.api.RemoteProService;
import com.yanzhu.system.api.domain.SysUserUniopen;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import com.yanzhu.common.core.constant.CacheConstants;
@ -124,14 +126,31 @@ public class SysLoginService
}
/**
*
*
*/
public Map<String,Object> maLogin(String code, String appId)
public String getMaOpenId(String code)
{
Map<String,Object> loginResult = remoteProService.maLogin(code,SecurityConstants.INNER).getData();
return loginResult;
Map<String,Object> loginResult = remoteUserService.getMaOpenId(code,SecurityConstants.INNER).getData();
return Convert.toStr(loginResult.get("openid"));
}
/**
*
*/
public Map<String,Object> maLogin(WxMaLoginBody loginBody)
{
// 查询小程序授权情况
R<SysUserUniopen> uniResult = remoteUserService.findByMaOpenId(loginBody.getOpenId(),SecurityConstants.INNER);
if(Objects.isNull(uniResult) || Objects.isNull(uniResult.getData())){
throw new ServiceException("当前微信还未绑定账号!!!请使用账号登录一次");
}
return null;
}
/**
* 退
*/
public void logout(String loginName)
{
recordLogService.recordLogininfor(loginName, Constants.LOGOUT, "退出成功");

View File

@ -113,6 +113,11 @@
<artifactId>swagger-annotations</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
<!-- Belerweb Pinyin4j -->
<dependency>
<groupId>com.belerweb</groupId>

View File

@ -77,12 +77,6 @@
<artifactId>yanzhu-common-swagger</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>

View File

@ -31,11 +31,11 @@ public class WxCallBackController {
*
*/
@InnerAuth
@GetMapping("/maLogin/{code}")
public R<Map<String, Object>> maLogin(@PathVariable("code") String code) {
@GetMapping("/getMaOpenId/{code}")
public R<Map<String, Object>> getMaOpenId(@PathVariable("code") String code) {
WxMaJscode2SessionResult sessionInfo =
wxMaService.getUserService().getSessionInfo(code);
log.info("wxLogin==>{}...{}",code,sessionInfo.getOpenid());
log.info("getMaOpenId==>{}...{}",code,sessionInfo.getOpenid());
try {
return R.ok(BeanUtils.beanToMap(sessionInfo));
}catch (Exception e){

View File

@ -0,0 +1,61 @@
package com.yanzhu.system.config;
import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.api.impl.WxMaServiceImpl;
import cn.binarywang.wx.miniapp.config.impl.WxMaDefaultConfigImpl;
import me.chanjar.weixin.mp.api.WxMpInMemoryConfigStorage;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
*
*/
@Configuration
public class WeChatConfig {
@Autowired
private WeChatProperties weChatProperties;
private static final Logger log = LoggerFactory.getLogger(WeChatConfig.class);
/**
*
* @return
*/
@Bean
public WxMpService wxMpService() {
WxMpInMemoryConfigStorage config = new WxMpInMemoryConfigStorage();
log.info("weChatProperties.mpAppId...{}",weChatProperties.getMpAppId());
log.info("weChatProperties.mpAppSecret...{}",weChatProperties.getMpAppSecret());
config.setAppId(weChatProperties.getMpAppId());
config.setSecret(weChatProperties.getMpAppSecret());
WxMpServiceImpl wxMpService = new WxMpServiceImpl();
wxMpService.setWxMpConfigStorage(config);
return wxMpService;
}
/**
*
* @return
*/
@Bean
public WxMaService wxMaService() {
WxMaDefaultConfigImpl wxMaConfig = new WxMaDefaultConfigImpl();
log.info("weChatProperties.maAppId...{}",weChatProperties.getMaAppId());
log.info("weChatProperties.maAppSecret...{}",weChatProperties.getMaAppSecret());
wxMaConfig.setAppid(weChatProperties.getMaAppId());
wxMaConfig.setSecret(weChatProperties.getMaAppSecret());
WxMaService wxMaService = new WxMaServiceImpl();
wxMaService.setWxMaConfig(wxMaConfig);
return wxMaService;
}
}

View File

@ -0,0 +1,26 @@
package com.yanzhu.system.config;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
/**
*
*/
@Data
@Component
@ConfigurationProperties(prefix = "wechat")
public class WeChatProperties {
/**
*
*/
private String mpAppId;
private String mpAppSecret;
/**
*
*/
private String maAppId;
private String maAppSecret;
}

View File

@ -1,33 +1,9 @@
package com.yanzhu.system.controller;
import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import javax.servlet.http.HttpServletResponse;
import com.yanzhu.common.core.constant.Constants;
import com.yanzhu.common.core.domain.R;
import com.yanzhu.common.core.enums.UserTypeEnums;
import com.yanzhu.common.core.text.Convert;
import com.yanzhu.common.redis.service.RedisService;
import com.yanzhu.system.domain.vo.TreeSelect;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.ArrayUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import com.yanzhu.common.core.domain.R;
import com.yanzhu.common.core.utils.StringUtils;
import com.yanzhu.common.core.utils.poi.ExcelUtil;
import com.yanzhu.common.core.web.controller.BaseController;
@ -35,6 +11,7 @@ import com.yanzhu.common.core.web.domain.AjaxResult;
import com.yanzhu.common.core.web.page.TableDataInfo;
import com.yanzhu.common.log.annotation.Log;
import com.yanzhu.common.log.enums.BusinessType;
import com.yanzhu.common.redis.service.RedisService;
import com.yanzhu.common.security.annotation.InnerAuth;
import com.yanzhu.common.security.annotation.RequiresPermissions;
import com.yanzhu.common.security.utils.SecurityUtils;
@ -42,12 +19,23 @@ import com.yanzhu.system.api.domain.SysDept;
import com.yanzhu.system.api.domain.SysRole;
import com.yanzhu.system.api.domain.SysUser;
import com.yanzhu.system.api.model.LoginUser;
import com.yanzhu.system.service.ISysConfigService;
import com.yanzhu.system.service.ISysDeptService;
import com.yanzhu.system.service.ISysPermissionService;
import com.yanzhu.system.service.ISysPostService;
import com.yanzhu.system.service.ISysRoleService;
import com.yanzhu.system.service.ISysUserService;
import com.yanzhu.system.domain.vo.TreeSelect;
import com.yanzhu.system.service.*;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.ArrayUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
/**
*
@ -57,6 +45,7 @@ import com.yanzhu.system.service.ISysUserService;
@RestController
@RequestMapping("/user")
public class SysUserController extends BaseController {
@Autowired
private RedisService redisService;
@ -387,4 +376,5 @@ public class SysUserController extends BaseController {
List<SysUser> list = userService.selectUserList(user);
return AjaxResult.success(list);
}
}

View File

@ -0,0 +1,157 @@
package com.yanzhu.system.controller;
import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult;
import com.yanzhu.common.core.domain.R;
import com.yanzhu.common.core.utils.bean.BeanUtils;
import com.yanzhu.common.core.utils.poi.ExcelUtil;
import com.yanzhu.common.core.web.controller.BaseController;
import com.yanzhu.common.core.web.domain.AjaxResult;
import com.yanzhu.common.core.web.page.TableDataInfo;
import com.yanzhu.common.log.annotation.Log;
import com.yanzhu.common.log.enums.BusinessType;
import com.yanzhu.common.security.annotation.InnerAuth;
import com.yanzhu.common.security.annotation.RequiresPermissions;
import com.yanzhu.system.api.domain.SysUserUniopen;
import com.yanzhu.system.service.ISysUserUniopenService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;
/**
* Controller
*
* @author JiangYuQi
* @date 2024-10-13
*/
@RestController
@RequestMapping("/sysUserUniopen")
public class SysUserUniopenController extends BaseController
{
@Autowired
private ISysUserUniopenService sysUserUniopenService;
@Autowired
private WxMaService wxMaService;
private static final Logger log = LoggerFactory.getLogger(SysUserController.class);
/**
*
*/
@RequiresPermissions("@ss.hasPermi('system:sysUserUniopen:list')")
@GetMapping("/list")
public TableDataInfo list(SysUserUniopen sysUserUniopen)
{
startPage();
List<SysUserUniopen> list = sysUserUniopenService.selectSysUserUniopenList(sysUserUniopen);
return getDataTable(list);
}
/**
*
*/
@RequiresPermissions("@ss.hasPermi('system:sysUserUniopen:export')")
@Log(title = "用户授权", businessType = BusinessType.EXPORT)
@PostMapping("/export")
public void export(HttpServletResponse response, SysUserUniopen sysUserUniopen)
{
List<SysUserUniopen> list = sysUserUniopenService.selectSysUserUniopenList(sysUserUniopen);
ExcelUtil<SysUserUniopen> util = new ExcelUtil<SysUserUniopen>(SysUserUniopen.class);
util.exportExcel(response, list, "用户授权数据");
}
/**
*
*/
@RequiresPermissions("@ss.hasPermi('system:sysUserUniopen:query')")
@GetMapping(value = "/{id}")
public AjaxResult getInfo(@PathVariable("id") Long id)
{
return success(sysUserUniopenService.selectSysUserUniopenById(id));
}
/**
*
*/
@RequiresPermissions("@ss.hasPermi('system:sysUserUniopen:add')")
@Log(title = "用户授权", businessType = BusinessType.INSERT)
@PostMapping
public AjaxResult add(@RequestBody SysUserUniopen sysUserUniopen)
{
return toAjax(sysUserUniopenService.insertSysUserUniopen(sysUserUniopen));
}
/**
*
*/
@RequiresPermissions("@ss.hasPermi('system:sysUserUniopen:edit')")
@Log(title = "用户授权", businessType = BusinessType.UPDATE)
@PutMapping
public AjaxResult edit(@RequestBody SysUserUniopen sysUserUniopen)
{
return toAjax(sysUserUniopenService.updateSysUserUniopen(sysUserUniopen));
}
/**
*
*/
@RequiresPermissions("@ss.hasPermi('system:sysUserUniopen:remove')")
@Log(title = "用户授权", businessType = BusinessType.DELETE)
@DeleteMapping("/{ids}")
public AjaxResult remove(@PathVariable Long[] ids)
{
return toAjax(sysUserUniopenService.deleteSysUserUniopenByIds(ids));
}
/**
*
*/
@InnerAuth
@GetMapping("/getMaOpenId/{code}")
public R<Map<String, Object>> getMaOpenId(@PathVariable("code") String code) {
WxMaJscode2SessionResult sessionInfo =
wxMaService.getUserService().getSessionInfo(code);
log.info("getMaOpenId==>{}...{}",code,sessionInfo.getOpenid());
try {
return R.ok(BeanUtils.beanToMap(sessionInfo));
}catch (Exception e){
return R.fail("小程序授权异常!!!");
}
}
@InnerAuth
@GetMapping("/findByUserId/{userId}")
public R<List<SysUserUniopen>> findByUserId(@PathVariable("userId") Long userId) {
return R.ok(sysUserUniopenService.selectSysUserUniopenByUserId(userId));
}
@InnerAuth
@GetMapping("/findByUserName/{userName}")
public R<List<SysUserUniopen>> findByUserName(@PathVariable("userName") String userName) {
return R.ok(sysUserUniopenService.selectSysUserUniopenByUserName(userName));
}
@InnerAuth
@GetMapping("/findByUnionid/{unionid}")
public R<SysUserUniopen> findByUnionid(@PathVariable("unionid") String unionid) {
return R.ok(sysUserUniopenService.selectSysUserUniopenByUnionid(unionid));
}
@InnerAuth
@GetMapping("/findByMaOpenId/{maOpenId}")
public R<SysUserUniopen> findByMaOpenId(@PathVariable("maOpenId") String maOpenId) {
return R.ok(sysUserUniopenService.selectSysUserUniopenByMaOpenId(maOpenId));
}
@InnerAuth
@GetMapping("/findByMpOpenId/{mpOpenId}")
public R<SysUserUniopen> findByMpOpenId(@PathVariable("mpOpenId") String mpOpenId) {
return R.ok(sysUserUniopenService.selectSysUserUniopenByMpOpenId(mpOpenId));
}
}

View File

@ -0,0 +1,102 @@
package com.yanzhu.system.mapper;
import com.yanzhu.system.api.domain.SysUserUniopen;
import java.util.List;
/**
* Mapper
*
* @author JiangYuQi
* @date 2024-10-13
*/
public interface SysUserUniopenMapper
{
/**
*
*
* @param id
* @return
*/
public SysUserUniopen selectSysUserUniopenById(Long id);
/**
*
*
* @param userId
* @return
*/
public List<SysUserUniopen> selectSysUserUniopenByUserId(Long userId);
/**
*
*
* @param userName
* @return
*/
public List<SysUserUniopen> selectSysUserUniopenByUserName(String userName);
/**
*
*
* @param unionid id
* @return
*/
public SysUserUniopen selectSysUserUniopenByUnionid(String unionid);
/**
*
*
* @param maOpenId id
* @return
*/
public SysUserUniopen selectSysUserUniopenByMaOpenId(String maOpenId);
/**
*
*
* @param mpOpenId id
* @return
*/
public SysUserUniopen selectSysUserUniopenByMpOpenId(String mpOpenId);
/**
*
*
* @param sysUserUniopen
* @return
*/
public List<SysUserUniopen> selectSysUserUniopenList(SysUserUniopen sysUserUniopen);
/**
*
*
* @param sysUserUniopen
* @return
*/
public int insertSysUserUniopen(SysUserUniopen sysUserUniopen);
/**
*
*
* @param sysUserUniopen
* @return
*/
public int updateSysUserUniopen(SysUserUniopen sysUserUniopen);
/**
*
*
* @param id
* @return
*/
public int deleteSysUserUniopenById(Long id);
/**
*
*
* @param ids
* @return
*/
public int deleteSysUserUniopenByIds(Long[] ids);
}

View File

@ -0,0 +1,102 @@
package com.yanzhu.system.service;
import com.yanzhu.system.api.domain.SysUserUniopen;
import java.util.List;
/**
* Service
*
* @author JiangYuQi
* @date 2024-10-13
*/
public interface ISysUserUniopenService
{
/**
*
*
* @param id
* @return
*/
public SysUserUniopen selectSysUserUniopenById(Long id);
/**
*
*
* @param userId
* @return
*/
public List<SysUserUniopen> selectSysUserUniopenByUserId(Long userId);
/**
*
*
* @param userName
* @return
*/
public List<SysUserUniopen> selectSysUserUniopenByUserName(String userName);
/**
*
*
* @param unionid id
* @return
*/
public SysUserUniopen selectSysUserUniopenByUnionid(String unionid);
/**
*
*
* @param maOpenId id
* @return
*/
public SysUserUniopen selectSysUserUniopenByMaOpenId(String maOpenId);
/**
*
*
* @param mpOpenId id
* @return
*/
public SysUserUniopen selectSysUserUniopenByMpOpenId(String mpOpenId);
/**
*
*
* @param sysUserUniopen
* @return
*/
public List<SysUserUniopen> selectSysUserUniopenList(SysUserUniopen sysUserUniopen);
/**
*
*
* @param sysUserUniopen
* @return
*/
public int insertSysUserUniopen(SysUserUniopen sysUserUniopen);
/**
*
*
* @param sysUserUniopen
* @return
*/
public int updateSysUserUniopen(SysUserUniopen sysUserUniopen);
/**
*
*
* @param ids
* @return
*/
public int deleteSysUserUniopenByIds(Long[] ids);
/**
*
*
* @param id
* @return
*/
public int deleteSysUserUniopenById(Long id);
}

View File

@ -0,0 +1,149 @@
package com.yanzhu.system.service.impl;
import java.util.List;
import com.yanzhu.system.api.domain.SysUserUniopen;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.yanzhu.system.mapper.SysUserUniopenMapper;
import com.yanzhu.system.service.ISysUserUniopenService;
/**
* Service
*
* @author JiangYuQi
* @date 2024-10-13
*/
@Service
public class SysUserUniopenServiceImpl implements ISysUserUniopenService
{
@Autowired
private SysUserUniopenMapper sysUserUniopenMapper;
/**
*
*
* @param id
* @return
*/
@Override
public SysUserUniopen selectSysUserUniopenById(Long id)
{
return sysUserUniopenMapper.selectSysUserUniopenById(id);
}
/**
*
*
* @param userId
* @return
*/
@Override
public List<SysUserUniopen> selectSysUserUniopenByUserId(Long userId){
return sysUserUniopenMapper.selectSysUserUniopenByUserId(userId);
}
/**
*
*
* @param userName
* @return
*/
@Override
public List<SysUserUniopen> selectSysUserUniopenByUserName(String userName){
return sysUserUniopenMapper.selectSysUserUniopenByUserName(userName);
}
/**
*
*
* @param unionid id
* @return
*/
@Override
public SysUserUniopen selectSysUserUniopenByUnionid(String unionid){
return sysUserUniopenMapper.selectSysUserUniopenByUnionid(unionid);
}
/**
*
*
* @param maOpenId id
* @return
*/
@Override
public SysUserUniopen selectSysUserUniopenByMaOpenId(String maOpenId){
return sysUserUniopenMapper.selectSysUserUniopenByMaOpenId(maOpenId);
}
/**
*
*
* @param mpOpenId id
* @return
*/
@Override
public SysUserUniopen selectSysUserUniopenByMpOpenId(String mpOpenId){
return sysUserUniopenMapper.selectSysUserUniopenByMpOpenId(mpOpenId);
}
/**
*
*
* @param sysUserUniopen
* @return
*/
@Override
public List<SysUserUniopen> selectSysUserUniopenList(SysUserUniopen sysUserUniopen)
{
return sysUserUniopenMapper.selectSysUserUniopenList(sysUserUniopen);
}
/**
*
*
* @param sysUserUniopen
* @return
*/
@Override
public int insertSysUserUniopen(SysUserUniopen sysUserUniopen)
{
return sysUserUniopenMapper.insertSysUserUniopen(sysUserUniopen);
}
/**
*
*
* @param sysUserUniopen
* @return
*/
@Override
public int updateSysUserUniopen(SysUserUniopen sysUserUniopen)
{
return sysUserUniopenMapper.updateSysUserUniopen(sysUserUniopen);
}
/**
*
*
* @param ids
* @return
*/
@Override
public int deleteSysUserUniopenByIds(Long[] ids)
{
return sysUserUniopenMapper.deleteSysUserUniopenByIds(ids);
}
/**
*
*
* @param id
* @return
*/
@Override
public int deleteSysUserUniopenById(Long id)
{
return sysUserUniopenMapper.deleteSysUserUniopenById(id);
}
}

View File

@ -0,0 +1,105 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.yanzhu.system.mapper.SysUserUniopenMapper">
<resultMap type="SysUserUniopen" id="SysUserUniopenResult">
<result property="id" column="id" />
<result property="userId" column="user_id" />
<result property="userName" column="user_name" />
<result property="userNick" column="user_nick" />
<result property="unionid" column="unionid" />
<result property="maOpenId" column="ma_open_id" />
<result property="mpOpenId" column="mp_open_id" />
</resultMap>
<sql id="selectSysUserUniopenVo">
select id, user_id, user_name, user_nick, unionid, ma_open_id, mp_open_id from sys_user_uniopen
</sql>
<select id="selectSysUserUniopenList" parameterType="SysUserUniopen" resultMap="SysUserUniopenResult">
<include refid="selectSysUserUniopenVo"/>
<where>
<if test="userId != null "> and user_id = #{userId}</if>
<if test="userName != null and userName != ''"> and user_name = #{userName}</if>
<if test="unionid != null and unionid != ''"> and unionid = #{unionid}</if>
<if test="maOpenId != null and maOpenId != ''"> and ma_open_id = #{maOpenId}</if>
<if test="mpOpenId != null and mpOpenId != ''"> and mp_open_id = #{mpOpenId}</if>
</where>
</select>
<select id="selectSysUserUniopenById" parameterType="Long" resultMap="SysUserUniopenResult">
<include refid="selectSysUserUniopenVo"/>
where id = #{id}
</select>
<select id="selectSysUserUniopenByUserId" parameterType="Long" resultMap="SysUserUniopenResult">
<include refid="selectSysUserUniopenVo"/>
where user_id = #{userId}
</select>
<select id="selectSysUserUniopenByUserName" parameterType="String" resultMap="SysUserUniopenResult">
<include refid="selectSysUserUniopenVo"/>
where user_name = #{userName}
</select>
<select id="selectSysUserUniopenByUnionid" parameterType="String" resultMap="SysUserUniopenResult">
<include refid="selectSysUserUniopenVo"/>
where unionid = #{unionid}
</select>
<select id="selectSysUserUniopenByMaOpenId" parameterType="String" resultMap="SysUserUniopenResult">
<include refid="selectSysUserUniopenVo"/>
where ma_open_id = #{maOpenId}
</select>
<select id="selectSysUserUniopenByMpOpenId" parameterType="String" resultMap="SysUserUniopenResult">
<include refid="selectSysUserUniopenVo"/>
where mp_open_id = #{mpOpenId}
</select>
<insert id="insertSysUserUniopen" parameterType="SysUserUniopen" useGeneratedKeys="true" keyProperty="id">
insert into sys_user_uniopen
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="userId != null">user_id,</if>
<if test="userName != null">user_name,</if>
<if test="userNick != null">user_nick,</if>
<if test="unionid != null">unionid,</if>
<if test="maOpenId != null">ma_open_id,</if>
<if test="mpOpenId != null">mp_open_id,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="userId != null">#{userId},</if>
<if test="userName != null">#{userName},</if>
<if test="userNick != null">#{userNick},</if>
<if test="unionid != null">#{unionid},</if>
<if test="maOpenId != null">#{maOpenId},</if>
<if test="mpOpenId != null">#{mpOpenId},</if>
</trim>
</insert>
<update id="updateSysUserUniopen" parameterType="SysUserUniopen">
update sys_user_uniopen
<trim prefix="SET" suffixOverrides=",">
<if test="userId != null">user_id = #{userId},</if>
<if test="userName != null">user_name = #{userName},</if>
<if test="userNick != null">user_nick = #{userNick},</if>
<if test="unionid != null">unionid = #{unionid},</if>
<if test="maOpenId != null">ma_open_id = #{maOpenId},</if>
<if test="mpOpenId != null">mp_open_id = #{mpOpenId},</if>
</trim>
where id = #{id}
</update>
<delete id="deleteSysUserUniopenById" parameterType="Long">
delete from sys_user_uniopen where id = #{id}
</delete>
<delete id="deleteSysUserUniopenByIds" parameterType="String">
delete from sys_user_uniopen where id in
<foreach item="id" collection="array" open="(" separator="," close=")">
#{id}
</foreach>
</delete>
</mapper>

View File

@ -17,6 +17,24 @@ export function login(data) {
})
}
// 获取授权
export function getMaOpenId(code) {
return request({
url: '/getMaOpenId',
method: 'post',
data: data,
})
}
// 登录方法
export function maLogin(data) {
return request({
url: '/maLogin',
method: 'post',
data: data,
})
}
// 登录方法
export function updatePwd(data) {
return request({

View File

@ -38,7 +38,7 @@ App({
projectInfoList: [],
},
onLaunch: function () {
onLaunch: function (options) {
if (!wx.cloud) {
console.error('请使用 2.2.3 或以上的基础库以使用云能力')
} else {
@ -56,15 +56,19 @@ App({
/**
* 初始化页面未登录时跳转到登录页
*/
if(options && options.proId){
//扫码进入时不效验登录...跳转授权登录页
}else{
if (!getToken()) {
setTimeout(() => {
this.toast("请使用手机号码登录");
}, 1000);
// setTimeout(() => {
// this.toast("请使用手机号码登录");
// }, 1000);
wx.redirectTo({
url: '/pages/login/index',
});
return false;
}
}
},
onLoad() {

View File

@ -2,7 +2,6 @@
module.exports = {
timeout: 60000,
appId: "wx2350a5efb3f28e66",
baseUrl: 'https://guangzhou.sxyanzhu.com/YZLJXM',
//baseUrl: 'http://127.0.0.1:8080/yanZhuProject',
noSecuritys:['/captchaImage','/wxApi/login']
baseUrl: 'http://127.0.0.1:8080',
noSecuritys:['/captchaImage','/login','/']
};

View File

@ -1,10 +1,14 @@
import {
getToken,
setToken
setToken,
getOpenId,
setOpenId
} from '../../utils/auth'
import {
login,
maLogin,
getCodeImg,
getMaOpenId,
refreshUser,
} from '../../api/login'
@ -20,7 +24,6 @@ Page({
code: '',
uuid: '',
codeUrl: '',
show: false,
checked: true
},
@ -43,19 +46,8 @@ Page({
})
},
onClickShow() {
this.setData({
show: true
});
},
onClickHide() {
this.setData({
show: false
});
},
onLoad: function (option) {
this.getMaOpenId();
if (getToken()) {
console.log("Authorization...{}", getToken());
//刷新权限信息
@ -74,6 +66,19 @@ Page({
}
},
/**
* 授权登录
*/
getMaOpenId: function () {
wx.login({
success: res => {
getMaOpenId(res.code).then(response => {
//
});
}
})
},
loadCodeImage: function () {
getCodeImg().then(res => {
let captchaEnabled = res.captchaEnabled === undefined ? true : res.captchaEnabled
@ -104,7 +109,6 @@ Page({
return;
}
//启动蒙版
//this.onClickShow();
let that = this;
//发送请求
login({
@ -126,7 +130,17 @@ Page({
},
getPhoneNumber(e) {
var_this = this
if(e.detail.code){
let data = {
code:e.detail.code,
iv: e.detail.iv,
encryptedData: e.detail.encryptedData
}
maLogin({})
}else{
//用户决绝授权
app.toast("请允许微信手机号一键登录");
}
console.log("getPhoneNumber", e)
},

View File

@ -27,10 +27,10 @@
</van-row>
<view class="login_btn" bindtap="userLogin">
立 即 登 录
账 号 登 录
</view>
<view class="wxlogin_btn">
<button open-type="getPhoneNumber">微 信 登 录</button>
<button open-type="getPhoneNumber" bindgetphonenumber="getPhoneNumber">微 信 登 录</button>
</view>
</view>

View File

@ -1,12 +1,22 @@
const TokenKey = 'YanZhu-App-Token'
const TokenKey = 'YanZhu-XD-App-Token'
const OpenIdKey = 'YanZhu-XD-App-OpenId'
export function getToken() {
return wx.getStorageSync(TokenKey)
}
export function setToken(token) {
return wx.setStorageSync(TokenKey, token)
}
export function removeToken() {
return wx.removeStorageSync(TokenKey)
}
export function getOpenId() {
return wx.getStorageSync(OpenIdKey)
}
export function setOpenId(openId) {
return wx.setStorageSync(OpenIdKey, openId)
}
export function removeOpenId() {
return wx.removeStorageSync(OpenIdKey)
}

View File

@ -16,7 +16,7 @@ function doRequest(url, method = 'GET', data, header = {}) {
}
wx.showLoading({
mask: true,
title: url == config.noSecuritys[1] ? '登录中' : '请等待'
title: url == config.noSecuritys[1] ? '登录中' : '加载中'
})
return new Promise((resolve, reject) => {
wx.request({