支付宝支付的几种方式

1、create_direct_pay_by_user  

支付宝即时到账交易接口  

支付宝_纯网关接口

public Result<TpOrder> createAliDirectPayByUser(final AppInfo appInfo, final String subject,
      final Double totalFee, final AccountDomain receivingParty, final AccountDomain fuKuanfang,
      final Map<String, Object> f) {
    return Templates.<TpOrder>builder().template(new Template<TpOrder, ApiService<AppInfo>>() {

      @Override
      public TpOrder execute(ApiService<AppInfo> e) throws Exception {
        /*
         * 校验参数
         */
        checkParam(e, appInfo, subject, totalFee, receivingParty);
        checkArgument(totalFee >= 0.01 && totalFee <= 10000000, "金额必须大于0.01小于10000000");
        Money money = new Money(totalFee);
        final OrderEntity entity = OrderEntity.create(OrderEntity.class);
        entity.setAmount(money.getCent());
        entity.setOrderType(OrderType.WaitPayment);
        entity.setProductName(subject);
        entity.setTradeNo(OrderUUIDHexGenerator.instance.generate().toString());
        if (receivingParty.isBuy()) {
          entity.setUserId(receivingParty.getUserId());
          entity.setUserName(receivingParty.getUserName());
          entity.addFeatures(Tag.BUY_ORDER, true);
        } else if (receivingParty.isSeller()) {
          entity.setMerchantId(receivingParty.getMerchantId());
          entity.setMerchantName(receivingParty.getMerchantName());
        } else {
          throw new UnsupportedOperationException("未实现");
        }
        entity.addFeatures(Tag.receivingPartyId, receivingParty.getId());
        entity.addFeatures(Tag.receivingPartyAppId, receivingParty.getAppId());
        entity.setPayType(PayType.AliPay);
        StopWatch stopWatch = new StopWatch("Alipay");
        stopWatch = stopWatch.start("Ali Pay TraderNo");
        AlipayFactory factory =
            AlipayFactory.getDefaultInstance(new SysConfigProperties(SysConfigEntity.config()));
        RequestBase req =
            factory.newCreateDirectPayByUser().setProperty("out_trade_no", entity.getTradeNo())
                .setProperty("subject", subject).setProperty("payment_type", "1")
                .setProperty("total_fee", money.getAmount().toString())
                .setProperty("notify_url", SysConfigEntity.config().getNotifyURL());
        stopWatch = stopWatch.stop();
        logger.info("支付下订耗时:" + stopWatch.totalTime().toString());
        stopWatch = stopWatch.start("Create Pc Pay Url");
        String url = (req.build().sign().toURL());
        stopWatch = stopWatch.stop();
        logger.info("生成Pc Pay rul耗时:" + stopWatch.totalTime().toString());
        logger.info("url:" + url);
        if (f != null) entity.getFeatures().putAll(f);
        if (fuKuanfang != null) {
          AccountEntity fuKuanfangAccountEntity =
              AccountEntity.create(AccountEntity.class).findUnique(
                  SpecificationBuilder.builder().where(Account_.appId.eq(fuKuanfang.getAppId()))
                      .and(Account_.id.eq(fuKuanfang.getId())).build(), null);
          checkArgument(fuKuanfangAccountEntity != null, "付款方的帐号不存在");
          entity.addFeatures(Tag.FU_KUANFANG_ID, fuKuanfang.getId());
          entity.addFeatures(Tag.FU_KUANFANG_APP_ID, fuKuanfang.getAppId());
        }
        entity.setQrCodeUrl(url).setAppId(appInfo.getId()).setAppName(appInfo.getAppName())
            .createOrUpdate();
        return BeanMapper.map(entity, OrderDto.class);
      }

    }).build();
  }

