app微信支付的集成步骤
Posted 宇悟行
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了app微信支付的集成步骤相关的知识,希望对你有一定的参考价值。
1.引用地址
//微信支付
compile ‘com.tencent.mm.opensdk:wechat-sdk-android-with-mta:+‘
2.注册
private IWXAPI api;
api = WXAPIFactory.createWXAPI(this, appid);
3. 发起请求 (结果是后台返回的)
PayReq req = new PayReq();
req.appId = "wxa9f8f372188a6867";
req.partnerId = "1487600712";
req.packageValue = "Sign=WXPay";
req.prepayId = "wx201710032153051e158cdeb50210343037";
req.nonceStr = "6md852kc4uik1m3bzr4sl3v5lr1ohh4d";
req.timeStamp = "1507038785";
req.sign = "0D684FF4D47E0E265E33FD67B3AE4CA7";
api.sendReq(req);
4.回调结果:
1.要在项目包名下新建wxapi包,
2.WXPayEntryActivity必须是这个类,实现这个接口IWXAPIEventHandler
3. 在清单文件中注册
<activity
android:name=".wxapi.WXPayEntryActivity"
android:exported="true"
android:launchMode="singleTop"/>
//回调的页面
public class WXPayEntryActivity extends Activity implements IWXAPIEventHandler {
private static final String TAG = "MicroMsg.SDKSample.WXPayEntryActivity";
private IWXAPI api;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.pay_result);
api = WXAPIFactory.createWXAPI(this,appid);
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("提示");
builder.setMessage(getString(R.string.pay_result_callback_msg, String.valueOf(resp.errCode)));
builder.show();
}
}
}
以上是关于app微信支付的集成步骤的主要内容,如果未能解决你的问题,请参考以下文章