package com.toppms.khapp;
import com.tencent.mm.sdk.constants.ConstantsAPI;
import com.tencent.mm.sdk.modelbase.BaseReq;
import com.tencent.mm.sdk.modelbase.BaseResp;
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.app.AlertDialog;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
public class WXPayEntryActivity extends Activity implements IWXAPIEventHandler {
private WechatPlugin wechatPlugin;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
wechatPlugin = WechatPlugin.getInstance();
if (wechatPlugin != null)
wechatPlugin.handleIntent(getIntent(), this);
}
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
setIntent(intent);
if (wechatPlugin == null)
wechatPlugin = WechatPlugin.getInstance();
if (wechatPlugin != null)
wechatPlugin.handleIntent(getIntent(), this);
}
@Override
public void onReq(BaseReq req) {
}
@Override
public void onResp(BaseResp resp) {
if (resp.getType() == ConstantsAPI.COMMAND_PAY_BY_WX) {
Intent intent = new Intent();
intent.setAction(OnlinePayPlugin.ACTION_ONLINE_PAY_RESULT_NOTIFIER);
intent.putExtra("payType", "WECHAT_PAY");
switch (resp.errCode) {
case 0: //支付成功
intent.putExtra("message", "微信支付成功");
intent.putExtra("state", 1);
break;
case -1: //支付错误
intent.putExtra("message", "微信支付失败, 错误:" + resp.errStr);
intent.putExtra("state", -1);
break;
case -2: //用户取消
intent.putExtra("message", "您已取消微信支付");
intent.putExtra("state", 0);
break;
}
LocalBroadcastManager.getInstance(this).sendBroadcast(intent);
}
finish();
}
}