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)); } } }