重庆分公司,新征程启航
为企业提供网站建设、域名注册、服务器等服务
主要就是官方的这个图:
10年积累的网站设计、做网站经验,可以快速应对客户对网站的新想法和需求。提供各种问题对应的解决方案。让选择我们的客户得到更好、更有力的网络服务。我虽然不认识你,你也不认识我。但先做网站后付款的网站建设流程,更有霸州免费网站建设让你可以放心的选择与我们合作。前端调用接口,得到腾讯发过来的几个数据,前端把这几个数据给后端,后端拿到这些数据后传给腾讯,让其判断是否正常,以及其他属性。
程序运行截图如下:
点击登录后,拖动正确进行跳转,拖动错误就重新输入
看看后台的打印:
这个是腾讯反馈的数据,response为1说明是正常,风险等级为0
程序结构如下:
源码如下:
LoginServlet.java
import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.net.URLEncoder; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import org.apache.http.HttpEntity; import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.HttpGet; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; import org.apache.http.util.EntityUtils; @WebServlet(value = "/login") public class LoginServlet extends HttpServlet{ private static final String APP_ID = "xxxxxxxxxx"; private static final String APP_SECRET = "xxxxxxxxxx**"; private static final String VERIFY_URI = "https://ssl.captcha.qq.com/ticket/verify?aid=%s&AppSecretKey=%s&Ticket=%s&Randstr=%s&UserIP=%s"; public static int verifyTicket(String ticket, String rand, String userIp) { CloseableHttpClient httpclient = HttpClients.createDefault(); HttpGet httpGet; CloseableHttpResponse response = null; try { httpGet = new HttpGet(String.format(VERIFY_URI, APP_ID, APP_SECRET, URLEncoder.encode(ticket, "UTF-8"), URLEncoder.encode(rand, "UTF-8"), URLEncoder.encode(userIp, "UTF-8") )); response = httpclient.execute(httpGet); HttpEntity entity = response.getEntity(); if (entity != null) { String res = EntityUtils.toString(entity); System.out.println(res); // 临时输出 JSONObject result = JSON.parseObject(res); // 返回码 int code = result.getInteger("response"); // 恶意等级 int evilLevel = result.getInteger("evil_level"); // 验证成功 if (code == 1) return evilLevel; } } catch (java.io.IOException e) { // 忽略 } finally { try { response.close(); } catch (Exception ignore) { } } return -1; } public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { this.doPost(request, response); } protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { //验证 String ticket = request.getParameter("Ticket"); String randstr = request.getParameter("Randstr"); String userIP = request.getRemoteAddr(); verifyTicket(ticket, randstr, userIP); response.sendRedirect("success.jsp"); } }
另外有需要云服务器可以了解下创新互联建站www.cdcxhl.com,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。