dev-v2 #3
|
@ -50,11 +50,11 @@ spring:
|
|||
- id: service-order
|
||||
uri: lb://service-order
|
||||
predicates:
|
||||
- Path=/*/order/*/**
|
||||
- Path=/*/order/orderInfo/**
|
||||
- id: service-pay
|
||||
uri: lb://service-pay
|
||||
predicates:
|
||||
- Path=/*/*/alipay/**
|
||||
- Path=/*/order/alipay/**
|
||||
data:
|
||||
redis:
|
||||
host: ${bunny.redis.host}
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
-----------------▄██-█▄---------
|
||||
-----------------███▄██▄--------
|
||||
-----------------███████--------
|
||||
-----------------▀███████-------
|
||||
-------------------██████▄▄-----
|
||||
-------------------█████████▄---
|
||||
-------------------██████▄████--
|
||||
-------▄███████████████████████-
|
||||
-----▄███████████████████████▀--
|
||||
---▄██████████████████████------
|
||||
---███████████████████████------
|
||||
---███████████████████████------
|
||||
-▄▄██████████████████████▀------
|
||||
-█████████████████▀█████--------
|
||||
-▀██████████████▀▀-▀█████▄------
|
||||
-------▀▀▀▀▀▀▀▀▀------▀▀▀▀------
|
Binary file not shown.
After Width: | Height: | Size: 13 KiB |
|
@ -1,14 +1,14 @@
|
|||
package com.atguigu.pay;
|
||||
|
||||
import com.atguigu.pay.properties.AlipayProperties;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.cloud.openfeign.EnableFeignClients;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
|
||||
@SpringBootApplication
|
||||
@EnableConfigurationProperties(value = {AlipayProperties.class})
|
||||
// @EnableConfigurationProperties(value = {AlipayProperties.class})
|
||||
@ComponentScan("com.atguigu")
|
||||
@EnableFeignClients(basePackages = {"com.atguigu.feign"})
|
||||
@Slf4j
|
||||
public class PayApplication {
|
||||
|
|
|
@ -3,17 +3,20 @@ package com.atguigu.pay.configuration;
|
|||
import com.alipay.api.AlipayClient;
|
||||
import com.alipay.api.DefaultAlipayClient;
|
||||
import com.atguigu.pay.properties.AlipayProperties;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration
|
||||
@Slf4j
|
||||
public class AlipayConfiguration {
|
||||
@Autowired
|
||||
private AlipayProperties alipayProperties;
|
||||
|
||||
@Bean
|
||||
public AlipayClient alipayClient() {
|
||||
log.info("注入===>AlipayConfiguration");
|
||||
return new DefaultAlipayClient(alipayProperties.getAlipayUrl(),
|
||||
alipayProperties.getAppId(),
|
||||
alipayProperties.getAppPrivateKey(),
|
||||
|
|
|
@ -1,26 +1,67 @@
|
|||
package com.atguigu.pay.controller;
|
||||
|
||||
import com.alipay.api.AlipayApiException;
|
||||
import com.alipay.api.internal.util.AlipaySignature;
|
||||
import com.atguigu.pay.properties.AlipayProperties;
|
||||
import com.atguigu.pay.service.AlipayService;
|
||||
import com.atguigu.pay.service.PaymentInfoService;
|
||||
import com.atguigu.spzx.model.vo.result.Result;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@RestController
|
||||
@Tag(name = "支付宝接口")
|
||||
@RequestMapping("/api/order/alipay")
|
||||
@Slf4j
|
||||
public class AlipayController {
|
||||
@Autowired
|
||||
private AlipayService alipayService;
|
||||
@Autowired
|
||||
private AlipayProperties alipayProperties;
|
||||
@Autowired
|
||||
private PaymentInfoService paymentInfoService;
|
||||
|
||||
@Operation(summary = "支付宝下单")
|
||||
@GetMapping("submitAlipay/{orderNo}")
|
||||
@ResponseBody
|
||||
public Result<String> submitAlipay(@Parameter(name = "orderNo", description = "订单号", required = true) @PathVariable(value = "orderNo") String orderNo) throws AlipayApiException {
|
||||
public Result<String> submitAlipay(@Parameter(name = "orderNo", description = "订单号", required = true)
|
||||
@PathVariable(value = "orderNo") String orderNo) throws AlipayApiException {
|
||||
String form = alipayService.submitAlipay(orderNo);
|
||||
return Result.success(form);
|
||||
}
|
||||
|
||||
@Operation(summary = "支付宝异步回调")
|
||||
@RequestMapping("callback/notify")
|
||||
@ResponseBody
|
||||
public String alipayNotify(@RequestParam Map<String, String> paramMap, HttpServletRequest request) {
|
||||
log.info("AlipayController...alipayNotify方法执行了...");
|
||||
boolean signVerified = false; // 调用SDK验证签名
|
||||
try {
|
||||
signVerified = AlipaySignature.rsaCheckV1(paramMap, alipayProperties.getAlipayPublicKey(), AlipayProperties.charset, AlipayProperties.sign_type);
|
||||
} catch (AlipayApiException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
// 交易状态
|
||||
String trade_status = paramMap.get("trade_status");
|
||||
// true
|
||||
if (signVerified) {
|
||||
// TODO 验签成功后,按照支付结果异步通知中的描述,对支付结果中的业务内容进行二次校验,校验成功后在response中返回success并继续商户自身业务处理,校验失败返回failure
|
||||
if ("TRADE_SUCCESS".equals(trade_status) || "TRADE_FINISHED".equals(trade_status)) {
|
||||
// 正常的支付成功,我们应该更新交易记录状态
|
||||
paymentInfoService.updatePaymentStatus(paramMap, 2);
|
||||
return "success";
|
||||
}
|
||||
} else {
|
||||
// TODO 验签失败则记录异常日志,并在response中返回failure.
|
||||
return "failure";
|
||||
}
|
||||
return "failure";
|
||||
}
|
||||
}
|
|
@ -19,4 +19,11 @@ public interface PaymentInfoMapper {
|
|||
* @param paymentInfo paymentInfo
|
||||
*/
|
||||
void save(PaymentInfo paymentInfo);
|
||||
|
||||
/**
|
||||
* 根据ID进行更新
|
||||
*
|
||||
* @param paymentInfo 支付信息实体类
|
||||
*/
|
||||
void updateById(PaymentInfo paymentInfo);
|
||||
}
|
||||
|
|
|
@ -2,6 +2,8 @@ package com.atguigu.pay.service;
|
|||
|
||||
import com.atguigu.spzx.model.entity.pay.PaymentInfo;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public interface PaymentInfoService {
|
||||
/**
|
||||
* 保存支付记录
|
||||
|
@ -10,4 +12,12 @@ public interface PaymentInfoService {
|
|||
* @return 支付信息
|
||||
*/
|
||||
PaymentInfo savePaymentInfo(String orderNo);
|
||||
|
||||
/**
|
||||
* 支付完成后更新状态
|
||||
*
|
||||
* @param paramMap paramMap
|
||||
* @param i i
|
||||
*/
|
||||
void updatePaymentStatus(Map<String, String> paramMap, int i);
|
||||
}
|
||||
|
|
|
@ -23,10 +23,8 @@ import java.util.HashMap;
|
|||
public class AlipayServiceImpl implements AlipayService {
|
||||
@Autowired
|
||||
private AlipayClient alipayClient;
|
||||
|
||||
@Autowired
|
||||
private PaymentInfoService paymentInfoService;
|
||||
|
||||
@Autowired
|
||||
private AlipayProperties alipayProperties;
|
||||
|
||||
|
@ -46,7 +44,6 @@ public class AlipayServiceImpl implements AlipayService {
|
|||
|
||||
// 同步回调
|
||||
alipayRequest.setReturnUrl(alipayProperties.getReturnPaymentUrl());
|
||||
|
||||
// 异步回调
|
||||
alipayRequest.setNotifyUrl(alipayProperties.getNotifyPaymentUrl());
|
||||
// 准备请求参数 ,声明一个map 集合
|
||||
|
@ -64,6 +61,7 @@ public class AlipayServiceImpl implements AlipayService {
|
|||
try {
|
||||
response = alipayClient.pageExecute(alipayRequest);
|
||||
} catch (AlipayApiException exception) {
|
||||
log.error("com.atguigu.pay.service.impl===>submitAlipay发送支付请求失败");
|
||||
throw new BunnyException(exception.getMessage());
|
||||
}
|
||||
|
||||
|
@ -71,7 +69,7 @@ public class AlipayServiceImpl implements AlipayService {
|
|||
log.info("调用成功");
|
||||
return response.getBody();
|
||||
} else {
|
||||
log.info("调用失败");
|
||||
log.error("调用失败");
|
||||
throw new BunnyException(ResultCodeEnum.DATA_ERROR);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.atguigu.pay.service.impl;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.atguigu.feign.order.OrderFeignClient;
|
||||
import com.atguigu.pay.mapper.PaymentInfoMapper;
|
||||
import com.atguigu.pay.service.PaymentInfoService;
|
||||
|
@ -9,6 +10,9 @@ import com.atguigu.spzx.model.entity.pay.PaymentInfo;
|
|||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.Map;
|
||||
|
||||
@Service
|
||||
public class PaymentInfoServiceImpl implements PaymentInfoService {
|
||||
@Autowired
|
||||
|
@ -46,4 +50,26 @@ public class PaymentInfoServiceImpl implements PaymentInfoService {
|
|||
}
|
||||
return paymentInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* 支付完成后更新状态
|
||||
*
|
||||
* @param paramMap paramMap
|
||||
* @param i i
|
||||
*/
|
||||
@Override
|
||||
public void updatePaymentStatus(Map<String, String> map, int i) {
|
||||
// 查询PaymentInfo
|
||||
PaymentInfo paymentInfo = paymentInfoMapper.getByOrderNo(map.get("out_trade_no"));
|
||||
if (paymentInfo.getPaymentStatus() == 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 更新支付信息
|
||||
paymentInfo.setPaymentStatus(1);
|
||||
paymentInfo.setOutTradeNo(map.get("trade_no"));
|
||||
paymentInfo.setCallbackTime(new Date());
|
||||
paymentInfo.setCallbackContent(JSON.toJSONString(map));
|
||||
paymentInfoMapper.updateById(paymentInfo);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,5 +3,5 @@ alipay:
|
|||
app_id: 2021000122609658
|
||||
app_private_key: MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQCXHXwKl51d5htttzJDQg1Oq+w/RAdjdGlTgGlodWxM5Vszd9IgnEff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U3Sy8faWdJ2yhZPrGA7faIyrk9w9mQClMupHLqBmCyVj2LNPkEol7JG4t5s0baPyuztq38UNCt1xWEky61ZZQOw+dlAoGAQdEhD0bEwlpCPZhQBn8jRlWaOun94jJjfreQRJgDiAXkYcu9aXnrHIPogrUOZJ3DXcSyBv2/FU5HlbVT6/nl/cLMqNUWj2O7grb5jyzmvJJnzXLaxK7bWjZQt/ssNt4mYFJNNG2cMgofzDsW0lYhMdh+CCy5Wv9nl3e3IUtNq/8CgYASPcPdaCBLzCSGlTV9HMhQwRhOpWLOzQNKprebQf0fubNFGd6+yfM6DdejHXf6KH4IgV9l8OPe5ro85tmrBkvMlbh7KHbpYJ/V9cdMKd+kbxoJTkRKCnoZhY5QSuEMoC8OB1qhzJeuoqUvmpi0q569IBXrxZguD29ZqwGxoa1KNg==
|
||||
alipay_public_key: MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAk41ooyX7utKM9B7jNcc4EzmyVU0Qfs18KFVFwyhl7YQMw/PB2YVQreVSvvb1rS/2YVxcjLK/9ehD//79b8aoxhFlEGqA7fGu0C2UR6pl+PhmRLcHeyN+DOG87Fhqb1t4JXmXQc1LXUfelJoh+r5XnMPWDAlY5JJtH3GZIU+AoBt9PuEtfhh03LL6WtnJMwOnqH94T8qHymLDftEGOWme1iAlenB692cUId20BmLJal621EAN+xpmkeJZEpx1wQ2fGhyTo7pm4v8LVLuqzOXkraffITvfbPl5IU0kjjs/QECwItAI0IBbNsDutezw/a0JobijjoF28uo4gtwmncBoQwIDAQAB
|
||||
return_payment_url: http://localhost/#/pages/money/paySuccess
|
||||
notify_payment_url: http://4c428eff.r7.cpolar.top/api/order/alipay/callback/notify
|
||||
return_payment_url: http://5e0d1fdf.r28.cpolar.top/#/pages/money/paySuccess
|
||||
notify_payment_url: https://4c428eff.r7.cpolar.top/api/order/alipay/callback/notify
|
|
@ -0,0 +1,16 @@
|
|||
-----------------▄██-█▄---------
|
||||
-----------------███▄██▄--------
|
||||
-----------------███████--------
|
||||
-----------------▀███████-------
|
||||
-------------------██████▄▄-----
|
||||
-------------------█████████▄---
|
||||
-------------------██████▄████--
|
||||
-------▄███████████████████████-
|
||||
-----▄███████████████████████▀--
|
||||
---▄██████████████████████------
|
||||
---███████████████████████------
|
||||
---███████████████████████------
|
||||
-▄▄██████████████████████▀------
|
||||
-█████████████████▀█████--------
|
||||
-▀██████████████▀▀-▀█████▄------
|
||||
-------▀▀▀▀▀▀▀▀▀------▀▀▀▀------
|
Binary file not shown.
After Width: | Height: | Size: 13 KiB |
|
@ -30,6 +30,41 @@
|
|||
#{callbackContent})
|
||||
</insert>
|
||||
|
||||
<!-- 根据ID进行更新 -->
|
||||
<update id="updateById">
|
||||
update payment_info set
|
||||
<if test="userId != null and userId != ''">
|
||||
user_id = #{userId},
|
||||
</if>
|
||||
<if test="orderNo != null and orderNo != ''">
|
||||
order_no = #{orderNo},
|
||||
</if>
|
||||
<if test="payType != null">
|
||||
pay_type = #{payType},
|
||||
</if>
|
||||
<if test="outTradeNo != null and outTradeNo != ''">
|
||||
out_trade_no = #{outTradeNo},
|
||||
</if>
|
||||
<if test="amount != null and amount != ''">
|
||||
amount = #{amount},
|
||||
</if>
|
||||
<if test="content != null and content != ''">
|
||||
content = #{content},
|
||||
</if>
|
||||
<if test="paymentStatus != null">
|
||||
payment_status = #{paymentStatus},
|
||||
</if>
|
||||
<if test="callbackTime != null">
|
||||
callback_time = #{callbackTime},
|
||||
</if>
|
||||
<if test="callbackContent != null and callbackContent != ''">
|
||||
callback_content = #{callbackContent},
|
||||
</if>
|
||||
update_time = now()
|
||||
where
|
||||
id = #{id}
|
||||
</update>
|
||||
|
||||
<!-- 根据订单编号查询支付记录 -->
|
||||
<select id="getByOrderNo" resultType="com.atguigu.spzx.model.entity.pay.PaymentInfo">
|
||||
select
|
||||
|
|
Loading…
Reference in New Issue