微信支付(商户支付模式一)扫码支付接口回调详解
来源:互联网 发布:linux解压tgz文件命令 编辑:程序博客网 时间:2024/04/29 11:17
微信支付(商户支付模式一)扫码支付接口回调详解
- 获取用户扫描二维码后,微信返回的信息
InputStream inStream;try {inStream = request.getInputStream();ByteArrayOutputStream outSteam = new ByteArrayOutputStream();byte[] buffer = new byte[1024];int len = 0;while ((len = inStream.read(buffer)) != -1) {outSteam.write(buffer, 0, len);}outSteam.close();inStream.close();String result = new String(outSteam.toByteArray(), "utf-8");//System.out.println(result);/*String xmla = "<xml><appid><![CDATA[wxcb1fe0d]]></appid>"+ "<openid><![CDATA[oBhusSzmARE1xYP9Y]]></openid>"+ "<mch_id><![CDATA[108942]]></mch_id>" + "<is_subscribe><![CDATA[Y]]></is_subscribe>"+ "<nonce_str><![CDATA[jU3nuUAOTTAo]]></nonce_str>"+ "<product_id><![CDATA[ 116027]]></product_id>"+ "<sign><![CDATA[6FFDCCF6AB74DF1220AEEEF4]]></sign>" + "</xml>";*/
- 获取返回的信息内容中各个参数的值
Map<String, String> map =ParseXml.callXMLToMap(result);String appid = map.get("appid");String openid = map.get("openid");String mch_id = map.get("mch_id");String is_subscribe = map.get("is_subscribe");String nonce_str = map.get("nonce_str");String product_id = map.get("product_id");String sign = map.get("sign");
- 封装获取到的信息生成签名并生成参数传送给微信后台获取预支付订单
Map<String, String> packageParams = new HashMap<String, String>();packageParams.put("appid", appid);packageParams.put("openid", openid);packageParams.put("mch_id", mch_id);packageParams.put("is_subscribe", is_subscribe);packageParams.put("nonce_str", nonce_str);packageParams.put("product_id", product_id);String paternerKey = "KtPNdgMLgpreh0wUbtMeXrXKtZFPLv3i";String packageSign = CreateSign.getSign(packageParams, paternerKey);//System.out.println("签名返回 :" + packageSign);PayUrlBackController.product_id=product_id;int price = 1;//((int) (Float.valueOf(10) * 100));BillNo billNo=billNoService.select(product_id);if(billNo != null){if(billNo.getAmountrmb() != null && billNo.getAmountrmb().length() > 0){DecimalFormat df = new DecimalFormat("0");String a=billNo.getAmountrmb();float b=Float.valueOf(a);//System.out.println(df.format(b*100));price=Integer.valueOf(df.format(b*100));}else{price = 1;}}// 统一下单文档地址:https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_1//System.out.println("支付的钱为:"+billNo.getAmountrmb());Map<String, String> params = new HashMap<String, String>();params.put("appid", appid);params.put("mch_id", mch_id);params.put("body", "NO."+product_id);String out_trade_no = product_id;//Long.toString(System.currentTimeMillis());params.put("out_trade_no", out_trade_no);params.put("total_fee", price+"");//params.put("total_fee", "1");params.put("attach", out_trade_no);params.put("spbill_create_ip","8.8.8.8");params.put("trade_type", "NATIVE");params.put("nonce_str", System.currentTimeMillis() / 1000 + "");params.put("notify_url", "http://192.168.1.8:8080/WeChat/pay/back");params.put("openid", openid);String paysign = CreateSign.getSign(params, paternerKey);params.put("sign", paysign);byte[] byteXml=ParseXml.callMapToXML(params);String pushXml=new String(byteXml,"UTF-8");//System.out.println("返回的xml数据:"+pushXml);String xmlResult=HttpRequest.sendPost("https://api.mch.weixin.qq.com/pay/unifiedorder", pushXml);//System.out.println("prepay_xml:" + xmlResult);
- 如果获取预支付订单成功prepay_id,然后把成功的信息返回给微信服务器
Map<String, String> payResult = ParseXml.callXMLToMap(xmlResult); String return_code = payResult.get("return_code"); String result_code = payResult.get("result_code"); if (StrKit.notBlank(return_code) && StrKit.notBlank(result_code) && return_code.equalsIgnoreCase("SUCCESS")&&result_code.equalsIgnoreCase("SUCCESS")) { // 以下字段在return_code 和result_code都为SUCCESS的时候有返回 String prepay_id = payResult.get("prepay_id"); Map<String, String> prepayParams = new HashMap<String, String>(); prepayParams.put("return_code", "SUCCESS"); prepayParams.put("appid", appid); prepayParams.put("mch_id", mch_id); prepayParams.put("nonce_str", System.currentTimeMillis() + ""); prepayParams.put("prepay_id", prepay_id); String prepaySign = null; if (sign.equals(packageSign)) { prepayParams.put("result_code", "SUCCESS"); }else { prepayParams.put("result_code", "FAIL"); prepayParams.put("err_code_des", "订单失效"); //result_code为FAIL时,添加该键值对,value值是微信告诉客户的信息 } prepaySign =CreateSign.getSign(prepayParams, paternerKey); prepayParams.put("sign", prepaySign); byte[] byteXmls=ParseXml.callMapToXML(prepayParams); String xml=new String(byteXmls); //System.out.println("最终xml:"+xml); //renderText(xml);
源码地址:http://download.csdn.net/detail/qq_29428121/9869975
InputStream inStream;try {inStream = request.getInputStream();ByteArrayOutputStream outSteam = new ByteArrayOutputStream();byte[] buffer = new byte[1024];int len = 0;while ((len = inStream.read(buffer)) != -1) {outSteam.write(buffer, 0, len);}outSteam.close();inStream.close();String result = new String(outSteam.toByteArray(), "utf-8");//System.out.println(result);/*String xmla = "<xml><appid><![CDATA[wxcb1fe0d]]></appid>"+ "<openid><![CDATA[oBhusSzmARE1xYP9Y]]></openid>"+ "<mch_id><![CDATA[108942]]></mch_id>" + "<is_subscribe><![CDATA[Y]]></is_subscribe>"+ "<nonce_str><![CDATA[jU3nuUAOTTAo]]></nonce_str>"+ "<product_id><![CDATA[ 116027]]></product_id>"+ "<sign><![CDATA[6FFDCCF6AB74DF1220AEEEF4]]></sign>" + "</xml>";*/
- 获取返回的信息内容中各个参数的值
Map<String, String> map =ParseXml.callXMLToMap(result);String appid = map.get("appid");String openid = map.get("openid");String mch_id = map.get("mch_id");String is_subscribe = map.get("is_subscribe");String nonce_str = map.get("nonce_str");String product_id = map.get("product_id");String sign = map.get("sign");
- 封装获取到的信息生成签名并生成参数传送给微信后台获取预支付订单
Map<String, String> packageParams = new HashMap<String, String>();packageParams.put("appid", appid);packageParams.put("openid", openid);packageParams.put("mch_id", mch_id);packageParams.put("is_subscribe", is_subscribe);packageParams.put("nonce_str", nonce_str);packageParams.put("product_id", product_id);String paternerKey = "KtPNdgMLgpreh0wUbtMeXrXKtZFPLv3i";String packageSign = CreateSign.getSign(packageParams, paternerKey);//System.out.println("签名返回 :" + packageSign);PayUrlBackController.product_id=product_id;int price = 1;//((int) (Float.valueOf(10) * 100));BillNo billNo=billNoService.select(product_id);if(billNo != null){if(billNo.getAmountrmb() != null && billNo.getAmountrmb().length() > 0){DecimalFormat df = new DecimalFormat("0");String a=billNo.getAmountrmb();float b=Float.valueOf(a);//System.out.println(df.format(b*100));price=Integer.valueOf(df.format(b*100));}else{price = 1;}}// 统一下单文档地址:https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_1//System.out.println("支付的钱为:"+billNo.getAmountrmb());Map<String, String> params = new HashMap<String, String>();params.put("appid", appid);params.put("mch_id", mch_id);params.put("body", "NO."+product_id);String out_trade_no = product_id;//Long.toString(System.currentTimeMillis());params.put("out_trade_no", out_trade_no);params.put("total_fee", price+"");//params.put("total_fee", "1");params.put("attach", out_trade_no);params.put("spbill_create_ip","8.8.8.8");params.put("trade_type", "NATIVE");params.put("nonce_str", System.currentTimeMillis() / 1000 + "");params.put("notify_url", "http://192.168.1.8:8080/WeChat/pay/back");params.put("openid", openid);String paysign = CreateSign.getSign(params, paternerKey);params.put("sign", paysign);byte[] byteXml=ParseXml.callMapToXML(params);String pushXml=new String(byteXml,"UTF-8");//System.out.println("返回的xml数据:"+pushXml);String xmlResult=HttpRequest.sendPost("https://api.mch.weixin.qq.com/pay/unifiedorder", pushXml);//System.out.println("prepay_xml:" + xmlResult);
- 如果获取预支付订单成功prepay_id,然后把成功的信息返回给微信服务器
Map<String, String> payResult = ParseXml.callXMLToMap(xmlResult); String return_code = payResult.get("return_code"); String result_code = payResult.get("result_code"); if (StrKit.notBlank(return_code) && StrKit.notBlank(result_code) && return_code.equalsIgnoreCase("SUCCESS")&&result_code.equalsIgnoreCase("SUCCESS")) { // 以下字段在return_code 和result_code都为SUCCESS的时候有返回 String prepay_id = payResult.get("prepay_id"); Map<String, String> prepayParams = new HashMap<String, String>(); prepayParams.put("return_code", "SUCCESS"); prepayParams.put("appid", appid); prepayParams.put("mch_id", mch_id); prepayParams.put("nonce_str", System.currentTimeMillis() + ""); prepayParams.put("prepay_id", prepay_id); String prepaySign = null; if (sign.equals(packageSign)) { prepayParams.put("result_code", "SUCCESS"); }else { prepayParams.put("result_code", "FAIL"); prepayParams.put("err_code_des", "订单失效"); //result_code为FAIL时,添加该键值对,value值是微信告诉客户的信息 } prepaySign =CreateSign.getSign(prepayParams, paternerKey); prepayParams.put("sign", prepaySign); byte[] byteXmls=ParseXml.callMapToXML(prepayParams); String xml=new String(byteXmls); //System.out.println("最终xml:"+xml); //renderText(xml);
源码地址:http://download.csdn.net/detail/qq_29428121/9869975
阅读全文
0 0
- 微信支付(商户支付模式一)扫码支付接口回调详解
- 微信商户开发文档之扫码支付
- 微信支付——扫码支付模式二
- 微信支付--扫码支付模式二实现
- 微信支付-扫码支付备忘
- 微信支付扫码支付
- ThinkPHP整合微信支付之Native 扫码支付 模式一
- ThinkPHP整合微信支付之Native 扫码支付 模式一
- Java微信支付开发之扫码支付模式一
- ThinkPHP之微信支付(扫码支付)
- 第三方支付之微信支付(扫码支付)
- 微信支付之-扫码支付-模式2(模式1)
- 支付宝支付-扫码支付详解
- 微信支付商户-APP支付接入
- 微信支付-商户后台(1)
- 微信支付-商户后台(2)
- 微信支付-商户后台(3)
- 微信支付-商户后台(4)
- 从零开始搭建 ResNet 之 残差网络(持续更新)
- 向梦想出发
- NDK各个版本链接
- S-MAC协议
- 获取手机IMSI,区分移动联通 电信,4G问题
- 微信支付(商户支付模式一)扫码支付接口回调详解
- 4.关于laravel框架中Blade模板引擎
- 算法竞赛入门经典Chap5笔记
- T-MAC协议
- MySql需要注意的知识点
- Centos7.2相关命令
- mysql中count(*)、count(列)、count(1)分析
- Elicpse使用技巧-打开选中文件文件夹或者包的当前目录
- UICollectionView的单选