7 changed files with 0 additions and 306 deletions
-
28src/main/java/com/example/demo/DemoApplicationBank.java
-
28src/main/java/com/example/demo/bank/Server.java
-
44src/main/java/com/example/demo/controller/cash/BankController.java
-
21src/main/java/com/example/demo/domain/DTO/BankDTO.java
-
30src/main/java/com/example/demo/domain/DTO/PaymentDTO.java
-
18src/main/java/com/example/demo/service/cash/BankService.java
-
137src/main/java/com/example/demo/serviceImpl/cash/BankServiceImpl.java
@ -1,28 +0,0 @@ |
|||||
package com.example.demo; |
|
||||
|
|
||||
|
|
||||
|
|
||||
import org.mybatis.spring.annotation.MapperScan; |
|
||||
import org.springframework.boot.SpringApplication; |
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication; |
|
||||
import org.springframework.scheduling.annotation.EnableScheduling; |
|
||||
|
|
||||
@EnableScheduling // 启用调度功能 |
|
||||
@SpringBootApplication |
|
||||
@MapperScan(basePackages = "com.example.demo.mapper.coin", sqlSessionTemplateRef = "mysql1SqlSessionTemplate") |
|
||||
@MapperScan(basePackages = "com.example.demo.mapper.bean", sqlSessionTemplateRef = "mysql2SqlSessionTemplate") |
|
||||
@MapperScan(basePackages = "com.example.demo.mapper.pay", sqlSessionTemplateRef = "mysql3SqlSessionTemplate") |
|
||||
@MapperScan(basePackages = "com.example.demo.mapper.cms", sqlSessionTemplateRef = "mysql4SqlSessionTemplate") |
|
||||
@MapperScan(basePackages = "com.example.demo.mapper.live", sqlSessionTemplateRef = "mysql5SqlSessionTemplate") |
|
||||
@MapperScan(basePackages = "com.example.demo.mapper.sqlserver", sqlSessionTemplateRef = "sqlserver1SqlSessionTemplate") |
|
||||
@MapperScan(basePackages = "com.example.demo.mapper.cash", sqlSessionTemplateRef = "mysql1SqlSessionTemplate") |
|
||||
public class DemoApplicationBank { |
|
||||
|
|
||||
public static void main(String[] args) { |
|
||||
System.setProperty("https.protocols", "TLSv1,TLSv1.2,TLSv1.3"); |
|
||||
// 设置客户端协议版本 |
|
||||
System.setProperty("jdk.tls.client.protocols", "TLSv1,TLSv1.2,TLSv1.3"); |
|
||||
SpringApplication.run(DemoApplication.class, args); |
|
||||
} |
|
||||
|
|
||||
} |
|
||||
@ -1,28 +0,0 @@ |
|||||
package com.example.demo.bank; |
|
||||
|
|
||||
import com.stripe.Stripe; |
|
||||
import com.stripe.exception.StripeException; |
|
||||
import com.stripe.model.*; |
|
||||
import com.stripe.param.*; |
|
||||
|
|
||||
public class Server { |
|
||||
public static void main(String[] args) throws StripeException { |
|
||||
// Stripe.apiKey = "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"; |
|
||||
|
|
||||
// BalanceTransactionListParams params = |
|
||||
// BalanceTransactionListParams.builder().setLimit(3L).build(); |
|
||||
// BalanceTransactionCollection balanceTransactions = BalanceTransaction.list(params); |
|
||||
// System.out.println(balanceTransactions); |
|
||||
// BalanceTransaction balanceTransaction = |
|
||||
// BalanceTransaction.retrieve("txn_3SNkDjJHMNYcqBc01q4yHgvq"); |
|
||||
// System.out.println(balanceTransaction); |
|
||||
// Charge resource = Charge.retrieve("ch_3MrVHGLkdIwHu7ix1mN3zEiP"); |
|
||||
// ChargeCaptureParams params = ChargeCaptureParams.builder().build(); |
|
||||
// Charge charge = resource.capture(params); |
|
||||
// System.out.println(charge); |
|
||||
// ChargeListParams params = ChargeListParams.builder().setLimit(1L).build(); |
|
||||
// ChargeCollection charges = Charge.list(params); |
|
||||
// System.out.println(charges); |
|
||||
|
|
||||
} |
|
||||
} |
|
||||
@ -1,44 +0,0 @@ |
|||||
package com.example.demo.controller.cash; |
|
||||
|
|
||||
import com.example.demo.config.interfac.Log; |
|
||||
import com.example.demo.domain.DTO.BankDTO; |
|
||||
import com.example.demo.domain.vo.cash.Bank; |
|
||||
import com.example.demo.domain.vo.coin.AuditRequest; |
|
||||
import com.example.demo.domain.vo.coin.Result; |
|
||||
import com.example.demo.service.cash.BankService; |
|
||||
import com.example.demo.service.cash.CashAuditService; |
|
||||
import lombok.RequiredArgsConstructor; |
|
||||
import lombok.extern.slf4j.Slf4j; |
|
||||
import org.springframework.beans.factory.annotation.Autowired; |
|
||||
import org.springframework.web.bind.annotation.*; |
|
||||
|
|
||||
/** |
|
||||
* @program: gold-java |
|
||||
* @ClassName BankController |
|
||||
* @description: |
|
||||
* @author: Double |
|
||||
* @create: 2025−10-27 10:50 |
|
||||
* @Version 1.0 |
|
||||
**/ |
|
||||
|
|
||||
@RestController |
|
||||
@RequestMapping("/admin/cash/bank") |
|
||||
@RequiredArgsConstructor |
|
||||
@Slf4j |
|
||||
@CrossOrigin |
|
||||
public class BankController { |
|
||||
|
|
||||
@Autowired |
|
||||
private BankService bankService; |
|
||||
|
|
||||
//payment银行接口 |
|
||||
@Log("payment银行接口") |
|
||||
@PostMapping("/payment") |
|
||||
public Result getPayment(@RequestBody Bank bank){ |
|
||||
try { |
|
||||
BankDTO bankDTO = bankService.getPayment(bank); |
|
||||
return Result.success(bankDTO); |
|
||||
}catch (Exception e){ |
|
||||
return Result.error(e.getMessage()); |
|
||||
}} |
|
||||
} |
|
||||
@ -1,21 +0,0 @@ |
|||||
package com.example.demo.domain.DTO; |
|
||||
|
|
||||
import lombok.Data; |
|
||||
import lombok.NoArgsConstructor; |
|
||||
|
|
||||
import java.util.List; |
|
||||
|
|
||||
/** |
|
||||
* @program: gold-java |
|
||||
* @ClassName BankDTO |
|
||||
* @description: |
|
||||
* @author: Double |
|
||||
* @create: 2025−10-27 11:16 |
|
||||
* @Version 1.0 |
|
||||
**/ |
|
||||
|
|
||||
@Data |
|
||||
@NoArgsConstructor |
|
||||
public class BankDTO { |
|
||||
private List<PaymentDTO> paymentDTOList; |
|
||||
} |
|
||||
@ -1,30 +0,0 @@ |
|||||
package com.example.demo.domain.DTO; |
|
||||
|
|
||||
/** |
|
||||
* @program: gold-java |
|
||||
* @ClassName PaymentDTO |
|
||||
* @description: |
|
||||
* @author: Double |
|
||||
* @create: 2025−10-27 13:35 |
|
||||
* @Version 1.0 |
|
||||
**/ |
|
||||
|
|
||||
import lombok.Data; |
|
||||
import lombok.NoArgsConstructor; |
|
||||
|
|
||||
@Data |
|
||||
@NoArgsConstructor |
|
||||
public class PaymentDTO { |
|
||||
private String type; |
|
||||
private String provider; |
|
||||
private String request_reference; |
|
||||
private String merchant_reference; |
|
||||
private String provider_reference; |
|
||||
private String currency; |
|
||||
private String order_amount; |
|
||||
private String charge; |
|
||||
private String net_amount; |
|
||||
private String status; |
|
||||
private String created_time; |
|
||||
private String completed_time; |
|
||||
} |
|
||||
@ -1,18 +0,0 @@ |
|||||
package com.example.demo.service.cash; |
|
||||
|
|
||||
|
|
||||
import com.example.demo.domain.DTO.BankDTO; |
|
||||
import com.example.demo.domain.vo.cash.Bank; |
|
||||
|
|
||||
/** |
|
||||
* @program: gold-java |
|
||||
* @ClassName BankService |
|
||||
* @description: |
|
||||
* @author: Double |
|
||||
* @create: 2025−10-27 11:17 |
|
||||
* @Version 1.0 |
|
||||
**/ |
|
||||
|
|
||||
public interface BankService { |
|
||||
BankDTO getPayment(Bank bank); |
|
||||
} |
|
||||
@ -1,137 +0,0 @@ |
|||||
package com.example.demo.serviceImpl.cash; |
|
||||
|
|
||||
import com.alibaba.fastjson.JSON; |
|
||||
import com.alibaba.fastjson.JSONArray; |
|
||||
import com.alibaba.fastjson.JSONObject; |
|
||||
import com.example.demo.domain.DTO.BankDTO; |
|
||||
import com.example.demo.domain.DTO.PaymentDTO; |
|
||||
import com.example.demo.domain.vo.cash.Bank; |
|
||||
import com.example.demo.service.cash.BankService; |
|
||||
import lombok.extern.slf4j.Slf4j; |
|
||||
import org.springframework.http.*; |
|
||||
import org.springframework.stereotype.Service; |
|
||||
import org.springframework.util.LinkedMultiValueMap; |
|
||||
import org.springframework.util.MultiValueMap; |
|
||||
import org.springframework.web.client.RestTemplate; |
|
||||
|
|
||||
import java.nio.charset.StandardCharsets; |
|
||||
import java.security.MessageDigest; |
|
||||
import java.security.NoSuchAlgorithmException; |
|
||||
import java.util.List; |
|
||||
import java.util.Map; |
|
||||
import java.util.TreeMap; |
|
||||
|
|
||||
/** |
|
||||
* @program: gold-java |
|
||||
* @ClassName BankServiceImpl |
|
||||
* @description: |
|
||||
* @author: Double |
|
||||
* @create: 2025−10-27 11:18 |
|
||||
* @Version 1.0 |
|
||||
**/ |
|
||||
|
|
||||
@Service |
|
||||
@Slf4j |
|
||||
public class BankServiceImpl implements BankService { |
|
||||
// 第三方API地址 |
|
||||
private static final String API_URL = "https://gateway.pa-sys.com/v1.1/reconciliation/519e26b2-8145-418c-b3e7-c1e88e52b946/settlement"; |
|
||||
// 签名密钥 |
|
||||
private static final String SECRET = "8987d1b8-1d82-4b15-af06-828d0b12076f"; |
|
||||
|
|
||||
// 注入RestTemplate用于HTTP请求(需在Spring配置类中定义) |
|
||||
private final RestTemplate restTemplate; |
|
||||
|
|
||||
public BankServiceImpl(RestTemplate restTemplate) { |
|
||||
this.restTemplate = restTemplate; |
|
||||
} |
|
||||
|
|
||||
@Override |
|
||||
public BankDTO getPayment(Bank bank) { |
|
||||
try { |
|
||||
// 1. 准备参数 |
|
||||
String settlementDate = bank.getTime(); // 从Bank对象获取time作为settlement_date |
|
||||
String network = "FPS"; // 固定值 |
|
||||
|
|
||||
// 2. 生成签名 |
|
||||
Map<String, String> params = new TreeMap<>(); // 按key升序排序 |
|
||||
params.put("settlement_date", settlementDate); |
|
||||
params.put("network", network); |
|
||||
|
|
||||
String signSource = buildQueryString(params) + SECRET; |
|
||||
String sign = sha512(signSource); |
|
||||
|
|
||||
// 3. 构建form-data请求参数 |
|
||||
MultiValueMap<String, String> formData = new LinkedMultiValueMap<>(); |
|
||||
formData.add("settlement_date", settlementDate); |
|
||||
formData.add("network", network); |
|
||||
formData.add("sign", sign); |
|
||||
|
|
||||
// 4. 发送HTTP POST请求(优化:显式设置multipart/form-data的字符集) |
|
||||
HttpHeaders headers = new HttpHeaders(); |
|
||||
// 补充charset=UTF-8,避免部分服务器对编码敏感 |
|
||||
headers.setContentType(new MediaType("multipart", "form-data", StandardCharsets.UTF_8)); |
|
||||
HttpEntity<MultiValueMap<String, String>> requestEntity = new HttpEntity<>(formData, headers); |
|
||||
|
|
||||
// 调用第三方API(使用配置好SSL协议的RestTemplate) |
|
||||
ResponseEntity<String> response = restTemplate.exchange( |
|
||||
API_URL, |
|
||||
HttpMethod.POST, |
|
||||
requestEntity, |
|
||||
String.class |
|
||||
); |
|
||||
|
|
||||
if (response.getStatusCode().is2xxSuccessful()) { |
|
||||
String responseBody = response.getBody(); |
|
||||
log.info("第三方API响应: {}", responseBody); |
|
||||
|
|
||||
// 解析JSON获取payload.transactions数组 |
|
||||
JSONObject jsonObject = JSON.parseObject(responseBody); |
|
||||
JSONArray transactions = jsonObject.getJSONObject("payload").getJSONArray("transactions"); |
|
||||
|
|
||||
// 创建BankDTO并设置paymentDTOList |
|
||||
BankDTO bankDTO = new BankDTO(); |
|
||||
List<PaymentDTO> paymentDTOList = transactions.toJavaList(PaymentDTO.class); |
|
||||
bankDTO.setPaymentDTOList(paymentDTOList); |
|
||||
|
|
||||
return bankDTO; |
|
||||
} else { |
|
||||
throw new RuntimeException("API请求失败,状态码: " + response.getStatusCodeValue()); |
|
||||
} |
|
||||
|
|
||||
} catch (Exception e) { |
|
||||
log.error("payment银行接口处理失败", e); |
|
||||
throw new RuntimeException("处理失败: " + e.getMessage()); |
|
||||
} |
|
||||
} |
|
||||
/** |
|
||||
* http_build_query的查询字符串(key=value&key=value) |
|
||||
*/ |
|
||||
private String buildQueryString(Map<String, String> params) { |
|
||||
StringBuilder sb = new StringBuilder(); |
|
||||
for (Map.Entry<String, String> entry : params.entrySet()) { |
|
||||
if (sb.length() > 0) { |
|
||||
sb.append("&"); |
|
||||
} |
|
||||
sb.append(entry.getKey()).append("=").append(entry.getValue()); |
|
||||
} |
|
||||
return sb.toString(); |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* SHA512加密 |
|
||||
*/ |
|
||||
private String sha512(String content) throws NoSuchAlgorithmException { |
|
||||
MessageDigest md = MessageDigest.getInstance("SHA-512"); |
|
||||
byte[] bytes = md.digest(content.getBytes(StandardCharsets.UTF_8)); |
|
||||
// 转换为十六进制字符串 |
|
||||
StringBuilder hexStr = new StringBuilder(); |
|
||||
for (byte b : bytes) { |
|
||||
String hex = Integer.toHexString(0xff & b); |
|
||||
if (hex.length() == 1) { |
|
||||
hexStr.append('0'); |
|
||||
} |
|
||||
hexStr.append(hex); |
|
||||
} |
|
||||
return hexStr.toString(); |
|
||||
} |
|
||||
} |
|
||||
Write
Preview
Loading…
Cancel
Save
Reference in new issue