|
@@ -3,15 +3,10 @@ package com.example.controller;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.alipay.api.AlipayApiException;
|
|
|
import com.alipay.api.AlipayClient;
|
|
|
-import com.alipay.api.domain.AlipayTradePagePayModel;
|
|
|
-import com.alipay.api.domain.AlipayTradePrecreateModel;
|
|
|
-import com.alipay.api.domain.AlipayTradeRefundModel;
|
|
|
-import com.alipay.api.domain.AlipayTradeWapPayModel;
|
|
|
+import com.alipay.api.domain.*;
|
|
|
import com.alipay.api.internal.util.AlipaySignature;
|
|
|
-import com.alipay.api.request.AlipayTradePagePayRequest;
|
|
|
-import com.alipay.api.request.AlipayTradePrecreateRequest;
|
|
|
-import com.alipay.api.request.AlipayTradeRefundRequest;
|
|
|
-import com.alipay.api.request.AlipayTradeWapPayRequest;
|
|
|
+import com.alipay.api.request.*;
|
|
|
+import com.alipay.api.response.AlipayTradePayResponse;
|
|
|
import com.alipay.api.response.AlipayTradePrecreateResponse;
|
|
|
import com.alipay.api.response.AlipayTradeRefundResponse;
|
|
|
import com.example.base.BaseController;
|
|
@@ -112,6 +107,54 @@ public class AlipayPagePayController extends BaseController {
|
|
|
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 条码支付
|
|
|
+ *
|
|
|
+ * @return
|
|
|
+ * @throws AlipayApiException
|
|
|
+ */
|
|
|
+ @GetMapping("/barcode")
|
|
|
+ @ResponseBody
|
|
|
+ public ResponseBase barcode(String authCode) throws AlipayApiException {
|
|
|
+ SnowFlake snowFlake = new SnowFlake(2, 3);
|
|
|
+ String outTradeNo = snowFlake.nextId() + "";
|
|
|
+
|
|
|
+ AlipayTradePayRequest request = new AlipayTradePayRequest();
|
|
|
+
|
|
|
+ AlipayTradePayModel model = new AlipayTradePayModel();
|
|
|
+ model.setOutTradeNo(outTradeNo);
|
|
|
+ model.setScene("bar_code");
|
|
|
+ //扫码枪的二维码
|
|
|
+ model.setAuthCode(authCode);
|
|
|
+ model.setSubject("条码支付测试");
|
|
|
+ String amount = String.valueOf(0.01);
|
|
|
+ model.setStoreId("NJ_001");
|
|
|
+ model.setTotalAmount(amount);
|
|
|
+ model.setTimeoutExpress("2m");
|
|
|
+ request.setBizModel(model);
|
|
|
+ request.setNotifyUrl(alipayProperties.getNotifyUrl());
|
|
|
+
|
|
|
+ logger.info("发起AliPay下单请求");
|
|
|
+
|
|
|
+ AlipayTradePayResponse response = null;
|
|
|
+ try {
|
|
|
+ response = alipayClient.execute(request);
|
|
|
+ String result = response.getBody();
|
|
|
+ JSONObject res = JSONObject.parseObject(result);
|
|
|
+ res = res.getJSONObject("alipay_trade_pay_response");
|
|
|
+ String code = res.getString("code");
|
|
|
+ if (code.equals("10000")) {
|
|
|
+ return responseSuccess(success("成功"));
|
|
|
+ } else {
|
|
|
+ return responseSuccess(error("条幅支付失败"));
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ return responseSuccess(error("条幅支付失败!"));
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* h5 页面支付
|
|
|
*
|
|
@@ -150,7 +193,6 @@ public class AlipayPagePayController extends BaseController {
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
@ApiOperation(value = "网页扫码支付", notes = "跳转到支付宝扫码支付页面,用户可通过扫码进行支付,成功则跳转到成功页面")
|
|
|
@GetMapping("/gotoPayPage")
|
|
|
public void gotoPayPage(HttpServletResponse response) throws AlipayApiException, IOException {
|