WXPayEntryActivity.java
2.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package com.cnlive.goldenline.wxapi;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import com.cnlive.goldenline.Configs;
import com.cnlive.goldenline.R;
import com.cnlive.goldenline.pay.model.EventPayment;
import com.cnlive.goldenline.pay.SignUtil;
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.modelpay.PayResp;
import com.tencent.mm.sdk.openapi.IWXAPI;
import com.tencent.mm.sdk.openapi.IWXAPIEventHandler;
import com.tencent.mm.sdk.openapi.WXAPIFactory;
import org.greenrobot.eventbus.EventBus;
import cn.cmvideo.sdk.common.util.ToastUtil;
import static com.cnlive.goldenline.util.LogUtils.LOGD;
public class WXPayEntryActivity extends Activity implements IWXAPIEventHandler {
private static final String TAG = WXPayEntryActivity.class.getSimpleName();
private IWXAPI api;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.pay_result);
api = WXAPIFactory.createWXAPI(this, Configs.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) {
PayResp payResp = (PayResp) resp;
LOGD("onPayFinish, errCode = " + resp.errCode+"订单号:"+payResp.extData);
if (resp.getType() == ConstantsAPI.COMMAND_PAY_BY_WX) {
if (resp.errCode == BaseResp.ErrCode.ERR_OK) {
ToastUtil.show(this, "支付成功");
EventBus.getDefault().post(new EventPayment(SignUtil.PAY_TYPE_WEIXIN, SignUtil.PAY_RESULT_STATUS_SUCCESS));
} else {
if (resp.errCode == BaseResp.ErrCode.ERR_COMM) {
ToastUtil.show(this, "支付失败" + resp.toString());
} else if (resp.errCode == BaseResp.ErrCode.ERR_USER_CANCEL) {
ToastUtil.show(this, "取消支付");
} else if (resp.errCode == BaseResp.ErrCode.ERR_SENT_FAILED) {
ToastUtil.show(this, "发送失败");
}
EventBus.getDefault().post(new EventPayment(SignUtil.PAY_TYPE_WEIXIN, SignUtil.PAY_RESULT_STATUS_FAIL));
}
}
this.finish();
}
}