generated from root/miduo_server
增加DNA01登录sdk
parent
bd3b3ecfdf
commit
ff63f74f61
|
@ -91,6 +91,8 @@ public class GetUserController extends HttpServlet {
|
|||
//西游悠谷直播1
|
||||
serviceMap.put("XYYGZB01", new XiyouYouGuZhiboVerifyService("XYYGZB01"));
|
||||
serviceMap.put("XYFANLI01", new QuickXyFanli01VerifyService("XYFANLI01"));
|
||||
//太初行DNA01
|
||||
serviceMap.put("DNA01", new Dna01VerifyService("DNA01"));
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,137 @@
|
|||
package com.ljsd.service;
|
||||
|
||||
import com.ljsd.pojo.VerifyParams;
|
||||
import com.ljsd.util.AppConstans;
|
||||
import com.ljsd.util.HttpUtils;
|
||||
import com.ljsd.util.MD5Util;
|
||||
import com.ljsd.util.StringUtils;
|
||||
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;
|
||||
public class Dna01VerifyService extends AbstractVerifyService {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(QuickVerifyService.class);
|
||||
public static int isTestLan=0;
|
||||
public final static String adAppId = "3";
|
||||
public final static String adAppKey = "915c3274597aa3edc802a52315ffc48f";
|
||||
public final static String iosAppId = "4";
|
||||
public final static String iosAppKey = "94b817ed89ffe487fcdd280c35feb7fa";
|
||||
|
||||
public Dna01VerifyService(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.isEmpty()) {
|
||||
if (sub_channel.equals("1000")) {
|
||||
//测试服构建参数
|
||||
VerifyParams params = new VerifyParams();
|
||||
VerifyParams testParam = getTestParam(params,request, openId, token);
|
||||
result = verifyTest(testParam);
|
||||
}else {
|
||||
//正式服appId
|
||||
VerifyParams params = new VerifyParams();
|
||||
VerifyParams formatParam = getFormatParam(params,request, openId, token);
|
||||
formatParam.setPlatformId(platform);
|
||||
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) {
|
||||
String platForm = params.getPlatformId();
|
||||
LOGGER.info("dna01登录验证-->{},{}",params.getOpenId(),platForm);
|
||||
if(StringUtils.checkIsEmpty(platForm)){
|
||||
LOGGER.info("dna01登录验证-->platForm null");
|
||||
return false;
|
||||
}
|
||||
String appId = null;
|
||||
String appKey = null;
|
||||
if("android".equals(platForm)){
|
||||
appId = adAppId;
|
||||
appKey = adAppKey;
|
||||
}else if("ios".equals(platForm)){
|
||||
appId = iosAppId;
|
||||
appKey = iosAppKey;
|
||||
}else{
|
||||
LOGGER.info("dna01登录验证-->platForm error --- platForm : " + platForm);
|
||||
return false;
|
||||
}
|
||||
String url = "https://sdk.gmdna.com/cp/user/check";
|
||||
Map<String,String> parms = new HashMap<>();
|
||||
parms.put("user_token",params.getToken());
|
||||
parms.put("mem_id",params.getOpenId());
|
||||
parms.put("app_id",appId);
|
||||
String str = "app_id="+appId + "&mem_id="+params.getOpenId() +"&user_token=" + params.getToken() + "&app_key=" + appKey;
|
||||
String sign = MD5Util.encrypByMd5(str);
|
||||
parms.put("sign",sign);
|
||||
boolean result = false;
|
||||
try {
|
||||
String r = HttpUtils.doPost(url, parms);
|
||||
LOGGER.info("dna01请求结果:{}",r);
|
||||
if (r != null && r.equals("1")) {
|
||||
result = true;
|
||||
}
|
||||
}catch (IOException e){
|
||||
LOGGER.info("dna01验证失败,IOException:{}",e.getMessage());
|
||||
return false;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected VerifyParams getTestParam(VerifyParams params, HttpServletRequest request, String openId, String token) {
|
||||
params.setToken(token);
|
||||
params.setOpenId(openId);
|
||||
return params;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected VerifyParams getFormatParam(VerifyParams params, HttpServletRequest request, String openId, String token) {
|
||||
params.setToken(token);
|
||||
params.setOpenId(openId);
|
||||
return params;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue