WXEntryActivity.java 1.67 KB
package com.polysoft.nafmii.wxapi;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;

import com.polysoft.nafmii.broadcast.ShareReceiver;
import com.polysoft.nafmii.wechat.ShareResult;
import com.polysoft.nafmii.wechat.WechatApi;
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;

public class WXEntryActivity extends Activity implements IWXAPIEventHandler {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        WechatApi.getInstance(this).handleIntent(getIntent(), this);
    }

    @Override
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        setIntent(intent);
        WechatApi.getInstance(this).handleIntent(intent, this);
    }

    @Override
    public void onReq(BaseReq baseReq) {
    }

    @Override
    public void onResp(BaseResp resp) {
        if (resp instanceof SendAuth.Resp) {

        }

        int code = resp.errCode;
        if (code == BaseResp.ErrCode.ERR_OK) { // 分享成功
            ShareReceiver.sendBroadcast(this, ShareResult.shareSuccess());
        } else if (code == BaseResp.ErrCode.ERR_USER_CANCEL) { // 用户取消
            ShareReceiver.sendBroadcast(this, ShareResult.shareCancel());
        } else { // 分享失败
            String errStr = resp.errStr;
            ShareReceiver.sendBroadcast(this, ShareResult.shareFail(errStr));
        }
        super.finish();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }


}