2、alipay.wap.trade.create.direct
 @Override
  public Result<TpOrder> wapAliAuthAndExecute(final AppInfo appInfo, final String subject,
      final Double totalFee, final AccountDomain receivingParty, final AccountDomain fuKuanfang,
      final Map<String, Object> f) {
    return Templates.<TpOrder>builder().template(new Template<TpOrder, ApiService<AppInfo>>() {

      @Override
      public TpOrder execute(ApiService<AppInfo> e) throws Exception {
        /*
         * 校验参数
         */
        checkParam(e, appInfo, subject, totalFee, receivingParty);
        checkArgument(totalFee >= 0.01 && totalFee <= 10000000, "金额必须大于0.01小于10000000");
        Money money = new Money(totalFee);
        final OrderEntity entity = OrderEntity.create(OrderEntity.class);
        entity.setAmount(money.getCent());
        entity.setOrderType(OrderType.WaitPayment);
        entity.setProductName(subject);
        entity.setTradeNo(OrderUUIDHexGenerator.instance.generate().toString());
        if (receivingParty.isBuy()) {
          entity.setUserId(receivingParty.getUserId());
          entity.setUserName(receivingParty.getUserName());
          entity.addFeatures(Tag.BUY_ORDER, true);
        } else if (receivingParty.isSeller()) {
          entity.setMerchantId(receivingParty.getMerchantId());
          entity.setMerchantName(receivingParty.getMerchantName());
        } else {
          throw new UnsupportedOperationException("未实现");
        }
        entity.addFeatures(Tag.receivingPartyId, receivingParty.getId());
        entity.addFeatures(Tag.receivingPartyAppId, receivingParty.getAppId());
        entity.setPayType(PayType.AliPay);
        StopWatch stopWatch = new StopWatch("Alipay");
        stopWatch = stopWatch.start("Ali Pay TraderNo");
        AlipayFactory factory =
            AlipayFactory.getDefaultInstance(new SysConfigProperties(SysConfigEntity.config()));

        RequestBase req =
            factory.newWapTradeCreateDirect().setProperty("req_id", entity.getTradeNo())
                .setProperty("out_trade_no", entity.getTradeNo())
                .setProperty("total_fee", money.getAmount().toString())
                .setProperty("subject", subject)
                .setProperty("notify_url", SysConfigEntity.config().getNotifyURL());
        ResponseBase base = (req.build().sign().execute());
        RequestBase requestBase = factory.newWapAuthAndExecute(base.getProperties());

        stopWatch = stopWatch.stop();
        logger.info("支付下订耗时:" + stopWatch.totalTime().toString());
        stopWatch = stopWatch.start("Create Wap Url");
        String url = (requestBase.build().sign().toURL());
        stopWatch = stopWatch.stop();
        logger.info("生成wap url耗时:" + stopWatch.totalTime().toString());
        if (f != null) entity.getFeatures().putAll(f);
        if (fuKuanfang != null) {
          AccountEntity fuKuanfangAccountEntity =
              AccountEntity.create(AccountEntity.class).findUnique(
                  SpecificationBuilder.builder().where(Account_.appId.eq(fuKuanfang.getAppId()))
                      .and(Account_.id.eq(fuKuanfang.getId())).build(), null);
          checkArgument(fuKuanfangAccountEntity != null, "付款方的帐号不存在");
          entity.addFeatures(Tag.FU_KUANFANG_ID, fuKuanfang.getId());
          entity.addFeatures(Tag.FU_KUANFANG_APP_ID, fuKuanfang.getAppId());
        }
        entity.setQrCodeUrl(url).setAppId(appInfo.getId()).setAppName(appInfo.getAppName())
            .createOrUpdate();
        return BeanMapper.map(entity, OrderDto.class);
      }

    }).build();
  }

3、mobile.securitypay.pay  移动支付 扫码支付

 @Override
  public Result<TpOrder> qrCodePay(final AppInfo appInfo, final QrCodeDomain qrCodeDomain,
      final PayType payType, final String detailed, final Double amount,
      final AccountDomain receivingParty, final AccountDomain fuKuanfang,
      final Map<String, Object> f) {
    return Templates.<TpOrder>builder().template(new Template<TpOrder, ApiService<AppInfoDto>>() {

      @Override
      public TpOrder execute(ApiService<AppInfoDto> e) throws Exception {
        /*
         * 校验一下参数
         */
        checkArgument(appInfo != null, "应用不能为空");
        checkArgument(qrCodeDomain != null, "二维码的基础属性不能为空");
        checkArgument(payType != null && PayType.AliPay.equals(payType), "支付宝支付类型不能为空");
        checkArgument(detailed != null && !detailed.trim().isEmpty(), "明细项目不能为空");
        checkArgument(amount != null, "金额不能为空");
        checkArgument(
            receivingParty != null && receivingParty.getAppId() != null
                && receivingParty.getId() != null, "收款的帐号不能为空或者属性不全");
        Result<AppInfoDto> result = e.load(appInfo.getId());
        checkArgument(result.isSuccess() && result.domain() != null, "应用不存在");
        AccountEntity accountEntity =
            AccountEntity.create(AccountEntity.class).findUnique(
                SpecificationBuilder.builder().where(Account_.appId.eq(receivingParty.getAppId()))
                    .and(Account_.id.eq(receivingParty.getId())).build(), null);
        checkArgument(accountEntity != null, "收款的帐号不存在");
        Money aMoney = new Money(amount);
        checkArgument(aMoney.getCent() >= 1, "金额必须大于等于一分");
        final OrderEntity entity = OrderEntity.create(OrderEntity.class);
        entity.setAmount(aMoney.getCent());
        entity.setOrderType(OrderType.WaitPayment);
        entity.setProductName(detailed);
        entity.setTradeNo(OrderUUIDHexGenerator.instance.generate().toString());
        if (receivingParty.isBuy()) {
          entity.setUserId(receivingParty.getUserId());
          entity.setUserName(receivingParty.getUserName());
          entity.addFeatures(Tag.BUY_ORDER, true);
        } else if (receivingParty.isSeller()) {
          entity.setMerchantId(receivingParty.getMerchantId());
          entity.setMerchantName(receivingParty.getMerchantName());
        } else {
          throw new UnsupportedOperationException("未实现");
        }
        entity.addFeatures(Tag.receivingPartyId, receivingParty.getId());
        entity.addFeatures(Tag.receivingPartyAppId, receivingParty.getAppId());
        entity.setPayType(PayType.AliPay);
        StopWatch stopWatch = new StopWatch("Alipay");
        stopWatch = stopWatch.start("Ali Pay TraderNo");
        final AlipayTradePrecreateResponse response =
            scanCodePay.qrPay(entity.getTradeNo(), amount.toString(), detailed, SysConfigEntity
                .config().getNotifyURL(), SysConfigEntity.config().getTimeExpire());
        stopWatch = stopWatch.stop();
        logger.info("支付下订耗时:" + stopWatch.totalTime().toString());
        stopWatch = stopWatch.start("Create Qr Code Img");
        String url =
            QrCodes.getInstance().qrCode(response.getQrCode(), qrCodeDomain.getLogoImgUrl(),
                qrCodeDomain.getWidth(), qrCodeDomain.getHeight());
        stopWatch = stopWatch.stop();
        logger.info("生成二维码耗时:" + stopWatch.totalTime().toString());
        if (f != null) {
          entity.getFeatures().putAll(f);
        }
        if (fuKuanfang != null) {
          AccountEntity fuKuanfangAccountEntity =
              AccountEntity.create(AccountEntity.class).findUnique(
                  SpecificationBuilder.builder().where(Account_.appId.eq(fuKuanfang.getAppId()))
                      .and(Account_.id.eq(fuKuanfang.getId())).build(), null);
          checkArgument(fuKuanfangAccountEntity != null, "付款方的帐号不存在");
          entity.addFeatures(Tag.FU_KUANFANG_ID, fuKuanfang.getId());
          entity.addFeatures(Tag.FU_KUANFANG_APP_ID, fuKuanfang.getAppId());
        }
        entity.addFeatures(Tag.PAY_RESPONE, response.getBody());
        // 生成app支付的url
        // partner="2088101568358171"&seller_id="xxx@alipay.com"&out_trade_no="0819145412-6177"&subject="测试"&body="测试测试"&total_fee="0.01"&notify_url="http://notify.msp.hk/notify.htm"&service="mobile.securitypay.pay"&payment_type="1"&_input_charset="utf-8"&it_b_pay="30m"&sign="lBBK%2F0w5LOajrMrji7DUgEqNjIhQbidR13GovA5r3TgIbNqv231yC1NksLdw%2Ba3JnfHXoXuet6XNNHtn7VE%2BeCoRO1O%2BR1KugLrQEZMtG5jmJIe2pbjm%2F3kb%2FuGkpG%2BwYQYI51%2BhA3YBbvZHVQBYveBqK%2Bh8mUyb7GM1HxWs9k4%3D"&sign_type="RSA"
        AlipayRequestData data =
            mobileDirectSDK.makeSimpleMobileTrade(entity.getTradeNo(), entity.getProductName(),
                entity.getProductName(), null, aMoney.getAmount().doubleValue(), SysConfigEntity
                    .config().getAppNotifyUrl());
        String appOrderInfo = mobileDirectSDK.create(data);
        logger.info("生成app支付的字符串:" + appOrderInfo);
        entity.addFeatures("appOrderInfo", appOrderInfo);
        return entity.setQrCodeUrl(url).setXml(response.getBody()).setAppId(appInfo.getId())
            .setAppName(appInfo.getAppName()).createOrUpdate().toDomain();
      }
    }).build();
  }



原文地址:https://www.cnblogs.com/wjlstation/p/5973701.html