Android 集成微信支付,Android最新实习面试经验总结

这篇博客介绍了如何在Android应用中集成微信支付,包括获取预支付订单、生成支付请求和发送支付请求的过程。同时,博主分享了Android实习面试的经验,提到了在大厂如华为、OPPO工作的心得,并提供了一份全面的Android开发学习资料。
摘要由CSDN通过智能技术生成

public void onClick(DialogInterface dialoginterface, int i) {

//

((Activity)context).finish();

}

}).show();

return;

}

api = WXAPIFactory.createWXAPI(context, null);

req = new PayReq();

//生成prepay_id

GetPrepayIdTask getPrepayId = new GetPrepayIdTask();

getPrepayId.execute();

}

/**

  • 用于获取

  • @author 95

*/

private class GetPrepayIdTask extends AsyncTask<void, string=“”>> {

private ProgressDialog dialog;

@Override

protected void onPreExecute() {

dialog = ProgressDialog.show(context, “提示”, “正在获取预支付订单…”);

}

@Override

protected void onPostExecute(Map<string,string> result) {

if (dialog != null) {

dialog.dismiss();

}

resultunifiedorder=result;

genPayReq();

}

@Override

protected void onCancelled() {

super.onCancelled();

}

@Override

protected Map<string,string> doInBackground(Void… params) {

String url = String.format(“https://api.mch.weixin.qq.com/pay/unifiedorder”);

String entity = genProductArgs();

Log.e(“orion”,entity);

byte[] buf = httpPost(url, entity);

String content = new String(buf);

Log.e(“orion”, content);

Map<string,string> xml=decodeXml(content);

return xml;

}

}

private void genPayReq() {

req.appId = ParameterConfig.WX_APP_ID;

req.partnerId = ParameterConfig.WX_MCH_ID;

req.prepayId = resultunifiedorder.get(“prepay_id”);

req.packageValue = “prepay_id=”+resultunifiedorder.get(“prepay_id”);

req.nonceStr = genNonceStr();

req.timeStamp = String.valueOf(genTimeStamp());

List signParams = new LinkedList();

signParams.add(new BasicNameValuePair(“appid”, req.appId));

signParams.add(new BasicNameValuePair(“noncestr”, req.nonceStr));

signParams.add(new BasicNameValuePair(“package”, req.packageValue));

signParams.add(new BasicNameValuePair(“partnerid”, req.partnerId));

signParams.add(new BasicNameValuePair(“prepayid”, req.prepayId));

signParams.add(new BasicNameValuePair(“timestamp”, req.timeStamp));

req.sign = genAppSign(signParams);

Log.e(“orion”, signParams.toString());

sendPayReq();

}

private void sendPayReq() {

api.registerApp(ParameterConfig.WX_APP_ID);

api.sendReq(req);

}

private String genProductArgs() {

StringBuffer xml = new StringBuffer();

try {

String nonceStr = genNonceStr();

xml.append(“”);

List packageParams = ne

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值