主函数:
package com.tianyu; import java.sql.Connection; import java.sql.DriverManager; import com.alibaba.fastjson.JSONObject; public class Main { public static String game_url = "http://ka.game.163.com/service/cardsvc/taohao?id=12374"; public static String driver_url = "jdbc:mysql://localhost:3306/tianyu?user=root&password=bianbian"; public static String active_url = "http://s.webcgi.163.com/tianyu-active-code/activate_code?callback=jQuery16405689243660308421_1425463449791&[email protected]&[email protected]&code=88888888&phone=18319381102&server_id=4&r=0.936580075416714&_=1425463512824"; public static String active_cookie = "usertrack=c+5+hlTugfWFJRdQnnwNAg==; _ntes_nnid=4904adbda635e2b4c3300430f25a4b60,1424916988772; _ntes_nuid=4904adbda635e2b4c3300430f25a4b60; Province=020; City=0755; vjuids=-a362cb80.14bd01c11ac.0.919a8084; ne_analysis_trace_id=1425459633430; pgr_n_f_l_n3=42bfb7239ea4e51514254596334311653; vjlast=1425125675.1425459653.11; vinfo_n_f_l_n3=42bfb7239ea4e515.1.2.1425125675451.1425264968449.1425462798644; s_n_f_l_n3=42bfb7239ea4e5151425459633463; NTES_SESS=sG7cR1yOdzYSSkeCondwkOZNSblPgdE8TnwNABR_wA3a449dfwF.1PEJrGGB8aENb.xrEX3o1LRrk_1EgYmHPDdPgqyDC1UeROp9TYiwiVE8dANEwXI3akfykJWJ7KQxB37FwI96wGFwp.w8OsQOCipt.; S_INFO=1425462851|0|##|[email protected]; [email protected]|1425462851|0|other|00&99|gud&1425383570&other#gud&440300#10#0#0|&0||[email protected]; ANTICSRF=335fae91042b660cf700404af040b584"; public static void main(String[] args) { try { Class.forName("com.mysql.jdbc.Driver"); Connection conn = DriverManager.getConnection(driver_url); while(true) { CallUrl call = new CallUrl(); JSONObject obj = call.getJSONByTianYu(game_url); System.out.println(active_url.replaceAll("code=88888888", "code="+obj.getJSONObject("data").getString("used_key"))); GameACTIVE.Active(active_url.replaceAll("code=88888888", "code="+obj.getJSONObject("data").getString("used_key")), active_cookie); SaveJSON.saveData(conn, obj); } } catch(Exception e) { e.printStackTrace(); } } }
账号激活类:
package com.tianyu; import java.io.InputStream; import java.net.HttpURLConnection; import java.net.URL; public class GameACTIVE { public static boolean Active(String active_url,String cookie_url) { try { Thread.sleep(10000); URL u = new URL(active_url); HttpURLConnection conn = (HttpURLConnection) u.openConnection(); conn.setConnectTimeout(5*1000); conn.setRequestMethod("GET"); conn.setRequestProperty("Cookie", cookie_url); //conn.connect(); InputStream stream = conn.getInputStream(); byte[] data = CallUrl.streamToByte(stream); stream.close(); System.out.println(new String(data,"utf-8")); } catch (Exception e) { e.printStackTrace(); } finally { } return false; } }
获取验证码数据类:
package com.tianyu; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; import java.net.HttpURLConnection; import java.net.URL; import com.alibaba.fastjson.JSONObject; public class CallUrl { public JSONObject getJSONByTianYu(String url) { JSONObject obj = null; HttpURLConnection conn = null; try { URL u = new URL(url); conn = (HttpURLConnection) u.openConnection(); conn.setConnectTimeout(5*1000); conn.setRequestMethod("GET"); InputStream inStream = conn.getInputStream(); byte[] data =streamToByte(inStream); String result = new String(data, "UTF-8"); return obj.parseObject(result); } catch (Exception e) { e.printStackTrace(); } finally { } return null; } public static byte[] streamToByte(InputStream stream) throws IOException { ByteArrayOutputStream swapStream = new ByteArrayOutputStream(); byte[] buff = new byte[100]; int rc = 0; while ((rc = stream.read(buff, 0, 100)) > 0) { swapStream.write(buff, 0, rc); } byte[] in2b = swapStream.toByteArray(); return in2b; } }
保存激活码类:
package com.tianyu; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.SQLException; import com.alibaba.fastjson.JSONObject; public class SaveJSON { public static String sql = "insert into tianyu(status,use_count,used_key) values(?,?,?)"; public static boolean saveData(Connection conn, JSONObject obj) { try { PreparedStatement statement = conn.prepareStatement(sql); statement.setString(1, obj.getString("status")); JSONObject o = obj.getJSONObject("data"); statement.setString(2, o.getString("use_count")); statement.setString(3, o.getString("used_key")); System.out.println(obj); return statement.execute(); } catch (SQLException e) { e.printStackTrace(); } return false; } }
最后附上pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.tianyu</groupId> <artifactId>TianYu</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>jar</packaging> <name>TianYu</name> <url>http://maven.apache.org</url> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.1</version> <scope>test</scope> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>5.1.27</version> </dependency> <dependency> <groupId>com.alibaba</groupId> <artifactId>fastjson</artifactId> <version>1.2.4</version> </dependency> </dependencies> </project>
游戏虽好,但不要贪杯噢。饥饿营销去屎吧!!!
时间: 2024-10-04 22:37:37