Back to project page Music-Share-Android.
The source code is released under:
GNU General Public License
If you think the Android project Music-Share-Android listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.weibo.sdk.android; //from w w w . ja va 2s . c o m import org.json.JSONException; import org.json.JSONObject; import android.text.TextUtils; /** * ??????access_token???expires_in???"refresh_token"? *??????????????? * @author luopeng (luopeng@staff.sina.com.cn) */ public class Oauth2AccessToken { private String mAccessToken = ""; private String mRefreshToken = ""; private long mExpiresTime = 0; // private String mOauth_verifier = ""; // protected String[] responseStr = null; // protected SecretKeySpec mSecretKeySpec; /** * Oauth2AccessToken ????? */ public Oauth2AccessToken() { } /** * ???????????responsetext???Oauth2AccessToken ?????? * ?????responsetext??access_token???expires_in???"refresh_token"??????? * @param responsetext ???????responsetext */ public Oauth2AccessToken(String responsetext) { if (responsetext != null) { if (responsetext.indexOf("{") >= 0) { try { JSONObject json = new JSONObject(responsetext); setToken(json.optString("access_token")); setExpiresIn(json.optString("expires_in")); setRefreshToken(json.optString("refresh_token")); } catch (JSONException e) { } } } } /** * Oauth2AccessToken??????????accessToken ?expires_in ???Oauth2AccessToken?? * @param accessToken ???? * @param expires_in ?????????????????????????expires_in????????????????????? */ public Oauth2AccessToken(String accessToken, String expires_in) { mAccessToken = accessToken; mExpiresTime = System.currentTimeMillis() + Long.parseLong(expires_in)*1000; } /** * AccessToken??????,??accessToken????expiresTime?????false???????true * @return ??accessToken????expiresTime?????false???????true */ public boolean isSessionValid() { return (!TextUtils.isEmpty(mAccessToken) && (mExpiresTime == 0 || (System .currentTimeMillis() < mExpiresTime))); } /** * ????accessToken */ public String getToken() { return this.mAccessToken; } /** * ????refreshToken */ public String getRefreshToken() { return mRefreshToken; } /** * ??refreshToken * @param mRefreshToken */ public void setRefreshToken(String mRefreshToken) { this.mRefreshToken = mRefreshToken; } /** * ??????????????: ?????????????1970?01?01?00?00?00??????? ??? */ public long getExpiresTime() { return mExpiresTime; } /** * ???????????????????????????????? * */ public void setExpiresIn(String expiresIn) { if (expiresIn != null && !expiresIn.equals("0")) { setExpiresTime(System.currentTimeMillis() + Long.parseLong(expiresIn) * 1000); } } /** * ??????? ??? * @param mExpiresTime ???????????????????1970?01?01?00?00?00??????? ??? * */ public void setExpiresTime(long mExpiresTime) { this.mExpiresTime = mExpiresTime; } /** * ??accessToken * @param mToken */ public void setToken(String mToken) { this.mAccessToken = mToken; } // /** // * ????? // * @param verifier // */ // public void setVerifier(String verifier) { // mOauth_verifier = verifier; // } // /** // * ??????? // * @return // */ // public String getVerifier() { // return mOauth_verifier; // } // // public String getParameter(String parameter) { // String value = null; // for (String str : responseStr) { // if (str.startsWith(parameter + '=')) { // value = str.split("=")[1].trim(); // break; // } // } // return value; // } // protected void setSecretKeySpec(SecretKeySpec secretKeySpec) { // this.mSecretKeySpec = secretKeySpec; // } // // protected SecretKeySpec getSecretKeySpec() { // return mSecretKeySpec; // } }