李雨欣 9.1 14:24 测试查询接口
parent
ce6e0bedf4
commit
070ef4bd18
|
@ -1,42 +0,0 @@
|
|||
package com.muyu.pay.config;
|
||||
import com.alipay.easysdk.factory.Factory;
|
||||
import com.alipay.easysdk.kernel.Config;
|
||||
import lombok.Data;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
|
||||
/**
|
||||
* @Author
|
||||
* @Date Created in 2023/5/5 15:06
|
||||
* @DESCRIPTION:
|
||||
* @Version V1.0
|
||||
*/
|
||||
|
||||
@Data
|
||||
@Component
|
||||
//读取yml文件中alipay 开头的配置
|
||||
@ConfigurationProperties(prefix = "alipay")
|
||||
public class AliPayConfig {
|
||||
private String appId;
|
||||
private String appPrivateKey;
|
||||
private String alipayPublicKey;
|
||||
private String notifyUrl;
|
||||
|
||||
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
// 设置参数(全局只需设置一次)
|
||||
Config config = new Config();
|
||||
config.protocol = "https";
|
||||
config.gatewayHost = "openapi.alipaydev.com";
|
||||
config.signType = "RSA2";
|
||||
config.appId = this.appId;
|
||||
config.merchantPrivateKey = this.appPrivateKey;
|
||||
config.alipayPublicKey = this.alipayPublicKey;
|
||||
config.notifyUrl = this.notifyUrl;
|
||||
Factory.setOptions(config);
|
||||
System.out.println("=======支付宝SDK初始化成功=======");
|
||||
}
|
||||
}
|
|
@ -2,16 +2,10 @@ package com.muyu.pay.domain;
|
|||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @Author
|
||||
* @Date Created in 2023/5/5 15:26
|
||||
* @DESCRIPTION:
|
||||
* @Version V1.0
|
||||
*/
|
||||
@Data
|
||||
public class AliPay {
|
||||
private String traceNo;
|
||||
private double totalAmount;
|
||||
private String totalAmount;
|
||||
private String subject;
|
||||
private String alipayTraceNo;
|
||||
}
|
||||
|
|
|
@ -1,42 +0,0 @@
|
|||
package com.muyu.market.server.config;
|
||||
import com.alipay.easysdk.factory.Factory;
|
||||
import com.alipay.easysdk.kernel.Config;
|
||||
import lombok.Data;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
|
||||
/**
|
||||
* @Author
|
||||
* @Date Created in 2023/5/5 15:06
|
||||
* @DESCRIPTION:
|
||||
* @Version V1.0
|
||||
*/
|
||||
|
||||
@Data
|
||||
@Component
|
||||
//读取yml文件中alipay 开头的配置
|
||||
@ConfigurationProperties(prefix = "alipay")
|
||||
public class AliPayConfig {
|
||||
private String appId;
|
||||
private String appPrivateKey;
|
||||
private String alipayPublicKey;
|
||||
private String notifyUrl;
|
||||
|
||||
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
// 设置参数(全局只需设置一次)
|
||||
Config config = new Config();
|
||||
config.protocol = "https";
|
||||
config.gatewayHost = "openapi.alipaydev.com";
|
||||
config.signType = "RSA2";
|
||||
config.appId = this.appId;
|
||||
config.merchantPrivateKey = this.appPrivateKey;
|
||||
config.alipayPublicKey = this.alipayPublicKey;
|
||||
config.notifyUrl = this.notifyUrl;
|
||||
Factory.setOptions(config);
|
||||
System.out.println("=======支付宝SDK初始化成功=======");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
package com.muyu.market.server.config;
|
||||
|
||||
|
||||
import com.alipay.easysdk.factory.Factory;
|
||||
import com.alipay.easysdk.kernel.Config;
|
||||
import lombok.Data;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
|
||||
@Data
|
||||
@Component
|
||||
@ConfigurationProperties(prefix = "alipay")
|
||||
public class MyAliPayConfig {
|
||||
private String appId;
|
||||
private String appPrivateKey;
|
||||
private String alipayPublicKey;
|
||||
private String notifyUrl;
|
||||
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
// 设置参数(全局只需设置一次)
|
||||
Config config = new Config();
|
||||
config.protocol = "https";
|
||||
config.gatewayHost = "https://openapi-sandbox.dl.alipaydev.com/gateway.do";
|
||||
config.signType = "RSA2";
|
||||
config.appId = this.appId;
|
||||
config.merchantPrivateKey = this.appPrivateKey;
|
||||
config.alipayPublicKey = this.alipayPublicKey;
|
||||
config.notifyUrl = this.notifyUrl;
|
||||
Factory.setOptions(config);
|
||||
System.out.println("=======支付宝SDK初始化成功=======");
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,96 @@
|
|||
package com.muyu.market.server.controller;
|
||||
|
||||
import com.alipay.api.AlipayApiException;
|
||||
import com.alipay.api.AlipayClient;
|
||||
import com.alipay.api.DefaultAlipayClient;
|
||||
import com.alipay.api.request.AlipayTradePagePayRequest;
|
||||
|
||||
import com.muyu.market.server.config.MyAliPayConfig;
|
||||
import com.muyu.pay.domain.AliPay;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/alipay")
|
||||
public class AliPayController {
|
||||
//-支付宝网关地址
|
||||
private static final String GATEWAY_URL = "https://openapi-sandbox.dl.alipaydev.com/gateway.do";
|
||||
private static final String FORMAT_JSON = "JSON";
|
||||
private static final String CHARSET_UTF8 = "UTF-8";
|
||||
private static final String SIGN_TYPE_RSA2 = "RSA2";
|
||||
@Autowired
|
||||
private MyAliPayConfig myAliPayConfig;
|
||||
|
||||
@GetMapping("/pay")
|
||||
public void pay(AliPay aliPay, HttpServletResponse httpResponse) throws Exception{
|
||||
AlipayClient alipayClient = new DefaultAlipayClient(GATEWAY_URL, myAliPayConfig.getAppId(),
|
||||
myAliPayConfig.getAppPrivateKey(), FORMAT_JSON, CHARSET_UTF8, myAliPayConfig.getAlipayPublicKey(), SIGN_TYPE_RSA2);
|
||||
AlipayTradePagePayRequest request = new AlipayTradePagePayRequest();
|
||||
request.setNotifyUrl(myAliPayConfig.getNotifyUrl());
|
||||
//-商品的内容可以从系统中传递过来,目前这里是手写的
|
||||
aliPay.setTraceNo(UUID.randomUUID().toString().replaceAll("-",""));
|
||||
aliPay.setTotalAmount("100");
|
||||
aliPay.setSubject("笔记本华硕");
|
||||
//=====
|
||||
request.setBizContent("{\"out_trade_no\":\"" + aliPay.getTraceNo() + "\","
|
||||
+ "\"total_amount\":\"" + aliPay.getTotalAmount() + "\","
|
||||
+ "\"subject\":\"" + aliPay.getSubject() + "\","
|
||||
+ "\"product_code\":\"FAST_INSTANT_TRADE_PAY\"}");
|
||||
String form = "";
|
||||
try {
|
||||
form = alipayClient.pageExecute(request).getBody(); // 调用SDK生成表单
|
||||
} catch (AlipayApiException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
httpResponse.setContentType("text/html;charset=" + CHARSET_UTF8);
|
||||
httpResponse.getWriter().write(form);// 直接将完整的表单html输出到页面
|
||||
httpResponse.getWriter().flush();
|
||||
httpResponse.getWriter().close();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@GetMapping("/notify") // 注意这里必须是POST接口
|
||||
public String payNotify(HttpServletRequest request) throws Exception {
|
||||
if (request.getParameter("trade_status").equals("TRADE_SUCCESS")) {
|
||||
System.out.println("=========支付宝异步回调========");
|
||||
|
||||
Map<String, String> params = new HashMap<>();
|
||||
Map<String, String[]> requestParams = request.getParameterMap();
|
||||
for (String name : requestParams.keySet()) {
|
||||
params.put(name, request.getParameter(name));
|
||||
// System.out.println(name + " = " + request.getParameter(name));
|
||||
}
|
||||
|
||||
String tradeNo = params.get("out_trade_no");
|
||||
String gmtPayment = params.get("gmt_payment");
|
||||
String alipayTradeNo = params.get("trade_no");
|
||||
// (不需要)支付宝验签
|
||||
//if (Factory.Payment.Common().verifyNotify(params)) {
|
||||
// 验签通过
|
||||
System.out.println("交易名称: " + params.get("subject"));
|
||||
System.out.println("交易状态: " + params.get("trade_status"));
|
||||
System.out.println("支付宝交易凭证号: " + params.get("trade_no"));
|
||||
System.out.println("商户订单号: " + params.get("out_trade_no"));
|
||||
System.out.println("交易金额: " + params.get("total_amount"));
|
||||
System.out.println("买家在支付宝唯一id: " + params.get("buyer_id"));
|
||||
System.out.println("买家付款时间: " + params.get("gmt_payment"));
|
||||
System.out.println("买家付款金额: " + params.get("buyer_pay_amount"));
|
||||
|
||||
// 更新订单未已支付
|
||||
// ordersMapper.updateState(tradeNo, "已支付", gmtPayment, alipayTradeNo);
|
||||
//}
|
||||
}
|
||||
return "success";
|
||||
}
|
||||
}
|
|
@ -5,14 +5,11 @@ import com.muyu.market.admain.Orders;
|
|||
import com.muyu.market.admain.Product;
|
||||
import com.muyu.market.admain.request.OrdersSelectReq;
|
||||
import com.muyu.market.admain.response.OrdersSelectResp;
|
||||
import com.muyu.market.admain.response.OrdersUpdResp;
|
||||
import com.muyu.market.server.service.OrdersService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
@ -24,6 +21,8 @@ import java.util.List;
|
|||
@Tag(name = "订单控制层",description = "订单查询")
|
||||
public class OrdersController {
|
||||
|
||||
|
||||
|
||||
@Autowired
|
||||
private OrdersService orderService;
|
||||
|
||||
|
@ -57,6 +56,7 @@ public class OrdersController {
|
|||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 修改订单
|
||||
* @param orders
|
||||
|
@ -68,6 +68,8 @@ public class OrdersController {
|
|||
return Result.success(integer);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// /**
|
||||
// * 修改订单
|
||||
// * @param orderId
|
||||
|
|
|
@ -28,6 +28,6 @@ public class PartyController {
|
|||
|
||||
//测试
|
||||
public static void main(String[] args) {
|
||||
SelectPhoneUtil.queryMobileLocation("18790307917");
|
||||
SelectPhoneUtil.queryMobileLocation("15066755856");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,40 +0,0 @@
|
|||
package com.muyu.market.server.controller;
|
||||
|
||||
import com.muyu.market.server.service.PayService;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
/**
|
||||
*@Author:Dear.fr
|
||||
*@Package:com.bawei.mall.pay.controller
|
||||
*@Project:mall_cloud
|
||||
*@name:PayController
|
||||
*@Date:2024/7/11 17:12
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/pay")
|
||||
@Tag(name = "支付宝支付控制层",description = "进行支付宝支付接口及回调接口调用")
|
||||
public class PayController {
|
||||
|
||||
@Resource
|
||||
private PayService aliPayService;
|
||||
|
||||
|
||||
@GetMapping("/aliPay")
|
||||
public String aliPay(@RequestParam("orderId") Long orderId,@RequestParam("payType") Integer payType){
|
||||
return aliPayService.pay(orderId,payType);
|
||||
}
|
||||
|
||||
/**
|
||||
* 回调
|
||||
* @param request
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/notify")
|
||||
public String notify(HttpServletRequest request) throws Exception {
|
||||
return aliPayService.aliApyNotify(request);
|
||||
}
|
||||
}
|
|
@ -27,6 +27,6 @@ public class WeatherController {
|
|||
|
||||
|
||||
public static void main(String[] args) {
|
||||
SelectWeatherUtil.queryWeather("南京");
|
||||
SelectWeatherUtil.queryWeather("烟台");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,10 +18,7 @@ public interface OrdersMapper extends BaseMapper<Orders>{
|
|||
|
||||
// List<OrdersSelectResp> findByorderList(OrdersSelectResp ordersSelectResp);
|
||||
|
||||
/**
|
||||
* 查询所有
|
||||
* @return
|
||||
*/
|
||||
|
||||
// List<OrdersSelectResp> findAll();
|
||||
|
||||
}
|
||||
|
|
|
@ -6,4 +6,5 @@ import org.apache.ibatis.annotations.Mapper;
|
|||
|
||||
@Mapper
|
||||
public interface ProductMapper extends BaseMapper<Product> {
|
||||
|
||||
}
|
||||
|
|
|
@ -1,161 +0,0 @@
|
|||
package com.muyu.market.server.service.Impl;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.alipay.easysdk.factory.Factory;
|
||||
import com.muyu.market.server.config.AliPayConfig;
|
||||
import com.muyu.market.server.service.PayService;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import com.alipay.api.AlipayApiException;
|
||||
import com.alipay.api.AlipayClient;
|
||||
import com.alipay.api.DefaultAlipayClient;
|
||||
import com.alipay.api.request.AlipayTradeWapPayRequest;
|
||||
import com.alipay.api.response.AlipayTradeWapPayResponse;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
|
||||
/**
|
||||
*@Author:Dear.fr
|
||||
*@Package:com.bawei.mall.pay.service.impl
|
||||
*@Project:mall_cloud
|
||||
*@name:AliPayServiceImpl
|
||||
*@Date:2024/7/11 17:13
|
||||
*/
|
||||
@Service
|
||||
public class AliPayServiceImpl implements PayService {
|
||||
|
||||
|
||||
private static final String GATEWAY_URL ="https://openapi-sandbox.dl.alipaydev.com/gateway.do";
|
||||
private static final String FORMAT ="JSON";
|
||||
private static final String CHARSET ="utf-8";
|
||||
private static final String SIGN_TYPE ="RSA2";
|
||||
private static final String QUICK_WAP_WAY ="QUICK_WAP_WAY";
|
||||
|
||||
@Autowired
|
||||
private AliPayConfig aliPayConfig;
|
||||
|
||||
@Override
|
||||
public String pay(Long orderId, Integer payType) {
|
||||
AlipayClient alipayClient = new DefaultAlipayClient(
|
||||
GATEWAY_URL,
|
||||
aliPayConfig.getAppId(),
|
||||
aliPayConfig.getAppPrivateKey(),
|
||||
FORMAT,
|
||||
CHARSET,
|
||||
aliPayConfig.getAlipayPublicKey(),
|
||||
SIGN_TYPE);
|
||||
AlipayTradeWapPayRequest request = new AlipayTradeWapPayRequest();
|
||||
//异步接收地址,仅支持http/https,公网可访问
|
||||
request.setNotifyUrl(aliPayConfig.getNotifyUrl());
|
||||
//同步跳转地址,仅支持http/https
|
||||
request.setReturnUrl("");
|
||||
/******必传参数******/
|
||||
JSONObject bizContent = new JSONObject();
|
||||
//商户订单号,商家自定义,保持唯一性
|
||||
String orderSn = generateMerchantOrderId(orderId);
|
||||
bizContent.put("out_trade_no",orderSn);
|
||||
//支付金额,最小值0.01元
|
||||
bizContent.put("total_amount", 100);
|
||||
//订单标题,不可使用特殊符号
|
||||
bizContent.put("subject", "测试商品");
|
||||
|
||||
/******可选参数******/
|
||||
//手机网站支付默认传值QUICK_WAP_WAY
|
||||
bizContent.put("product_code",QUICK_WAP_WAY);
|
||||
//bizContent.put("time_expire", "2022-08-01 22:00:00");
|
||||
|
||||
//// 商品明细信息,按需传入
|
||||
//JSONArray goodsDetail = new JSONArray();
|
||||
//JSONObject goods1 = new JSONObject();
|
||||
//goods1.put("goods_id", "goodsNo1");
|
||||
//goods1.put("goods_name", "子商品1");
|
||||
//goods1.put("quantity", 1);
|
||||
//goods1.put("price", 0.01);
|
||||
//goodsDetail.add(goods1);
|
||||
//bizContent.put("goods_detail", goodsDetail);
|
||||
|
||||
//// 扩展信息,按需传入
|
||||
//JSONObject extendParams = new JSONObject();
|
||||
//extendParams.put("sys_service_provider_id", "2088511833207846");
|
||||
//bizContent.put("extend_params", extendParams);
|
||||
|
||||
request.setBizContent(bizContent.toString());
|
||||
AlipayTradeWapPayResponse response = null;
|
||||
try {
|
||||
response = alipayClient.pageExecute(request,"POST");
|
||||
} catch (AlipayApiException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
// 如果需要返回GET请求,请使用
|
||||
// AlipayTradeWapPayResponse response = alipayClient.pageExecute(request,"GET");
|
||||
String pageRedirectionData = response.getBody();
|
||||
System.out.println(pageRedirectionData);
|
||||
|
||||
if(response.isSuccess()){
|
||||
System.out.println("调用成功");
|
||||
} else {
|
||||
System.out.println("调用失败");
|
||||
}
|
||||
return pageRedirectionData;
|
||||
}
|
||||
|
||||
|
||||
@Override // 注意这里必须是POST接口
|
||||
public String aliApyNotify(HttpServletRequest request) throws Exception {
|
||||
if (request.getParameter("trade_status").equals("TRADE_SUCCESS")) {
|
||||
System.out.println("=========支付宝异步回调========");
|
||||
|
||||
Map<String, String> params = new HashMap<>();
|
||||
Map<String, String[]> requestParams = request.getParameterMap();
|
||||
for (String name : requestParams.keySet()) {
|
||||
params.put(name, request.getParameter(name));
|
||||
// System.out.println(name + " = " + request.getParameter(name));
|
||||
}
|
||||
|
||||
String tradeNo = params.get("out_trade_no");
|
||||
String gmtPayment = params.get("gmt_payment");
|
||||
String alipayTradeNo = params.get("trade_no");
|
||||
// 支付宝验签
|
||||
if (Factory.Payment.Common().verifyNotify(params)) {
|
||||
// 验签通过
|
||||
System.out.println("交易名称: " + params.get("subject"));
|
||||
System.out.println("交易状态: " + params.get("trade_status"));
|
||||
System.out.println("支付宝交易凭证号: " + params.get("trade_no"));
|
||||
System.out.println("商户订单号: " + params.get("out_trade_no"));
|
||||
System.out.println("交易金额: " + params.get("total_amount"));
|
||||
System.out.println("买家在支付宝唯一id: " + params.get("buyer_id"));
|
||||
System.out.println("买家付款时间: " + params.get("gmt_payment"));
|
||||
System.out.println("买家付款金额: " + params.get("buyer_pay_amount"));
|
||||
/*// 更新订单未已支付
|
||||
ShopOrder order = new ShopOrder();
|
||||
order.setId(tradeNo);
|
||||
order.setStatus("1");
|
||||
Date payTime = DateUtil.parse(gmtPayment, "yyyy-MM-dd HH:mm:ss");
|
||||
order.setZhhifuTime(payTime);
|
||||
shopOrderMapper.updateById(order);*/
|
||||
}
|
||||
}
|
||||
return "success";
|
||||
}
|
||||
|
||||
|
||||
private String generateMerchantOrderId(Long orderId) {
|
||||
// 获取当前日期并格式化为yyyyMMdd
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMdd");
|
||||
String dateStr = now.format(formatter);
|
||||
|
||||
// 生成6位随机数
|
||||
Random random = new Random();
|
||||
int randomNumber = random.nextInt(999999); // 0 to 999998
|
||||
String randomStr = String.format("%06d", randomNumber); // 补零至6位
|
||||
|
||||
// 拼接商户订单号
|
||||
return dateStr + orderId + randomStr;
|
||||
}
|
||||
}
|
|
@ -5,10 +5,13 @@ import com.muyu.market.admain.Orders;
|
|||
import com.muyu.market.admain.Product;
|
||||
import com.muyu.market.admain.request.OrdersSelectReq;
|
||||
import com.muyu.market.admain.response.OrdersSelectResp;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public interface OrdersService extends IService<Orders>{
|
||||
|
||||
|
||||
List<OrdersSelectResp> orderSelect(OrdersSelectReq ordersSelectReq);
|
||||
|
||||
void saveOrder(Product product);
|
||||
|
|
|
@ -1,17 +0,0 @@
|
|||
package com.muyu.market.server.service;
|
||||
|
||||
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
|
||||
/**
|
||||
*@Author:Dear.fr
|
||||
*@Package:com.bawei.mall.pay.service
|
||||
*@Project:mall_cloud
|
||||
*@name:PayService
|
||||
*@Date:2024/7/11 17:13
|
||||
*/
|
||||
public interface PayService {
|
||||
String pay(Long orderId, Integer payType);
|
||||
|
||||
String aliApyNotify(HttpServletRequest request) throws Exception;
|
||||
}
|
|
@ -1,74 +0,0 @@
|
|||
package com.muyu.market.server.util;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.alipay.api.AlipayApiException;
|
||||
import com.alipay.api.AlipayClient;
|
||||
import com.alipay.api.DefaultAlipayClient;
|
||||
import com.alipay.api.request.AlipayTradeWapPayRequest;
|
||||
import com.alipay.api.response.AlipayTradeWapPayResponse;
|
||||
|
||||
|
||||
|
||||
public class PayUtils {
|
||||
public static void main(String[] args) {
|
||||
AlipayClient alipayClient = new DefaultAlipayClient(
|
||||
"https://openapi-sandbox.dl.alipaydev.com/gateway.do",
|
||||
"9021000140631838",
|
||||
"MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQCWxZholdxU/C9Vh+4hjD4yWH5MUn3ZK7zkFKB09KY1Kz5k6t0fhcdMRbTaJulyQVL21wneb83f+5hhAzk9+j6RLrvIbE1YZyvt9uoUIpljMkEFyVL2L97/m/Bc+D+PMXMor0DxWMgdkGvmm/1Phjaoxr+HZn6WI1ZFXjKNdIUMNs8H5oLXkBpfTVDS8GLXfDxrUT2gx9g2AH8NJMLlWObHwG3ZPQenRg5szhjLHxuuNgcfJXyoW0agSnRqzn8QeYyq5H0XVElrtF+JbBsnvuUgJn/+h/oVoKeFekEYjfqogzx/1oROereXdEk3OxmzrlW0+EUYBEMViv7EGi0z8/jLAgMBAAECggEAYDm+OsmidK76+silZ83dCD7IZKelYEx04tBzVBGsXnS5/qiS9gJonzpB4ZVCGsSsUZQO3WNX7uLhbtEi4HZtJjXAbXsJpik6tUaIQM+QO+of67SA+VS2K0b4Ei3ySs6Ro96uQRqbpZq98tGNywpqqi8moCD/G410CxPCidta6t64jgMigJr1llhzUDNa6KnEZTTof0D9E4HPYm+zQelRa3xDSYojw3VGUr+Ar0gopsyYLUlUgJJLTA4nzKfL7CP0d2+9qrP7OvcpNexe9/PsXTh2rJPKqttYJjXTEzi4+a6GfpX/XF8E9mCAg1QyIl+wZtKhhJDdlwvFf58cddvgoQKBgQDU8znRH+/d253tFPhlqJcUpaNFPzv7r1R3WWt9e5QsHHy60r6CnDpHeu2Q+0xYfeqEonUstM8qCkNqFx68MghYp79SKSEXrPhELdV25GNvF1XjrNB8BNBgd+NO1FiSJjiwXHmZ9f+Sw967lVABZhCvykkKEORN/UVLEvxo+ppGMQKBgQC1QHfiQpmhmQ0mnok+s9VQtkdWl5SvYn0Urpghe31hjnUa30pGEPIlYhpJWpyN1kL77HHr9+NRDfR1pN1TDHf+P3Ru2Kue5C70vLqIWhVJxs6RKVAWAgnrfnBJsM4TVAR93uWHv8Livdj+wf3D/ZLb8FVeOa76pYeu4okAm8ojuwKBgA5AYOQwAPuWERGmz6DuEX5eP3kI7FjBuSNrppf1R0tUdLyEEh/nmLbj8TY8uzVI6AMMZE8joqGroitddL8fkhNs1o8HFaHh/5OAhcK5MjZjF2pvTFygbdmm7F2ANJVDXZPf/HtjTUFjPmrLaVlOnVtGbHDyBHV7t8F4edAExYJhAoGAUUKT/OarBh4eHUBae7gYXNU76oCO8oqPVWRpZCl/Luu1aNTO8dbLGSOAcX6kTZrP8S4ybP539XDyNoQxjfg7G8vLIZ8WYmge/S5X2qW4gZkWJ1KESzmixOes4/zWhyfV07DI6zF36DwBO0YxxVq8Ksr3GwV1g34O9MMvdQxjdd0CgYBu00EaXBQaxANpO+6oH3KECxvxspKZvk4exI72OFbZ1mZayHNG7BVyfuAMNNp/SRoFXGC4/dVq+tycIOQutvRHrBSRRsv1db8No1j8oEYHvQ5br7OxjS941S/KWeIZefBAyajyCzUjIDZBRTBMGVyJ2p2c/SdUmPs2XTMQnG+mUg==",
|
||||
"JSON",
|
||||
"UTF-8",
|
||||
"MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAvAodOIG6vaqMsl5DXjcRYPRro+C/SeTswVo5gqQdikK3qy118GWkVwL9gvEovq23EMCTmSV+KAFsHz8f0UxLEK9FZcfRuM5E7GfnP7sdY0ctjfmUhQ7fWVOTGLuH0h5DiQ+4voO/2Hi6SElvtLXAUBSqMKw6J0PsJ0uUY9CBZCQnZkFJWAAroUWw5ARUMy62KPZSAW2s8Qg4gacdhSk7SBACNGBFcJZHCS09xQJi5SxCHaTRLhhIckLBvuKEWhBsh+jU75BKYAC4ovoWhMAFnIWKwCmubhXqmYjuJ4egUQTQBbD1hasK99I1YzdXRH8OKwKD4Lufb42B9buZ/2hOywIDAQAB",
|
||||
"RSA2");
|
||||
AlipayTradeWapPayRequest request = new AlipayTradeWapPayRequest();
|
||||
//异步接收地址,仅支持http/https,公网可访问
|
||||
request.setNotifyUrl("");
|
||||
//同步跳转地址,仅支持http/https
|
||||
request.setReturnUrl("");
|
||||
/******必传参数******/
|
||||
JSONObject bizContent = new JSONObject();
|
||||
//商户订单号,商家自定义,保持唯一性
|
||||
bizContent.put("out_trade_no", "2088721039266985");
|
||||
//支付金额,最小值0.01元
|
||||
bizContent.put("total_amount", 0.01);
|
||||
//订单标题,不可使用特殊符号
|
||||
bizContent.put("subject", "测试商品");
|
||||
|
||||
/******可选参数******/
|
||||
//手机网站支付默认传值QUICK_WAP_WAY
|
||||
bizContent.put("product_code", "QUICK_WAP_WAY");
|
||||
//bizContent.put("time_expire", "2022-08-01 22:00:00");
|
||||
|
||||
//// 商品明细信息,按需传入
|
||||
//JSONArray goodsDetail = new JSONArray();
|
||||
//JSONObject goods1 = new JSONObject();
|
||||
//goods1.put("goods_id", "goodsNo1");
|
||||
//goods1.put("goods_name", "子商品1");
|
||||
//goods1.put("quantity", 1);
|
||||
//goods1.put("price", 0.01);
|
||||
//goodsDetail.add(goods1);
|
||||
//bizContent.put("goods_detail", goodsDetail);
|
||||
|
||||
//// 扩展信息,按需传入
|
||||
//JSONObject extendParams = new JSONObject();
|
||||
//extendParams.put("sys_service_provider_id", "2088511833207846");
|
||||
//bizContent.put("extend_params", extendParams);
|
||||
|
||||
request.setBizContent(bizContent.toString());
|
||||
AlipayTradeWapPayResponse response = null;
|
||||
try {
|
||||
response = alipayClient.pageExecute(request,"POST");
|
||||
} catch (AlipayApiException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
// 如果需要返回GET请求,请使用
|
||||
// AlipayTradeWapPayResponse response = alipayClient.pageExecute(request,"GET");
|
||||
String pageRedirectionData = response.getBody();
|
||||
System.out.println(pageRedirectionData);
|
||||
|
||||
if(response.isSuccess()){
|
||||
System.out.println("调用成功");
|
||||
} else {
|
||||
System.out.println("调用失败");
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue