package com.miyou.xylive.wxapi; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import com.kaopu.xylive.bean.respone.WXTokenInfo; import com.kaopu.xylive.bean.respone.WXUserInfo; import com.kaopu.xylive.tools.http.HttpUtil; import com.kaopu.xylive.tools.login.LoginMagaer; import com.kaopu.xylive.tools.third_share.WXManager; import com.kaopu.xylive.ui.widget.WaitDialog; import com.tencent.mm.opensdk.constants.ConstantsAPI; 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.openapi.IWXAPIEventHandler; import rx.Subscriber; public class WXEntryActivity extends Activity implements IWXAPIEventHandler { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); WXManager.getInstance().getWxapi().handleIntent(getIntent(), this); } @Override public void onReq(BaseReq baseReq) { //注册API WXManager.getInstance().getWxapi().handleIntent(getIntent(), this); } @Override protected void onNewIntent(Intent intent) { super.onNewIntent(intent); WXManager.getInstance().getWxapi().handleIntent(intent, this); } @Override public void onResp(BaseResp baseResp) { WaitDialog.showDialog(this); if (baseResp instanceof SendAuth.Resp) { SendAuth.Resp newResp = (SendAuth.Resp) baseResp; switch (newResp.errCode) { case BaseResp.ErrCode.ERR_OK: if (ConstantsAPI.COMMAND_SENDMESSAGE_TO_WX == newResp.getType()) { // Toast.makeText(context, "分享成功", Toast.LENGTH_LONG).show(); break; } //获取微信传回的code String code = newResp.code; HttpUtil.loadWXToken(new WXSubscriber(), "wx6fb15236e5b48598", "520508150ab20dc87625fef69e90611e", code, "authorization_code"); break; } } } private class WXSubscriber extends Subscriber<WXTokenInfo> { @Override public void onCompleted() { } @Override public void onError(Throwable e) { e.printStackTrace(); } @Override public void onNext(WXTokenInfo o) { HttpUtil.loadWXUserInfo(new WXUserInfoSubscriber(), o.access_token, o.openid); } } private class WXUserInfoSubscriber extends Subscriber<WXUserInfo> { @Override public void onCompleted() { } @Override public void onError(Throwable e) { e.printStackTrace(); } @Override public void onNext(WXUserInfo o) { LoginMagaer.getInstance().loginOnThird(o.openid, o.unionid, o.nickname, o.sex, o.headimgurl, "", 2); WaitDialog.showDialog(WXEntryActivity.this); finish(); } } }
微信第三方登录
最新推荐文章于 2021-03-25 13:51:03 发布