李雨欣 8.27 19:09 测试查询
parent
fd3647778c
commit
6c4373f0f2
|
@ -22,5 +22,17 @@
|
||||||
<groupId>com.muyu</groupId>
|
<groupId>com.muyu</groupId>
|
||||||
<artifactId>cloud-common-core</artifactId>
|
<artifactId>cloud-common-core</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<!--支付宝依赖 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.alipay.sdk</groupId>
|
||||||
|
<artifactId>alipay-easysdk</artifactId>
|
||||||
|
<version>2.2.0</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.alipay.sdk</groupId>
|
||||||
|
<artifactId>alipay-sdk-java</artifactId>
|
||||||
|
<version>4.22.113.ALL</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
||||||
|
|
|
@ -9,6 +9,8 @@ import com.fasterxml.jackson.annotation.JsonFormat;
|
||||||
import com.muyu.common.core.annotation.Excel;
|
import com.muyu.common.core.annotation.Excel;
|
||||||
import com.muyu.common.core.web.domain.BaseEntity;
|
import com.muyu.common.core.web.domain.BaseEntity;
|
||||||
|
|
||||||
|
import com.muyu.market.admain.request.OrdersUpdResp;
|
||||||
|
import com.muyu.market.admain.request.ProductUpdReq;
|
||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
@ -18,6 +20,7 @@ import lombok.experimental.SuperBuilder;
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
@SuperBuilder
|
@SuperBuilder
|
||||||
|
@ -78,4 +81,21 @@ public class Orders extends BaseEntity {
|
||||||
private String note;
|
private String note;
|
||||||
|
|
||||||
|
|
||||||
|
public static Orders UpdOrdersReq(OrdersUpdResp ordersUpdResp, Supplier<Long> orderId){
|
||||||
|
|
||||||
|
return Orders
|
||||||
|
.builder()
|
||||||
|
.orderId(orderId.get())
|
||||||
|
.userId(ordersUpdResp.getUserId())
|
||||||
|
.productId(ordersUpdResp.getProductId())
|
||||||
|
.orderNo(ordersUpdResp.getOrderNo())
|
||||||
|
.orderStatus(ordersUpdResp.getOrderStatus())
|
||||||
|
.totalAmount(ordersUpdResp.getTotalAmount())
|
||||||
|
.createTime(ordersUpdResp.getCreateTime())
|
||||||
|
.updateTime(ordersUpdResp.getUpdateTime())
|
||||||
|
.note(ordersUpdResp.getNote())
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,70 @@
|
||||||
|
package com.muyu.market.admain.request;
|
||||||
|
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import lombok.experimental.SuperBuilder;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
@SuperBuilder
|
||||||
|
@Tag(name = "订单查询", description = "订单查询")
|
||||||
|
public class OrdersUpdResp {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 订单的唯一标识
|
||||||
|
*/
|
||||||
|
@Schema(type = "Long",description = "订单ID",defaultValue = "1")
|
||||||
|
private Long orderId;
|
||||||
|
/**
|
||||||
|
*用户ID
|
||||||
|
*/
|
||||||
|
@Schema(type = "Long",defaultValue = "用户ID",description = "用户ID")
|
||||||
|
private Long userId;
|
||||||
|
/**
|
||||||
|
* 商品ID
|
||||||
|
*/
|
||||||
|
@Schema(type = "Long",defaultValue = "商品ID",description = "1")
|
||||||
|
private Long productId;
|
||||||
|
/**
|
||||||
|
* 订单号
|
||||||
|
*/
|
||||||
|
@Schema(type = "String",defaultValue = "订单号",description = "订单号")
|
||||||
|
private String orderNo;
|
||||||
|
/**
|
||||||
|
* 订单状态
|
||||||
|
*/
|
||||||
|
@Schema(type = "String",defaultValue = "订单状态",description = "订单状态")
|
||||||
|
private String orderStatus;
|
||||||
|
/**
|
||||||
|
* 订单总金额
|
||||||
|
*/
|
||||||
|
@Schema(type = "BigDecimal",defaultValue = "25.3",description = "订单总金额")
|
||||||
|
private BigDecimal totalAmount;
|
||||||
|
/**
|
||||||
|
* 订单创建时间
|
||||||
|
*/
|
||||||
|
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||||
|
@Schema(description = "订单创建时间",defaultValue = "2024-5-15 10:00:52",type = "Date")
|
||||||
|
private Date createTime;
|
||||||
|
/**
|
||||||
|
* 订单更新时间
|
||||||
|
*/
|
||||||
|
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||||
|
@Schema(description = "订单更新时间",defaultValue = "2024-5-15 10:00:52",type = "Date")
|
||||||
|
private Date updateTime;
|
||||||
|
/**
|
||||||
|
* 订单备注
|
||||||
|
*/
|
||||||
|
@Schema(type = "String",defaultValue = "订单备注",description = "订单备注")
|
||||||
|
private String note;
|
||||||
|
|
||||||
|
}
|
|
@ -10,6 +10,7 @@ import lombok.NoArgsConstructor;
|
||||||
import lombok.experimental.SuperBuilder;
|
import lombok.experimental.SuperBuilder;
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
|
@ -53,13 +54,13 @@ public class OrdersSelectResp {
|
||||||
*/
|
*/
|
||||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||||
@Schema(description = "订单创建时间",defaultValue = "2024-5-15 10:00:52",type = "Date")
|
@Schema(description = "订单创建时间",defaultValue = "2024-5-15 10:00:52",type = "Date")
|
||||||
private Data createTime;
|
private Date createTime;
|
||||||
/**
|
/**
|
||||||
* 订单更新时间
|
* 订单更新时间
|
||||||
*/
|
*/
|
||||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||||
@Schema(description = "订单更新时间",defaultValue = "2024-5-15 10:00:52",type = "Date")
|
@Schema(description = "订单更新时间",defaultValue = "2024-5-15 10:00:52",type = "Date")
|
||||||
private Data updateTime;
|
private Date updateTime;
|
||||||
/**
|
/**
|
||||||
* 订单备注
|
* 订单备注
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -0,0 +1,42 @@
|
||||||
|
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初始化成功=======");
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,17 @@
|
||||||
|
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 subject;
|
||||||
|
private String alipayTraceNo;
|
||||||
|
}
|
|
@ -73,6 +73,12 @@
|
||||||
<artifactId>cloud-common-api-doc</artifactId>
|
<artifactId>cloud-common-api-doc</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.muyu</groupId>
|
||||||
|
<artifactId>cloud-market-common</artifactId>
|
||||||
|
<version>1.0.0</version>
|
||||||
|
</dependency>
|
||||||
<!-- XllJob定时任务 -->
|
<!-- XllJob定时任务 -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.muyu</groupId>
|
<groupId>com.muyu</groupId>
|
||||||
|
|
|
@ -4,11 +4,13 @@ import com.muyu.common.security.annotation.EnableCustomConfig;
|
||||||
import com.muyu.common.security.annotation.EnableMyFeignClients;
|
import com.muyu.common.security.annotation.EnableMyFeignClients;
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||||
|
|
||||||
|
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
@EnableCustomConfig
|
@EnableCustomConfig
|
||||||
@EnableMyFeignClients
|
@EnableMyFeignClients
|
||||||
|
//@EnableScheduling
|
||||||
public class MarketApplication {
|
public class MarketApplication {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
SpringApplication.run(MarketApplication.class);
|
SpringApplication.run(MarketApplication.class);
|
||||||
|
|
|
@ -0,0 +1,42 @@
|
||||||
|
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初始化成功=======");
|
||||||
|
}
|
||||||
|
}
|
|
@ -3,12 +3,15 @@ package com.muyu.market.server.controller;
|
||||||
import com.muyu.common.core.domain.Result;
|
import com.muyu.common.core.domain.Result;
|
||||||
import com.muyu.market.admain.Orders;
|
import com.muyu.market.admain.Orders;
|
||||||
import com.muyu.market.admain.Product;
|
import com.muyu.market.admain.Product;
|
||||||
|
import com.muyu.market.admain.request.OrdersUpdResp;
|
||||||
import com.muyu.market.admain.response.OrdersSelectResp;
|
import com.muyu.market.admain.response.OrdersSelectResp;
|
||||||
import com.muyu.market.server.service.OrdersService;
|
import com.muyu.market.server.service.OrdersService;
|
||||||
import io.swagger.v3.oas.annotations.Operation;
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
import lombok.extern.log4j.Log4j2;
|
import lombok.extern.log4j.Log4j2;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -23,6 +26,8 @@ public class OrdersController {
|
||||||
@Autowired
|
@Autowired
|
||||||
private OrdersService orderService;
|
private OrdersService orderService;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 点击下单 添加订单信息
|
* 点击下单 添加订单信息
|
||||||
* @param product
|
* @param product
|
||||||
|
@ -50,5 +55,39 @@ public class OrdersController {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据ID删除订单
|
||||||
|
* @param orderId
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@DeleteMapping
|
||||||
|
@Operation(summary = "刪除订单",description = "根据订单Id 删除订单")
|
||||||
|
public Result<String> removeById(@RequestParam(value = "orderId") Long orderId){
|
||||||
|
orderService.removeById(orderId);
|
||||||
|
return Result.success(null,"操作成功");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改订单
|
||||||
|
* @param orderId
|
||||||
|
* @param ordersUpdResp
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@PutMapping("/{orderId}")
|
||||||
|
@Operation(summary = "订单的修改",description = "通过ID修改订单")
|
||||||
|
public Result<String> update(
|
||||||
|
@Schema(title = "订单ID",type = "Long",description = "修改订单信息",defaultValue = "1")
|
||||||
|
@PathVariable("orderId") Long orderId,
|
||||||
|
@RequestBody @Validated OrdersUpdResp ordersUpdResp){
|
||||||
|
|
||||||
|
orderService.updateById(Orders.UpdOrdersReq(ordersUpdResp,()->orderId));
|
||||||
|
return Result.success(null,"操作成功");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,40 @@
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,161 @@
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,5 +1,6 @@
|
||||||
package com.muyu.market.server.service.Impl;
|
package com.muyu.market.server.service.Impl;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
import com.muyu.market.admain.Orders;
|
import com.muyu.market.admain.Orders;
|
||||||
import com.muyu.market.admain.Product;
|
import com.muyu.market.admain.Product;
|
||||||
|
@ -7,8 +8,12 @@ import com.muyu.market.admain.response.OrdersSelectResp;
|
||||||
import com.muyu.market.server.mapper.OrdersMapper;
|
import com.muyu.market.server.mapper.OrdersMapper;
|
||||||
import com.muyu.market.server.service.OrdersService;
|
import com.muyu.market.server.service.OrdersService;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.scheduling.annotation.Scheduled;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import com.muyu.common.security.utils.SecurityUtils;
|
import com.muyu.common.security.utils.SecurityUtils;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.time.temporal.ChronoUnit;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
@ -52,6 +57,8 @@ public class OrdersServiceImpl extends ServiceImpl<OrdersMapper, Orders> impleme
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -60,4 +67,31 @@ public class OrdersServiceImpl extends ServiceImpl<OrdersMapper, Orders> impleme
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// /**
|
||||||
|
// * 定时任务:每天执行一次,检查并取消24小时前未支付的订单
|
||||||
|
// */
|
||||||
|
// @Scheduled(cron = "0 0 0 * * ?") // 每天的0点0分0秒执行
|
||||||
|
// public void cancelUnpaidOrders() {
|
||||||
|
//
|
||||||
|
// LocalDateTime now = LocalDateTime.now();
|
||||||
|
// LocalDateTime threshold = now.minus(24, ChronoUnit.HOURS); // 24小时前的时间点
|
||||||
|
//
|
||||||
|
// // Orders实体中有一个createTime字段表示订单的创建时间
|
||||||
|
// QueryWrapper<Orders> queryWrapper = new QueryWrapper<>();
|
||||||
|
// queryWrapper.lt("create_time", threshold.toString()) // 创建时间小于24小时前
|
||||||
|
// .eq("status", "未支付"); // 订单状态为未支付
|
||||||
|
//
|
||||||
|
// // 执行查询并取消订单
|
||||||
|
// List<Orders> unpaidOrders = orderMapper.selectList(queryWrapper);
|
||||||
|
// for (Orders order : unpaidOrders) {
|
||||||
|
// // 取消订单的逻辑,比如更新订单状态为已取消
|
||||||
|
// order.setOrderStatus("已取消");
|
||||||
|
// orderMapper.updateById(order);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,17 @@
|
||||||
|
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;
|
||||||
|
}
|
|
@ -0,0 +1,73 @@
|
||||||
|
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+wZtKhhJD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jfmUhQ7fWVOTGLuH0h5DiQ+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("调用失败");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -54,3 +54,8 @@ spring:
|
||||||
logging:
|
logging:
|
||||||
level:
|
level:
|
||||||
com.muyu.system.mapper: DEBUG
|
com.muyu.system.mapper: DEBUG
|
||||||
|
alipay:
|
||||||
|
appId: 9021000140631838
|
||||||
|
appPrivateKey: MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQCWxZholdxU/C9Vh+4hjD4yWH5MUn3ZK7zkFKB09KY1Kz5k6t0fhcdMRbTaJulyQVL21wneb83f+5hhAzk9+j6RLrvIbE1YZyvt9uoUIpljMkEFyVL2L97/m/Bc+D+PMXMor0DxWMgdkGvmm/1Phjaoxr+HZn6WI1ZFXjKNdIUMNs8H5oLXkBpfTVDS8GLXfDxrUT2gx9g2AH8NJMLlWObHwG3ZPQenRg5szhjLHxuuNgcfJXyoW0agSnRqzn8QeYyq5H0XVElrtF+JbBsnvuUgJn/+h/oVoKeFekEYjfqogzx/1oROereXdEk3OxmzrlW0+EUYBEMViv7EGi0z8/jLAgMBAAECggEAYDm+OsmidK76+silZ83dCD7IZKelYEx04tBzVBGsXnS5/qiS9gJonzpB4ZVCGsSsUZQO3WNX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S/KWeIZefBAyajyCzUjIDZBRTBMGVyJ2p2c/SdUmPs2XTMQnG+mUg==
|
||||||
|
alipayPublicKey: MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAvAodOIG6vaqMsl5DXjcRYPRro+C/SeTswVo5gqQdikK3qy118GWkVwL9gvEovq23EMCTmSV+KAFsHz8f0UxLEK9FZcfRuM5E7GfnP7sdY0ctjfmUhQ7fWVOTGLuH0h5DiQ+4voO/2Hi6SElvtLXAUBSqMKw6J0PsJ0uUY9CBZCQnZkFJWAAroUWw5ARUMy62KPZSAW2s8Qg4gacdhSk7SBACNGBFcJZHCS09xQJi5SxCHaTRLhhIckLBvuKEWhBsh+jU75BKYAC4ovoWhMAFnIWKwCmubhXqmYjuJ4egUQTQBbD1hasK99I1YzdXRH8OKwKD4Lufb42B9buZ/2hOywIDAQAB
|
||||||
|
notifyUrl: http://r68vnm.natappfree.cc/notify
|
||||||
|
|
Loading…
Reference in New Issue