WXEntryActivity.java 2.29 KB
package com.tencent.youai.shushan.wxapi;






import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;

import com.tencent.mm.sdk.modelbase.BaseReq;
import com.tencent.mm.sdk.modelbase.BaseResp;
import com.tencent.mm.sdk.modelmsg.SendAuth.Resp;
import com.tencent.mm.sdk.openapi.IWXAPI;
import com.tencent.mm.sdk.openapi.IWXAPIEventHandler;
import com.tencent.mm.sdk.openapi.WXAPIFactory;
import com.youai.sdk.YouaiSDK;

public class WXEntryActivity extends Activity implements IWXAPIEventHandler{
	
	private static final String TAG = "MicroMsg.SDKSample.WXEntryActivity";
	
    private IWXAPI api;
	
    private Handler checkLoginHandler = new Handler(){
    	public void handleMessage(android.os.Message msg) {
    		YouaiSDK.open_url((String) msg.obj);
    	};
    };
    
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    	api = WXAPIFactory.createWXAPI(this, YouaiSDK.weixinAppId);
        api.handleIntent(getIntent(), this);
    }

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


	@Override
	public void onReq(BaseReq arg0) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void onResp(BaseResp resp) {
		Log.d(TAG, "0成功,-1错误,-2用户取消 onLoginFinish, errCode = " + resp.errCode);
		if (YouaiSDK.lastCallBack != null) {
			if(resp.errCode == 0){
				if(resp instanceof Resp) {
	                Resp var7 = (Resp)resp;
	                Log.d("YSDK_USER_WX", "code: " + var7.code);
	                Message msg = Message.obtain();
	                msg.obj = var7.code;
					checkLoginHandler.sendMessageDelayed(msg , 3000);
	                //YouaiSDK.open_url(var7.code);
	            }else{
	            	Intent i = new Intent();
					i.putExtra("msg", "充值成功");
					YouaiSDK.lastCallBack.onEventDispatch(YouaiSDK.PAY_ACTION_CODE, i);
	            }
//				YouaiSDK.lastCallBack.onEventDispatch(YouaiSDK.PAY_ACTION_CODE, i);
			}else if(resp.errCode == -2){
				Intent i = new Intent();
				i.putExtra("msg", "用户取消");
				YouaiSDK.lastCallBack.onEventDispatch(YouaiSDK.PAY_ACTION_CODE, i);
			}
		}
		finish();
	}
}