// Path: ezy.sdk3rd.social/src/main/java/ezy/sdk3rd/social/authorize/IAuthorize.java
// public interface IAuthorize extends IResult {
//     void authorize(OnCallback<String> callback);
// }
// 
// Path: ezy.sdk3rd.social/src/main/java/ezy/sdk3rd/social/sdk/OnCallback.java
// public interface OnCallback<T> {
//     void onStarted(Activity activity);
//     void onCompleted(Activity activity);
//     void onSucceed(Activity activity, T result);
//     void onFailed(Activity activity, int code, String message);
// }
// 
// Path: ezy.sdk3rd.social/src/main/java/ezy/sdk3rd/social/sdk/Platform.java
// public class Platform {
//     final String name;
//     final String appId;
// 
//     Map<String, String> extra;
// 
//     public Platform(@NonNull String name, @NonNull String appId) {
//         this.name = name;
//         this.appId = appId;
//     }
// 
//     public String getName() {
//         return name;
//     }
// 
//     public String getAppId() {
//         return appId;
//     }
// 
//     public String extra(String key) {
//         return extra == null ? "" : extra.get(key);
//     }
// 
//     public Platform extra(String key, String value) {
//         if (extra == null) {
//             extra = new HashMap<>();
//         }
//         extra.put(key, value);
//         return this;
//     }
// }
// 
// Path: ezy.sdk3rd.social/src/main/java/ezy/sdk3rd/social/sdk/ResultCode.java
// public class ResultCode {
//     public static final int RESULT_OK = 0;
//     public static final int RESULT_PENDING = 1;
//     public static final int RESULT_CANCELLED = 2;
//     public static final int RESULT_FAILED = 3;
// 
// }


import android.app.Activity;
import android.content.Intent;
import android.support.annotation.NonNull;
import android.text.TextUtils;
import android.util.Log;
import com.tencent.connect.common.Constants;
import com.tencent.tauth.IUiListener;
import com.tencent.tauth.Tencent;
import com.tencent.tauth.UiError;
import org.json.JSONObject;
import ezy.sdk3rd.social.authorize.IAuthorize;
import ezy.sdk3rd.social.sdk.OnCallback;
import ezy.sdk3rd.social.sdk.Platform;
import ezy.sdk3rd.social.sdk.ResultCode;
        mApi = Tencent.createInstance(platform.getAppId(), mActivity);
    }

    String toMessage(UiError error) {
        return "[" + error.errorCode + "]" + error.errorMessage;
    }

    @Override
    public void authorize(@NonNull final OnCallback<String> callback) {
        mListener = new IUiListener() {
            @Override
            public void onComplete(Object response) {
                Log.e(TAG, "complete ==> " + response);
                if (response instanceof JSONObject && ((JSONObject) response).length() > 0) {
                    JSONObject jo = (JSONObject) response;
                    String token = jo.optString(Constants.PARAM_ACCESS_TOKEN);
                    String expires = jo.optString(Constants.PARAM_EXPIRES_IN);
                    String openId = jo.optString(Constants.PARAM_OPEN_ID);
                    if (!TextUtils.isEmpty(token) && !TextUtils.isEmpty(expires) && !TextUtils.isEmpty(openId)) {
                        mApi.setAccessToken(token, expires);
                        mApi.setOpenId(openId);
                    }
                    callback.onSucceed(mActivity, "token|" + mApi.getOpenId() + "|" + mApi.getAccessToken());
                } else {
                    callback.onFailed(mActivity, ResultCode.RESULT_FAILED, "登录失败: 返回为空");
                }
                callback.onCompleted(mActivity);
            }


// Path: ezy.sdk3rd.social/src/main/java/ezy/sdk3rd/social/authorize/IAuthorize.java
// public interface IAuthorize extends IResult {
//     void authorize(OnCallback<String> callback);
// }
// 
// Path: ezy.sdk3rd.social/src/main/java/ezy/sdk3rd/social/sdk/OnCallback.java
// public interface OnCallback<T> {
//     void onStarted(Activity activity);
//     void onCompleted(Activity activity);
//     void onSucceed(Activity activity, T result);
//     void onFailed(Activity activity, int code, String message);
// }
// 
// Path: ezy.sdk3rd.social/src/main/java/ezy/sdk3rd/social/sdk/Platform.java
// public class Platform {
//     final String name;
//     final String appId;
// 
//     Map<String, String> extra;
// 
//     public Platform(@NonNull String name, @NonNull String appId) {
//         this.name = name;
//         this.appId = appId;
//     }
// 
//     public String getName() {
//         return name;
//     }
// 
//     public String getAppId() {
//         return appId;
//     }
// 
//     public String extra(String key) {
//         return extra == null ? "" : extra.get(key);
//     }
// 
//     public Platform extra(String key, String value) {
//         if (extra == null) {
//             extra = new HashMap<>();
//         }
//         extra.put(key, value);
//         return this;
//     }
// }
// 
// Path: ezy.sdk3rd.social/src/main/java/ezy/sdk3rd/social/sdk/ResultCode.java
// public class ResultCode {
//     public static final int RESULT_OK = 0;
//     public static final int RESULT_PENDING = 1;
//     public static final int RESULT_CANCELLED = 2;
//     public static final int RESULT_FAILED = 3;
// 
// }


// Path: ezy.sdk3rd.social/src/main/java/ezy/sdk3rd/social/platforms/qq/QQAuth.java
import android.app.Activity;
import android.content.Intent;
import android.support.annotation.NonNull;
import android.text.TextUtils;
import android.util.Log;
import com.tencent.connect.common.Constants;
import com.tencent.tauth.IUiListener;
import com.tencent.tauth.Tencent;
import com.tencent.tauth.UiError;
import org.json.JSONObject;
import ezy.sdk3rd.social.authorize.IAuthorize;
import ezy.sdk3rd.social.sdk.OnCallback;
import ezy.sdk3rd.social.sdk.Platform;
import ezy.sdk3rd.social.sdk.ResultCode;

        mApi = Tencent.createInstance(platform.getAppId(), mActivity);
    }

    String toMessage(UiError error) {
        return "[" + error.errorCode + "]" + error.errorMessage;
    }

    @Override
    public void authorize(@NonNull final OnCallback<String> callback) {
        mListener = new IUiListener() {
            @Override
            public void onComplete(Object response) {
                Log.e(TAG, "complete ==> " + response);
                if (response instanceof JSONObject && ((JSONObject) response).length() > 0) {
                    JSONObject jo = (JSONObject) response;
                    String token = jo.optString(Constants.PARAM_ACCESS_TOKEN);
                    String expires = jo.optString(Constants.PARAM_EXPIRES_IN);
                    String openId = jo.optString(Constants.PARAM_OPEN_ID);
                    if (!TextUtils.isEmpty(token) && !TextUtils.isEmpty(expires) && !TextUtils.isEmpty(openId)) {
                        mApi.setAccessToken(token, expires);
                        mApi.setOpenId(openId);
                    }
                    callback.onSucceed(mActivity, "token|" + mApi.getOpenId() + "|" + mApi.getAccessToken());
                } else {
                    callback.onFailed(mActivity, ResultCode.RESULT_FAILED, "登录失败: 返回为空");
                }
                callback.onCompleted(mActivity);
            }


            @Override