diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysLoginController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysLoginController.java index bbb8900..715486b 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysLoginController.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysLoginController.java @@ -75,9 +75,6 @@ public class SysLoginController @PostMapping("/login/app") public AjaxResult loginForApp(@RequestBody LoginBody loginBody) { logger.info("login for app :{}", loginBody.getUsername()); - if (!"123456".equals(loginBody.getPassword())) { - return AjaxResult.error("密码错误"); - } return loginService.loginForApp(loginBody.getUsername(), loginBody.getPassword()); } diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/WechatLoginController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/WechatLoginController.java index 17caa19..7611b93 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/WechatLoginController.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/WechatLoginController.java @@ -62,8 +62,8 @@ public class WechatLoginController extends BaseController { @PostMapping("/for/app") public AjaxResult loginForApp(@RequestBody @Validated LoginForAppReq req) { String token = iWechatService.loginForApp(req); - Map map = new HashMap<>(); - map.put(Constants.TOKEN, token); - return AjaxResult.success(map); + AjaxResult ajaxResult = AjaxResult.success(); + ajaxResult.put(Constants.TOKEN, token); + return ajaxResult; } } diff --git a/ruoyi-admin/src/main/resources/application.yml b/ruoyi-admin/src/main/resources/application.yml index 881a0f4..d85600a 100644 --- a/ruoyi-admin/src/main/resources/application.yml +++ b/ruoyi-admin/src/main/resources/application.yml @@ -132,8 +132,8 @@ xss: wx: mpAppId: wxcf05e06d4ab81582 mpSecret: 252594e6b980bc2bfc74bbaad92b5e7b - wechatAppId: wxcf05e06d4ab81582 - wechatSecret: 252594e6b980bc2bfc74bbaad92b5e7b + wechatAppId: wxce986661acb731be + wechatSecret: a494e8b7804d6e9f3cef984161486aec aiPost: ip: 111.6.25.30 diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/config/SecurityConfig.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/config/SecurityConfig.java index 942c32c..208cc36 100644 --- a/ruoyi-framework/src/main/java/com/ruoyi/framework/config/SecurityConfig.java +++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/config/SecurityConfig.java @@ -112,7 +112,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter .antMatchers("/webjars/**").anonymous() .antMatchers("/*/api-docs").anonymous() .antMatchers("/druid/**").anonymous() - .antMatchers("/wechat/login/get/openid","/wechat/login/for/mp").anonymous() + .antMatchers("/wechat/login/**").anonymous() .antMatchers("/api/app/hospital/list").anonymous() // 除上面外的所有请求全部需要鉴权认证 .anyRequest().authenticated() diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/SysLoginService.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/SysLoginService.java index 34d3ed0..2c9f3de 100644 --- a/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/SysLoginService.java +++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/SysLoginService.java @@ -119,6 +119,11 @@ public class SysLoginService ajax.put("flag", false); } else { SysUser sysUser = userService.selectUserByUserName(username); + // 验证密码 + if (!SecurityUtils.matchesPassword(password, sysUser.getPassword())) { + log.info("登录用户:{} 密码不正确.", username); + throw new ServiceException("登录失败!"); + } LoginUser loginUser = new LoginUser(); sysUser.setDoctorId(tDoctor.getId()); sysUser.setHospitalId(tDoctor.getHospitalId()); diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/WechatServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/WechatServiceImpl.java index 53c3c1a..bb10279 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/WechatServiceImpl.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/WechatServiceImpl.java @@ -1,11 +1,10 @@ package com.ruoyi.system.service.impl; import com.alibaba.fastjson.JSONObject; -import com.ruoyi.common.constant.Constants; import com.ruoyi.common.core.domain.entity.SysUser; import com.ruoyi.common.core.domain.model.LoginUser; import com.ruoyi.common.exception.ServiceException; -import com.ruoyi.common.utils.MessageUtils; +import com.ruoyi.common.utils.SecurityUtils; import com.ruoyi.common.utils.StringUtils; import com.ruoyi.common.utils.http.HttpUtils; import com.ruoyi.common.utils.ip.IpUtils; @@ -20,10 +19,12 @@ import com.ruoyi.system.domain.resp.GetOpenidResp; import com.ruoyi.system.mapper.TDoctorMapper; import com.ruoyi.system.mapper.TPatientMapper; import com.ruoyi.system.mapper.TWechatUserMapper; +import com.ruoyi.system.service.ISysUserService; import com.ruoyi.system.service.IWechatService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.BeanUtils; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; @@ -66,6 +67,9 @@ public class WechatServiceImpl implements IWechatService { @Resource private UserTokenService userTokenService; + @Autowired + private ISysUserService userService; + @Override public GetOpenidResp getOpenid(GetOpenidReq req, HttpServletRequest request) { //查询openid @@ -151,12 +155,24 @@ public class WechatServiceImpl implements IWechatService { wechatUser.setUserId(currentDoctor.getId()); tDoctor.setId(currentDoctor.getId()); } else { - // 不存在 患者信息入库 + SysUser sysUser = new SysUser(); + sysUser.setPhonenumber(req.getPhone()); + sysUser.setUserName(req.getPhone()); + sysUser.setNickName(req.getName()); + sysUser.setStatus("0"); + sysUser.setDelFlag("0"); + sysUser.setPassword(SecurityUtils.encryptPassword("123456")); + Long[] roles = new Long[]{3L}; + sysUser.setRoleIds(roles); + userService.insertUser(sysUser); + // 不存在 医生信息入库 tDoctor.setDelFlag("0"); tDoctor.setCreateTime(new Date()); tDoctor.setUpdateTime(new Date()); + tDoctor.setUserId(sysUser.getUserId()); tDoctorMapper.insertTDoctor(tDoctor); wechatUser.setUserId(tDoctor.getId()); + } // 绑定openid wechatUser.setUnionid(req.getUnionid()); @@ -183,6 +199,7 @@ public class WechatServiceImpl implements IWechatService { String url = String.format(WechatKeys.WECHAT_CODE_TO_UNIONID_URL, wechatAppId, wechatSecret, req.getCode()); String json = HttpUtils.sendGet(url); JSONObject jsonObject = JSONObject.parseObject(json); + logger.info("login wechat user info :{}", jsonObject.toJSONString()); String unionid = (String) jsonObject.get("unionid"); logger.info("login openid:{}", unionid); if (StringUtils.isEmpty(unionid)) { @@ -256,7 +273,8 @@ public class WechatServiceImpl implements IWechatService { loginUser.setUserId(tDoctor.getUserId()); SysUser user = new SysUser(); user.setUserId(tDoctor.getUserId()); - user.setUserName(tDoctor.getName()); + user.setUserName(tDoctor.getPhone()); + user.setNickName(tDoctor.getName()); user.setDelFlag(tDoctor.getDelFlag()); user.setSex(tDoctor.getSex()); user.setPhonenumber(tDoctor.getPhone());