|
@ -1,6 +1,7 @@
|
|
|
package com.yihu.wlyy.web.common.account;
|
|
|
|
|
|
import java.net.URLDecoder;
|
|
|
import java.net.URLEncoder;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.Map;
|
|
|
import java.util.UUID;
|
|
@ -19,6 +20,7 @@ import org.springframework.http.MediaType;
|
|
|
import org.springframework.stereotype.Controller;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
import org.springframework.web.bind.annotation.RequestParam;
|
|
|
import org.springframework.web.bind.annotation.ResponseBody;
|
|
|
|
|
|
import com.yihu.wlyy.entity.patient.Patient;
|
|
@ -314,66 +316,104 @@ public class WechatController extends WeixinBaseController {
|
|
|
/**
|
|
|
* 患者微信登录接口
|
|
|
*
|
|
|
* @param idcard 身份證号
|
|
|
* @param captcha 短信号
|
|
|
* @param mobile 电话号码
|
|
|
* @param password 登录密码
|
|
|
* @return
|
|
|
*/
|
|
|
@RequestMapping(value = "login")
|
|
|
@ResponseBody
|
|
|
public String login(String mobile, String captcha, String openid) {
|
|
|
public String login(
|
|
|
@RequestParam(required = false) String mobile,
|
|
|
@RequestParam(required = false) String captcha,
|
|
|
@RequestParam(required = false) String password,
|
|
|
String openid) {
|
|
|
try {
|
|
|
// 对验证码进行校验
|
|
|
int res = smsService.check(mobile, 4, captcha);
|
|
|
switch (res) {
|
|
|
case -2:
|
|
|
return error(-1, "验证码已过期!");
|
|
|
case -1:
|
|
|
return error(-1, "请输入正确的验证码!");
|
|
|
case 0:
|
|
|
return error(-1, "验证码无效!");
|
|
|
}
|
|
|
Patient patient = patientService.findByMobile(mobile);
|
|
|
if (patient == null) {
|
|
|
return error(-1, "该手机号暂未注册帐号,请确认后重新输入!");
|
|
|
} else if (patient.getStatus() == 0) {
|
|
|
return error(-1, "该手机号已被禁止使用!");
|
|
|
} else if (patient.getStatus() == 2) {
|
|
|
return error(-1, "该帐号正在审核中,请确认审核通过后再登录,“如有疑问,拨打400-6677-400转2人工客服”");
|
|
|
} else if (StringUtils.isEmpty(openid)) {
|
|
|
return error(-1, "无效的OpenID!");
|
|
|
}
|
|
|
// else if (StringUtils.isNotEmpty(patient.getOpenid()) && !StringUtils.equals(patient.getOpenid(), openid)) {
|
|
|
// return error(-1, "该微信号已绑定其他手机号!");
|
|
|
// }else if (StringUtils.isEmpty(patient.getOpenid())) {
|
|
|
// // 未绑定openid,查询是否绑定其他帐号
|
|
|
// if (patientService.countByOpenid(openid) > 0) {
|
|
|
// return error(-1, "该微信号已绑定其他手机号!");
|
|
|
// } else {
|
|
|
// // 绑定用户手机号和openid
|
|
|
// patient.setOpenid(openid);
|
|
|
// patientService.updatePatient(patient);
|
|
|
// }
|
|
|
// }
|
|
|
//账号登录
|
|
|
if(StringUtils.isNoneEmpty(mobile)&&StringUtils.isNoneEmpty(password)){
|
|
|
Patient patient = patientService.findByMobile(mobile);
|
|
|
if (patient == null) {
|
|
|
return error(-1, "该手机号暂未注册帐号,请确认后重新输入!");
|
|
|
} else if (patient.getStatus() == 0) {
|
|
|
return error(-1, "该手机号已被禁止使用!");
|
|
|
} else if (patient.getStatus() == 2) {
|
|
|
return error(-1, "该帐号正在审核中,请确认审核通过后再登录,“如有疑问,拨打400-6677-400转2人工客服”");
|
|
|
} else if (StringUtils.isEmpty(openid)) {
|
|
|
return error(-1, "无效的OpenID!");
|
|
|
}
|
|
|
//解密
|
|
|
password = RSAUtils.getInstance(patientService).decryptString(password);
|
|
|
//生成MD5
|
|
|
String loginPassword= MD5.GetMD5Code(password+patient.getSalt());
|
|
|
//判断d登录密码是否正确
|
|
|
if(loginPassword.equals(patient.getPassword())){
|
|
|
// 绑定用户手机号和openid
|
|
|
if (!StringUtils.equals(patient.getOpenid(), openid)) {
|
|
|
patient.setOpenid(openid);
|
|
|
patientService.updatePatient(patient);
|
|
|
}
|
|
|
|
|
|
// 绑定用户手机号和openid
|
|
|
if (!StringUtils.equals(patient.getOpenid(), openid)) {
|
|
|
patient.setOpenid(openid);
|
|
|
patientService.updatePatient(patient);
|
|
|
// 用户校验通过,生成token
|
|
|
Token token = tokenService.newTxToken(patient.getCode(), openid);
|
|
|
Map<Object, Object> map = new HashMap<Object, Object>();
|
|
|
map.put("id", patient.getId());
|
|
|
map.put("uid", patient.getCode());
|
|
|
map.put("name", patient.getName());
|
|
|
map.put("token", token.getToken());
|
|
|
map.put("photo", patient.getPhoto());
|
|
|
if(StringUtils.isNoneEmpty(openid)){
|
|
|
//发送微信模板
|
|
|
familyService.sendWXMessage(patient);
|
|
|
}
|
|
|
return write(200, "登录成功", "data", map);
|
|
|
}else{
|
|
|
return error(-1, "密码错误,登录失败");
|
|
|
}
|
|
|
}
|
|
|
//短信登录
|
|
|
if(StringUtils.isNoneEmpty(mobile)&&StringUtils.isNoneEmpty(captcha)){
|
|
|
// 对验证码进行校验
|
|
|
int res = smsService.check(mobile, 4, captcha);
|
|
|
switch (res) {
|
|
|
case -2:
|
|
|
return error(-1, "验证码已过期!");
|
|
|
case -1:
|
|
|
return error(-1, "请输入正确的验证码!");
|
|
|
case 0:
|
|
|
return error(-1, "验证码无效!");
|
|
|
}
|
|
|
Patient patient = patientService.findByMobile(mobile);
|
|
|
if (patient == null) {
|
|
|
return error(-1, "该手机号暂未注册帐号,请确认后重新输入!");
|
|
|
} else if (patient.getStatus() == 0) {
|
|
|
return error(-1, "该手机号已被禁止使用!");
|
|
|
} else if (patient.getStatus() == 2) {
|
|
|
return error(-1, "该帐号正在审核中,请确认审核通过后再登录,“如有疑问,拨打400-6677-400转2人工客服”");
|
|
|
} else if (StringUtils.isEmpty(openid)) {
|
|
|
return error(-1, "无效的OpenID!");
|
|
|
}
|
|
|
|
|
|
// 绑定用户手机号和openid
|
|
|
if (!StringUtils.equals(patient.getOpenid(), openid)) {
|
|
|
patient.setOpenid(openid);
|
|
|
patientService.updatePatient(patient);
|
|
|
}
|
|
|
|
|
|
// 用户校验通过,生成token
|
|
|
Token token = tokenService.newTxToken(patient.getCode(), openid);
|
|
|
Map<Object, Object> map = new HashMap<Object, Object>();
|
|
|
map.put("id", patient.getId());
|
|
|
map.put("uid", patient.getCode());
|
|
|
map.put("name", patient.getName());
|
|
|
map.put("token", token.getToken());
|
|
|
map.put("photo", patient.getPhoto());
|
|
|
if(StringUtils.isNoneEmpty(openid)){
|
|
|
//发送微信模板
|
|
|
familyService.sendWXMessage(patient);
|
|
|
// 用户校验通过,生成token
|
|
|
Token token = tokenService.newTxToken(patient.getCode(), openid);
|
|
|
Map<Object, Object> map = new HashMap<Object, Object>();
|
|
|
map.put("id", patient.getId());
|
|
|
map.put("uid", patient.getCode());
|
|
|
map.put("name", patient.getName());
|
|
|
map.put("token", token.getToken());
|
|
|
map.put("photo", patient.getPhoto());
|
|
|
if(StringUtils.isNoneEmpty(openid)){
|
|
|
//发送微信模板
|
|
|
familyService.sendWXMessage(patient);
|
|
|
}
|
|
|
return write(200, "登录成功", "data", map);
|
|
|
}
|
|
|
return write(200, "登录成功", "data", map);
|
|
|
return error(-1, "登录失败");
|
|
|
} catch (Exception e) {
|
|
|
error(e);
|
|
|
return error(-1, "系统异常,登录失败");
|