Skip to content

wangyx0055/WXPay-SDK-Java

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

6 Commits

Repository files navigation

微信支付 Java SDK

微信支付开发者文档中给出的API进行了封装。

com.qq.weixin.pay.WXPay类下提供了对应的方法:

方法名说明
microPay刷卡支付
unifiedOrder统一下单
orderQuery查询订单
reverse撤销订单
closeOrder关闭订单
refund申请退款
refundQuery查询退款
downloadBill下载对账单
report交易保障
shortUrl转换短链接
authCodeToOpenid授权码查询openid

参数为Map<String, String>对象,返回类型也是Map<String, String>。 方法内部会将参数会转换成含有appidmch_idnonce_strsign的XML; 通过HTTPS请求得到返回数据后会对其做必要的处理(例如验证签名,签名错误则抛出异常)。

对于downloadBill,无论是否成功都返回Map,且都含有return_codereturn_msg。 若成功,其中return_codeSUCCESS,另外data对应对账单数据。

安装

maven:

<dependency> <groupId>com.github.wxpay</groupId> <artifactId>wxpay-sdk</artifactId> <version>0.0.1</version> </dependency> 

示例

MyConfig.java:

importcom.github.wxpay.sdk.WXPayConfig; importjava.io.*; publicclassMyConfigimplementsWXPayConfig{privatebyte[] certData; publicMyConfig() throwsException{StringcertPath = "/path/to/apiclient_cert.p12"; Filefile = newFile(certPath); InputStreamcertStream = newFileInputStream(file); this.certData = newbyte[(int) file.length()]; certStream.read(this.certData); certStream.close()} publicStringgetAppID(){return"wx8888888888888888"} publicStringgetMchID(){return"12888888"} publicStringgetKey(){return"88888888888888888888888888888888"} publicInputStreamgetCertStream(){ByteArrayInputStreamcertBis = newByteArrayInputStream(this.certData); returncertBis} publicintgetTimeOutMs(){return10000} }

WXPayExample.java:

importcom.github.wxpay.sdk.WXPay; importjava.util.HashMap; importjava.util.Map; publicclassWXPayExample{privateWXPaywxpay; privateMyConfigconfig; publicWXPayExample() throwsException{config = newMyConfig(); wxpay = newWXPay(config)} /** * 扫码支付 下单 */publicvoiddoUnifiedOrder(){HashMap<String, String> data = newHashMap<String, String>(); data.put("body", "腾讯充值中心-QQ会员充值"); data.put("out_trade_no", "2016090910595900000012"); data.put("device_info", ""); data.put("fee_type", "CNY"); data.put("total_fee", ""+1); data.put("spbill_create_ip", "123.12.12.123"); data.put("notify_url", "http://www.example.com/wxpay/notify"); data.put("trade_type", "NATIVE"); data.put("product_id", "12"); try{Map<String, String> r = wxpay.unifiedOrder(data); System.out.println(r)} catch (Exceptione){e.printStackTrace()} } }

Java Doc

https://wxpay.github.io/sdk/javadoc/

License

BSD

About

微信支付 Java SDK

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages