微信支付V2账单查询接口orderquery示例代码

         关于微信的支付功能,相信不少人用过。谈谈关于微信支付接口的web开发经验吧。

        首先聊一下:

                  服务端签名支付。


        服务端签名支付,官方给出了server端的实例代码。可以在微信的开发平台下载到。代码结构图如下:

        

          导入项目以后只需要修改的是config.jsp下的参数。

          

//收款方

String spname = "xxxxx";                                           

//商户号
String partner = "xxxxxx";

//密钥
String partner_key = "xxxxx";

//appi
String app_id="xxxxx";

String app_secret = "xxxx";

//appkey
String app_key="xxxxxx";

//支付完成后的回调处理页面
String notify_url ="http://[ip]:[port]/app-java/payNotifyUrl.jsp";
//调试模式
boolean DEBUG_ = true;
  • 0
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
微信支付代码需要结合具体的开发语言和框架来实现。以下是一个基于Java语言和Spring框架的微信支付示例代码: 1. 创建一个微信支付配置类,例如WechatPayConfig.java,其中包含了微信支付的相关配置: ``` @Configuration public class WechatPayConfig { // 应用ID @Value("${wechat.pay.app-id}") private String appId; // 商户号 @Value("${wechat.pay.mch-id}") private String mchId; // API密钥 @Value("${wechat.pay.api-key}") private String apiKey; // 回调地址 @Value("${wechat.pay.notify-url}") private String notifyUrl; // 将配置类中的属性注入到WechatPayService中 @Bean public WechatPayService wechatPayService() { return new WechatPayServiceImpl(appId, mchId, apiKey, notifyUrl); } } ``` 2. 创建一个微信支付服务类,例如WechatPayService.java,其中包含了微信支付的相关接口: ``` public interface WechatPayService { // 统一下单接口 Map<String, String> unifiedOrder(String outTradeNo, String body, int totalFee, String spbillCreateIp) throws Exception; // 查询订单接口 Map<String, String> orderQuery(String outTradeNo) throws Exception; // 关闭订单接口 Map<String, String> closeOrder(String outTradeNo) throws Exception; // 申请退款接口 Map<String, String> refund(String outTradeNo, String outRefundNo, int totalFee, int refundFee) throws Exception; // 查询退款接口 Map<String, String> refundQuery(String outTradeNo) throws Exception; } ``` 3. 创建一个微信支付服务的实现类,例如WechatPayServiceImpl.java,其中实现了微信支付服务的相关接口。这里使用了官方提供的Java SDK: ``` @Service public class WechatPayServiceImpl implements WechatPayService { private final WxPayService wxPayService; public WechatPayServiceImpl(String appId, String mchId, String apiKey, String notifyUrl) { WxPayConfig payConfig = new WxPayConfig(); payConfig.setAppId(appId); payConfig.setMchId(mchId); payConfig.setMchKey(apiKey); payConfig.setNotifyUrl(notifyUrl); this.wxPayService = new WxPayServiceImpl(); this.wxPayService.setConfig(payConfig); } @Override public Map<String, String> unifiedOrder(String outTradeNo, String body, int totalFee, String spbillCreateIp) throws Exception { WxPayUnifiedOrderRequest request = new WxPayUnifiedOrderRequest(); request.setOutTradeNo(outTradeNo); request.setBody(body); request.setTotalFee(totalFee); request.setSpbillCreateIp(spbillCreateIp); request.setTradeType(WxPayConstants.TradeType.APP); WxPayUnifiedOrderResult result = wxPayService.unifiedOrder(request); return result.toMap(); } @Override public Map<String, String> orderQuery(String outTradeNo) throws Exception { WxPayOrderQueryRequest request = new WxPayOrderQueryRequest(); request.setOutTradeNo(outTradeNo); WxPayOrderQueryResult result = wxPayService.queryOrder(request); return result.toMap(); } @Override public Map<String, String> closeOrder(String outTradeNo) throws Exception { WxPayOrderCloseRequest request = new WxPayOrderCloseRequest(); request.setOutTradeNo(outTradeNo); WxPayOrderCloseResult result = wxPayService.closeOrder(request); return result.toMap(); } @Override public Map<String, String> refund(String outTradeNo, String outRefundNo, int totalFee, int refundFee) throws Exception { WxPayRefundRequest request = new WxPayRefundRequest(); request.setOutTradeNo(outTradeNo); request.setOutRefundNo(outRefundNo); request.setTotalFee(totalFee); request.setRefundFee(refundFee); WxPayRefundResult result = wxPayService.refund(request); return result.toMap(); } @Override public Map<String, String> refundQuery(String outTradeNo) throws Exception { WxPayRefundQueryRequest request = new WxPayRefundQueryRequest(); request.setOutTradeNo(outTradeNo); WxPayRefundQueryResult result = wxPayService.refundQuery(request); return result.toMap(); } } ``` 4. 在需要使用微信支付的地方,注入WechatPayService,调用相关接口即可。 以上仅是一个示例代码,具体实现需要根据实际情况进行调整和完善。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值