关闭

APP微信支付集成

384人阅读 评论(0) 收藏 举报
分类:
--------------------------------------------------------------------------------------------------------------
1、获取PrepayId


@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 = Util.httpPost(url, entity);


String content = new String(buf);
Log.e("orion", content);
Map<String,String> xml=decodeXml(content);


return xml;
}

2、生成支付参数
private void genPayReq() {


req.appId = Constants.APP_ID;
req.partnerId = Constants.MCH_ID;
req.prepayId = resultunifiedorder.get("prepay_id");
req.packageValue = "Sign=WXPay";
req.nonceStr = genNonceStr();
req.timeStamp = String.valueOf(genTimeStamp());




List<NameValuePair> signParams = new LinkedList<NameValuePair>();
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);


sb.append("sign\n"+req.sign+"\n\n");


show.setText(sb.toString());


Log.e("orion", signParams.toString());


}

3、发送支付请求
private void sendPayReq() {



msgApi.registerApp(Constants.APP_ID);
msgApi.sendReq(req);
}


4、检查回调结果
在net.sourceforge.simcpux.wxapi包路径中实现WXPayEntryActivity类(包名或类名不一致会造成无法回调)
public void onResp(BaseResp resp) {
if (resp.getType() == ConstantsAPI.COMMAND_PAY_BY_WX) {
  Log.d(TAG, "onPayFinish, errCode = " + resp.errCode);
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle(R.string.app_tip);
}
}


--------------------------------------------------------------------------------------------------------------
0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:54102次
    • 积分:1487
    • 等级:
    • 排名:千里之外
    • 原创:94篇
    • 转载:46篇
    • 译文:0篇
    • 评论:0条
    文章分类