医生微信登录接口

master
heminjian502 2 years ago
parent 049b8b13e9
commit 709bc39ffb

@ -75,9 +75,6 @@ public class SysLoginController
@PostMapping("/login/app") @PostMapping("/login/app")
public AjaxResult loginForApp(@RequestBody LoginBody loginBody) { public AjaxResult loginForApp(@RequestBody LoginBody loginBody) {
logger.info("login for app :{}", loginBody.getUsername()); logger.info("login for app :{}", loginBody.getUsername());
if (!"123456".equals(loginBody.getPassword())) {
return AjaxResult.error("密码错误");
}
return loginService.loginForApp(loginBody.getUsername(), loginBody.getPassword()); return loginService.loginForApp(loginBody.getUsername(), loginBody.getPassword());
} }

@ -62,8 +62,8 @@ public class WechatLoginController extends BaseController {
@PostMapping("/for/app") @PostMapping("/for/app")
public AjaxResult loginForApp(@RequestBody @Validated LoginForAppReq req) { public AjaxResult loginForApp(@RequestBody @Validated LoginForAppReq req) {
String token = iWechatService.loginForApp(req); String token = iWechatService.loginForApp(req);
Map map = new HashMap<>(); AjaxResult ajaxResult = AjaxResult.success();
map.put(Constants.TOKEN, token); ajaxResult.put(Constants.TOKEN, token);
return AjaxResult.success(map); return ajaxResult;
} }
} }

@ -132,8 +132,8 @@ xss:
wx: wx:
mpAppId: wxcf05e06d4ab81582 mpAppId: wxcf05e06d4ab81582
mpSecret: 252594e6b980bc2bfc74bbaad92b5e7b mpSecret: 252594e6b980bc2bfc74bbaad92b5e7b
wechatAppId: wxcf05e06d4ab81582 wechatAppId: wxce986661acb731be
wechatSecret: 252594e6b980bc2bfc74bbaad92b5e7b wechatSecret: a494e8b7804d6e9f3cef984161486aec
aiPost: aiPost:
ip: 111.6.25.30 ip: 111.6.25.30

@ -112,7 +112,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter
.antMatchers("/webjars/**").anonymous() .antMatchers("/webjars/**").anonymous()
.antMatchers("/*/api-docs").anonymous() .antMatchers("/*/api-docs").anonymous()
.antMatchers("/druid/**").anonymous() .antMatchers("/druid/**").anonymous()
.antMatchers("/wechat/login/get/openid","/wechat/login/for/mp").anonymous() .antMatchers("/wechat/login/**").anonymous()
.antMatchers("/api/app/hospital/list").anonymous() .antMatchers("/api/app/hospital/list").anonymous()
// 除上面外的所有请求全部需要鉴权认证 // 除上面外的所有请求全部需要鉴权认证
.anyRequest().authenticated() .anyRequest().authenticated()

@ -119,6 +119,11 @@ public class SysLoginService
ajax.put("flag", false); ajax.put("flag", false);
} else { } else {
SysUser sysUser = userService.selectUserByUserName(username); SysUser sysUser = userService.selectUserByUserName(username);
// 验证密码
if (!SecurityUtils.matchesPassword(password, sysUser.getPassword())) {
log.info("登录用户:{} 密码不正确.", username);
throw new ServiceException("登录失败!");
}
LoginUser loginUser = new LoginUser(); LoginUser loginUser = new LoginUser();
sysUser.setDoctorId(tDoctor.getId()); sysUser.setDoctorId(tDoctor.getId());
sysUser.setHospitalId(tDoctor.getHospitalId()); sysUser.setHospitalId(tDoctor.getHospitalId());

@ -1,11 +1,10 @@
package com.ruoyi.system.service.impl; package com.ruoyi.system.service.impl;
import com.alibaba.fastjson.JSONObject; 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.entity.SysUser;
import com.ruoyi.common.core.domain.model.LoginUser; import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.exception.ServiceException; 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.StringUtils;
import com.ruoyi.common.utils.http.HttpUtils; import com.ruoyi.common.utils.http.HttpUtils;
import com.ruoyi.common.utils.ip.IpUtils; 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.TDoctorMapper;
import com.ruoyi.system.mapper.TPatientMapper; import com.ruoyi.system.mapper.TPatientMapper;
import com.ruoyi.system.mapper.TWechatUserMapper; import com.ruoyi.system.mapper.TWechatUserMapper;
import com.ruoyi.system.service.ISysUserService;
import com.ruoyi.system.service.IWechatService; import com.ruoyi.system.service.IWechatService;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -66,6 +67,9 @@ public class WechatServiceImpl implements IWechatService {
@Resource @Resource
private UserTokenService userTokenService; private UserTokenService userTokenService;
@Autowired
private ISysUserService userService;
@Override @Override
public GetOpenidResp getOpenid(GetOpenidReq req, HttpServletRequest request) { public GetOpenidResp getOpenid(GetOpenidReq req, HttpServletRequest request) {
//查询openid //查询openid
@ -151,12 +155,24 @@ public class WechatServiceImpl implements IWechatService {
wechatUser.setUserId(currentDoctor.getId()); wechatUser.setUserId(currentDoctor.getId());
tDoctor.setId(currentDoctor.getId()); tDoctor.setId(currentDoctor.getId());
} else { } 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.setDelFlag("0");
tDoctor.setCreateTime(new Date()); tDoctor.setCreateTime(new Date());
tDoctor.setUpdateTime(new Date()); tDoctor.setUpdateTime(new Date());
tDoctor.setUserId(sysUser.getUserId());
tDoctorMapper.insertTDoctor(tDoctor); tDoctorMapper.insertTDoctor(tDoctor);
wechatUser.setUserId(tDoctor.getId()); wechatUser.setUserId(tDoctor.getId());
} }
// 绑定openid // 绑定openid
wechatUser.setUnionid(req.getUnionid()); 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 url = String.format(WechatKeys.WECHAT_CODE_TO_UNIONID_URL, wechatAppId, wechatSecret, req.getCode());
String json = HttpUtils.sendGet(url); String json = HttpUtils.sendGet(url);
JSONObject jsonObject = JSONObject.parseObject(json); JSONObject jsonObject = JSONObject.parseObject(json);
logger.info("login wechat user info :{}", jsonObject.toJSONString());
String unionid = (String) jsonObject.get("unionid"); String unionid = (String) jsonObject.get("unionid");
logger.info("login openid:{}", unionid); logger.info("login openid:{}", unionid);
if (StringUtils.isEmpty(unionid)) { if (StringUtils.isEmpty(unionid)) {
@ -256,7 +273,8 @@ public class WechatServiceImpl implements IWechatService {
loginUser.setUserId(tDoctor.getUserId()); loginUser.setUserId(tDoctor.getUserId());
SysUser user = new SysUser(); SysUser user = new SysUser();
user.setUserId(tDoctor.getUserId()); user.setUserId(tDoctor.getUserId());
user.setUserName(tDoctor.getName()); user.setUserName(tDoctor.getPhone());
user.setNickName(tDoctor.getName());
user.setDelFlag(tDoctor.getDelFlag()); user.setDelFlag(tDoctor.getDelFlag());
user.setSex(tDoctor.getSex()); user.setSex(tDoctor.getSex());
user.setPhonenumber(tDoctor.getPhone()); user.setPhonenumber(tDoctor.getPhone());

Loading…
Cancel
Save