MewX / KanTV-downloader-cli

(KanTV is down forever) “看TV”下载器,命令行版,使用Android API,Go语言编写。 Downloading KanTV videos via command line interface (CLI) written in Go.
GNU General Public License v3.0
2 stars 1 forks source link

Add login API, and store sessions to a user directory #3

Open MewX opened 5 years ago

MewX commented 5 years ago

need to check sessions regularly

MewX commented 5 years ago
curl -H 'User-Agent: suramic app1.0' -H 'Host: skyollie.com' --data "password=asdfasdfasdf&iso_code=AU&sign=16210abeec8a01c142727ac142db6282a7ae0a33&sbID=imei345701357430453&mobile=1234567890&timestamp=1566473347010&noncestr=0263d7e2-5a9f-4bd0-974c-0e8df907b8dc&devicetype=0&type=1&code=%2B61&interfaceVersion=103" --compressed 'https://skyollie.com/User/dologin'

Format explanation:

POST URL: https://skyollie.com/User/dologin
Content-Type: text/plain;charset=UTF-8

- password: the password
- ios_code: <AU|CA|NZ>
- sign: <40 HEX chars>
- sbID: imei<15 digits>
- mobile: <mobile number as a string>
- timestamp: timestamp
- noncestr: <uuid>
- devicetype: 0
- type: 1
- code: <%2B61|%2B1|%2B64>
- interfaceVersion: 103
MewX commented 5 years ago

Need to spend a bit time to decode the Response:

  HTTP/1.1 200 OK
Date Thu, 22 Aug 2019 11:41:09 GMT
Content-Type text/plain;charset=UTF-8
Set-Cookie __cfduid=d9644c35c7f6048b6c903423e595f7a2d1566474069; expires=Fri, 21-Aug-20 11:41:09 GMT; path=/; domain=.skyollie.com; HttpOnly
X-Powered-By PHP/7.2.16
Expect-CT max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"
Server cloudflare
CF-RAY 50a493769f4ed1ef-HKG
Content-Encoding gzip
Transfer-Encoding chunked
Connection Keep-alive
MewX commented 5 years ago

Oh, wait, the apk is not confused:

package com.kantv.ui.activity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import butterknife.BindView;
import butterknife.OnClick;
import com.google.android.gms.analytics.HitBuilders.ScreenViewBuilder;
import com.google.android.gms.analytics.Tracker;
import com.kantv.common.api.Api;
import com.kantv.common.api.ApiService;
import com.kantv.common.api.CommonCallBack;
import com.kantv.common.log.AILog;
import com.kantv.common.utils.StringUtils;
import com.kantv.common.utils.Utils;
import com.kantv.ui.MainActivity;
import com.kantv.ui.PackageActivity;
import com.kantv.ui.config.SignConfig;
import com.kantv.ui.utils.PreferenceUtil;
import com.kantv.ui.utils.ToastUtils;
import debug.KanApplication;
import java.util.Map;
import okhttp3.ResponseBody;
import org.json.JSONArray;
import org.json.JSONObject;
import retrofit2.Call;
import retrofit2.Response;

