更改签名
This commit is contained in:
parent
5cd4daddb4
commit
0fe181fdae
@ -1,17 +1,23 @@
|
||||
package com.suisung.mall.common.utils;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.suisung.mall.common.api.StateCode;
|
||||
import com.suisung.mall.common.exception.ApiException;
|
||||
import org.apache.logging.log4j.util.Strings;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.MessageDigest;
|
||||
import java.util.*;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
import org.apache.commons.codec.binary.Base64;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* 常用工具方法
|
||||
@ -227,7 +233,59 @@ public class CommonUtil {
|
||||
return rtn;
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成 md 摘要通用签名(参考了顺丰同城的做法)
|
||||
* 参考:https://openic.sf-express.com/#/quickstart
|
||||
* @param postData
|
||||
* @param appId
|
||||
* @param appKey
|
||||
* @return
|
||||
*/
|
||||
public static String generateOpenSign(String postData, String appId, String appKey) {
|
||||
try {
|
||||
|
||||
if (StrUtil.isBlank(postData)|| StrUtil.isBlank(appId)|| StrUtil.isBlank(appKey)) {
|
||||
logger.error("生成签名时缺少必要参数!");
|
||||
return Strings.EMPTY;
|
||||
}
|
||||
|
||||
StringBuilder sb = new StringBuilder(postData).append("&").append(appId).append("&").append(appKey);
|
||||
MessageDigest md = MessageDigest.getInstance("MD5");
|
||||
byte[] md5 = md.digest(sb.toString().getBytes(StandardCharsets.UTF_8));
|
||||
int i;
|
||||
StringBuffer buf = new StringBuffer("");
|
||||
for (byte b : md5) {
|
||||
i = b;
|
||||
if (i < 0) {
|
||||
i += 256;
|
||||
}
|
||||
if (i < 16) {
|
||||
buf.append("0");
|
||||
}
|
||||
buf.append(Integer.toHexString(i));
|
||||
}
|
||||
return Base64.encodeBase64String(buf.toString().getBytes(StandardCharsets.UTF_8));
|
||||
|
||||
} catch (Exception e) {
|
||||
logger.error(e.getMessage());
|
||||
return Strings.EMPTY;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean checkOpenSign(String sign, String postData, String appId, String appKey) {
|
||||
if (StrUtil.isBlank(sign) || StrUtil.isBlank(postData)|| StrUtil.isBlank(appId)|| StrUtil.isBlank(appKey)) {
|
||||
logger.error("验签时缺少必要参数!");
|
||||
return false;
|
||||
}
|
||||
|
||||
String sn = generateOpenSign(postData, appId, appKey);
|
||||
if(StringUtils.isEmpty(sn)){
|
||||
logger.error("签名无效!");
|
||||
return false;
|
||||
}
|
||||
|
||||
return sign.equals(sn);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -5107,8 +5107,8 @@ public class ShopProductBaseServiceImpl extends BaseServiceImpl<ShopProductBaseM
|
||||
Integer pages = com.suisung.mall.shop.sixun.utils.CommonUtil.getPagesCount(total.intValue(), pageSize);
|
||||
int successCnt = 0;
|
||||
|
||||
for (int i = 1; i <= pages; i++) {
|
||||
List<SxSyncGoods> goodsList = sxSyncGoodsService.pageByStoreId(storeId, CommonConstant.Disable2, i, pageSize).getRecords();
|
||||
for (int pageNum = 1; pageNum <= pages; pageNum++) {
|
||||
List<SxSyncGoods> goodsList = sxSyncGoodsService.pageByStoreId(storeId, CommonConstant.Disable2, pageNum, pageSize).getRecords();
|
||||
if (CollectionUtil.isEmpty(goodsList)) {
|
||||
continue;
|
||||
}
|
||||
@ -5189,7 +5189,7 @@ public class ShopProductBaseServiceImpl extends BaseServiceImpl<ShopProductBaseM
|
||||
shopProductInfo.setProduct_number(sxSyncGoods.getItem_no());// SPU商家编码:货号
|
||||
shopProductInfo.setProduct_assist("");
|
||||
shopProductInfo.setProduct_spec("");
|
||||
shopProductInfo.setProduct_buy_limit(0); // 没人限购
|
||||
shopProductInfo.setProduct_buy_limit(0); // 不限购
|
||||
//商品规格
|
||||
shopProductInfo.setSpec_ids("");
|
||||
|
||||
|
||||
@ -21,6 +21,7 @@ import com.suisung.mall.common.exception.ApiException;
|
||||
import com.suisung.mall.common.modules.store.ShopStoreSfOrder;
|
||||
import com.suisung.mall.common.pojo.req.*;
|
||||
import com.suisung.mall.common.pojo.res.SFExpressApiRes;
|
||||
import com.suisung.mall.common.utils.CommonUtil;
|
||||
import com.suisung.mall.common.utils.I18nUtil;
|
||||
import com.suisung.mall.common.utils.JsonUtil;
|
||||
import com.suisung.mall.common.utils.SseEmitterUtil;
|
||||
@ -50,7 +51,7 @@ public class SFExpressApiServiceImpl implements SFExpressApiService {
|
||||
private final static String sfExpressApiDomain = "https://openic.sf-express.com/open/api/external/";
|
||||
private static final Logger logger = LoggerFactory.getLogger(SFExpressApiServiceImpl.class);
|
||||
@Value("${sf-express.appid}")
|
||||
private Long appId;
|
||||
private String appId;
|
||||
@Value("${sf-express.appkey}")
|
||||
private String appKey;
|
||||
@Value("${sf-express.dev_id}")
|
||||
@ -657,29 +658,7 @@ public class SFExpressApiServiceImpl implements SFExpressApiService {
|
||||
* @return
|
||||
*/
|
||||
private String generateOpenSign(String postData) {
|
||||
try {
|
||||
String sb = postData +
|
||||
"&" + appId + "&" + appKey;
|
||||
|
||||
MessageDigest md = MessageDigest.getInstance("MD5");
|
||||
byte[] md5 = md.digest(sb.getBytes(StandardCharsets.UTF_8));
|
||||
int i;
|
||||
StringBuffer buf = new StringBuffer();
|
||||
for (byte b : md5) {
|
||||
i = b;
|
||||
if (i < 0) {
|
||||
i += 256;
|
||||
}
|
||||
if (i < 16) {
|
||||
buf.append("0");
|
||||
}
|
||||
buf.append(Integer.toHexString(i));
|
||||
}
|
||||
return Base64.encodeBase64String(buf.toString().getBytes(StandardCharsets.UTF_8));
|
||||
} catch (Exception e) {
|
||||
logger.error(e.getMessage());
|
||||
return "";
|
||||
}
|
||||
return CommonUtil.generateOpenSign(postData, appId, appKey);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -690,12 +669,7 @@ public class SFExpressApiServiceImpl implements SFExpressApiService {
|
||||
* @return
|
||||
*/
|
||||
private boolean checkOpenSign(String sign, String postData) {
|
||||
if (StrUtil.isBlank(sign) || StrUtil.isBlank(postData)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
String newSign = generateOpenSign(postData);
|
||||
return sign.equals(newSign);
|
||||
return CommonUtil.checkOpenSign(sign, postData, appId, appKey);
|
||||
}
|
||||
|
||||
private Map<String, Object> buildCommonParams() {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user