Initial commit
This commit is contained in:
128
sources/com/ubtrobot/ubtlib/social/FacebookUbtSocialImpl.java
Normal file
128
sources/com/ubtrobot/ubtlib/social/FacebookUbtSocialImpl.java
Normal file
@@ -0,0 +1,128 @@
|
||||
package com.ubtrobot.ubtlib.social;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import com.facebook.AccessToken;
|
||||
import com.facebook.CallbackManager;
|
||||
import com.facebook.FacebookCallback;
|
||||
import com.facebook.FacebookException;
|
||||
import com.facebook.GraphRequest;
|
||||
import com.facebook.GraphResponse;
|
||||
import com.facebook.login.LoginManager;
|
||||
import com.facebook.login.LoginResult;
|
||||
import com.facebook.share.model.ShareLinkContent;
|
||||
import com.facebook.share.widget.ShareDialog;
|
||||
import com.tencent.open.SocialConstants;
|
||||
import com.ubtrobot.ubtlib.share.ShareBuilder;
|
||||
import com.ubtrobot.ubtlib.share.UbtSocialShareListener;
|
||||
import com.unity3d.ads.metadata.MediationMetaData;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
/* loaded from: classes2.dex */
|
||||
public class FacebookUbtSocialImpl implements IUbtSocial {
|
||||
private Activity a;
|
||||
private LoginManager b;
|
||||
private CallbackManager c;
|
||||
private AccessToken d;
|
||||
private FacebookCallback<LoginResult> e;
|
||||
private String f;
|
||||
private ShareDialog g;
|
||||
|
||||
@Override // com.ubtrobot.ubtlib.social.IUbtSocial
|
||||
public void a(UbtSocialShareListener ubtSocialShareListener) {
|
||||
}
|
||||
|
||||
@Override // com.ubtrobot.ubtlib.social.IUbtSocial
|
||||
public boolean b() {
|
||||
try {
|
||||
this.a.getPackageManager().getPackageInfo("com.facebook.katana", 0);
|
||||
return true;
|
||||
} catch (PackageManager.NameNotFoundException unused) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override // com.ubtrobot.ubtlib.social.IUbtSocial
|
||||
public void a() {
|
||||
LoginManager.a().a(this.a, Arrays.asList("public_profile"));
|
||||
}
|
||||
|
||||
@Override // com.ubtrobot.ubtlib.social.IUbtSocial
|
||||
public void a(Activity activity) {
|
||||
this.a = activity;
|
||||
this.g = new ShareDialog(this.a);
|
||||
this.b = LoginManager.a();
|
||||
this.c = CallbackManager.Factory.a();
|
||||
this.d = AccessToken.getCurrentAccessToken();
|
||||
this.f = SocialTool.a((Context) this.a, "com.facebook.sdk.ApplicationId");
|
||||
}
|
||||
|
||||
@Override // com.ubtrobot.ubtlib.social.IUbtSocial
|
||||
public void a(int i, int i2, Intent intent) {
|
||||
this.c.a(i, i2, intent);
|
||||
}
|
||||
|
||||
@Override // com.ubtrobot.ubtlib.social.IUbtSocial
|
||||
public void a(final UbtSocialAuthListener ubtSocialAuthListener) {
|
||||
this.e = new FacebookCallback<LoginResult>() { // from class: com.ubtrobot.ubtlib.social.FacebookUbtSocialImpl.1
|
||||
@Override // com.facebook.FacebookCallback
|
||||
/* renamed from: a, reason: merged with bridge method [inline-methods] */
|
||||
public void onSuccess(LoginResult loginResult) {
|
||||
FacebookUbtSocialImpl.this.d = loginResult.a();
|
||||
GraphRequest a = GraphRequest.a(FacebookUbtSocialImpl.this.d, new GraphRequest.GraphJSONObjectCallback() { // from class: com.ubtrobot.ubtlib.social.FacebookUbtSocialImpl.1.1
|
||||
@Override // com.facebook.GraphRequest.GraphJSONObjectCallback
|
||||
public void a(JSONObject jSONObject, GraphResponse graphResponse) {
|
||||
if (graphResponse == null || graphResponse.b() == null) {
|
||||
ubtSocialAuthListener.a(new Throwable(""));
|
||||
return;
|
||||
}
|
||||
try {
|
||||
String string = graphResponse.b().getJSONObject(SocialConstants.PARAM_AVATAR_URI).getJSONObject("data").getString("url");
|
||||
String optString = graphResponse.b().optString(MediationMetaData.KEY_NAME);
|
||||
HashMap hashMap = new HashMap();
|
||||
hashMap.put("ubtsocial_user_id", FacebookUbtSocialImpl.this.d.getUserId());
|
||||
hashMap.put(AccessToken.ACCESS_TOKEN_KEY, FacebookUbtSocialImpl.this.d.getToken());
|
||||
hashMap.put("ubtsocial_app_id", FacebookUbtSocialImpl.this.f);
|
||||
hashMap.put("social_type", UbtSocialType.FACEBOOK.loginType);
|
||||
hashMap.put("nick_name", optString);
|
||||
hashMap.put("head_image", string);
|
||||
ubtSocialAuthListener.a(hashMap);
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
ubtSocialAuthListener.a(new Throwable(""));
|
||||
}
|
||||
}
|
||||
});
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putString("fields", "id,name,link,gender,picture.type(large)");
|
||||
a.a(bundle);
|
||||
a.b();
|
||||
}
|
||||
|
||||
@Override // com.facebook.FacebookCallback
|
||||
public void onCancel() {
|
||||
ubtSocialAuthListener.onCancel();
|
||||
}
|
||||
|
||||
@Override // com.facebook.FacebookCallback
|
||||
public void a(FacebookException facebookException) {
|
||||
ubtSocialAuthListener.a(facebookException);
|
||||
}
|
||||
};
|
||||
this.b.a(this.c, this.e);
|
||||
}
|
||||
|
||||
@Override // com.ubtrobot.ubtlib.social.IUbtSocial
|
||||
public void a(ShareBuilder shareBuilder) {
|
||||
ShareLinkContent.Builder builder = new ShareLinkContent.Builder();
|
||||
builder.a(Uri.parse(shareBuilder.e()));
|
||||
this.g.a((ShareDialog) builder.a());
|
||||
}
|
||||
}
|
23
sources/com/ubtrobot/ubtlib/social/IUbtSocial.java
Normal file
23
sources/com/ubtrobot/ubtlib/social/IUbtSocial.java
Normal file
@@ -0,0 +1,23 @@
|
||||
package com.ubtrobot.ubtlib.social;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import com.ubtrobot.ubtlib.share.ShareBuilder;
|
||||
import com.ubtrobot.ubtlib.share.UbtSocialShareListener;
|
||||
|
||||
/* loaded from: classes2.dex */
|
||||
public interface IUbtSocial {
|
||||
void a();
|
||||
|
||||
void a(int i, int i2, Intent intent);
|
||||
|
||||
void a(Activity activity);
|
||||
|
||||
void a(ShareBuilder shareBuilder);
|
||||
|
||||
void a(UbtSocialShareListener ubtSocialShareListener);
|
||||
|
||||
void a(UbtSocialAuthListener ubtSocialAuthListener);
|
||||
|
||||
boolean b();
|
||||
}
|
88
sources/com/ubtrobot/ubtlib/social/SocialTool.java
Normal file
88
sources/com/ubtrobot/ubtlib/social/SocialTool.java
Normal file
@@ -0,0 +1,88 @@
|
||||
package com.ubtrobot.ubtlib.social;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import com.tencent.mm.opensdk.modelbase.BaseResp;
|
||||
import com.tencent.mm.opensdk.modelmsg.SendAuth;
|
||||
import com.tencent.mm.opensdk.modelmsg.SendMessageToWX;
|
||||
import com.ubtrobot.jimu.robotapi.PeripheralType;
|
||||
import com.ubtrobot.ubtlib.share.UbtSocialShareListener;
|
||||
import java.text.MessageFormat;
|
||||
|
||||
/* loaded from: classes2.dex */
|
||||
public class SocialTool {
|
||||
private static UbtSocialAuthListener a;
|
||||
private static UbtSocialShareListener b;
|
||||
|
||||
public static String a(Context context, String str) {
|
||||
try {
|
||||
String string = context.getPackageManager().getApplicationInfo(context.getPackageName(), PeripheralType.SERVO).metaData.getString(str);
|
||||
if (!TextUtils.isEmpty(string)) {
|
||||
Log.d("UbtSocial", MessageFormat.format("meta data {0}:{1}", str, string));
|
||||
return string;
|
||||
}
|
||||
throw new RuntimeException(str + " don't exist in AndroidManifest.xml");
|
||||
} catch (PackageManager.NameNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
throw new RuntimeException(context.getPackageName() + " package name not found", e);
|
||||
}
|
||||
}
|
||||
|
||||
public static UbtSocialShareListener b() {
|
||||
return b;
|
||||
}
|
||||
|
||||
public static String a(Context context) {
|
||||
ApplicationInfo applicationInfo = context.getApplicationInfo();
|
||||
if (applicationInfo.labelRes != 0) {
|
||||
Log.d("UbtSocial", "labelRes : " + context.getString(applicationInfo.labelRes));
|
||||
return context.getString(applicationInfo.labelRes);
|
||||
}
|
||||
Log.d("UbtSocial", "nonLocalizedLabel : " + ((Object) applicationInfo.nonLocalizedLabel));
|
||||
if (applicationInfo.nonLocalizedLabel != null) {
|
||||
return (String) applicationInfo.nonLocalizedLabel;
|
||||
}
|
||||
String str = (String) context.getPackageManager().getApplicationLabel(applicationInfo);
|
||||
Log.d("UbtSocial", "ApplicationLabel " + str);
|
||||
if (str != null) {
|
||||
return str;
|
||||
}
|
||||
throw new RuntimeException("couldn't get application label");
|
||||
}
|
||||
|
||||
public static String a(BaseResp baseResp) {
|
||||
return MessageFormat.format("wechat errCode: {0}, errStr: {1}, openId: {2}, transaction: {3}, classname: {4}", Integer.valueOf(baseResp.errCode), baseResp.errStr, baseResp.openId, baseResp.transaction, baseResp.getClass().getName());
|
||||
}
|
||||
|
||||
public static String a(SendAuth.Resp resp) {
|
||||
return MessageFormat.format("code: {0}, state: {1}, url: {2}, lang: {3}, country: {4}", resp.code, resp.state, resp.url, resp.lang, resp.country);
|
||||
}
|
||||
|
||||
public static String a(SendMessageToWX.Resp resp) {
|
||||
return MessageFormat.format("wechat errCode: {0}, errStr: {1}, openId: {2}, transaction: {3}, type: {4}", Integer.valueOf(resp.errCode), resp.errStr, resp.openId, resp.transaction, Integer.valueOf(resp.getType()));
|
||||
}
|
||||
|
||||
public static void a(Activity activity, String str) {
|
||||
activity.runOnUiThread(new Runnable() { // from class: com.ubtrobot.ubtlib.social.SocialTool.1
|
||||
@Override // java.lang.Runnable
|
||||
public void run() {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static void a(UbtSocialAuthListener ubtSocialAuthListener) {
|
||||
a = ubtSocialAuthListener;
|
||||
}
|
||||
|
||||
public static UbtSocialAuthListener a() {
|
||||
return a;
|
||||
}
|
||||
|
||||
public static void a(UbtSocialShareListener ubtSocialShareListener) {
|
||||
b = ubtSocialShareListener;
|
||||
}
|
||||
}
|
169
sources/com/ubtrobot/ubtlib/social/TencentUbtSocialImpl.java
Normal file
169
sources/com/ubtrobot/ubtlib/social/TencentUbtSocialImpl.java
Normal file
@@ -0,0 +1,169 @@
|
||||
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;
|
||||
}
|
||||
}
|
126
sources/com/ubtrobot/ubtlib/social/TwitterUbtSocialImpl.java
Normal file
126
sources/com/ubtrobot/ubtlib/social/TwitterUbtSocialImpl.java
Normal file
@@ -0,0 +1,126 @@
|
||||
package com.ubtrobot.ubtlib.social;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import com.facebook.AccessToken;
|
||||
import com.twitter.sdk.android.core.Callback;
|
||||
import com.twitter.sdk.android.core.Result;
|
||||
import com.twitter.sdk.android.core.TwitterAuthConfig;
|
||||
import com.twitter.sdk.android.core.TwitterCore;
|
||||
import com.twitter.sdk.android.core.TwitterException;
|
||||
import com.twitter.sdk.android.core.TwitterSession;
|
||||
import com.twitter.sdk.android.core.identity.TwitterAuthClient;
|
||||
import com.twitter.sdk.android.core.models.User;
|
||||
import com.twitter.sdk.android.tweetcomposer.TweetComposer;
|
||||
import com.ubtrobot.ubtlib.share.ShareBuilder;
|
||||
import com.ubtrobot.ubtlib.share.UbtSocialShareListener;
|
||||
import io.fabric.sdk.android.Fabric;
|
||||
import java.util.HashMap;
|
||||
|
||||
/* loaded from: classes2.dex */
|
||||
public class TwitterUbtSocialImpl implements IUbtSocial {
|
||||
private UbtSocialAuthListener a;
|
||||
private Activity b;
|
||||
private TwitterAuthClient c;
|
||||
private Callback<TwitterSession> d;
|
||||
private String e;
|
||||
|
||||
@Override // com.ubtrobot.ubtlib.social.IUbtSocial
|
||||
public void a(UbtSocialShareListener ubtSocialShareListener) {
|
||||
}
|
||||
|
||||
@Override // com.ubtrobot.ubtlib.social.IUbtSocial
|
||||
public void a(ShareBuilder shareBuilder) {
|
||||
TweetComposer.Builder builder = new TweetComposer.Builder(this.b);
|
||||
builder.a(shareBuilder.b());
|
||||
builder.a(shareBuilder.a());
|
||||
builder.d();
|
||||
}
|
||||
|
||||
@Override // com.ubtrobot.ubtlib.social.IUbtSocial
|
||||
public boolean b() {
|
||||
try {
|
||||
this.b.getPackageManager().getPackageInfo("com.twitter.android", 0);
|
||||
return true;
|
||||
} catch (PackageManager.NameNotFoundException unused) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override // com.ubtrobot.ubtlib.social.IUbtSocial
|
||||
public void a() {
|
||||
try {
|
||||
this.c.a(this.b, this.d);
|
||||
} catch (Exception e) {
|
||||
UbtSocialAuthListener ubtSocialAuthListener = this.a;
|
||||
if (ubtSocialAuthListener != null) {
|
||||
ubtSocialAuthListener.a(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override // com.ubtrobot.ubtlib.social.IUbtSocial
|
||||
public void a(Activity activity) {
|
||||
this.e = SocialTool.a((Context) activity, "app_id_twitter");
|
||||
Fabric.a(activity, new TwitterCore(new TwitterAuthConfig(this.e, SocialTool.a((Context) activity, "app_secret_twitter"))), new TweetComposer());
|
||||
this.b = activity;
|
||||
this.c = new TwitterAuthClient();
|
||||
}
|
||||
|
||||
@Override // com.ubtrobot.ubtlib.social.IUbtSocial
|
||||
public void a(int i, int i2, Intent intent) {
|
||||
if (i2 == 0) {
|
||||
UbtSocialAuthListener ubtSocialAuthListener = this.a;
|
||||
if (ubtSocialAuthListener != null) {
|
||||
ubtSocialAuthListener.onCancel();
|
||||
return;
|
||||
}
|
||||
return;
|
||||
}
|
||||
this.c.a(i, i2, intent);
|
||||
}
|
||||
|
||||
@Override // com.ubtrobot.ubtlib.social.IUbtSocial
|
||||
public void a(UbtSocialAuthListener ubtSocialAuthListener) {
|
||||
this.a = ubtSocialAuthListener;
|
||||
this.d = new Callback<TwitterSession>() { // from class: com.ubtrobot.ubtlib.social.TwitterUbtSocialImpl.1
|
||||
@Override // com.twitter.sdk.android.core.Callback
|
||||
public void a(Result<TwitterSession> result) {
|
||||
final TwitterSession twitterSession = result.a;
|
||||
TwitterCore.z().p().a().verifyCredentials(false, false).enqueue(new Callback<User>() { // from class: com.ubtrobot.ubtlib.social.TwitterUbtSocialImpl.1.1
|
||||
@Override // com.twitter.sdk.android.core.Callback
|
||||
public void a(Result<User> result2) {
|
||||
HashMap hashMap = new HashMap();
|
||||
hashMap.put(AccessToken.ACCESS_TOKEN_KEY, twitterSession.a().token);
|
||||
hashMap.put("ubtsocial_user_id", twitterSession.c() + "");
|
||||
hashMap.put("ubtsocial_app_id", TwitterUbtSocialImpl.this.e);
|
||||
hashMap.put("social_type", UbtSocialType.TWITTER.loginType);
|
||||
User user = result2.a;
|
||||
String str = user.profileImageUrl;
|
||||
hashMap.put("nick_name", user.name);
|
||||
hashMap.put("head_image", str);
|
||||
if (TwitterUbtSocialImpl.this.a != null) {
|
||||
TwitterUbtSocialImpl.this.a.a(hashMap);
|
||||
}
|
||||
}
|
||||
|
||||
@Override // com.twitter.sdk.android.core.Callback
|
||||
public void a(TwitterException twitterException) {
|
||||
if (TwitterUbtSocialImpl.this.a != null) {
|
||||
TwitterUbtSocialImpl.this.a.a(twitterException);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override // com.twitter.sdk.android.core.Callback
|
||||
public void a(TwitterException twitterException) {
|
||||
if (TwitterUbtSocialImpl.this.a != null) {
|
||||
TwitterUbtSocialImpl.this.a.a(twitterException);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
105
sources/com/ubtrobot/ubtlib/social/UbtSocial.java
Normal file
105
sources/com/ubtrobot/ubtlib/social/UbtSocial.java
Normal file
@@ -0,0 +1,105 @@
|
||||
package com.ubtrobot.ubtlib.social;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import com.ubtrobot.ubtlib.share.ShareBuilder;
|
||||
import com.ubtrobot.ubtlib.share.UbtSocialShareListener;
|
||||
import java.text.MessageFormat;
|
||||
|
||||
/* loaded from: classes2.dex */
|
||||
public class UbtSocial implements IUbtSocial {
|
||||
private static IUbtSocial a;
|
||||
private static UbtSocial b;
|
||||
|
||||
/* renamed from: com.ubtrobot.ubtlib.social.UbtSocial$1, reason: invalid class name */
|
||||
static /* synthetic */ class AnonymousClass1 {
|
||||
static final /* synthetic */ int[] a = new int[UbtSocialType.values().length];
|
||||
|
||||
static {
|
||||
try {
|
||||
a[UbtSocialType.QQ.ordinal()] = 1;
|
||||
} catch (NoSuchFieldError unused) {
|
||||
}
|
||||
try {
|
||||
a[UbtSocialType.WECHAT.ordinal()] = 2;
|
||||
} catch (NoSuchFieldError unused2) {
|
||||
}
|
||||
try {
|
||||
a[UbtSocialType.TWITTER.ordinal()] = 3;
|
||||
} catch (NoSuchFieldError unused3) {
|
||||
}
|
||||
try {
|
||||
a[UbtSocialType.FACEBOOK.ordinal()] = 4;
|
||||
} catch (NoSuchFieldError unused4) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private UbtSocial() {
|
||||
}
|
||||
|
||||
public static synchronized UbtSocial a(Activity activity, UbtSocialType ubtSocialType) {
|
||||
IUbtSocial tencentUbtSocialImpl;
|
||||
UbtSocial ubtSocial;
|
||||
synchronized (UbtSocial.class) {
|
||||
if (b == null) {
|
||||
b = new UbtSocial();
|
||||
}
|
||||
int i = AnonymousClass1.a[ubtSocialType.ordinal()];
|
||||
if (i == 1) {
|
||||
tencentUbtSocialImpl = new TencentUbtSocialImpl();
|
||||
tencentUbtSocialImpl.a(activity);
|
||||
} else if (i == 2) {
|
||||
tencentUbtSocialImpl = new WechatUbtSocialImpl();
|
||||
tencentUbtSocialImpl.a(activity);
|
||||
} else if (i == 3) {
|
||||
tencentUbtSocialImpl = new TwitterUbtSocialImpl();
|
||||
tencentUbtSocialImpl.a(activity);
|
||||
} else {
|
||||
if (i != 4) {
|
||||
throw new RuntimeException(MessageFormat.format("social type : {0} not support", ubtSocialType.toString()));
|
||||
}
|
||||
tencentUbtSocialImpl = new FacebookUbtSocialImpl();
|
||||
tencentUbtSocialImpl.a(activity);
|
||||
}
|
||||
a = tencentUbtSocialImpl;
|
||||
ubtSocial = b;
|
||||
}
|
||||
return ubtSocial;
|
||||
}
|
||||
|
||||
@Override // com.ubtrobot.ubtlib.social.IUbtSocial
|
||||
public boolean b() {
|
||||
return a.b();
|
||||
}
|
||||
|
||||
@Override // com.ubtrobot.ubtlib.social.IUbtSocial
|
||||
public void a(ShareBuilder shareBuilder) {
|
||||
a.a(shareBuilder);
|
||||
}
|
||||
|
||||
@Override // com.ubtrobot.ubtlib.social.IUbtSocial
|
||||
public void a(UbtSocialShareListener ubtSocialShareListener) {
|
||||
a.a(ubtSocialShareListener);
|
||||
}
|
||||
|
||||
@Override // com.ubtrobot.ubtlib.social.IUbtSocial
|
||||
public void a() {
|
||||
a.a();
|
||||
}
|
||||
|
||||
@Override // com.ubtrobot.ubtlib.social.IUbtSocial
|
||||
public void a(UbtSocialAuthListener ubtSocialAuthListener) {
|
||||
a.a(ubtSocialAuthListener);
|
||||
}
|
||||
|
||||
@Override // com.ubtrobot.ubtlib.social.IUbtSocial
|
||||
public void a(Activity activity) {
|
||||
a.a(activity);
|
||||
}
|
||||
|
||||
@Override // com.ubtrobot.ubtlib.social.IUbtSocial
|
||||
public void a(int i, int i2, Intent intent) {
|
||||
a.a(i, i2, intent);
|
||||
}
|
||||
}
|
@@ -0,0 +1,12 @@
|
||||
package com.ubtrobot.ubtlib.social;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/* loaded from: classes2.dex */
|
||||
public interface UbtSocialAuthListener {
|
||||
void a(Throwable th);
|
||||
|
||||
void a(Map<String, String> map);
|
||||
|
||||
void onCancel();
|
||||
}
|
24
sources/com/ubtrobot/ubtlib/social/UbtSocialService.java
Normal file
24
sources/com/ubtrobot/ubtlib/social/UbtSocialService.java
Normal file
@@ -0,0 +1,24 @@
|
||||
package com.ubtrobot.ubtlib.social;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.tencent.open.SocialConstants;
|
||||
import com.ubt.jimu.base.entities.Course;
|
||||
import com.ubtrobot.ubtlib.tool.NetRequestBaseService;
|
||||
import java.util.HashMap;
|
||||
import okhttp3.Callback;
|
||||
|
||||
/* loaded from: classes2.dex */
|
||||
public class UbtSocialService extends NetRequestBaseService {
|
||||
public static void a(String str, String str2, String str3, Callback callback) {
|
||||
Preconditions.a(str, "access_token_code == null");
|
||||
Preconditions.a(str2, "appId == null");
|
||||
Preconditions.a(str3, "appSecret == null");
|
||||
Preconditions.a(callback, "callback == null");
|
||||
HashMap hashMap = new HashMap();
|
||||
hashMap.put(SocialConstants.PARAM_APP_ID, str2);
|
||||
hashMap.put("secret", str3);
|
||||
hashMap.put(Course.TYPE_BLOCKLY, str);
|
||||
hashMap.put("grant_type", "authorization_code");
|
||||
NetRequestBaseService.a.newCall(NetRequestBaseService.a("https://api.weixin.qq.com/sns/oauth2/access_token", hashMap)).enqueue(callback);
|
||||
}
|
||||
}
|
16
sources/com/ubtrobot/ubtlib/social/UbtSocialType.java
Normal file
16
sources/com/ubtrobot/ubtlib/social/UbtSocialType.java
Normal file
@@ -0,0 +1,16 @@
|
||||
package com.ubtrobot.ubtlib.social;
|
||||
|
||||
/* loaded from: classes2.dex */
|
||||
public enum UbtSocialType {
|
||||
SINA_WEIBO("sina"),
|
||||
QQ("QQ"),
|
||||
WECHAT("WX"),
|
||||
FACEBOOK("facebook"),
|
||||
TWITTER("twitter");
|
||||
|
||||
public String loginType;
|
||||
|
||||
UbtSocialType(String str) {
|
||||
this.loginType = str;
|
||||
}
|
||||
}
|
123
sources/com/ubtrobot/ubtlib/social/WeChatCallbackActivity.java
Normal file
123
sources/com/ubtrobot/ubtlib/social/WeChatCallbackActivity.java
Normal file
@@ -0,0 +1,123 @@
|
||||
package com.ubtrobot.ubtlib.social;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import com.facebook.AccessToken;
|
||||
import com.tencent.mm.opensdk.modelbase.BaseReq;
|
||||
import com.tencent.mm.opensdk.modelbase.BaseResp;
|
||||
import com.tencent.mm.opensdk.modelmsg.SendAuth;
|
||||
import com.tencent.mm.opensdk.modelmsg.SendMessageToWX;
|
||||
import com.tencent.mm.opensdk.openapi.IWXAPI;
|
||||
import com.tencent.mm.opensdk.openapi.IWXAPIEventHandler;
|
||||
import com.tencent.mm.opensdk.openapi.WXAPIFactory;
|
||||
import com.tencent.open.SocialConstants;
|
||||
import com.ubtrobot.ubtlib.share.UbtSocialShareListener;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import okhttp3.Call;
|
||||
import okhttp3.Callback;
|
||||
import okhttp3.Response;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
/* loaded from: classes2.dex */
|
||||
public class WeChatCallbackActivity extends Activity implements IWXAPIEventHandler {
|
||||
private static final String d = WeChatCallbackActivity.class.getSimpleName();
|
||||
private IWXAPI a;
|
||||
private String b;
|
||||
private String c;
|
||||
|
||||
@Override // android.app.Activity
|
||||
protected void onCreate(Bundle bundle) {
|
||||
super.onCreate(bundle);
|
||||
this.b = SocialTool.a((Context) this, "app_id_wechat");
|
||||
this.c = SocialTool.a((Context) this, "app_secret_wechat");
|
||||
this.a = WXAPIFactory.createWXAPI(this, this.b);
|
||||
this.a.handleIntent(getIntent(), this);
|
||||
}
|
||||
|
||||
@Override // android.app.Activity
|
||||
protected void onNewIntent(Intent intent) {
|
||||
super.onNewIntent(intent);
|
||||
setIntent(intent);
|
||||
this.a.handleIntent(intent, this);
|
||||
}
|
||||
|
||||
@Override // com.tencent.mm.opensdk.openapi.IWXAPIEventHandler
|
||||
public void onReq(BaseReq baseReq) {
|
||||
}
|
||||
|
||||
@Override // com.tencent.mm.opensdk.openapi.IWXAPIEventHandler
|
||||
public void onResp(BaseResp baseResp) {
|
||||
Log.d(d, SocialTool.a(baseResp));
|
||||
if (baseResp instanceof SendAuth.Resp) {
|
||||
a((SendAuth.Resp) baseResp);
|
||||
} else if (baseResp instanceof SendMessageToWX.Resp) {
|
||||
a((SendMessageToWX.Resp) baseResp);
|
||||
}
|
||||
finish();
|
||||
}
|
||||
|
||||
private void a(SendMessageToWX.Resp resp) {
|
||||
Log.d(d, SocialTool.a(resp));
|
||||
UbtSocialShareListener b = SocialTool.b();
|
||||
int i = resp.errCode;
|
||||
if (i == -2) {
|
||||
b.onCancel();
|
||||
} else if (i != 0) {
|
||||
b.a();
|
||||
} else {
|
||||
b.onSuccess();
|
||||
}
|
||||
}
|
||||
|
||||
private void a(final SendAuth.Resp resp) {
|
||||
Log.d(d, SocialTool.a(resp));
|
||||
final UbtSocialAuthListener a = SocialTool.a();
|
||||
int i = resp.errCode;
|
||||
if (i == -2) {
|
||||
if (a != null) {
|
||||
a.onCancel();
|
||||
}
|
||||
} else if (i == 0) {
|
||||
UbtSocialService.a(resp.code, this.b, this.c, new Callback() { // from class: com.ubtrobot.ubtlib.social.WeChatCallbackActivity.1
|
||||
@Override // okhttp3.Callback
|
||||
public void onFailure(Call call, IOException iOException) {
|
||||
UbtSocialAuthListener ubtSocialAuthListener = a;
|
||||
if (ubtSocialAuthListener != null) {
|
||||
ubtSocialAuthListener.a(iOException);
|
||||
}
|
||||
}
|
||||
|
||||
@Override // okhttp3.Callback
|
||||
public void onResponse(Call call, Response response) throws IOException {
|
||||
String string = response.body().string();
|
||||
Log.d(WeChatCallbackActivity.d, string);
|
||||
try {
|
||||
JSONObject jSONObject = new JSONObject(string);
|
||||
if (!jSONObject.has("errcode")) {
|
||||
HashMap hashMap = new HashMap();
|
||||
hashMap.put(AccessToken.ACCESS_TOKEN_KEY, jSONObject.getString(AccessToken.ACCESS_TOKEN_KEY));
|
||||
hashMap.put("ubtsocial_user_id", jSONObject.getString(SocialConstants.PARAM_OPEN_ID));
|
||||
hashMap.put("access_token_code", resp.code);
|
||||
hashMap.put("social_type", UbtSocialType.WECHAT.loginType);
|
||||
hashMap.put("ubtsocial_app_id", WeChatCallbackActivity.this.b);
|
||||
if (a != null) {
|
||||
a.a(hashMap);
|
||||
}
|
||||
} else if (a != null) {
|
||||
a.a(new Exception(string));
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
} else if (a != null) {
|
||||
a.a(new Exception("errcode: " + resp.errCode));
|
||||
}
|
||||
}
|
||||
}
|
82
sources/com/ubtrobot/ubtlib/social/WechatUbtSocialImpl.java
Normal file
82
sources/com/ubtrobot/ubtlib/social/WechatUbtSocialImpl.java
Normal file
@@ -0,0 +1,82 @@
|
||||
package com.ubtrobot.ubtlib.social;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.util.Log;
|
||||
import com.tencent.mm.opensdk.modelmsg.SendAuth;
|
||||
import com.tencent.mm.opensdk.modelmsg.SendMessageToWX;
|
||||
import com.tencent.mm.opensdk.modelmsg.WXMediaMessage;
|
||||
import com.tencent.mm.opensdk.modelmsg.WXWebpageObject;
|
||||
import com.tencent.mm.opensdk.openapi.IWXAPI;
|
||||
import com.tencent.mm.opensdk.openapi.WXAPIFactory;
|
||||
import com.ubtrobot.ubtlib.share.ShareBuilder;
|
||||
import com.ubtrobot.ubtlib.share.UbtSocialShareListener;
|
||||
|
||||
/* loaded from: classes2.dex */
|
||||
public class WechatUbtSocialImpl implements IUbtSocial {
|
||||
private IWXAPI a;
|
||||
|
||||
@Override // com.ubtrobot.ubtlib.social.IUbtSocial
|
||||
public void a() {
|
||||
SendAuth.Req req = new SendAuth.Req();
|
||||
req.scope = "snsapi_userinfo";
|
||||
req.state = "ubt_technology_jimu";
|
||||
this.a.sendReq(req);
|
||||
}
|
||||
|
||||
@Override // com.ubtrobot.ubtlib.social.IUbtSocial
|
||||
public boolean b() {
|
||||
return this.a.isWXAppInstalled();
|
||||
}
|
||||
|
||||
private SendMessageToWX.Req b(ShareBuilder shareBuilder) {
|
||||
WXWebpageObject wXWebpageObject = new WXWebpageObject();
|
||||
wXWebpageObject.webpageUrl = shareBuilder.e();
|
||||
WXMediaMessage wXMediaMessage = new WXMediaMessage(wXWebpageObject);
|
||||
wXMediaMessage.title = shareBuilder.d();
|
||||
wXMediaMessage.description = shareBuilder.b();
|
||||
SendMessageToWX.Req req = new SendMessageToWX.Req();
|
||||
req.message = wXMediaMessage;
|
||||
req.transaction = System.currentTimeMillis() + "";
|
||||
return req;
|
||||
}
|
||||
|
||||
@Override // com.ubtrobot.ubtlib.social.IUbtSocial
|
||||
public void a(Activity activity) {
|
||||
String a = SocialTool.a((Context) activity, "app_id_wechat");
|
||||
this.a = WXAPIFactory.createWXAPI(activity, a);
|
||||
if (!this.a.registerApp(a)) {
|
||||
throw new RuntimeException("register app id to wechat failed");
|
||||
}
|
||||
}
|
||||
|
||||
@Override // com.ubtrobot.ubtlib.social.IUbtSocial
|
||||
public void a(int i, int i2, Intent intent) {
|
||||
Log.e("xxxx", "");
|
||||
}
|
||||
|
||||
@Override // com.ubtrobot.ubtlib.social.IUbtSocial
|
||||
public void a(UbtSocialAuthListener ubtSocialAuthListener) {
|
||||
SocialTool.a(ubtSocialAuthListener);
|
||||
}
|
||||
|
||||
@Override // com.ubtrobot.ubtlib.social.IUbtSocial
|
||||
public void a(ShareBuilder shareBuilder) {
|
||||
int c = shareBuilder.c();
|
||||
SendMessageToWX.Req b = b(shareBuilder);
|
||||
if (c == 274) {
|
||||
b.scene = 0;
|
||||
} else if (c == 275) {
|
||||
b.scene = 1;
|
||||
} else {
|
||||
throw new IllegalArgumentException("share platform error, only support wechat, current platform " + c);
|
||||
}
|
||||
this.a.sendReq(b);
|
||||
}
|
||||
|
||||
@Override // com.ubtrobot.ubtlib.social.IUbtSocial
|
||||
public void a(UbtSocialShareListener ubtSocialShareListener) {
|
||||
SocialTool.a(ubtSocialShareListener);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user