public class LoginActivity
  extends PackageActivity
{
  private static final String TAG = "LoginActivity";
  @BindView(2131296777)
  TextView loginBtn;
  @BindView(2131296782)
  TextView loginType;
  @BindView(2131296776)
  TextView mLoginArea;
  @BindView(2131296778)
  ImageView mLoginEmail;
  @BindView(2131296780)
  EditText mLoginPhone;
  @BindView(2131296781)
  ImageView rmMobileImg;
  boolean statusUserExit = false;

  private void checkLoginPhone()
  {
    if (!StringUtils.isEmpty(this.mLoginPhone.getText()))
    {
      this.loginBtn.setEnabled(true);
      this.rmMobileImg.setVisibility(0);
      return;
    }
    this.loginBtn.setEnabled(false);
    this.rmMobileImg.setVisibility(4);
  }

  private void emailIsExistHandle()
  {
    if (!Utils.isEmail(this.mLoginPhone.getText().toString().trim()))
    {
      ToastUtils.showShort("请输入合法的邮箱");
      return;
    }
    this.request.clear();
    this.request.put("noncestr", SignConfig.noncestr);
    this.request.put("timestamp", SignConfig.timestamp);
    this.request.put("sbID", SignConfig.sbID);
    this.request.put("sign", SignConfig.sign);
    this.request.put("mail", this.mLoginPhone.getText().toString().trim());
    this.request.put("devicetype", "0");
    this.request.put("interfaceVersion", Utils.interfaceVersion);
    Api.getService().mailExist(this.request).enqueue(new CommonCallBack(this, false)
    {
      public void onResponse(Call<ResponseBody> paramAnonymousCall, Response<ResponseBody> paramAnonymousResponse)
      {
        super.onResponse(paramAnonymousCall, paramAnonymousResponse);
        if (LoginActivity.this.isDestroy) {
          return;
        }
        if (!StringUtils.isEmpty(this.json))
        {
          paramAnonymousCall = StringUtils.toJsonObject(this.json);
          if (paramAnonymousCall == null) {
            return;
          }
          if (paramAnonymousCall.optString("status").equals("200"))
          {
            PreferenceUtil.put(Utils.getContext(), "ACCOUNTID", LoginActivity.this.mLoginPhone.getText().toString().trim());
            if ((!StringUtils.isEmpty(paramAnonymousCall.optString("data"))) && (paramAnonymousCall.optString("data").equals("1")))
            {
              paramAnonymousCall = new Bundle();
              paramAnonymousCall.putString("type", "email");
              LoginActivity.this.gotoActivity(paramAnonymousCall, AccountLoginActivity.class);
              LoginActivity.this.statusUserExit = true;
              return;
            }
            LoginActivity.this.gotoActivity(EmailRegisterActivity.class);
            LoginActivity.this.statusUserExit = false;
          }
        }
      }
    });
  }

  private void initRequest()
  {
    this.request.clear();
    this.request.put("noncestr", SignConfig.noncestr);
    this.request.put("timestamp", SignConfig.timestamp);
    this.request.put("sbID", SignConfig.sbID);
    this.request.put("sign", SignConfig.sign);
    this.request.put("devicetype", "0");
    this.request.put("interfaceVersion", Utils.interfaceVersion);
    AILog.d(this.request);
    Api.getService().getCountry(this.request).enqueue(new CommonCallBack(this, true)
    {
      public void onResponse(Call<ResponseBody> paramAnonymousCall, Response<ResponseBody> paramAnonymousResponse)
      {
        super.onResponse(paramAnonymousCall, paramAnonymousResponse);
        if (LoginActivity.this.isDestroy) {
          return;
        }
        if (!StringUtils.isEmpty(this.json))
        {
          paramAnonymousCall = StringUtils.toJsonObject(this.json);
          if (paramAnonymousCall == null) {
            return;
          }
          if ((paramAnonymousCall.optString("status").equals("200")) && (!StringUtils.isEmpty(paramAnonymousCall.optString("data"))))
          {
            paramAnonymousCall = StringUtils.toJsonArray(paramAnonymousCall.optString("data"));
            if (paramAnonymousCall == null) {
              return;
            }
            int i = 0;
            while (i < paramAnonymousCall.length())
            {
              if ((StringUtils.getJSONobject(paramAnonymousCall, i) != null) && (StringUtils.getJSONobject(paramAnonymousCall, i).optString("location") != null) && (StringUtils.getJSONobject(paramAnonymousCall, i).optString("location").equals("1")))
              {
                paramAnonymousResponse = LoginActivity.this.mLoginArea;
                StringBuilder localStringBuilder = new StringBuilder();
                localStringBuilder.append("+");
                localStringBuilder.append(StringUtils.getJSONobject(paramAnonymousCall, i).optString("area_code"));
                paramAnonymousResponse.setText(localStringBuilder.toString());
                if (!StringUtils.isEmpty(StringUtils.getJSONobject(paramAnonymousCall, i).optString("iso_code"))) {
                  PreferenceUtil.put(Utils.getContext(), "iso_code", StringUtils.getJSONobject(paramAnonymousCall, i).optString("iso_code"));
                }
                paramAnonymousResponse = Utils.getContext();
                localStringBuilder = new StringBuilder();
                localStringBuilder.append("+");
                localStringBuilder.append(StringUtils.getJSONobject(paramAnonymousCall, i).optString("area_code"));
                PreferenceUtil.put(paramAnonymousResponse, "area_country", localStringBuilder.toString());
              }
              i += 1;
            }
          }
        }
      }
    });
  }

  private void initView()
  {
    checkLoginPhone();
    this.mLoginPhone.addTextChangedListener(new TextWatcher()
    {
      public void afterTextChanged(Editable paramAnonymousEditable) {}

      public void beforeTextChanged(CharSequence paramAnonymousCharSequence, int paramAnonymousInt1, int paramAnonymousInt2, int paramAnonymousInt3) {}

      public void onTextChanged(CharSequence paramAnonymousCharSequence, int paramAnonymousInt1, int paramAnonymousInt2, int paramAnonymousInt3)
      {
        LoginActivity.this.checkLoginPhone();
      }
    });
    String str = (String)PreferenceUtil.get(Utils.getContext(), "area_country", "");
    if (!StringUtils.isEmpty(str)) {
      this.mLoginArea.setText(str);
    }
  }

  private void userIsExistHandle()
  {
    if (this.mLoginArea.getText().toString().equals("区号"))
    {
      ToastUtils.showShort("请选择手机区号");
      return;
    }
    this.request.clear();
    this.request.put("noncestr", SignConfig.noncestr);
    this.request.put("timestamp", SignConfig.timestamp);
    this.request.put("sbID", SignConfig.sbID);
    this.request.put("sign", SignConfig.sign);
    this.request.put("code", this.mLoginArea.getText().toString().trim());
    this.request.put("mobile", this.mLoginPhone.getText().toString().trim());
    this.request.put("devicetype", "0");
    this.request.put("interfaceVersion", Utils.interfaceVersion);
    Api.getService().userExist(this.request).enqueue(new CommonCallBack(this, false)
    {
      public void onResponse(Call<ResponseBody> paramAnonymousCall, Response<ResponseBody> paramAnonymousResponse)
      {
        super.onResponse(paramAnonymousCall, paramAnonymousResponse);
        if (LoginActivity.this.isDestroy) {
          return;
        }
        if (!StringUtils.isEmpty(this.json))
        {
          paramAnonymousCall = StringUtils.toJsonObject(this.json);
          if (paramAnonymousCall == null) {
            return;
          }
          if (paramAnonymousCall.optString("status").equals("200"))
          {
            PreferenceUtil.put(Utils.getContext(), "ACCOUNTID", LoginActivity.this.mLoginPhone.getText().toString().trim());
            if ((!StringUtils.isEmpty(paramAnonymousCall.optString("data"))) && (paramAnonymousCall.optString("data").equals("1")))
            {
              paramAnonymousCall = new Bundle();
              paramAnonymousCall.putString("type", "phone");
              LoginActivity.this.gotoActivity(paramAnonymousCall, AccountLoginActivity.class);
              LoginActivity.this.statusUserExit = true;
              return;
            }
            LoginActivity.this.gotoActivity(RegisterActivity.class);
            LoginActivity.this.statusUserExit = false;
            return;
          }
          ToastUtils.showShort(paramAnonymousCall.optString("msg"));
        }
      }
    });
  }

  public void onActivityResult(int paramInt1, int paramInt2, Intent paramIntent)
  {
    super.onActivityResult(paramInt1, paramInt2, paramIntent);
    if ((paramInt1 == 10) && (paramIntent != null))
    {
      paramIntent = paramIntent.getExtras().getString("area");
      this.mLoginArea.setText(paramIntent);
    }
  }

  @OnClick({2131296776, 2131296781, 2131296782, 2131296733, 2131296777})
  public void onClick(View paramView)
  {
    switch (paramView.getId())
    {
    default: 
      return;
    case 2131296782: 
      if (this.mLoginEmail.getVisibility() == 0)
      {
        this.mLoginEmail.setVisibility(8);
        this.mLoginArea.setVisibility(0);
        this.mLoginPhone.setHint("手机号码");
        this.loginType.setText("邮箱登录");
        this.mLoginPhone.setInputType(2);
        return;
      }
      this.mLoginEmail.setVisibility(0);
      this.mLoginArea.setVisibility(8);
      this.mLoginPhone.setHint("邮箱账号");
      this.loginType.setText("手机号登录");
      this.mLoginPhone.setInputType(32);
      return;
    case 2131296781: 
      this.mLoginPhone.setText("");
      return;
    case 2131296777: 
      paramView = (String)PreferenceUtil.get(Utils.getContext(), "ACCOUNTID", "");
      if ((!StringUtils.isEmpty(paramView)) && (paramView.equals(this.mLoginPhone.getText().toString().trim())) && (this.statusUserExit))
      {
        paramView = new Bundle();
        if (this.mLoginEmail.getVisibility() == 0) {
          paramView.putString("type", "email");
        } else {
          paramView.putString("type", "phone");
        }
        gotoActivity(paramView, AccountLoginActivity.class);
        return;
      }
      if (this.mLoginEmail.getVisibility() == 0)
      {
        emailIsExistHandle();
        return;
      }
      userIsExistHandle();
      return;
    case 2131296776: 
      startActivityForResult(new Intent(Utils.getContext(), AreaActivity.class), 10);
      return;
    }
    gotoActivity(MainActivity.class);
  }

  protected void onCreate(Bundle paramBundle)
  {
    super.onCreate(paramBundle);
    setContentView(2131492901);
    initBase();
    initView();
    initRequest();
    KanApplication.clearTvDefaultIndexJson();
    KanApplication.getDefaultTracker().setScreenName("登录_首次登录");
    KanApplication.getDefaultTracker().send(new HitBuilders.ScreenViewBuilder().build());
  }
}