shop 项目增加拉卡拉的业务逻辑
This commit is contained in:
parent
c1896f3c39
commit
18da67511e
@ -3,14 +3,12 @@ package com.suisung.mall.common.utils;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.tika.Tika;
|
||||
import org.springframework.util.Base64Utils;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.*;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URI;
|
||||
import java.net.URL;
|
||||
import java.net.URLEncoder;
|
||||
import java.net.*;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.StandardCopyOption;
|
||||
@ -25,14 +23,17 @@ public class UploadUtil {
|
||||
* token通过header传递的名称
|
||||
*/
|
||||
public static final String TOKEN_HEADER_NAME = "Authorization";
|
||||
|
||||
|
||||
// 除 text/* 外也需要设置输出编码的 content-type
|
||||
private final static List<String> SET_CHARSET_CONTENT_TYPES = Arrays.asList(
|
||||
"application/json",
|
||||
"application/javascript"
|
||||
);
|
||||
|
||||
public static void main(String[] args) {
|
||||
String base64 = URLFileToBase64("http://gips3.baidu.com/it/u=1022347589,1106887837&fm=3028&app=3028&f=JPEG&fmt=auto?w=960&h=1280");
|
||||
System.out.println(base64);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查看文件, 支持断点续传
|
||||
*
|
||||
@ -269,11 +270,40 @@ public class UploadUtil {
|
||||
// inputStream 用完之后,记得关闭
|
||||
return inputStream;
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
log.error("发生 I/O 错误: ", e.getMessage());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 将URL地址转换为Base64字符串
|
||||
*
|
||||
* @param fileUrl
|
||||
* @return
|
||||
*/
|
||||
public static String URLFileToBase64(String fileUrl) {
|
||||
try {
|
||||
URL url = new URL(fileUrl);
|
||||
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
||||
connection.setRequestMethod("GET");
|
||||
|
||||
try (InputStream inputStream = connection.getInputStream()) {
|
||||
byte[] buffer = new byte[inputStream.available()];
|
||||
inputStream.read(buffer);
|
||||
return Base64Utils.encodeToString(buffer);
|
||||
} finally {
|
||||
connection.disconnect();
|
||||
}
|
||||
} catch (MalformedURLException e) {
|
||||
log.error("输入的 URL 格式不正确: {}", e.getMessage());
|
||||
} catch (IOException e) {
|
||||
log.error("在连接或读取文件时发生 I/O 错误: {}", e.getMessage());
|
||||
} catch (Exception e) {
|
||||
log.error("发生未知异常: {}", e.getMessage());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 下载图片到本地
|
||||
*
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
@ -161,6 +161,7 @@
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
<configuration>
|
||||
<!-- 拉卡拉外部引用了jar 必须配置-->
|
||||
<includeSystemScope>true</includeSystemScope>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
@ -286,13 +286,15 @@
|
||||
<systemPath>${project.basedir}/src/main/resources/lib/lkl-java-sdk-1.0.7.jar</systemPath>
|
||||
<scope>system</scope>
|
||||
</dependency>
|
||||
<!--拉卡拉支付与分账 结束-->
|
||||
|
||||
<dependency>
|
||||
<groupId>com.github.javen205</groupId>
|
||||
<artifactId>IJPay-Core</artifactId>
|
||||
<version>2.8.0</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<!--拉卡拉支付与分账 结束-->
|
||||
|
||||
|
||||
</dependencies>
|
||||
|
||||
@ -363,6 +365,10 @@
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
<configuration>
|
||||
<!-- 拉卡拉外部引用了jar 必须配置-->
|
||||
<includeSystemScope>true</includeSystemScope>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>com.spotify</groupId>
|
||||
|
||||
@ -138,6 +138,9 @@ public class LakalaPayServiceImpl implements LakalaPayService {
|
||||
try {
|
||||
//3. 发送请求
|
||||
String responseStr = LKLSDK.httpPost(v3LabsTransPreorderWechatReq);
|
||||
if (StrUtil.isBlank(responseStr)) {
|
||||
throw new ApiException(I18nUtil._("下单无响应!"));
|
||||
}
|
||||
|
||||
//4. 响应
|
||||
return JSONUtil.parseObj(responseStr);
|
||||
@ -210,7 +213,7 @@ public class LakalaPayServiceImpl implements LakalaPayService {
|
||||
String responseStr = LKLSDK.httpPost(v3LabsTransPreorderWechatReq);
|
||||
log.info("拉卡拉预下单响应数据:{}", responseStr);
|
||||
if (StrUtil.isBlank(responseStr)) {
|
||||
return null;
|
||||
throw new ApiException(I18nUtil._("下单无响应!"));
|
||||
}
|
||||
|
||||
JSONObject lakalaRespJSON = JSONUtil.parseObj(responseStr);
|
||||
@ -257,6 +260,9 @@ public class LakalaPayServiceImpl implements LakalaPayService {
|
||||
try {
|
||||
//3. 发送请求
|
||||
String responseStr = LKLSDK.httpPost(v3LabsQueryTradequeryRequest);
|
||||
if (StrUtil.isBlank(responseStr)) {
|
||||
throw new ApiException(I18nUtil._("交易查询无响应!"));
|
||||
}
|
||||
|
||||
JSONObject lakalaRespJSON = JSONUtil.parseObj(responseStr);
|
||||
// || !lakalaRespJSON.getStr("code").equals("BBS00000")
|
||||
@ -295,7 +301,7 @@ public class LakalaPayServiceImpl implements LakalaPayService {
|
||||
ShopStoreBase shopStoreBase = shopService.getLklMerchantNoAndTermNo(storeId);
|
||||
if (shopStoreBase == null || StrUtil.isBlank(shopStoreBase.getLkl_merchant_no()) || StrUtil.isBlank(shopStoreBase.getLkl_term_no())) {
|
||||
log.error("缺少参数,退款交易失败!");
|
||||
return null;
|
||||
throw new ApiException(I18nUtil._("缺少必要参数!"));
|
||||
}
|
||||
|
||||
//2. 装配数据
|
||||
@ -313,6 +319,9 @@ public class LakalaPayServiceImpl implements LakalaPayService {
|
||||
try {
|
||||
//3. 发送请求
|
||||
String responseStr = LKLSDK.httpPost(req);
|
||||
if (StrUtil.isBlank(responseStr)) {
|
||||
throw new ApiException(I18nUtil._("退款交易失败!"));
|
||||
}
|
||||
|
||||
JSONObject lakalaRespJSON = JSONUtil.parseObj(responseStr);
|
||||
|
||||
@ -353,6 +362,9 @@ public class LakalaPayServiceImpl implements LakalaPayService {
|
||||
try {
|
||||
//3. 发送请求
|
||||
String responseStr = LKLSDK.httpPost(req);
|
||||
if (StrUtil.isBlank(responseStr)) {
|
||||
throw new ApiException(I18nUtil._("账户余额查询无响应!"));
|
||||
}
|
||||
|
||||
JSONObject lakalaRespJSON = JSONUtil.parseObj(responseStr);
|
||||
|
||||
@ -393,8 +405,10 @@ public class LakalaPayServiceImpl implements LakalaPayService {
|
||||
String responseStr = LKLSDK.httpPost(req);
|
||||
|
||||
JSONObject lakalaRespJSON = JSONUtil.parseObj(responseStr);
|
||||
if (lakalaRespJSON == null || !lakalaRespJSON.getStr("retCode").equals(lklSuccessCode)) {
|
||||
throw new ApiException(I18nUtil._(lakalaRespJSON.getStr("retMsg")));
|
||||
if (StrUtil.isBlank(responseStr)
|
||||
|| lakalaRespJSON == null
|
||||
|| !lakalaRespJSON.getStr("retCode").equals(lklSuccessCode)) {
|
||||
throw new ApiException(I18nUtil._("文件上传无响应或失败!"));
|
||||
}
|
||||
|
||||
return (JSONObject) lakalaRespJSON.get("respData");
|
||||
@ -448,10 +462,12 @@ public class LakalaPayServiceImpl implements LakalaPayService {
|
||||
String responseStr = LKLSDK.httpPost(req);
|
||||
|
||||
JSONObject lakalaRespJSON = JSONUtil.parseObj(responseStr);
|
||||
if (lakalaRespJSON == null || !lakalaRespJSON.getStr("retCode").equals(lklSuccessCode)) {
|
||||
throw new ApiException(I18nUtil._(lakalaRespJSON.getStr("retMsg")));
|
||||
// responseStr="{'retCode':'000000','retMsg':'申请已受理,请等待审核结果','respData':{'version':'1.0','orderNo':'KFPT20230223181025407788734','orgCode':'1','applyId':681201215598657536}}";
|
||||
// lakalaRespJSON = JSONUtil.parseObj(responseStr);
|
||||
if (StrUtil.isBlank(responseStr)
|
||||
|| lakalaRespJSON == null
|
||||
|| !lakalaRespJSON.getStr("retCode").equals(lklSuccessCode)) {
|
||||
throw new ApiException(I18nUtil._("分账申请失败!"));
|
||||
// 成功返回示例:{'retCode':'000000','retMsg':'申请已受理,请等待审核结果','respData':{'version':'1.0','orderNo':'KFPT20230223181025407788734','orgCode':'1','applyId':681201215598657536}}
|
||||
|
||||
}
|
||||
|
||||
paramsJSON.set("apply_id", lakalaRespJSON.getByPath("respData.applyId"));
|
||||
@ -479,7 +495,7 @@ public class LakalaPayServiceImpl implements LakalaPayService {
|
||||
*/
|
||||
@Override
|
||||
public JSONObject applyLedgerMerNotify(HttpServletRequest request) {
|
||||
log.info("商户分账申请业务回调收到通知");
|
||||
log.info("商户分账申请业务异步通知开始");
|
||||
// 验签
|
||||
String authorization = request.getHeader("Authorization");
|
||||
String requestBody = LakalaUtil.getBody(request);
|
||||
@ -511,7 +527,8 @@ public class LakalaPayServiceImpl implements LakalaPayService {
|
||||
reqData.getStr("entrustFilePath"),
|
||||
reqData.getStr("auditStatus"),
|
||||
reqData.getStr("auditStatusText"),
|
||||
reqData.getStr("remark"));
|
||||
reqData.getStr("remark")
|
||||
);
|
||||
|
||||
if (success) {
|
||||
respData.put("retCode", lklSuccessCode);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user