quick登陆sdk

master
mengchengzhen 2021-06-25 16:03:02 +08:00
parent 76e8691845
commit cff54262c9
2 changed files with 122 additions and 5 deletions

View File

@ -1,10 +1,7 @@
package com.ljsd.controller;
import com.ljsd.redis.RedisKey;
import com.ljsd.service.CaohuaVerifyService;
import com.ljsd.service.LdVerifyService;
import com.ljsd.service.VerifyService;
import com.ljsd.service.XPVerifyService;
import com.ljsd.service.*;
import com.ljsd.util.BaseGlobal;
import com.ljsd.util.MD5Util;
import com.mongodb.BasicDBObject;
@ -32,7 +29,7 @@ public class GetUserController extends HttpServlet {
serviceMap.put("MHT", new LdVerifyService("MHT"));
serviceMap.put("XP", new XPVerifyService("XP"));
serviceMap.put("CH",new CaohuaVerifyService("CH"));//草花
serviceMap.put("QUICK", new QuickVerifyService("QUICK"));
}

View File

@ -0,0 +1,120 @@
package com.ljsd.service;
import com.ljsd.pojo.VerifyParams;
import com.ljsd.util.AppConstans;
import com.ljsd.util.HttpUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
public class QuickVerifyService extends AbstractVerifyService {
private static final Logger LOGGER = LoggerFactory.getLogger(AbstractVerifyService.class);
public static int isTestLan=0;
private final static String product_code = "98413963499457078085779851192112";
public QuickVerifyService(String sign) {
super(sign);
}
@Override
public boolean verify(HttpServletResponse response, HttpServletRequest request, String admin, String platform, String pid, String openId, String token){
try {
//如果是自己人不需要验证了
if(AppConstans.appsecret.equals(admin)) {
return true;
}
if (isTestLan == 1) { //test
boolean result = loginVerfifyByTestLan(openId, token);
if (!result) {
response.sendError(400, "verify fail");
LOGGER.error("test verify fail");
return false;
}
} else if (!"3".equals(platform) ) {//正式 切不是pc
String sub_channel = request.getParameter("sub_channel");
boolean result = false;
if (sub_channel != null && !sub_channel.equals("")) {
if (sub_channel.equals("1000")) {
//测试服构建参数
VerifyParams params = new VerifyParams();
params.setProductCode(product_code);
VerifyParams testParam = getTestParam(params,request, openId, token);
result = verifyTest(testParam);
} else if(sub_channel.equals("20201222")){
//商务服
//result = loginVerfifyShangwu("MHT", openId, token, MHTSDKConstans.rhappIdshangwu);
} else {
//正式服appId
VerifyParams params = new VerifyParams();
params.setProductCode(product_code);
VerifyParams formatParam = getFormatParam(params,request, openId, token);
result = verifyFormat(formatParam);
}
}
if (!result) {
response.sendError(400, "verify fail");
LOGGER.error("verify fail");
return false;
}
}
}catch (Exception e){
e.printStackTrace();
}
return true;
}
@Override
public boolean verifyTest(VerifyParams params) {
return doVerify(params);
}
@Override
public boolean verifyFormat(VerifyParams params) {
return doVerify(params);
}
@Override
boolean doVerify(VerifyParams params) {
LOGGER.info("quick登录验证-->{}",params.getOpenId());
String url = "http://checkuser.quickapi.net/v2/checkUserInfo";
Map<String,String> parms = new HashMap<>();
parms.put("token",params.getToken());
parms.put("product_code",params.getProductCode());
parms.put("uid",params.getOpenId());
boolean result = false;
try {
String r = HttpUtils.doPost(url, parms);
LOGGER.info("QUICK请求结果:{}",r);
if(r.equals("1")){
result = true;
}
}catch (IOException e){
LOGGER.info("quick验证失败,IOException");
return false;
}
return result;
}
@Override
protected VerifyParams getTestParam(VerifyParams params, HttpServletRequest request, String openId, String token) {
params.setChannel("QUICK");
params.setToken(token);
params.setOpenId(openId);
return params;
}
@Override
protected VerifyParams getFormatParam(VerifyParams params, HttpServletRequest request, String openId, String token) {
params.setChannel("QUICK");
params.setToken(token);
params.setOpenId(openId);
return params;
}
}