微信支付(java版本)

您所在的位置:网站首页 java微信支付接口开发流程博客园 微信支付(java版本)

微信支付(java版本)

2024-07-02 02:23| 来源: 网络整理| 查看: 265

最近工作接触到微信支付,刚开始解决微信支付很神秘,接触之后发现并没有那么神秘,就是有很多坑,在开发的时候需要注意,整理出来:

1.准备工作

首先需要登录微信支付公众平台阅读接口文档,地址:https://pay.weixin.qq.com/wiki/doc/api/app.php?chapter=9_12&index=2 ;

其次了解微信支付商户系统和微信支付系统主要交互说明:

步骤1:用户在商户APP中选择商品,提交订单,选择微信支付。

步骤2:商户后台收到用户支付单,调用微信支付统一下单接口。参见【统一下单API】。

步骤3:统一下单接口返回正常的prepay_id,再按签名规范重新生成签名后,将数据传输给APP。参与签名的字段名为appId,partnerId,prepayId,nonceStr,timeStamp,package。注意:package的值格式为Sign=WXPay

步骤4:商户APP调起微信支付。api参见本章节【app端开发步骤说明】

步骤5:商户后台接收支付通知。api参见【支付结果通知API】

步骤6:商户后台查询支付结果。,api参见【查询订单API】

然后是微信支付交互过程

2.开始工作

不需要导入微信支付的jar包,需要哪些jar导入哪些就可以,

发送统一下单请求调用:

/** *  * @方法名称:sendWxPayRequest * @内容摘要: <发送统一下单请求> * @param body * @param outTradeNo * @param totalFee * @param spBillCreateIP * @return  * String * @exception  * @author:鹿伟伟 * @创建日期:2016年2月19日-下午2:24:05 */ public String sendWxPayRequest(String body,String detail,String outTradeNo,int totalFee,String spBillCreateIP     ) { // 构造HTTP请求 HttpClient httpclient = new HttpClient(); PostMethod postMethod = new PostMethod(Configure.PAY_API); WxPayReqData wxdata = new WxPayReqData(body,detail,outTradeNo,totalFee,spBillCreateIP); StringBuffer requestStr = new StringBuffer( ""); requestStr.append(""); requestStr.append(""); requestStr.append(""); requestStr.append(""); requestStr.append(""); requestStr.append(""); requestStr.append(""); requestStr.append(""); requestStr.append(""); requestStr.append(""); requestStr.append(""); // 发送请求 String strResponse = null; try { RequestEntity entity = new StringRequestEntity( requestStr.toString(), "text/xml", "UTF-8"); postMethod.setRequestEntity(entity); httpclient.executeMethod(postMethod); strResponse = new String(postMethod.getResponseBody(), "utf-8"); Logger.getLogger(getClass()).debug(strResponse); } catch (HttpException e) { Logger.getLogger(getClass()).error("sendWxPayRequest", e); } catch (IOException e) { Logger.getLogger(getClass()).error("sendWxPayRequest", e); } finally { postMethod.releaseConnection(); } return strResponse; }

3.问题:

客户端调起微信支付接口是一直返回-1:

a.你要用验证过的keystore打包出来安装才能正常进入支付,否则不能进入微信,有可能出现-1的情况; b.你的手机确认要有安装微信app;



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3