|
|
@@ -0,0 +1,58 @@
|
|
|
+package com.sheep.jiuyan.samllsheep.wxapi;
|
|
|
+
|
|
|
+import android.content.Intent;
|
|
|
+import android.os.Bundle;
|
|
|
+import android.util.Log;
|
|
|
+
|
|
|
+import com.sheep.gamegroup.event.WXLoginAuthEvent;
|
|
|
+import com.sheep.jiuyan.samllsheep.Config;
|
|
|
+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.IWXAPI;
|
|
|
+import com.tencent.mm.opensdk.openapi.WXAPIFactory;
|
|
|
+import com.umeng.socialize.weixin.view.WXCallbackActivity;
|
|
|
+
|
|
|
+import org.greenrobot.eventbus.EventBus;
|
|
|
+
|
|
|
+public class WXEntryActivity extends WXCallbackActivity {//implements IWXAPIEventHandler
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onCreate(Bundle bundle) {
|
|
|
+ super.onCreate(bundle);
|
|
|
+ IWXAPI wxapi = WXAPIFactory.createWXAPI(this, Config.WX_AUTH_APP_ID, true);
|
|
|
+ wxapi.registerApp(Config.WX_AUTH_APP_ID);
|
|
|
+ wxapi.handleIntent(getIntent(), this);
|
|
|
+ finish();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onNewIntent(Intent newIntent) {
|
|
|
+ IWXAPI wxapi = WXAPIFactory.createWXAPI(this, Config.WX_AUTH_APP_ID, true);
|
|
|
+ wxapi.registerApp(Config.WX_AUTH_APP_ID);
|
|
|
+ wxapi.handleIntent(getIntent(), this);
|
|
|
+ finish();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onReq(BaseReq baseReq) {
|
|
|
+ if(!(baseReq instanceof SendAuth.Req)){
|
|
|
+ super.onReq(baseReq);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onResp(BaseResp resp) {
|
|
|
+ if (resp instanceof SendAuth.Resp) {
|
|
|
+ if (resp.errCode == BaseResp.ErrCode.ERR_OK) {
|
|
|
+ String code = ((SendAuth.Resp) resp).code;
|
|
|
+ EventBus.getDefault().post(new WXLoginAuthEvent(code));
|
|
|
+ } else{
|
|
|
+ EventBus.getDefault().post(new WXLoginAuthEvent(null));
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ super.onResp(resp);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+}
|