uopspop

Untitled

Aug 25th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.66 KB | None | 0 0
  1. import java.io.IOException;
  2. import java.io.UnsupportedEncodingException;
  3. import java.util.ArrayList;
  4. import java.util.List;
  5. import java.util.regex.Matcher;
  6. import java.util.regex.Pattern;
  7.  
  8. import org.apache.http.HttpResponse;
  9. import org.apache.http.NameValuePair;
  10. import org.apache.http.client.entity.UrlEncodedFormEntity;
  11. import org.apache.http.client.methods.HttpGet;
  12. import org.apache.http.client.methods.HttpPost;
  13. import org.apache.http.entity.StringEntity;
  14. import org.apache.http.message.BasicNameValuePair;
  15. import org.apache.http.util.EntityUtils;
  16.  
  17. public class DailyQuizHttpPost extends HttpPost{
  18.     static private final String DAILY_QUIZ_URL = "http://www.1point3acres.com/bbs/plugin.php?id=ahome_dayquestion:pop";
  19.     static private final String DAILY_QUIZ_PAGE_URL = "http://www.1point3acres.com/bbs/plugin.php?id=ahome_dayquestion:pop";
  20.     static private String PAYLOAD_FORMAT =
  21.             "------WebKitFormBoundarybDMuZYRqRgOKYQWW\r\n" +
  22.             "Content-Disposition: form-data; name=\"formhash\"\r\n" +
  23.             "\r\n" +
  24.             "formhash_to_replace\r\n" +
  25.             "------WebKitFormBoundarybDMuZYRqRgOKYQWW\r\n" +
  26.             "Content-Disposition: form-data; name=\"answer\"\r\n" +
  27.             "\r\n" +
  28.             "answer_to_replace\r\n" +
  29.             "------WebKitFormBoundarybDMuZYRqRgOKYQWW\r\n" +
  30.             "Content-Disposition: form-data; name=\"submit\"\r\n" +
  31.             "\r\n" +
  32.             "true\r\n" +
  33.             "------WebKitFormBoundarybDMuZYRqRgOKYQWW--";
  34.    
  35.     private DailyQuizHttpPost(String formhash, String answer) throws UnsupportedEncodingException {
  36.         super(DailyQuizHttpPost.DAILY_QUIZ_URL);
  37.        
  38.         /** set form data **/
  39.         PAYLOAD_FORMAT = PAYLOAD_FORMAT.replace("formhash_to_replace", formhash);
  40.         PAYLOAD_FORMAT = PAYLOAD_FORMAT.replace("answer_to_replace", answer);
  41. //        StringEntity se = new StringEntity(payLoadLogin);
  42. //        this.setEntity(new StringEntity(PAYLOAD_FORMAT, "UTF-8"));
  43.         this.setEntity(new StringEntity(PAYLOAD_FORMAT));
  44.        
  45.         /** set headers **/
  46.         this.setHeader("Origin", "http://www.1point3acres.com");
  47.         this.setHeader("Referer", "http://www.1point3acres.com/bbs/");
  48.         this.setHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36");
  49.         this.setHeader("Host", "www.1point3acres.com");
  50.         this.setHeader("Content-Type", "multipart/form-data; boundary=----WebKitFormBoundarybDMuZYRqRgOKYQWW"); // important header
  51.     }
  52.    
  53.     static public HttpPost getNewInstance(org.apache.http.client.HttpClient client) {
  54.         HttpPost signInHttpPost = null;
  55.         try {
  56.             String formhash = getFormHash(client);
  57.             if (!formhash.isEmpty()) {
  58.                 signInHttpPost = new DailyQuizHttpPost(formhash, "3");
  59.             }
  60.         } catch (IOException e) {
  61.             e.printStackTrace();
  62.         }
  63.         return signInHttpPost;
  64.  
  65.     }
  66.    
  67.     static private String getFormHash(org.apache.http.client.HttpClient client) {
  68.         String formhash = "";
  69.         try {
  70.             HttpGet httpGetSignIn = new HttpGet(DailyQuizHttpPost.DAILY_QUIZ_PAGE_URL);
  71.             HttpResponse SignInRespGet = client.execute(httpGetSignIn);
  72.             String resStrGetSignin = EntityUtils.toString(SignInRespGet.getEntity());
  73.            
  74.             if (resStrGetSignin.contains("已经参加过")
  75.                 || resStrGetSignin.contains("您今天已经参加过答题")) {
  76.                 System.out.println("您今天已经参加过答题");
  77.             }else {
  78.                 Pattern pattern = Pattern.compile("<input type=\"hidden\" name=\"formhash\" value=\"(.*?)\">");
  79.                 Matcher matcher = pattern.matcher(resStrGetSignin);
  80.  
  81.                 if (matcher.find()) {
  82.                     formhash = matcher.group(1);
  83.                     System.out.println(formhash);
  84.                 }              
  85.             }
  86.         } catch (IOException e) {
  87.             e.printStackTrace();
  88.         }
  89.         return formhash;   
  90.     }
  91.    
  92. }
Add Comment
Please, Sign In to add comment