Anonymous social networking 1 -- login, anonymous social networking 1 --
1. Logon
The user logs in using the mobile phone number + SMS verification code. The server does not save the user's mobile phone number.
After successful login, the client can obtain the login identity, and the client can maintain a relatively long period of access to the server through the login identity.
2. Interface
Get verification code:
{\"status\":1}
Anonymous Login:
{\"status\":1,\"token\":\"asdasdasdsadasd\"}
3. Code
MainActivity
@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);String token = Config.getCachedToken(this);String phone_num = Config.getCachedPhoneNum(this);if (token!=null&&phone_num!=null) {Intent i =new Intent(this, AtyTimeline.class);i.putExtra(Config.KEY_TOKEN, token);i.putExtra(Config.KEY_PHONE_NUM, phone_num);startActivity(i);}else{startActivity(new Intent(this, AtyLogin.class));}finish();}
LoginActivity
findViewById(R.id.btnGetCode).setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View arg0) {if (TextUtils.isEmpty(etPhone.getText())) {Toast.makeText(AtyLogin.this, R.string.phone_num_can_not_be_empty, Toast.LENGTH_LONG).show();return;}final ProgressDialog pd = ProgressDialog.show(AtyLogin.this, getResources().getString(R.string.connecting), getResources().getString(R.string.connecting_to_server));new GetCode(etPhone.getText().toString(), new GetCode.SuccessCallback() {@Overridepublic void onSuccess() {pd.dismiss();Toast.makeText(AtyLogin.this, R.string.suc_to_get_code, Toast.LENGTH_LONG).show();}}, new GetCode.FailCallback() {@Overridepublic void onFail() {pd.dismiss();Toast.makeText(AtyLogin.this, R.string.fail_to_get_code, Toast.LENGTH_LONG).show();}});}});findViewById(R.id.btnLogin).setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View arg0) {if (TextUtils.isEmpty(etPhone.getText())) {Toast.makeText(AtyLogin.this, R.string.phone_num_can_not_be_empty, Toast.LENGTH_LONG).show();return;}if (TextUtils.isEmpty(etCode.getText())) {Toast.makeText(AtyLogin.this, R.string.code_can_not_be_empty, Toast.LENGTH_LONG).show();return;}final ProgressDialog pd = ProgressDialog.show(AtyLogin.this, getResources().getString(R.string.connecting), getResources().getString(R.string.connecting_to_server));new Login(MD5Tool.md5(etPhone.getText().toString()), etCode.getText().toString(), new Login.SuccessCallback() {@Overridepublic void onSuccess(String token) {pd.dismiss();Config.cacheToken(AtyLogin.this, token);Config.cachePhoneNum(AtyLogin.this, etPhone.getText().toString());Intent i = new Intent(AtyLogin.this, AtyTimeline.class);i.putExtra(Config.KEY_TOKEN, token);i.putExtra(Config.KEY_PHONE_NUM, etPhone.getText().toString());startActivity(i);finish();}}, new Login.FailCallback() {@Overridepublic void onFail() {pd.dismiss();Toast.makeText(AtyLogin.this, R.string.fail_to_login, Toast.LENGTH_LONG).show();}});}});