启用微信支付

1、微信支付配置

[info] 预支付订单、跳转及回调处理Controller /dodo/src/main/java/com/pay/action/front/PayAction.java

2、定义一些业务类型,用于回调的时候,区分

// 修改此枚举,添加有意义的业务类型
package com.pay;

public enum PayBusiType{
    BUSI1,BUSI2
}

3、获取预支付订单

 /**
  * 参见:PayAction.java
  */
@RequestMapping("/ten_pay/prepay.json")
    @ResponseBody
    public RespData tenpayPrepay(HttpServletRequest request, String accountName, String tradeNo, String openId) {
        // 待支付的业务类型
        PayBusiType payBusiType = PayBusiType.BUSI1;
        // 商品名称
        String remark = "Test";//query
        // 支付的金额,单位:分
        BigDecimal total_fee = new BigDecimal(1000);//query
        // 收款账户
        TenpayAccount account = PayConfig.getTenpayAccount(accountName);
        // 打包支付请求
        PayPack pack = new PayPack();
        // 系统内部订单号
        pack.setOut_trade_no(tradeNo);
        // 支付的业务类型
        pack.setPayBusiType(payBusiType);
        // 商品名称
        pack.setRemark(remark);
        // 待支付金额
        pack.setTotal_fee(total_fee);
        // 支付成功后的回调URL
        pack.setNotifyUrl(account.getNotifyUrl());
        // APP支付,获取预支付订单
        if (account.getType() == AccountType.APP) {
            return RespData.success(PayUtil.makeWeixinPrepayOrderAPP(pack, request, accountName));
        }
        // JSAPI支付,获取预支付订单 
        else {
            return RespData.success(PayUtil.makeWeixinPrepayOrderJSAPI(openId, pack, request, accountName));
        }
    }

4、接收回调

参见方法:PayAction.java:tenpayNotify

......省略代码......
    // 业务1的回调
    if (payBusiType == PayBusiType.BUSI1) {

    }
    // 业务2的回调
    else if (payBusiType == PayBusiType.BUSI2) {
    }
......省略代码......
Copyright © Dodo Framework 2019 all right reservedModify At: 2019-12-24 10:51:25