forked from macrozheng/mall
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9b4343e
commit b3bc051
Showing
13 changed files
with
434 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
mall-portal/src/main/java/com/macro/mall/portal/config/AlipayClientConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.macro.mall.portal.config; | ||
|
||
import com.alipay.api.AlipayClient; | ||
import com.alipay.api.DefaultAlipayClient; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
/** | ||
* @auther macrozheng | ||
* @description 支付宝请求客户端配置 | ||
* @date 2023/9/8 | ||
* @github https://github.com/macrozheng | ||
*/ | ||
@Configuration | ||
public class AlipayClientConfig { | ||
|
||
@Bean | ||
public AlipayClient alipayClient(AlipayConfig config){ | ||
return new DefaultAlipayClient(config.getGatewayUrl(),config.getAppId(),config.getAppPrivateKey(), config.getFormat(),config.getCharset(),config.getAlipayPublicKey(),config.getSignType()); | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
mall-portal/src/main/java/com/macro/mall/portal/config/AlipayConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package com.macro.mall.portal.config; | ||
|
||
import lombok.Getter; | ||
import lombok.Setter; | ||
import org.springframework.boot.context.properties.ConfigurationProperties; | ||
import org.springframework.stereotype.Component; | ||
|
||
/** | ||
* @auther macrozheng | ||
* @description 支付宝支付相关配置 | ||
* @date 2023/9/8 | ||
* @github https://github.com/macrozheng | ||
*/ | ||
@Getter | ||
@Setter | ||
@Component | ||
@ConfigurationProperties(prefix = "alipay") | ||
public class AlipayConfig { | ||
/** | ||
* 支付宝网关 | ||
*/ | ||
private String gatewayUrl; | ||
/** | ||
* 应用ID | ||
*/ | ||
private String appId; | ||
/** | ||
* 应用私钥 | ||
*/ | ||
private String appPrivateKey; | ||
/** | ||
* 支付宝公钥 | ||
*/ | ||
private String alipayPublicKey; | ||
/** | ||
* 用户确认支付后,支付宝调用的页面返回路径 | ||
* 开发环境为:http://localhost:8060/#/pages/money/paySuccess | ||
*/ | ||
private String returnUrl; | ||
/** | ||
* 支付成功后,支付宝服务器主动通知商户服务器里的异步通知回调(需要公网能访问) | ||
* 开发环境为:http://localhost:8085/alipay/notify | ||
*/ | ||
private String notifyUrl; | ||
/** | ||
* 参数返回格式,只支持JSON | ||
*/ | ||
private String format = "JSON"; | ||
/** | ||
* 请求使用的编码格式 | ||
*/ | ||
private String charset = "UTF-8"; | ||
/** | ||
* 生成签名字符串所使用的签名算法类型 | ||
*/ | ||
private String signType = "RSA2"; | ||
} |
74 changes: 74 additions & 0 deletions
74
mall-portal/src/main/java/com/macro/mall/portal/controller/AlipayController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package com.macro.mall.portal.controller; | ||
|
||
import com.macro.mall.common.api.CommonResult; | ||
import com.macro.mall.portal.config.AlipayConfig; | ||
import com.macro.mall.portal.domain.AliPayParam; | ||
import com.macro.mall.portal.service.AlipayService; | ||
import io.swagger.annotations.Api; | ||
import io.swagger.annotations.ApiOperation; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Controller; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestMethod; | ||
import org.springframework.web.bind.annotation.ResponseBody; | ||
|
||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
import java.io.IOException; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
/** | ||
* @auther macrozheng | ||
* @description 支付宝支付Controller | ||
* @date 2023/9/8 | ||
* @github https://github.com/macrozheng | ||
*/ | ||
@Controller | ||
@Api(tags = "AlipayController") | ||
@Tag(name = "AlipayController", description = "支付宝支付相关接口") | ||
@RequestMapping("/alipay") | ||
public class AlipayController { | ||
|
||
@Autowired | ||
private AlipayConfig alipayConfig; | ||
@Autowired | ||
private AlipayService alipayService; | ||
|
||
@ApiOperation("支付宝电脑网站支付") | ||
@RequestMapping(value = "/pay", method = RequestMethod.GET) | ||
public void pay(AliPayParam aliPayParam, HttpServletResponse response) throws IOException { | ||
response.setContentType("text/html;charset=" + alipayConfig.getCharset()); | ||
response.getWriter().write(alipayService.pay(aliPayParam)); | ||
response.getWriter().flush(); | ||
response.getWriter().close(); | ||
} | ||
|
||
@ApiOperation("支付宝手机网站支付") | ||
@RequestMapping(value = "/webPay", method = RequestMethod.GET) | ||
public void webPay(AliPayParam aliPayParam, HttpServletResponse response) throws IOException { | ||
response.setContentType("text/html;charset=" + alipayConfig.getCharset()); | ||
response.getWriter().write(alipayService.webPay(aliPayParam)); | ||
response.getWriter().flush(); | ||
response.getWriter().close(); | ||
} | ||
|
||
@ApiOperation(value = "支付宝异步回调",notes = "必须为POST请求,执行成功返回success,执行失败返回failure") | ||
@RequestMapping(value = "/notify", method = RequestMethod.POST) | ||
public String notify(HttpServletRequest request){ | ||
Map<String, String> params = new HashMap<>(); | ||
Map<String, String[]> requestParams = request.getParameterMap(); | ||
for (String name : requestParams.keySet()) { | ||
params.put(name, request.getParameter(name)); | ||
} | ||
return alipayService.notify(params); | ||
} | ||
|
||
@ApiOperation(value = "支付宝统一收单线下交易查询",notes = "订单支付成功返回:TRADE_SUCCESS") | ||
@RequestMapping(value = "/query", method = RequestMethod.GET) | ||
@ResponseBody | ||
public CommonResult<String> query(String outTradeNo, String tradeNo){ | ||
return CommonResult.success(alipayService.query(outTradeNo,tradeNo)); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
mall-portal/src/main/java/com/macro/mall/portal/domain/AliPayParam.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package com.macro.mall.portal.domain; | ||
|
||
import lombok.Data; | ||
|
||
import java.math.BigDecimal; | ||
|
||
/** | ||
* @auther macrozheng | ||
* @description 支付宝支付请求参数 | ||
* @date 2023/9/8 | ||
* @github https://github.com/macrozheng | ||
*/ | ||
@Data | ||
public class AliPayParam { | ||
/** | ||
* 商户订单号,商家自定义,保持唯一性 | ||
*/ | ||
private String outTradeNo; | ||
/** | ||
* 商品的标题/交易标题/订单标题/订单关键字等 | ||
*/ | ||
private String subject; | ||
/** | ||
* 订单总金额,单位为元,精确到小数点后两位 | ||
*/ | ||
private BigDecimal totalAmount; | ||
} |
36 changes: 36 additions & 0 deletions
36
mall-portal/src/main/java/com/macro/mall/portal/service/AlipayService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package com.macro.mall.portal.service; | ||
|
||
|
||
import com.macro.mall.portal.domain.AliPayParam; | ||
|
||
import java.util.Map; | ||
|
||
/** | ||
* @auther macrozheng | ||
* @description 支付宝支付Service | ||
* @date 2023/9/8 | ||
* @github https://github.com/macrozheng | ||
*/ | ||
public interface AlipayService { | ||
/** | ||
* 根据提交参数生成电脑支付页面 | ||
*/ | ||
String pay(AliPayParam aliPayParam); | ||
|
||
/** | ||
* 支付宝异步回调处理 | ||
*/ | ||
String notify(Map<String, String> params); | ||
|
||
/** | ||
* @param outTradeNo 商户订单编号 | ||
* @param tradeNo 支付宝交易编号 | ||
* @return 支付宝交易状态 | ||
*/ | ||
String query(String outTradeNo, String tradeNo); | ||
|
||
/** | ||
* 根据提交参数生成手机支付页面 | ||
*/ | ||
String webPay(AliPayParam aliPayParam); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.