package com.jiandanhuiwu.wxapi;
import com.jiandanhuiwu.Constants;
import com.jiandanhuiwu.R;
import com.tencent.mm.opensdk.constants.ConstantsAPI;
import com.tencent.mm.opensdk.modelbase.BaseReq;
import com.tencent.mm.opensdk.modelbase.BaseResp;
import com.tencent.mm.opensdk.openapi.IWXAPI;
import com.tencent.mm.opensdk.openapi.IWXAPIEventHandler;
import com.tencent.mm.opensdk.openapi.WXAPIFactory;  
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;  
import static com.jiandanhuiwu.R.string.pay_result_callback_msg;
public class WXPayEntryActivity extends Activity implements IWXAPIEventHandler{
private IWXAPI api;  
@Override  
public void onCreate(Bundle savedInstanceState) {  
    super.onCreate(savedInstanceState);  
    setContentView(R.layout.pay_result);  
    api = WXAPIFactory.createWXAPI(this, Constants.APP_ID);  
    api.handleIntent(getIntent(), this);  
}  
@Override  
protected void onNewIntent(Intent intent) {  
    super.onNewIntent(intent);  
    setIntent(intent);  
    api.handleIntent(intent, this);  
}  
@Override  
public void onReq(BaseReq req) {  
}  
@Override  
public void onResp(BaseResp resp) {  //      if (resp.getType() == ConstantsAPI.COMMAND_PAY_BY_WX) {
//          AlertDialog.Builder builder = new AlertDialog.Builder(this);
//          builder.setTitle(R.string.app_tip);
//          builder.setMessage(getString(pay_result_callback_msg, new Object[]{String.valueOf(resp.errCode)}));
//          builder.show();
//      }  
    if (resp.getType() == ConstantsAPI.COMMAND_PAY_BY_WX) {  
        int errCode = resp.errCode;  
        if (errCode == -1) {/*支付失败*/  
            Toast.makeText(this, "支付失败", Toast.LENGTH_SHORT).show();  
        } else if (errCode == 0) {/*支付成功*/  
            Toast.makeText(this, "支付成功", Toast.LENGTH_SHORT).show();  
        } else if (errCode == -2) {/*取消支付*/  
            Toast.makeText(this, "取消支付", Toast.LENGTH_SHORT).show();  
        }  
        overridePendingTransition(0,0);  
        finish();  
    }  
}  }
 
             
             
             
			 
                                        
                                     
            
0 个回复