/museum/src/com/museum/main/DigBatch.java

http://museumworker.googlecode.com/ · Java · 133 lines · 112 code · 17 blank · 4 comment · 6 complexity · 68213d7a5669eb9c4d6e85880d77b6e1 MD5 · raw file

  1. /*
  2. * To change this template, choose Tools | Templates
  3. * and open the template in the editor.
  4. */
  5. package com.museum.main;
  6. import java.net.URI;
  7. import java.text.SimpleDateFormat;
  8. import java.util.Date;
  9. import org.apache.http.client.methods.HttpPost;
  10. import org.apache.http.impl.client.DefaultHttpClient;
  11. import com.google.gson.JsonObject;
  12. import com.google.gson.JsonParser;
  13. import com.museum.utils.Utils;
  14. public class DigBatch {
  15. String[] users = new String[] { "chinesegxf" };
  16. String[] uids = new String[] { "4209691217" };
  17. String[] cookies = new String[] { "MY:SESSION=4e8025b303teliiha73008eb2284e0b3; MY:my_sig_prefix=http%3A%2F%2Fwww.btbird.com%2F; city_id=0; city_old_id=0; MY:UserID=4209691217; MY:SNID=9471d911b04f701f4f3f19151e814da6", };
  18. int delay = 2000 / users.length;
  19. boolean debug = true;
  20. SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  21. DefaultHttpClient hc = new DefaultHttpClient();
  22. public void dig() throws Exception {
  23. HttpPost post = Utils.createPost();
  24. while (true) {
  25. for (int j = 0; j < uids.length; j++) {
  26. try {
  27. Thread.sleep(delay);
  28. String url = "http://my.mowhere.com/interface/manage_treasure.php";
  29. post.setURI(new URI(url));
  30. post.setHeader("Cookie", cookies[j]);
  31. post.setEntity(Utils.genDigBatchOkEntity(uids[j]));
  32. String resjson = Utils.trans(hc.execute(post));
  33. JsonObject js = new JsonParser().parse(resjson)
  34. .getAsJsonObject();
  35. debug(j, js);
  36. String err = js.get("err").getAsString();
  37. info(j, err);
  38. sell(post, j);
  39. buy(post, j);
  40. use(post, j);
  41. Thread.sleep(2000);
  42. post.setEntity(Utils.genDigBatchEntity(uids[j]));
  43. resjson = Utils.trans(hc.execute(post));
  44. js = new JsonParser().parse(resjson).getAsJsonObject();
  45. debug(j, js);
  46. err = js.get("err").getAsString();
  47. info(j, err);
  48. } catch (Exception e) {
  49. e.printStackTrace();
  50. }
  51. }
  52. Thread.sleep(60 * 60 * 1000);
  53. }
  54. }
  55. public void buy(HttpPost post, int uidx) throws Exception {
  56. String url = "http://my.mowhere.com/interface/manage_treasure.php";
  57. post.setURI(new URI(url));
  58. post.setHeader("Cookie", cookies[uidx]);
  59. post.setEntity(Utils.genBuyEntity(uids[uidx], "402"));
  60. String err = "1";
  61. while (!"".equals(err)) {
  62. Thread.sleep(2000);
  63. String resjson = Utils.trans(hc.execute(post));
  64. JsonObject js = new JsonParser().parse(resjson).getAsJsonObject();
  65. err = js.get("err").getAsString();
  66. JsonObject data = js.getAsJsonObject("data");
  67. String r = data.get("text").getAsString();
  68. info(uidx, r);
  69. }
  70. }
  71. public void use(HttpPost post, int uidx) throws Exception {
  72. String url = "http://my.mowhere.com/interface/manage_treasure.php";
  73. post.setURI(new URI(url));
  74. post.setHeader("Cookie", cookies[uidx]);
  75. post.setEntity(Utils.genUseEntity(uids[uidx], "402"));
  76. String err = "1";
  77. while (!"".equals(err)) {
  78. Thread.sleep(2000);
  79. String resjson = Utils.trans(hc.execute(post));
  80. JsonObject js = new JsonParser().parse(resjson).getAsJsonObject();
  81. err = js.get("err").getAsString();
  82. JsonObject data = js.getAsJsonObject("data");
  83. String r = data.get("text").getAsString();
  84. info(uidx, r);
  85. }
  86. }
  87. public void sell(HttpPost post, int uidx) throws Exception {
  88. String url = "http://my.mowhere.com/interface/manage_treasure.php";
  89. post.setURI(new URI(url));
  90. post.setHeader("Cookie", cookies[uidx]);
  91. post.setEntity(Utils.genSellEntity(uids[uidx], ""));
  92. String err = "1";
  93. while (!"".equals(err)) {
  94. Thread.sleep(2000);
  95. String resjson = Utils.trans(hc.execute(post));
  96. JsonObject js = new JsonParser().parse(resjson).getAsJsonObject();
  97. err = js.get("err").getAsString();
  98. JsonObject data = js.getAsJsonObject("data");
  99. String r = data.get("text").getAsString();
  100. info(uidx, r);
  101. }
  102. }
  103. private void debug(int i, Object s) {
  104. if (debug)
  105. System.out.println(users[i] + " # " + df.format(new Date())
  106. + " debug: " + s);
  107. }
  108. private void info(int i, Object s) {
  109. System.out.println(users[i] + " # " + df.format(new Date()) + " info: "
  110. + s);
  111. }
  112. public static void main(String[] args) throws Exception {
  113. DigBatch r = new DigBatch();
  114. r.dig();
  115. }
  116. }