generated from root/miduo_server
灵动单独校验,增加校验返回描述
parent
3f28e276fc
commit
42d672d6eb
|
@ -1,5 +1,7 @@
|
|||
package com.ljsd.controller;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.ljsd.pojo.VerifyParams;
|
||||
import com.ljsd.redis.RedisKey;
|
||||
import com.ljsd.service.*;
|
||||
import com.ljsd.util.BaseGlobal;
|
||||
|
@ -127,8 +129,26 @@ public class GetUserController extends HttpServlet {
|
|||
if(channel==null||channel.equals("")){
|
||||
channel="MHT";
|
||||
}
|
||||
boolean verify = serviceMap.get(channel).verify(response, request, admin, platform, pid, openId, token);
|
||||
|
||||
boolean verify = false;
|
||||
String msg = "";
|
||||
String sub_channel = request.getParameter("sub_channel");
|
||||
if ("MHT".equals(channel) && !"3".equals(platform) && !"1000".equals(sub_channel) && !"20201222".equals(sub_channel)) {
|
||||
LdVerifyServiceStr instance = LdVerifyServiceStr.getInstance();
|
||||
VerifyParams params = new VerifyParams();
|
||||
params.setAppId(instance.properties.getProperty("appId_online"));
|
||||
params.setSecretKey(instance.properties.getProperty("secretKey_online"));
|
||||
VerifyParams formatParam = instance.getFormatParam(params,request, openId, token);
|
||||
String result = instance.verifyFormat(formatParam);
|
||||
if (result != null && !result.isEmpty()) {
|
||||
JSONObject jsonObject = JSONObject.parseObject(result);
|
||||
int state = jsonObject.getIntValue("code");
|
||||
if(state != 200){
|
||||
msg = jsonObject.getString("message");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
verify = serviceMap.get(channel).verify(response, request, admin, platform, pid, openId, token);
|
||||
}
|
||||
if(!verify){
|
||||
returnErrorToFront(res,response,"校验失败,请重新登录");
|
||||
return;
|
||||
|
@ -191,6 +211,7 @@ public class GetUserController extends HttpServlet {
|
|||
res.put("uid", uid);
|
||||
res.put("token", utoken);
|
||||
res.put("errorCode", 0);
|
||||
res.put("msg", msg);
|
||||
BaseGlobal.getInstance().redisApp.set(RedisKey.TOKEN, String.valueOf(uid), utoken, -1, false);
|
||||
BaseGlobal.getInstance().redisApp.set(RedisKey.PIDGIDTEMP, String.valueOf(uid), pid+"#"+gid, -1, false);
|
||||
|
||||
|
|
|
@ -0,0 +1,116 @@
|
|||
package com.ljsd.service;
|
||||
|
||||
import com.ljsd.pojo.VerifyParams;
|
||||
import com.ljsd.util.BaseGlobal;
|
||||
import com.ljsd.util.HttpUtils;
|
||||
import com.ljsd.util.MD5Util;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
|
||||
/**
|
||||
* @author lvxinran
|
||||
* @date 2021/5/26
|
||||
* @discribe
|
||||
*/
|
||||
public class LdVerifyServiceStr{
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(LdVerifyServiceStr.class);
|
||||
|
||||
private LdVerifyServiceStr() {
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取单例
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static LdVerifyServiceStr getInstance() {
|
||||
return LdVerifyServiceStr.Instance.instance;
|
||||
}
|
||||
|
||||
public static class Instance {
|
||||
public final static LdVerifyServiceStr instance = new LdVerifyServiceStr();
|
||||
}
|
||||
|
||||
|
||||
public Properties properties = BaseGlobal.getInstance().properties;
|
||||
public String sign = "MHT";
|
||||
|
||||
private static String getParamString(Map<String,String> param){
|
||||
|
||||
StringBuilder builder = new StringBuilder();
|
||||
param.forEach((k,v)->{
|
||||
if(builder.length()>0){
|
||||
builder.append("&");
|
||||
}
|
||||
builder.append(k).append("=").append(v);
|
||||
});
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
|
||||
// public boolean parseLoginResult(String orderResult){
|
||||
// try {
|
||||
// JSONObject jsonObject = JSONObject.parseObject(orderResult);
|
||||
// int state = jsonObject.getIntValue("code");
|
||||
// if(state != 200){
|
||||
// String content = jsonObject.getString("message");
|
||||
// LOGGER.info("parseLoginResult content={}",content);
|
||||
// return false;
|
||||
// }
|
||||
// } catch (Exception e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// return true;
|
||||
// }
|
||||
/**
|
||||
* 构建签名
|
||||
* sign=md5hex(paramString+md5hex(appid)+md5hex(secret))
|
||||
* @return
|
||||
*/
|
||||
private static String getSign(String paramString,String appid,String secret){
|
||||
|
||||
return MD5Util.encrypByMd5(paramString + MD5Util.encrypByMd5(appid) + MD5Util.encrypByMd5(secret));
|
||||
}
|
||||
|
||||
String doVerify(VerifyParams verifyParams){
|
||||
try{
|
||||
String login_url = properties.getProperty("login_url");
|
||||
|
||||
LOGGER.info("login_url={}",login_url);
|
||||
|
||||
Map<String, String> params = new HashMap<>();
|
||||
|
||||
params.put("sid", verifyParams.getToken());
|
||||
params.put("appid", verifyParams.getAppId());
|
||||
params.put("channellevel1", verifyParams.getChannel());
|
||||
String sign = getSign(getParamString(params), verifyParams.getAppId(), verifyParams.getSecretKey() );
|
||||
params.put("sign", sign);
|
||||
String loginResult = HttpUtils.doPost(login_url,params);
|
||||
LOGGER.info("loginResult=>{}",loginResult);
|
||||
return (loginResult);
|
||||
}catch(Exception e){
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public String verifyFormat(VerifyParams params) {
|
||||
|
||||
return doVerify(params);
|
||||
}
|
||||
|
||||
public VerifyParams getFormatParam(VerifyParams params,HttpServletRequest request, String openId, String token) {
|
||||
return getMHTParam(params,token);
|
||||
}
|
||||
|
||||
private VerifyParams getMHTParam(VerifyParams params,String token){
|
||||
params.setChannel("MHT");
|
||||
params.setToken(token);
|
||||
return params;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue