记得上下班打卡 | git大法好,push需谨慎

Commit 51a0654c authored by wangyifan's avatar wangyifan

收钱吧签名

parent eb5718c7
......@@ -24,7 +24,7 @@ public class MallProductsQueryData {
private String title;
@ApiModelProperty(value = "商品规格")
private List<Sku> skuModels;
private List<Sku> skuResults;
@Data
......
......@@ -17,6 +17,24 @@ public class ShouqianbaProperties {
private String appCode;
/**
* 商户ID
*/
private String merchantId;
/**
* 商户UserID
*/
private String merchantUserId;
/**
* 角色
*/
private String role;
/**
* 公钥
*/
private String publicKey;
private String baseApi;
......
package com.liquidnet.service.goblin.service.impl;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.liquidnet.commons.lang.util.HttpUtil;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.liquidnet.commons.lang.util.MD5Utils;
import com.liquidnet.service.goblin.config.properties.ShouqianbaProperties;
import com.liquidnet.service.goblin.param.shouqianba.callback.CallbackParams;
......@@ -11,9 +11,14 @@ import com.liquidnet.service.goblin.param.shouqianba.response.*;
import com.liquidnet.service.goblin.param.shouqianba.response.data.*;
import com.liquidnet.service.goblin.service.IGoblinShouQianBaService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.http.converter.StringHttpMessageConverter;
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.KeyFactory;
......@@ -22,7 +27,6 @@ import java.security.Signature;
import java.security.spec.X509EncodedKeySpec;
import java.util.Base64;
import java.util.List;
import java.util.TreeMap;
/**
* 收钱吧对接实现类
......@@ -44,9 +48,21 @@ public class GoblinShouQianBaServiceImpl implements IGoblinShouQianBaService {
}
}
private static final ObjectMapper objectMapper = new ObjectMapper();
private static final ObjectMapper objectMapper;
private static final RestTemplate restTemplate;
static {
// 1. 初始化 RestTemplate 并强制设置 String 转换器为 UTF-8
restTemplate = new RestTemplate();
restTemplate.getMessageConverters().set(1, new StringHttpMessageConverter(StandardCharsets.UTF_8));
// 2. 初始化紧凑型 ObjectMapper (签名专用:无空格、无换行、不含空字段)
objectMapper = new ObjectMapper();
objectMapper.configure(SerializationFeature.INDENT_OUTPUT, false);
objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
}
/**
* 创建结算明细
*
......@@ -144,7 +160,7 @@ public class GoblinShouQianBaServiceImpl implements IGoblinShouQianBaService {
*/
@Override
public List<MallListQueryData> queryMallList(MallListQueryRequest request) {
return executeShouQianBaRequest("/optimus/open/mall/queryMallList", "查询门店列表", request, MallListQueryResponse.class);
return executeShouQianBaRequest("/optimus/core/open/mall/queryMallList", "查询门店列表", request, MallListQueryResponse.class);
}
/**
......@@ -155,7 +171,7 @@ public class GoblinShouQianBaServiceImpl implements IGoblinShouQianBaService {
*/
@Override
public List<MallProductsQueryData> queryMallProducts(MallProductsQueryRequest request) {
return executeShouQianBaRequest("/optimus/open/mall/queryMallProducts", "查询门店商品", request, MallProductsQueryResponse.class);
return executeShouQianBaRequest("/optimus/core/open/mall/queryMallProducts", "查询门店商品", request, MallProductsQueryResponse.class);
}
/**
......@@ -168,18 +184,30 @@ public class GoblinShouQianBaServiceImpl implements IGoblinShouQianBaService {
try {
// body进行序列化成TreeMap以后 最后转成json(为了排序稳定)
TreeMap<String, Object> map = objectMapper.convertValue(
request,
new TypeReference<TreeMap<String, Object>>() {
}
);
String requestBody = objectMapper.writeValueAsString(map);
// TreeMap<String, Object> map = objectMapper.convertValue(
// request,
// new TypeReference<TreeMap<String, Object>>() {
// }
// );
String requestBody = objectMapper.writeValueAsString(request);
// 去除可能存在的空格和换行符,以保证签名通过
log.info("request body: {}", requestBody);
// 构建请求头(添加签名参数)
final String sign = getSign(requestBody);
log.info("request header: {}", sign);
MultiValueMap<String, String> headers = new LinkedMultiValueMap<>();
headers.add("Authorization", getSign(requestBody));
headers.add("Authorization", sign);
headers.add("Content-Type", "application/json");
headers.add("X-env-flag", "41508");
// 4. 发送请求
// 注意:传入的是 String jsonBody,接收的也是 String.class,确保不被二次处理
HttpEntity<String> entity = new HttpEntity<>(requestBody, headers);
ResponseEntity<String> responseEntity = restTemplate.exchange(url, HttpMethod.POST, entity, String.class);
String responseStr = HttpUtil.postJson(url, requestBody, headers);
String responseStr = responseEntity.getBody();
log.info("[收钱吧] {}, 响应体: {}", businessName, responseStr);
// 转换响应报文
......
......@@ -123,7 +123,7 @@ public class GoblinSqbGoodsServiceImpl implements IGoblinSqbGoodsService {
List<MallProductsQueryData> products = goblinShouQianBaService.queryMallProducts(productRequest);
if (!CollectionUtils.isEmpty(products)) {
for (MallProductsQueryData product : products) {
List<MallProductsQueryData.Sku> skus = product.getSkuModels();
List<MallProductsQueryData.Sku> skus = product.getSkuResults();
if (CollectionUtils.isEmpty(skus)) {
result.add(buildPerfGoodsVo(product, null));
} else {
......@@ -211,7 +211,7 @@ public class GoblinSqbGoodsServiceImpl implements IGoblinSqbGoodsService {
goblinstoreMgtGoodsService.goodsAdd(goodsInfoVo, goodsSkuInfoVoList);
// 4. 建立映射
List<MallProductsQueryData.Sku> sqbSkus = productsData.getSkuModels();
List<MallProductsQueryData.Sku> sqbSkus = productsData.getSkuResults();
if (CollectionUtils.isEmpty(sqbSkus)) {
String skuId = goodsSkuInfoVoList.get(0).getSkuId();
goblinSqbGoodsExtMapper.insert(buildExt(goodsInfoVo.getSpuId(), skuId, mallSn, sqbProductId, sqbProductSn, null, now));
......@@ -272,7 +272,7 @@ public class GoblinSqbGoodsServiceImpl implements IGoblinSqbGoodsService {
sqbToSysSkuMap.put(ext.getSqbSkuId() != null ? ext.getSqbSkuId() : "PLACEHOLDER", ext.getSkuId());
}
List<MallProductsQueryData.Sku> sqbSkus = productsData.getSkuModels();
List<MallProductsQueryData.Sku> sqbSkus = productsData.getSkuResults();
if (CollectionUtils.isEmpty(sqbSkus)) {
String skuId = sqbToSysSkuMap.get("PLACEHOLDER");
if (skuId != null) processSkuUpdate(currentUid, storeId, skuId, productsData, null);
......@@ -366,7 +366,7 @@ public class GoblinSqbGoodsServiceImpl implements IGoblinSqbGoodsService {
param.setVirtualFlg("1");
List<GoblinStoreMgtGoodsAddSkuParam> skuParams = new ArrayList<>();
List<MallProductsQueryData.Sku> sqbSkus = productsData.getSkuModels();
List<MallProductsQueryData.Sku> sqbSkus = productsData.getSkuResults();
if (CollectionUtils.isEmpty(sqbSkus)) {
skuParams.add(buildMgtSkuParam(productsData.getTitle(), null, productsData.getConverImages()));
} else {
......
......@@ -31,22 +31,32 @@ public class GoblinShouQianBaServiceImplTest {
CommonRequest.Seller seller = new CommonRequest.Seller();
seller.setRole("super_admin");
seller.setMerchantId("fd567f94-9a44-4ae5-879f-9acc919d0f89");
seller.setMerchantUserId("42c556cc-1509-4de0-bfc3-dfbcb48eae57");
seller.setMerchantId("1c904b2df056-4afa-a819-0328a4774320");
seller.setMerchantUserId("6ce169d1-1289-4e98-b4a3-ea8b6145046f");
MallListQueryRequest.Filter filter = new MallListQueryRequest.Filter();
filter.setSeller(seller);
MallListQueryRequest.Cursor cursor = new MallListQueryRequest.Cursor();
cursor.setCount(10);
cursor.setCursorField("id");
MallListQueryRequest.Sort sort = new MallListQueryRequest.Sort();
sort.setSort("DESC");
sort.setSortField("id");
MallListQueryRequest mallListQueryRequest = new MallListQueryRequest();
mallListQueryRequest.setAppid("2025082700005615");
mallListQueryRequest.setFilter(filter);
mallListQueryRequest.setCursor(cursor);
mallListQueryRequest.setSort(sort);
List<MallListQueryData> mallListQueryData = goblinShouQianBaService.queryMallList(mallListQueryRequest);
Assert.assertNotNull(mallListQueryData);
}
@Test
public void queryMallProducts(){
public void queryMallProductsTest(){
CommonRequest.Seller seller = new CommonRequest.Seller();
seller.setMerchantId("1c904b2d-f056-4afa-a819-0328a4774320");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment