/skkj_server-english-webmagic-0580f61df038/src/main/java/net/onemost/english/util/GetCode.java

https://bitbucket.org/tonyfeng1002/english-crawler · Java · 32 lines · 21 code · 11 blank · 0 comment · 2 complexity · 297de21d7b083dfcbb0ec8b2abf3c24b MD5 · raw file

  1. package net.onemost.english.util;
  2. import com.alibaba.fastjson.JSON;
  3. import com.alibaba.fastjson.JSONObject;
  4. import net.onemost.english.dto.LoginInfo;
  5. import us.codecraft.webmagic.Page;
  6. public class GetCode {
  7. public static LoginInfo getInfo(Page page) {
  8. JSONObject jsonObject = JSON.parseObject(page.getJson().toString());
  9. jsonObject = jsonObject.getJSONObject("data");
  10. if(jsonObject == null) {
  11. throw new RuntimeException("登录失败");
  12. }
  13. String tokenCode = jsonObject.getString("tokenCode");
  14. jsonObject = jsonObject.getJSONObject("user");
  15. String userCode = jsonObject.getString("userCode");
  16. LoginInfo loginInfo = new LoginInfo();
  17. loginInfo.setTokenCode(tokenCode);
  18. loginInfo.setUserCode(userCode);
  19. return loginInfo;
  20. }
  21. }