写法一:
import com.tencent.mm.sdk.modelbase.BaseReq;import com.tencent.mm.sdk.modelbase.BaseResp;import com.tencent.mm.sdk.modelmsg.SendAuth;import com.tencent.mm.sdk.openapi.IWXAPI;import com.tencent.mm.sdk.openapi.IWXAPIEventHandler;import com.tencent.mm.sdk.openapi.WXAPIFactory;import android.app.Activity;import android.content.Intent;import android.os.Bundle;import android.util.Log;public class WXEntryActivity extends Activity implements IWXAPIEventHandler { private IWXAPI api; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Log.e("WXEntryActivity", "onCreate"); api = WXAPIFactory.createWXAPI(this, APP_ID_WECHAT, false); api.registerApp(APP_ID_WECHAT); handleIntent(getIntent()); } @Override protected void onNewIntent(Intent intent) { super.onNewIntent(intent); Log.e("WXEntryActivity", "onNewIntent"); handleIntent(intent); } private void handleIntent(Intent intent) { setIntent(intent); api.handleIntent(intent, this); } @Override public void onReq(BaseReq arg0) { // TODO Auto-generated method stub Log.e("WXEntryActivity", "onReq"); } @Override public void onResp(BaseResp resp) { Log.e("WXEntryActivity", "onResp"); // TODO Auto-generated method stub if (resp.errCode == BaseResp.ErrCode.ERR_OK) { // 用户同意 Log.e("WXEntryActivity", "onResp" + resp.errCode); Log.e("WXEntryActivity", "onResp" + resp.errStr); Log.e("WXEntryActivity", "onResp" + resp.openId); } }}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
写法二:
import com.tencent.mm.sdk.modelbase.BaseResp;import com.tencent.mm.sdk.modelmsg.SendAuth;import android.app.Activity;import android.content.Intent;import android.os.Bundle;import android.util.Log;public class WXEntryActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Log.e("WXEntryActivity", "onCreate"); handleIntent(getIntent()); } @Override protected void onNewIntent(Intent intent) { super.onNewIntent(intent); Log.e("WXEntryActivity", "onNewIntent"); handleIntent(intent); } private void handleIntent(Intent intent) { SendAuth.Resp resp = new SendAuth.Resp(intent.getExtras()); if (resp.errCode == BaseResp.ErrCode.ERR_OK) { Log.e("WXEntryActivity", "handleIntent" + resp.errCode); Log.e("WXEntryActivity", "handleIntent" + resp.errStr); Log.e("WXEntryActivity", "handleIntent" + resp.openId); Log.e("WXEntryActivity", "handleIntent" + resp.code); } }}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34