170 lines
7.3 KiB
Java
170 lines
7.3 KiB
Java
package com.ubtrobot.ubtlib.social;
|
|
|
|
import android.app.Activity;
|
|
import android.content.Context;
|
|
import android.content.Intent;
|
|
import android.content.pm.PackageManager;
|
|
import android.os.Bundle;
|
|
import android.util.Log;
|
|
import com.facebook.AccessToken;
|
|
import com.tencent.connect.UserInfo;
|
|
import com.tencent.open.SocialConstants;
|
|
import com.tencent.tauth.IUiListener;
|
|
import com.tencent.tauth.Tencent;
|
|
import com.tencent.tauth.UiError;
|
|
import com.ubtrobot.ubtlib.share.ShareBuilder;
|
|
import com.ubtrobot.ubtlib.share.UbtSocialShareListener;
|
|
import java.text.MessageFormat;
|
|
import java.util.HashMap;
|
|
import org.json.JSONException;
|
|
import org.json.JSONObject;
|
|
|
|
/* loaded from: classes2.dex */
|
|
public class TencentUbtSocialImpl implements IUbtSocial {
|
|
private UbtSocialAuthListener a;
|
|
private UbtSocialShareListener b;
|
|
private Activity c;
|
|
private IUiListener d;
|
|
private Tencent e;
|
|
private String f;
|
|
|
|
@Override // com.ubtrobot.ubtlib.social.IUbtSocial
|
|
public void a(Activity activity) {
|
|
this.f = SocialTool.a((Context) activity, "app_id_qq");
|
|
this.e = Tencent.a(this.f, activity.getApplicationContext());
|
|
this.c = activity;
|
|
}
|
|
|
|
@Override // com.ubtrobot.ubtlib.social.IUbtSocial
|
|
public boolean b() {
|
|
try {
|
|
this.c.getPackageManager().getPackageInfo("com.tencent.mobileqq", 0);
|
|
return true;
|
|
} catch (PackageManager.NameNotFoundException unused) {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
@Override // com.ubtrobot.ubtlib.social.IUbtSocial
|
|
public void a(UbtSocialAuthListener ubtSocialAuthListener) {
|
|
this.a = ubtSocialAuthListener;
|
|
this.d = new IUiListener() { // from class: com.ubtrobot.ubtlib.social.TencentUbtSocialImpl.1
|
|
@Override // com.tencent.tauth.IUiListener
|
|
public void onCancel() {
|
|
if (TencentUbtSocialImpl.this.a != null) {
|
|
TencentUbtSocialImpl.this.a.onCancel();
|
|
}
|
|
}
|
|
|
|
@Override // com.tencent.tauth.IUiListener
|
|
public void onComplete(Object obj) {
|
|
try {
|
|
JSONObject jSONObject = (JSONObject) obj;
|
|
Log.i("UbtSocial", jSONObject.toString());
|
|
final HashMap hashMap = new HashMap();
|
|
hashMap.put("ubtsocial_user_id", jSONObject.getString(SocialConstants.PARAM_OPEN_ID));
|
|
hashMap.put(AccessToken.ACCESS_TOKEN_KEY, jSONObject.getString(AccessToken.ACCESS_TOKEN_KEY));
|
|
hashMap.put("ubtsocial_app_id", TencentUbtSocialImpl.this.f);
|
|
hashMap.put("social_type", UbtSocialType.QQ.loginType);
|
|
TencentUbtSocialImpl.this.e.b().a(jSONObject.getString(SocialConstants.PARAM_OPEN_ID));
|
|
TencentUbtSocialImpl.this.e.b().a(jSONObject.getString(AccessToken.ACCESS_TOKEN_KEY), jSONObject.getString(AccessToken.EXPIRES_IN_KEY));
|
|
new UserInfo(TencentUbtSocialImpl.this.c, TencentUbtSocialImpl.this.e.b()).a(new IUiListener() { // from class: com.ubtrobot.ubtlib.social.TencentUbtSocialImpl.1.1
|
|
@Override // com.tencent.tauth.IUiListener
|
|
public void onCancel() {
|
|
if (TencentUbtSocialImpl.this.a != null) {
|
|
TencentUbtSocialImpl.this.a.onCancel();
|
|
}
|
|
}
|
|
|
|
@Override // com.tencent.tauth.IUiListener
|
|
public void onComplete(Object obj2) {
|
|
JSONObject jSONObject2 = (JSONObject) obj2;
|
|
try {
|
|
hashMap.put("nick_name", jSONObject2.getString("nickname"));
|
|
hashMap.put("head_image", jSONObject2.getString("figureurl"));
|
|
} catch (JSONException e) {
|
|
e.printStackTrace();
|
|
}
|
|
if (TencentUbtSocialImpl.this.a != null) {
|
|
TencentUbtSocialImpl.this.a.a(hashMap);
|
|
}
|
|
}
|
|
|
|
@Override // com.tencent.tauth.IUiListener
|
|
public void onError(UiError uiError) {
|
|
String format = MessageFormat.format("errorCode: {0}, errorMessage: {1}, errorDetail: {2}", Integer.valueOf(uiError.a), uiError.b, uiError.c);
|
|
if (TencentUbtSocialImpl.this.a != null) {
|
|
TencentUbtSocialImpl.this.a.a(new Exception(format));
|
|
}
|
|
}
|
|
});
|
|
} catch (JSONException e) {
|
|
if (TencentUbtSocialImpl.this.a != null) {
|
|
TencentUbtSocialImpl.this.a.a(e);
|
|
}
|
|
}
|
|
}
|
|
|
|
@Override // com.tencent.tauth.IUiListener
|
|
public void onError(UiError uiError) {
|
|
String format = MessageFormat.format("errorCode: {0}, errorMessage: {1}, errorDetail: {2}", Integer.valueOf(uiError.a), uiError.b, uiError.c);
|
|
if (TencentUbtSocialImpl.this.a != null) {
|
|
TencentUbtSocialImpl.this.a.a(new Exception(format));
|
|
}
|
|
}
|
|
};
|
|
}
|
|
|
|
@Override // com.ubtrobot.ubtlib.social.IUbtSocial
|
|
public void a(int i, int i2, Intent intent) {
|
|
Tencent.a(i, i2, intent, this.d);
|
|
}
|
|
|
|
@Override // com.ubtrobot.ubtlib.social.IUbtSocial
|
|
public void a() {
|
|
this.e.a(this.c, "all", this.d);
|
|
}
|
|
|
|
@Override // com.ubtrobot.ubtlib.social.IUbtSocial
|
|
public void a(ShareBuilder shareBuilder) {
|
|
if (Thread.currentThread() == this.c.getMainLooper().getThread()) {
|
|
Bundle bundle = new Bundle();
|
|
bundle.putString("title", shareBuilder.d());
|
|
bundle.putString(SocialConstants.PARAM_TARGET_URL, shareBuilder.e());
|
|
this.d = new IUiListener() { // from class: com.ubtrobot.ubtlib.social.TencentUbtSocialImpl.2
|
|
@Override // com.tencent.tauth.IUiListener
|
|
public void onCancel() {
|
|
TencentUbtSocialImpl.this.b.onCancel();
|
|
}
|
|
|
|
@Override // com.tencent.tauth.IUiListener
|
|
public void onComplete(Object obj) {
|
|
TencentUbtSocialImpl.this.b.onSuccess();
|
|
}
|
|
|
|
@Override // com.tencent.tauth.IUiListener
|
|
public void onError(UiError uiError) {
|
|
TencentUbtSocialImpl.this.b.a();
|
|
}
|
|
};
|
|
int c = shareBuilder.c();
|
|
if (c == 272) {
|
|
this.e.a(this.c, bundle, this.d);
|
|
return;
|
|
} else {
|
|
if (c == 273) {
|
|
this.e.b(this.c, bundle, this.d);
|
|
return;
|
|
}
|
|
throw new IllegalArgumentException("share platform error, only support qq and qzone, current platform " + c);
|
|
}
|
|
}
|
|
throw new RuntimeException("没有在主线程调用!");
|
|
}
|
|
|
|
@Override // com.ubtrobot.ubtlib.social.IUbtSocial
|
|
public void a(UbtSocialShareListener ubtSocialShareListener) {
|
|
this.b = ubtSocialShareListener;
|
|
}
|
|
}
|