You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
team_noob/src/main/java/com/payment/utils/TokenUtils.java

32 lines
1.1 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

package com.payment.utils;
import android.content.Context;
import android.content.SharedPreferences;
public class TokenUtils {
private static final String SP_NAME = "payment_token";
private static final String KEY_TOKEN = "token";
// 保存Token
public static void saveToken(Context context, String token) {
SharedPreferences sp = context.getSharedPreferences(SP_NAME, Context.MODE_PRIVATE);
sp.edit().putString(KEY_TOKEN, token).apply();
}
// 获取Token
public static String getToken(Context context) {
SharedPreferences sp = context.getSharedPreferences(SP_NAME, Context.MODE_PRIVATE);
return sp.getString(KEY_TOKEN, "");
}
// 清除Token退出登录
public static void clearToken(Context context) {
SharedPreferences sp = context.getSharedPreferences(SP_NAME, Context.MODE_PRIVATE);
sp.edit().remove(KEY_TOKEN).apply();
}
// 判断Token是否存在登录状态
public static boolean isLogin(Context context) {
return !getToken(context).isEmpty();
}
}