public ResultModel getcheckUser(String userName, String passWord, int appType){
JSONObject json = new JSONObject();
ResultModel rm = new ResultModel();
String userCode = this.getUserCode(userName, null);
switch (appType){
case 1:
System.out.println("1管理APP业务,有登录权限认证");
if(userCode==null){
json.put("userCode", "账号不存在");
json.put("result", "2");
return rm.renderSuccessResultModelList(json);
}else{
User user=userMapper.selectBycode(userCode);
String userCodes = this.getUserCode(userName,encryptionPassWord(passWord, userCode, userName));
if(userCodes==null){
json.put("userCode", "密码错误");
json.put("result", "1");
}else if(user.getUserType().equals("1")){
json.put("result", "3");
json.put("userCode", userCode);
}else{
json.put("result", "4");
json.put("userCode", "没有权限");
}
return rm.renderSuccessResultModelList(json);
}
case 2:
System.out.println("3维修APP业务,有单点登录");
if(userCode!=null){
String userCodes = this.getUserCode(userName,encryptionPassWord(passWord, userCode, userName));
if(userCodes!=null){
User user = userMapper.selectBycode(userCodes);
String logKey = user.getLogKey();
if( logKey != null && logKey.length() != 0){
this.singleVerificationNew(logKey);
String newlogKey = UUID.randomUUID().toString();
user.setUserCode(userCode);
user.setLogKey(newlogKey);
userMapper.update(user);
json.put("result", "3");
json.put("logKey", newlogKey);
json.put("userCode", userCode);
}else{
String newlogKey = UUID.randomUUID().toString();
user.setUserCode(userCode);
user.setLogKey(newlogKey);
userMapper.update(user);
json.put("result", "3");
json.put("logKey", newlogKey);
json.put("userCode", userCode);
}
return rm.renderSuccessResultModelList(json);
}else{
json.put("userCode", "密码错误");
json.put("result", "1");
return rm.renderSuccessResultModelList(json);
}
}else{
json.put("userCode", "账号不存在");
json.put("result", "2");
return rm.renderSuccessResultModelList(json);
}
default:
System.out.println("2安装APP和4巡检APP业务");
if(userCode!=null){
String userCodes = this.getUserCode(userName,encryptionPassWord(passWord, userCode, userName));
if(userCodes!=null){
json.put("result", "3");
json.put("userCode", userCode);
return rm.renderSuccessResultModelList(json);
}else{
json.put("userCode", "密码错误");
json.put("result", "1");
return rm.renderSuccessResultModelList(json);
}
}else{
json.put("userCode", "账号不存在");
json.put("result", "2");
return rm.renderSuccessResultModelList(json);
}
}
}
用到的方法
public String getUserCode(String userName,String passWord) {
return userMapper.getUserCode(userName, passWord);
}
public String encryptionPassWord(String passWord,String userCode,String userName){
String SaltValue =userCode.substring(5, 10)+userName;
Md5Hash md5 = new Md5Hash(passWord, SaltValue, 828);
return md5.toString();
}
public void singleVerificationNew(String logKey){
if(logKey!=null && logKey!="" && logKey != "del") {
sendIOS(logKey);
sendAndroid(logKey);
}
}
public void sendIOS(String key) {
MessageIOS message = new MessageIOS();
JSONObject obj = new JSONObject();
JSONObject aps = new JSONObject();
aps.put("content-available", 1);
aps.put("code", "1");
obj.put("aps", aps);
message.setRaw(obj.toString());
XingeApp xinapp = new XingeApp(2200295273L, sysConfigService.queryMap().get("IosSecretKey"));
JSONObject s = xinapp.pushSingleAccount(0,key,message,XingeApp.IOSENV_PROD);
}
public void sendAndroid(String key){
XingeApp android = new XingeApp(2100295082,sysConfigService.queryMap().get("AndroidSecretKey"));
Message message = new Message();
Map<String,Object> map = new HashMap<String,Object>();
map.put("code", "1");
message.setCustom(map);
message.setType(Message.TYPE_MESSAGE);
JSONObject pushSingleAccount = android.pushSingleAccount(0,key, message);
}
<select id="getUserCode" resultType="String">
select
user_code
from sys_user
<where>
<if test="userName != null and userName !='' ">
and user_name = #{userName}
if>
<if test="passWord != null and passWord !='' ">
and password = #{passWord}
if>
and status =0
where>
select>