miduo_login/src/main/java/com/ljsd/service/EightUVerifyService.java

92 lines
3.0 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

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;
public class EightUVerifyService extends AbstractVerifyService {
private static final Logger LOGGER = LoggerFactory.getLogger(EightUVerifyService.class);
public static final String app_id = "8600";
public EightUVerifyService(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 (!"3".equals(platform) ) {//正式 切不是pc
VerifyParams params = new VerifyParams();
VerifyParams formatParam = getFormatParam(params,request, openId, token);
boolean 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 loginUrl = "https://h5.8uyx.com/cp/api_check_user";
Map<String,String> paras = new HashMap<>();
paras.put("appid",params.getAppId());
paras.put("uid",params.getOpenId());
paras.put("token",params.getToken());
LOGGER.info("8U渠道登录验证参数-->{}{}",loginUrl,params);
boolean result = false;
try {
String r = HttpUtils.doPost(loginUrl, paras);
LOGGER.info("8U渠道登录验证请求结果:{}",r);
if (r != null && r.equals("1")) {
result = true;
}
}catch (IOException e){
LOGGER.info("8U渠道登录验证验证失败,{}",e.getMessage());
return false;
}
return result;
}
@Override
protected VerifyParams getTestParam(VerifyParams params, HttpServletRequest request, String openId, String token) {
return getFormatParam(params,request,openId,token);
}
@Override
protected VerifyParams getFormatParam(VerifyParams params, HttpServletRequest request, String openId, String token) {
params.setAppId(app_id);
params.setToken(token);
params.setOpenId(openId);
return params;
}
}