官网地址
微信支付-小白无头脑接入
下面几点需要注意一下:
1.应用签名,AS默认使用签名文件与最后的可能有冲突,控件调不出来。
2.回调 WXPayEntryActivity 包名 :在微信注册的时候上传的包名.wxapi
下面代码也必须
api = WXAPIFactory.createWXAPI(this, APP_ID, false);
api.handleIntent(getIntent(), this);
onResp 处理
public void onResp(BaseResp baseResp) {
if (baseResp.getType() == ConstantsAPI.COMMAND_PAY_BY_WX) {
switch (baseResp.errCode) {
case 0:
Toast.makeText(getBaseContext(), "支付成功", Toast.LENGTH_SHORT).show();
// 处理之后的逻辑 必要时可以 使用Broadcast发送信息
break;
case -1:
case -2:
Toast.makeText(getBaseContext(), "支付失败,请重试!", Toast.LENGTH_SHORT).show();
break;
}
}
// 关闭页面
finish();
}
下边放一个完整 的
public class WXPayEntryActivity extends ATBaseActivity implements IWXAPIEventHandler {
private IWXAPI f6945c;
protected void onCreate(Bundle bundle) {
super.onCreate(bundle);
setContentView((int) C0784R.layout.activity_wei_xin_pay_res_layout);
this.f6945c = WXAPIFactory.createWXAPI(this, "");
this.f6945c.handleIntent(getIntent(), this);
}
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
setIntent(intent);
this.f6945c.handleIntent(intent, this);
}
public void onReq(BaseReq baseReq) {
}
public void onResp(BaseResp baseResp) {
if (baseResp.getType() == 5) {
if (baseResp.errCode == 0) {
Intent intent = new Intent();
intent.putExtra("at_pay_flag", String.valueOf(baseResp.errCode));
intent.putExtra("at_pay_type", ATPaymentType.WECHAT.m7066a());
intent.setAction("android.wechat.pay.RECIVER");
sendBroadcast(intent);
} else {
af.m8459a((Context) this, getString(C0784R.string.errcode_unfinished));
}
}
finish();
}
}