package com.gh.gamecenter.wxapi;

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

import com.gh.common.util.Utils;
import com.tencent.mm.sdk.openapi.BaseReq;
import com.tencent.mm.sdk.openapi.BaseResp;
import com.tencent.mm.sdk.openapi.IWXAPI;
import com.tencent.mm.sdk.openapi.IWXAPIEventHandler;
import com.tencent.mm.sdk.openapi.WXAPIFactory;

/**
 * 微信客户端回调activity示例
 * 注意：WXEntryActivity类只能在wxapi包下
 */
public class WXEntryActivity extends Activity implements IWXAPIEventHandler {

    private IWXAPI mWxApi;

    private String shareResult;


    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mWxApi = WXAPIFactory.createWXAPI(this, "wx3ffd0785fad18396", false);
        mWxApi.handleIntent(getIntent(), this);

    }

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

    @Override
    public void onReq(BaseReq baseReq) {
        Utils.toast(this, "微信主动请求我们");
    }

    @Override
    public void onResp(BaseResp baseResp) {
        switch (baseResp.errCode){
            case BaseResp.ErrCode.ERR_OK:
                shareResult = "分享成功";
                break;
            case BaseResp.ErrCode.ERR_USER_CANCEL:
                shareResult = "分享已取消";
                break;
            case BaseResp.ErrCode.ERR_AUTH_DENIED:
                shareResult = "分享被拒绝";
                break;
            default:
                shareResult = "分享错误";
                break;
        }
        Utils.toast(this, shareResult);
        this.finish();
        overridePendingTransition(0, 0);//禁止退出Activity 动画
    }
}