拉卡拉支付增加接口

This commit is contained in:
Jack 2025-01-17 22:35:04 +08:00
parent e559ac5dc5
commit db71764d8a
12 changed files with 184 additions and 96 deletions

View File

@ -26,4 +26,8 @@ mall-im
"weixin_key": "商户API秘钥", "weixin_key": "商户API秘钥",
"apiclient_cert": "apiclient_cert.pem", "apiclient_cert": "apiclient_cert.pem",
"sslkey_name": "apiclient_key.pem" "sslkey_name": "apiclient_key.pem"
} }
清除 docker 日志
docker ps -aq | xargs docker inspect --format='{{.LogPath}}' | xargs truncate -s 0

View File

@ -47,4 +47,8 @@ public class SyncThirdMemberReq implements Serializable {
private BigDecimal user_money; private BigDecimal user_money;
@ApiModelProperty("加入时间") @ApiModelProperty("加入时间")
private Date join_time; private Date join_time;
@ApiModelProperty("秒级别时间戳")
private Long time_stamp;
@ApiModelProperty("随机字符串")
private String nonce_str;
} }

View File

@ -62,8 +62,9 @@ public class IndexController extends BaseControllerImpl {
@ApiOperation(value = "测试接口", notes = "测试接口") @ApiOperation(value = "测试接口", notes = "测试接口")
@RequestMapping(value = "/test/case", method = RequestMethod.POST) @RequestMapping(value = "/test/case", method = RequestMethod.POST)
public JSONObject testCase(@RequestBody JSONObject objectJSON){ public JSONObject testCase(HttpServletRequest request, HttpServletResponse response,
return lakalaService.transPreOrder((String) objectJSON.get("orderId")); @RequestBody JSONObject objectJSON){
return lakalaService.transPreOrder(request,response, (String) objectJSON.get("orderId"));
} }
@ApiOperation(value = "获取支付密码", notes = "获取支付密码") @ApiOperation(value = "获取支付密码", notes = "获取支付密码")
@ -179,23 +180,21 @@ public class IndexController extends BaseControllerImpl {
} }
Map<String, Object> requestParams = new HashMap<>(); // 请求参数 Map<String, Object> requestParams = new HashMap<>(); // 请求参数
BigDecimal trade_payment_money = getParameter("pm_money", BigDecimal.ZERO); // 选中余额支付方式 BigDecimal trade_payment_money = getParameter("pm_money", BigDecimal.ZERO); // 选中余额支付方式
BigDecimal trade_payment_recharge_card = getParameter("pm_recharge_card", BigDecimal.ZERO); // 选中充值卡支付方式 BigDecimal trade_payment_recharge_card = getParameter("pm_recharge_card", BigDecimal.ZERO); // 选中充值卡支付方式
BigDecimal trade_payment_points = getParameter("pm_points", BigDecimal.ZERO); BigDecimal trade_payment_points = getParameter("pm_points", BigDecimal.ZERO);
BigDecimal trade_payment_sp = getParameter("pm_sp", BigDecimal.ZERO); BigDecimal trade_payment_sp = getParameter("pm_sp", BigDecimal.ZERO);
BigDecimal trade_payment_credit = getParameter("pm_credit", BigDecimal.ZERO); BigDecimal trade_payment_credit = getParameter("pm_credit", BigDecimal.ZERO);
BigDecimal trade_payment_redpack = getParameter("pm_redpack", BigDecimal.ZERO); BigDecimal trade_payment_redpack = getParameter("pm_redpack", BigDecimal.ZERO);
String order_id_str = getParameter("pay_sn", getParameter("order_id")); String order_id_str = getParameter("pay_sn", getParameter("order_id"));
List<String> order_id_row = Convert.toList(String.class, order_id_str); List<String> order_id_row = Convert.toList(String.class, order_id_str);
if (CollUtil.isEmpty(order_id_row)) { if (CollUtil.isEmpty(order_id_row)) {
throw new ApiException(I18nUtil._("没有可支付订单!")); throw new ApiException(I18nUtil._("没有可支付订单!"));
} }
// todo $payment_channel_code 是否启用 // todo $payment_channel_code 是否启用
String payment_channel_code = getParameter("payment_channel_code"); String payment_channel_code = getParameter("payment_channel_code");// payment_channel_codewx_native alipay
if (StrUtil.isBlank(payment_channel_code)) { if (StrUtil.isBlank(payment_channel_code)) {
Integer payment_channel_id = Convert.toInt(getParameter("payment_channel_id")); Integer payment_channel_id = Convert.toInt(getParameter("payment_channel_id"));
PayPaymentChannel payPaymentChannel = payPaymentChannelService.get(payment_channel_id); PayPaymentChannel payPaymentChannel = payPaymentChannelService.get(payment_channel_id);
@ -205,7 +204,7 @@ public class IndexController extends BaseControllerImpl {
} }
Integer user_id = getParameter("perm_id", Integer.class); Integer user_id = getParameter("perm_id", Integer.class);
String password = getParameter("password"); String password = getParameter("password"); // 支付密码
requestParams.put("trade_payment_money", trade_payment_money); requestParams.put("trade_payment_money", trade_payment_money);
requestParams.put("trade_payment_recharge_card", trade_payment_recharge_card); requestParams.put("trade_payment_recharge_card", trade_payment_recharge_card);

View File

@ -10,7 +10,10 @@ package com.suisung.mall.pay.service;
import cn.hutool.json.JSONObject; import cn.hutool.json.JSONObject;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public interface LakalaService { public interface LakalaService {
JSONObject transPreOrder(String orderId); JSONObject transPreOrder(HttpServletRequest request, HttpServletResponse response, String orderId);
} }

View File

@ -10,6 +10,7 @@ package com.suisung.mall.pay.service.impl;
import cn.hutool.json.JSONUtil; import cn.hutool.json.JSONUtil;
import com.ijpay.core.kit.IpKit;
import com.lkl.laop.sdk.Config; import com.lkl.laop.sdk.Config;
import com.lkl.laop.sdk.LKLSDK; import com.lkl.laop.sdk.LKLSDK;
import com.lkl.laop.sdk.exception.SDKException; import com.lkl.laop.sdk.exception.SDKException;
@ -21,13 +22,16 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@Slf4j @Slf4j
@Service @Service
public class LakalaServiceImpl implements LakalaService { public class LakalaServiceImpl implements LakalaService {
private static volatile boolean init = false;
@Value("${lakala.term_no}") @Value("${lakala.term_no}")
private String termNo; private String termNo;
private static volatile boolean init = false;
@Value("${lakala.app_id}") @Value("${lakala.app_id}")
private String appId; // 拉卡拉appId private String appId; // 拉卡拉appId
@Value("${lakala.serial_no}") @Value("${lakala.serial_no}")
@ -94,9 +98,10 @@ public class LakalaServiceImpl implements LakalaService {
} }
@Override @Override
public cn.hutool.json.JSONObject transPreOrder(String orderId) { public cn.hutool.json.JSONObject transPreOrder(HttpServletRequest request, HttpServletResponse response, String orderId) {
// 1. 配置初始化 // 1. 配置初始化
doInit(); doInit();
//2. 装配数据 //2. 装配数据
/*** 微信主扫场景示例 */ /*** 微信主扫场景示例 */
V3LabsTransPreorderRequest v3LabsTransPreorderWechatReq = new V3LabsTransPreorderRequest(); V3LabsTransPreorderRequest v3LabsTransPreorderWechatReq = new V3LabsTransPreorderRequest();
@ -111,26 +116,23 @@ public class LakalaServiceImpl implements LakalaService {
v3LabsTransPreorderWechatReq.setRemark("测试预下单备注"); v3LabsTransPreorderWechatReq.setRemark("测试预下单备注");
//地址位置信息 //地址位置信息
V3LabsTradeLocationInfo v3LabsTradePreorderLocationInfo1 = new V3LabsTradeLocationInfo("12.34.56.78"); V3LabsTradeLocationInfo v3LabsTradePreorderLocationInfo1 = new V3LabsTradeLocationInfo(IpKit.getRealIp(request));
v3LabsTransPreorderWechatReq.setLocationInfo(v3LabsTradePreorderLocationInfo1); v3LabsTransPreorderWechatReq.setLocationInfo(v3LabsTradePreorderLocationInfo1);
//微信主扫场景下acc_busi_fields域内容 //微信主扫场景下acc_busi_fields域内容
V3LabsTradePreorderWechatBus wechatBus = new V3LabsTradePreorderWechatBus(); V3LabsTradePreorderWechatBus wechatBus = new V3LabsTradePreorderWechatBus();
wechatBus.setSubAppid("wx5a73f844dac0da5c"); wechatBus.setSubAppid("wx5a73f844dac0da5c"); // 小程序appId
wechatBus.setUserId("oDVKR7T0qxg6O8tqIL9SgY6LXqqQ"); wechatBus.setUserId("oDVKR7T0qxg6O8tqIL9SgY6LXqqQ"); // 微信 openId
wechatBus.setGoodsTag("农家食品");
wechatBus.setLimitPayer("ADULT");
v3LabsTransPreorderWechatReq.setAccBusiFields(wechatBus); v3LabsTransPreorderWechatReq.setAccBusiFields(wechatBus);
//3. 发送请求
String response = "";
try { try {
response = LKLSDK.httpPost(v3LabsTransPreorderWechatReq); //3. 发送请求
String responseStr = LKLSDK.httpPost(v3LabsTransPreorderWechatReq);
//4. 响应 //4. 响应
return JSONUtil.parseObj(response); return JSONUtil.parseObj(responseStr);
} catch (SDKException e) { } catch (SDKException e) {
log.error("doInit error", e); log.error("transPreOrder error", e);
throw new RuntimeException(e); throw new RuntimeException(e);
} }

View File

@ -340,7 +340,6 @@ public class PayConsumeDepositServiceImpl extends BaseServiceImpl<PayConsumeDepo
} }
// 不是充值订单, 订单支付完成 // 不是充值订单, 订单支付完成
if (ObjectUtil.equal(StateCode.TRADE_TYPE_SHOPPING, trade_type_id)) { if (ObjectUtil.equal(StateCode.TRADE_TYPE_SHOPPING, trade_type_id)) {
paid_order_id_row.add(order_id); paid_order_id_row.add(order_id);
} }
@ -542,7 +541,6 @@ public class PayConsumeDepositServiceImpl extends BaseServiceImpl<PayConsumeDepo
paid_order_id_service_row.add(order_id); paid_order_id_service_row.add(order_id);
} }
// 余额变动 消息提醒 // 余额变动 消息提醒
String message_id = "balance-change-reminder"; String message_id = "balance-change-reminder";
Map<Object, Object> args = new HashMap<>(); Map<Object, Object> args = new HashMap<>();

View File

@ -151,7 +151,6 @@ public class PayUserPayServiceImpl extends BaseServiceImpl<PayUserPayMapper, Pay
// 判断是门店 店铺 平台 // 判断是门店 店铺 平台
Integer payment_store_id = 0; Integer payment_store_id = 0;
Integer payment_chain_id = 0; Integer payment_chain_id = 0;
if (!accountBaseConfigService.getTradeModePlantform()) { if (!accountBaseConfigService.getTradeModePlantform()) {
// 不可以联合支付 // 不可以联合支付
if (order_id_row.size() > 1) { if (order_id_row.size() > 1) {
@ -193,7 +192,7 @@ public class PayUserPayServiceImpl extends BaseServiceImpl<PayUserPayMapper, Pay
BigDecimal trade_payment_money = (BigDecimal) requestParams.get("trade_payment_money"); BigDecimal trade_payment_money = (BigDecimal) requestParams.get("trade_payment_money");
// 待支付额 // 待支付
BigDecimal trade_payment_amount = trade_rows.stream().map(PayConsumeTrade::getTrade_payment_amount).reduce(BigDecimal::add).get(); BigDecimal trade_payment_amount = trade_rows.stream().map(PayConsumeTrade::getTrade_payment_amount).reduce(BigDecimal::add).get();
if (trade_payment_amount.compareTo(BigDecimal.ZERO) > 0 && !StrUtil.equals(payment_channel_code, "offline")) { if (trade_payment_amount.compareTo(BigDecimal.ZERO) > 0 && !StrUtil.equals(payment_channel_code, "offline")) {
@ -237,6 +236,7 @@ public class PayUserPayServiceImpl extends BaseServiceImpl<PayUserPayMapper, Pay
} }
trade_row.setOrder_id(ctc_id); trade_row.setOrder_id(ctc_id);
} else { } else {
// 多个订单 Id 合并
trade_row.setOrder_id(CollUtil.join(trade_order_id_row, ",")); trade_row.setOrder_id(CollUtil.join(trade_order_id_row, ","));
} }
@ -246,7 +246,6 @@ public class PayUserPayServiceImpl extends BaseServiceImpl<PayUserPayMapper, Pay
// 付款金额 // 付款金额
BigDecimal payment_amount = trade_rows.stream().map(PayConsumeTrade::getTrade_payment_amount).reduce(BigDecimal::add).get(); BigDecimal payment_amount = trade_rows.stream().map(PayConsumeTrade::getTrade_payment_amount).reduce(BigDecimal::add).get();
trade_row.setTrade_payment_amount(payment_amount); trade_row.setTrade_payment_amount(payment_amount);
// 取消的不给支付
if (payment_amount.compareTo(BigDecimal.ZERO) > 0) { if (payment_amount.compareTo(BigDecimal.ZERO) > 0) {
List<Integer> order_state_ids = trade_rows.stream().map(PayConsumeTrade::getOrder_state_id).distinct().collect(Collectors.toList()); List<Integer> order_state_ids = trade_rows.stream().map(PayConsumeTrade::getOrder_state_id).distinct().collect(Collectors.toList());
if (!order_state_ids.contains(StateCode.ORDER_STATE_CANCEL)) { if (!order_state_ids.contains(StateCode.ORDER_STATE_CANCEL)) {
@ -264,6 +263,7 @@ public class PayUserPayServiceImpl extends BaseServiceImpl<PayUserPayMapper, Pay
notify_row.setPayment_channel_id(StateCode.PAYMENT_MONEY); // 余额支付 notify_row.setPayment_channel_id(StateCode.PAYMENT_MONEY); // 余额支付
notify_row.setOrder_id(StrUtil.join(",", order_id_row)); // todo 考虑是否为list 所属店铺 notify_row.setOrder_id(StrUtil.join(",", order_id_row)); // todo 考虑是否为list 所属店铺
// 小费支付交易记录
PayConsumeTrade payConsumeTrade = trade_rows.get(0); PayConsumeTrade payConsumeTrade = trade_rows.get(0);
if (ObjectUtil.equal(StateCode.TRADE_TYPE_SHOPPING, payConsumeTrade.getTrade_type_id())) { if (ObjectUtil.equal(StateCode.TRADE_TYPE_SHOPPING, payConsumeTrade.getTrade_type_id())) {
payConsumeDepositService.notifyShop(notify_row); payConsumeDepositService.notifyShop(notify_row);
@ -1100,10 +1100,12 @@ public class PayUserPayServiceImpl extends BaseServiceImpl<PayUserPayMapper, Pay
// 不同支付方式 获取返回值并验签 // 不同支付方式 获取返回值并验签
try { try {
if (ObjectUtil.equal("alipay", payment_channel_code)) { if (ObjectUtil.equal("alipay", payment_channel_code)) {
// 支付宝
params = AliPayApi.toMap(request); params = AliPayApi.toMap(request);
// verifyResult = AlipaySignature.rsaCertCheckV1(params, aliPayBean.getAliPayCertPath(), "UTF-8", "RSA2"); // 支付配置为绝对路径时使用 // verifyResult = AlipaySignature.rsaCertCheckV1(params, aliPayBean.getAliPayCertPath(), "UTF-8", "RSA2"); // 支付配置为绝对路径时使用
verifyResult = AlipaySignature.rsaCheckV1(params, aliPayBean.getAlipayPublicKey(), "UTF-8", "RSA2"); // 支付配置为相对路径时使用 verifyResult = AlipaySignature.rsaCheckV1(params, aliPayBean.getAlipayPublicKey(), "UTF-8", "RSA2"); // 支付配置为相对路径时使用
} else if (ObjectUtil.equal("wx_native", payment_channel_code)) { } else if (ObjectUtil.equal("wx_native", payment_channel_code)) {
// 微信
if (trade_type.equals("APP")) { if (trade_type.equals("APP")) {
verifyResult = WxPayKit.verifyNotify(params, WxPayApiConfigKit.getWxPayApiConfig().getPartnerKey(), SignType.MD5) && WxPayKit.codeIsOk(params.get("return_code")); verifyResult = WxPayKit.verifyNotify(params, WxPayApiConfigKit.getWxPayApiConfig().getPartnerKey(), SignType.MD5) && WxPayKit.codeIsOk(params.get("return_code"));
} else { } else {
@ -1131,7 +1133,7 @@ public class PayUserPayServiceImpl extends BaseServiceImpl<PayUserPayMapper, Pay
return notifyMsg(true, payment_channel_code, "非支付完成回调!"); return notifyMsg(true, payment_channel_code, "非支付完成回调!");
} }
} else if (ObjectUtil.equal("wx_native", payment_channel_code)) { } else if (ObjectUtil.equal("wx_native", payment_channel_code)) {
// TODO 不处理微信吗
} }

View File

@ -15,11 +15,9 @@ import com.suisung.mall.shop.sync.service.SyncThirdDataService;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
import java.util.List; import java.util.List;
@Api(tags = "第三方数据同步") @Api(tags = "第三方数据同步")
@ -32,31 +30,46 @@ public class SyncThirdDataController {
@ApiOperation(value = "商品分类数据同步", notes = "商品分类数据同步") @ApiOperation(value = "商品分类数据同步", notes = "商品分类数据同步")
@RequestMapping(value = "/goods/category", method = RequestMethod.POST) @RequestMapping(value = "/goods/category", method = RequestMethod.POST)
public ThirdApiRes syncGoodsCategory(@RequestBody JSONArray categoryListJSON) { public ThirdApiRes syncGoodsCategory(HttpServletRequest request,
return syncThirdDataService.saveOrUpdateShopBaseProductCategoryBatch(categoryListJSON); @RequestParam String appId,
@RequestParam String sign,
@RequestBody JSONArray categoryListJSON) {
return syncThirdDataService.saveOrUpdateShopBaseProductCategoryBatch(appId, sign, categoryListJSON);
} }
@ApiOperation(value = "商品品牌数据同步", notes = "商品品牌数据同步") @ApiOperation(value = "商品品牌数据同步", notes = "商品品牌数据同步")
@RequestMapping(value = "/goods/brand", method = RequestMethod.POST) @RequestMapping(value = "/goods/brand", method = RequestMethod.POST)
public ThirdApiRes syncGoodsBrand(@RequestBody JSONArray brandListJSON) { public ThirdApiRes syncGoodsBrand(HttpServletRequest request,
return syncThirdDataService.saveOrUpdateShopBaseProductBrandBatch(brandListJSON); @RequestParam String appId,
@RequestParam String sign,
@RequestBody JSONArray brandListJSON) {
return syncThirdDataService.saveOrUpdateShopBaseProductBrandBatch(appId, sign, brandListJSON);
} }
@ApiOperation(value = "商品辅助属性数据同步", notes = "商品辅助属性数据同步") @ApiOperation(value = "商品辅助属性数据同步", notes = "商品辅助属性数据同步")
@RequestMapping(value = "/goods/assist", method = RequestMethod.POST) @RequestMapping(value = "/goods/assist", method = RequestMethod.POST)
public ThirdApiRes syncGoodsAssist(@RequestBody String reqBody) { public ThirdApiRes syncGoodsAssist(HttpServletRequest request,
@RequestParam String appId,
@RequestParam String sign,
@RequestBody String reqBody) {
return null; return null;
} }
@ApiOperation(value = "商品数据同步", notes = "商品数据同步") @ApiOperation(value = "商品数据同步", notes = "商品数据同步")
@RequestMapping(value = "/goods", method = RequestMethod.POST) @RequestMapping(value = "/goods", method = RequestMethod.POST)
public ThirdApiRes syncGoods(@RequestBody String reqBody) { public ThirdApiRes syncGoods(HttpServletRequest request,
@RequestParam String appId,
@RequestParam String sign,
@RequestBody String reqBody) {
return null; return null;
} }
@ApiOperation(value = "会员数据同步", notes = "会员数据同步") @ApiOperation(value = "会员数据同步", notes = "会员数据同步")
@RequestMapping(value = "/member", method = RequestMethod.POST) @RequestMapping(value = "/member", method = RequestMethod.POST)
public ThirdApiRes syncMember(@RequestBody List<SyncThirdMemberReq> memberList) { public ThirdApiRes syncMember(HttpServletRequest request,
@RequestParam String appId,
@RequestParam String sign,
@RequestBody List<SyncThirdMemberReq> memberList) {
return null; return null;
} }

View File

@ -14,12 +14,12 @@ import com.suisung.mall.common.modules.sync.SyncApp;
public interface SyncAppService { public interface SyncAppService {
/** /**
* 根据 appId 获取一条记录 * 根据 appKey 获取一条记录
* *
* @param appId * @param appKey
* @return * @return
*/ */
SyncApp getSyncApp(String appId); SyncApp getSyncApp(String appKey);
/** /**
* 根据关键字搜索记录分页列表 * 根据关键字搜索记录分页列表
@ -51,20 +51,19 @@ public interface SyncAppService {
/** /**
* 修改 app key app 密钥 * 修改 app key app 密钥
* *
* @param appId
* @param appKey * @param appKey
* @param appSecret * @param appSecret
* @return * @return
*/ */
Boolean updateAppKey(String appId, String appKey, String appSecret); Boolean updateAppKey(String appKey, String appSecret);
/** /**
* 删除一条记录 * 删除一条记录
* *
* @param appId * @param appKey
* @return * @return
*/ */
Boolean deleteSyncApp(String appId); Boolean deleteSyncApp(String appKey);
/** /**
* 删除一条记录 * 删除一条记录
@ -73,4 +72,14 @@ public interface SyncAppService {
* @return * @return
*/ */
Boolean deleteSyncApp(Long id); Boolean deleteSyncApp(Long id);
/**
* 验证签名是否正确
* @param appKey
* @param sign
* @param postData
* @return
*/
SyncApp checkAppSign(String appKey, String sign, String postData);
} }

View File

@ -22,7 +22,7 @@ public interface SyncThirdDataService {
* @param categoryListJSON * @param categoryListJSON
* @return * @return
*/ */
ThirdApiRes saveOrUpdateShopBaseProductCategoryBatch(JSONArray categoryListJSON); ThirdApiRes saveOrUpdateShopBaseProductCategoryBatch(String appId, String sign, JSONArray categoryListJSON);
/** /**
* 批量保存商品品牌记录 * 批量保存商品品牌记录
@ -30,19 +30,19 @@ public interface SyncThirdDataService {
* @param brandListJSON * @param brandListJSON
* @return * @return
*/ */
ThirdApiRes saveOrUpdateShopBaseProductBrandBatch(JSONArray brandListJSON); ThirdApiRes saveOrUpdateShopBaseProductBrandBatch(String appId, String sign, JSONArray brandListJSON);
/** /**
* 批量保存商品记录 * 批量保存商品记录
* @param goodsListJSON * @param goodsListJSON
* @return * @return
*/ */
ThirdApiRes saveOrUpdateGoodsBatch(JSONArray goodsListJSON); ThirdApiRes saveOrUpdateGoodsBatch(String appId, String sign, JSONArray goodsListJSON);
/** /**
* 批量保存会员记录 * 批量保存会员记录
* @param memberList * @param memberList
* @return * @return
*/ */
ThirdApiRes saveOrUpdateMemberBatch(List<SyncThirdMemberReq> memberList); ThirdApiRes saveOrUpdateMemberBatch(String appId, String sign, List<SyncThirdMemberReq> memberList);
} }

View File

@ -13,6 +13,8 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
import com.suisung.mall.common.modules.sync.SyncApp; import com.suisung.mall.common.modules.sync.SyncApp;
import com.suisung.mall.common.utils.CommonUtil;
import com.suisung.mall.common.utils.StringUtils;
import com.suisung.mall.core.web.service.impl.BaseServiceImpl; import com.suisung.mall.core.web.service.impl.BaseServiceImpl;
import com.suisung.mall.shop.sync.mapper.SyncAppMapper; import com.suisung.mall.shop.sync.mapper.SyncAppMapper;
import com.suisung.mall.shop.sync.service.SyncAppService; import com.suisung.mall.shop.sync.service.SyncAppService;
@ -28,21 +30,22 @@ public class SyncAppServiceImpl extends BaseServiceImpl<SyncAppMapper, SyncApp>
private SyncAppMapper syncAppMapper; private SyncAppMapper syncAppMapper;
/** /**
* 根据 appId 获取一条记录 * 根据 appKey 获取一条记录
* *
* @param appId * @param appKey
* @return * @return
*/ */
@Override @Override
public SyncApp getSyncApp(String appId) { public SyncApp getSyncApp(String appKey) {
if (StrUtil.isBlank(appId)) { if (StrUtil.isBlank(appKey)) {
return null; return null;
} }
QueryWrapper<SyncApp> queryWrapper = new QueryWrapper<>(); QueryWrapper<SyncApp> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("app_id", appId); queryWrapper.eq("app_key", appKey);
return getOne(queryWrapper); return getOne(queryWrapper);
} }
/** /**
* 根据关键字搜索记录分页列表 * 根据关键字搜索记录分页列表
* *
@ -99,26 +102,20 @@ public class SyncAppServiceImpl extends BaseServiceImpl<SyncAppMapper, SyncApp>
/** /**
* 修改 app key app 密钥 * 修改 app key app 密钥
* *
* @param appId
* @param appKey * @param appKey
* @param appSecret * @param appSecret
* @return * @return
*/ */
@Override @Override
public Boolean updateAppKey(String appId, String appKey, String appSecret) { public Boolean updateAppKey(String appKey, String appSecret) {
if (appId == null || (appKey == null && appSecret == null)) { if (appKey == null || appSecret == null) {
return false; return false;
} }
UpdateWrapper<SyncApp> updateWrapper = new UpdateWrapper<>(); UpdateWrapper<SyncApp> updateWrapper = new UpdateWrapper<>();
updateWrapper.eq("app_id", appId); updateWrapper.eq("app_key", appKey);
if (StrUtil.isNotBlank(appKey)) { updateWrapper.eq("app_secret", appSecret);
updateWrapper.eq("app_key", appKey);
}
if (StrUtil.isNotBlank(appSecret)) {
updateWrapper.eq("app_secret", appSecret);
}
return update(updateWrapper); return update(updateWrapper);
} }
@ -126,17 +123,17 @@ public class SyncAppServiceImpl extends BaseServiceImpl<SyncAppMapper, SyncApp>
/** /**
* 删除一条记录 * 删除一条记录
* *
* @param appId * @param appKey
* @return * @return
*/ */
@Override @Override
public Boolean deleteSyncApp(String appId) { public Boolean deleteSyncApp(String appKey) {
if (appId == null) { if (appKey == null) {
return false; return false;
} }
QueryWrapper<SyncApp> queryWrapper = new QueryWrapper<>(); QueryWrapper<SyncApp> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("app_id", appId); queryWrapper.eq("app_key", appKey);
return remove(queryWrapper); return remove(queryWrapper);
} }
@ -153,4 +150,35 @@ public class SyncAppServiceImpl extends BaseServiceImpl<SyncAppMapper, SyncApp>
} }
return remove(id); return remove(id);
} }
/**
* 验证签名是否正确
*
* @param appKey
* @param sign
* @param postData
* @return
*/
@Override
public SyncApp checkAppSign(String appKey, String sign, String postData) {
if (StrUtil.isBlank(appKey) || StrUtil.isBlank(sign) || StrUtil.isBlank(postData)) {
return null;
}
SyncApp result = getSyncApp(appKey);
if (result == null) {
return null;
}
if(result.getStatus().equals(3)){
// 不验证签名
return result;
}
String newSign = CommonUtil.generateOpenSign(postData, result.getApp_key(), result.getApp_secret());
if (!StringUtils.equals(newSign, sign)) {
return null;
}
return result;
}
} }

View File

@ -15,6 +15,7 @@ import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import cn.hutool.crypto.SecureUtil; import cn.hutool.crypto.SecureUtil;
import cn.hutool.json.JSON;
import cn.hutool.json.JSONArray; import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject; import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil; import cn.hutool.json.JSONUtil;
@ -31,6 +32,7 @@ import com.suisung.mall.common.modules.base.ShopBaseProductType;
import com.suisung.mall.common.modules.pay.PayUserResource; import com.suisung.mall.common.modules.pay.PayUserResource;
import com.suisung.mall.common.modules.product.*; import com.suisung.mall.common.modules.product.*;
import com.suisung.mall.common.modules.store.ShopStoreBase; import com.suisung.mall.common.modules.store.ShopStoreBase;
import com.suisung.mall.common.modules.sync.SyncApp;
import com.suisung.mall.common.pojo.req.SyncThirdMemberReq; import com.suisung.mall.common.pojo.req.SyncThirdMemberReq;
import com.suisung.mall.common.pojo.res.ThirdApiRes; import com.suisung.mall.common.pojo.res.ThirdApiRes;
import com.suisung.mall.common.utils.DateTimeUtils; import com.suisung.mall.common.utils.DateTimeUtils;
@ -42,8 +44,8 @@ import com.suisung.mall.shop.base.service.ShopBaseProductTypeService;
import com.suisung.mall.shop.product.service.ShopProductBaseService; import com.suisung.mall.shop.product.service.ShopProductBaseService;
import com.suisung.mall.shop.product.service.impl.ShopProductBaseServiceImpl; import com.suisung.mall.shop.product.service.impl.ShopProductBaseServiceImpl;
import com.suisung.mall.shop.store.service.ShopStoreBaseService; import com.suisung.mall.shop.store.service.ShopStoreBaseService;
import com.suisung.mall.shop.sync.service.SyncAppService;
import com.suisung.mall.shop.sync.service.SyncThirdDataService; import com.suisung.mall.shop.sync.service.SyncThirdDataService;
import io.swagger.models.auth.In;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -73,12 +75,15 @@ public class SyncThirdDataServiceImpl implements SyncThirdDataService {
private PayService payService; private PayService payService;
@Autowired @Autowired
ShopProductBaseService shopProductBaseService; private ShopProductBaseService shopProductBaseService;
@Autowired @Autowired
ShopStoreBaseService shopStoreBaseService; private ShopStoreBaseService shopStoreBaseService;
private int limitCnt = 300; @Autowired
private SyncAppService syncAppService;
private final int limitCnt = 300;
/** /**
* 批量保存商品的分类 * 批量保存商品的分类
@ -87,24 +92,27 @@ public class SyncThirdDataServiceImpl implements SyncThirdDataService {
* @return * @return
*/ */
@Override @Override
public ThirdApiRes saveOrUpdateShopBaseProductCategoryBatch(JSONArray categoryListJSON) { public ThirdApiRes saveOrUpdateShopBaseProductCategoryBatch(String appId, String sign, JSONArray categoryListJSON) {
// TODO 验签appid必要参数判断 if (StrUtil.isBlank(appId) || StrUtil.isBlank(sign) || ObjectUtil.isEmpty(categoryListJSON)) {
if (ObjectUtil.isEmpty(categoryListJSON)) {
return new ThirdApiRes().fail(1003, I18nUtil._("缺少必要参数!")); return new ThirdApiRes().fail(1003, I18nUtil._("缺少必要参数!"));
} }
// 验签appid必要参数判断
SyncApp syncApp = syncAppService.checkAppSign(appId, sign, categoryListJSON.toString());
if (syncApp == null) {
return new ThirdApiRes().fail(1001, I18nUtil._("签名有误!"));
}
String storeId = syncApp.getStore_id();
List<ShopBaseProductCategory> list = JSONUtil.toList(categoryListJSON, ShopBaseProductCategory.class); List<ShopBaseProductCategory> list = JSONUtil.toList(categoryListJSON, ShopBaseProductCategory.class);
if (list == null) { if (list == null) {
return new ThirdApiRes().fail(1004, I18nUtil._("请求参数有误!")); return new ThirdApiRes().fail(1004, I18nUtil._("请求参数有误!"));
} }
if (list != null && list.size() > limitCnt) { if (list != null && list.size() > limitCnt) {
return new ThirdApiRes().fail(1004, I18nUtil._("单次同步记录最多"+limitCnt+"条!")); return new ThirdApiRes().fail(1004, I18nUtil._("单次同步记录最多" + limitCnt + "条!"));
} }
String storeId = "3";
int count = 0; int count = 0;
for (int i = 0; i < list.size(); i++) { for (int i = 0; i < list.size(); i++) {
list.get(i).setStore_id(storeId); // app 记录传进来 list.get(i).setStore_id(storeId); // app 记录传进来
@ -171,27 +179,32 @@ public class SyncThirdDataServiceImpl implements SyncThirdDataService {
* @return * @return
*/ */
@Override @Override
public ThirdApiRes saveOrUpdateShopBaseProductBrandBatch(JSONArray brandListJSON) { public ThirdApiRes saveOrUpdateShopBaseProductBrandBatch(String appId, String sign, JSONArray brandListJSON) {
// TODO 验签appid必要参数判断 if (StrUtil.isBlank(appId) || StrUtil.isBlank(sign) || ObjectUtil.isEmpty(brandListJSON)) {
if (ObjectUtil.isEmpty(brandListJSON)) {
return new ThirdApiRes().fail(1003, I18nUtil._("缺少必要参数!")); return new ThirdApiRes().fail(1003, I18nUtil._("缺少必要参数!"));
} }
// 验签appid必要参数判断
SyncApp syncApp = syncAppService.checkAppSign(appId, sign, brandListJSON.toString());
if (syncApp == null) {
return new ThirdApiRes().fail(1001, I18nUtil._("签名有误!"));
}
String storeId = syncApp.getStore_id();
List<ShopBaseProductBrand> goodBrandList = JSONUtil.toList(brandListJSON, ShopBaseProductBrand.class); List<ShopBaseProductBrand> goodBrandList = JSONUtil.toList(brandListJSON, ShopBaseProductBrand.class);
if (goodBrandList == null) { if (goodBrandList == null) {
return new ThirdApiRes().fail(1004, I18nUtil._("请求参数有误!")); return new ThirdApiRes().fail(1004, I18nUtil._("请求参数有误!"));
} }
if (goodBrandList != null && goodBrandList.size() > limitCnt) { if (goodBrandList != null && goodBrandList.size() > limitCnt) {
return new ThirdApiRes().fail(1004, I18nUtil._("单次同步记录最多"+limitCnt+"条!")); return new ThirdApiRes().fail(1004, I18nUtil._("单次同步记录最多" + limitCnt + "条!"));
} }
Integer storeId = 3;
int count = 0; int count = 0;
for (int i = 0; i < goodBrandList.size(); i++) { for (int i = 0; i < goodBrandList.size(); i++) {
goodBrandList.get(i).setStore_id(storeId); // app 记录传进来 goodBrandList.get(i).setStore_id(Integer.valueOf(storeId)); // app 记录传进来
// 处理大分类字段 // 处理大分类字段
JSONObject o = (JSONObject) brandListJSON.get(i); JSONObject o = (JSONObject) brandListJSON.get(i);
if (o != null && StrUtil.isNotBlank(o.getStr("category"))) { if (o != null && StrUtil.isNotBlank(o.getStr("category"))) {
@ -217,23 +230,27 @@ public class SyncThirdDataServiceImpl implements SyncThirdDataService {
* @return * @return
*/ */
@Override @Override
public ThirdApiRes saveOrUpdateGoodsBatch(JSONArray goodsListJSON) { public ThirdApiRes saveOrUpdateGoodsBatch(String appId, String sign, JSONArray goodsListJSON) {
// TODO 验签appid必要参数判断 if (StrUtil.isBlank(appId) || StrUtil.isBlank(sign) || ObjectUtil.isEmpty(goodsListJSON)) {
if (ObjectUtil.isEmpty(goodsListJSON)) {
return new ThirdApiRes().fail(1003, I18nUtil._("缺少必要参数!")); return new ThirdApiRes().fail(1003, I18nUtil._("缺少必要参数!"));
} }
// 验签appid必要参数判断
SyncApp syncApp = syncAppService.checkAppSign(appId, sign, goodsListJSON.toString());
if (syncApp == null) {
return new ThirdApiRes().fail(1001, I18nUtil._("签名有误!"));
}
String storeId = syncApp.getStore_id();
List<ShopBaseProductBrand> goodBrandList = JSONUtil.toList(goodsListJSON, ShopBaseProductBrand.class); List<ShopBaseProductBrand> goodBrandList = JSONUtil.toList(goodsListJSON, ShopBaseProductBrand.class);
if (goodBrandList == null) { if (goodBrandList == null) {
return new ThirdApiRes().fail(1004, I18nUtil._("请求参数有误!")); return new ThirdApiRes().fail(1004, I18nUtil._("请求参数有误!"));
} }
if (goodsListJSON.size() > limitCnt) { if (goodsListJSON.size() > limitCnt) {
return new ThirdApiRes().fail(1004, I18nUtil._("单次同步记录最多"+limitCnt+"条!")); return new ThirdApiRes().fail(1004, I18nUtil._("单次同步记录最多" + limitCnt + "条!"));
} }
Integer storeId = 3;
int count = 0; int count = 0;
for (JSONObject jsonObj : goodsListJSON.jsonIter()) { for (JSONObject jsonObj : goodsListJSON.jsonIter()) {
@ -355,12 +372,19 @@ public class SyncThirdDataServiceImpl implements SyncThirdDataService {
* @return * @return
*/ */
@Override @Override
public ThirdApiRes saveOrUpdateMemberBatch(List<SyncThirdMemberReq> memberList) { public ThirdApiRes saveOrUpdateMemberBatch(String appId, String sign, List<SyncThirdMemberReq> memberList) {
if (CollUtil.isEmpty(memberList)) { if (StrUtil.isBlank(appId) || StrUtil.isBlank(sign) || CollUtil.isEmpty(memberList)) {
return new ThirdApiRes().fail(1003, I18nUtil._("缺少必要参数!")); return new ThirdApiRes().fail(1003, I18nUtil._("缺少必要参数!"));
} }
String storeId = "3"; // 验签appid必要参数判断
SyncApp syncApp = syncAppService.checkAppSign(appId, sign, JSONUtil.toJsonStr(memberList));
if (syncApp == null) {
return new ThirdApiRes().fail(1001, I18nUtil._("签名有误!"));
}
String storeId = syncApp.getStore_id();
if (memberList.size() > limitCnt) { if (memberList.size() > limitCnt) {
return new ThirdApiRes().fail(1004, I18nUtil._("单次同步记录最多" + limitCnt + "条!")); return new ThirdApiRes().fail(1004, I18nUtil._("单次同步记录最多" + limitCnt + "条!"));
} }
@ -415,7 +439,9 @@ public class SyncThirdDataServiceImpl implements SyncThirdDataService {
success = payService.saveOrUpdatePayUserResource(payUserResource); success = payService.saveOrUpdatePayUserResource(payUserResource);
} }
if(success) {count += 1;} if (success) {
count += 1;
}
} }
Map<String, Integer> resp = new HashMap<>(); Map<String, Integer> resp = new HashMap<>();