diff --git a/README.md b/README.md index 20127e45..cebd0154 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ curl --location --request POST 'localhost:8080/base/cloud/spi' \ --data-raw '{ "appId":"123456", "authId":"888999", -"method":"dsTestJavaRequest", +"method":"shopAuthCallback", "data":"{\"userId\":\"30459766\",\"\":\"\"}" }' diff --git a/ms-biz/src/main/java/com/ms/api/DsTestJavaRequestService.java b/ms-biz/src/main/java/com/ms/api/DsTestJavaRequestService.java index b81f369c..92cda5e8 100644 --- a/ms-biz/src/main/java/com/ms/api/DsTestJavaRequestService.java +++ b/ms-biz/src/main/java/com/ms/api/DsTestJavaRequestService.java @@ -7,6 +7,10 @@ import com.jinritemai.cloud.base.api.ExtensionService; import com.jinritemai.cloud.base.api.ExtensionServiceHandler; import com.ms.api.common.R; import com.ms.api.dto.ItemDTO; +import com.ms.api.dto.move.GetChoicenessSourceItemTagRequestDTO; +import com.ms.api.dto.move.GetCurrentShopMoveSettingRequestDTO; +import com.ms.api.dto.move.GetMoveHistoryProductListRequestDTO; +import com.ms.api.dto.move.SaveBatchMoveTaskRequestDTO; import com.ms.api.tool.DsFormRequestTemplate; import com.ms.api.common.UniqueKeyMultiValueMap; import com.ms.api.tool.DsJsonRequestTemplate; @@ -14,7 +18,7 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.util.MultiValueMap; -import java.util.HashMap; +import java.util.*; @ExtensionService("dsTestJavaRequest") @Slf4j @@ -28,33 +32,42 @@ public class DsTestJavaRequestService implements ExtensionServiceHandler handle(BaseRequest req) { - MultiValueMap params = new UniqueKeyMultiValueMap<>(); + HashMap params = new HashMap<>(); -// List arrayString = new ArrayList(); -// arrayString.add("arrayString1"); -// arrayString.add("arrayString2"); -// params.add("arrayString", JSON.toJSONString(arrayString)); + List arrayString = new ArrayList<>(); + arrayString.add("arrayString1"); + arrayString.add("arrayString2"); + params.put("arrayString", arrayString); - HashMap mapStringString = new HashMap<>(); + HashMap mapStringString = new HashMap<>(); mapStringString.put("A","mapStringString1"); mapStringString.put("B","mapStringString2"); - params.add("mapStringString", mapStringString); -// -// List arrayInt64 = new ArrayList(); -// arrayInt64.add(10000); -// arrayInt64.add(10000); -// params.add("arrayInt64", JSON.toJSONString(arrayInt64)); -// -// params.add("int16", String.valueOf(10000)); -// params.add("int32", String.valueOf(10000)); -// params.add("int64", String.valueOf(10000)); -// params.add("double", String.valueOf(10.1)); - params.add("string", "test"); -// params.put("boolean", JSON.toJSONString(true)); + params.put("mapStringString", mapStringString); -// params.put("struct", ); -// params.put("arrayStruct", ); -// params.put("mapStringStruct", ); + List arrayInt64 = new ArrayList<>(); + arrayInt64.add(10000); + arrayInt64.add(10000); + params.put("arrayInt64", arrayInt64); + + params.put("int16", 10000); + params.put("int32", 10000); + params.put("int64", 10000); +// params.put("double", 10.1); + params.put("string", "test"); + + params.put("struct", new GetCurrentShopMoveSettingRequestDTO()); + + List arrayStruct = new LinkedList<>(); + arrayStruct.add(new GetCurrentShopMoveSettingRequestDTO()); + arrayStruct.add(new GetMoveHistoryProductListRequestDTO()); + arrayStruct.add(new SaveBatchMoveTaskRequestDTO()); + params.put("arrayStruct", arrayStruct); + + Map mapStringStruct = new HashMap<>(); + mapStringStruct.put("mapstruct1", new GetCurrentShopMoveSettingRequestDTO()); + mapStringStruct.put("mapstruct2", new GetMoveHistoryProductListRequestDTO()); + mapStringStruct.put("mapstruct3", new SaveBatchMoveTaskRequestDTO()); + params.put("mapStringStruct", mapStringStruct); String res = null; try { diff --git a/ms-biz/src/main/java/com/ms/api/spi/callback/DsMessageCallbackService.java b/ms-biz/src/main/java/com/ms/api/spi/callback/DsMessageCallbackService.java new file mode 100644 index 00000000..aeb8f1ff --- /dev/null +++ b/ms-biz/src/main/java/com/ms/api/spi/callback/DsMessageCallbackService.java @@ -0,0 +1,36 @@ +package com.ms.api.spi.callback; + +import com.alibaba.fastjson.JSON; +import com.jinritemai.cloud.base.api.BaseRequest; +import com.jinritemai.cloud.base.api.BaseResponse; +import com.jinritemai.cloud.base.api.ExtensionService; +import com.jinritemai.cloud.base.api.ExtensionServiceHandler; +import com.ms.api.common.R; +import com.ms.api.common.SPIBaseService; +import com.ms.api.dto.auth.PlatformAuthCallBackRequestDTO; +import com.ms.api.tool.CommonTool; +import lombok.extern.slf4j.Slf4j; + +import java.util.Map; + +/** + * 1688分销采购单消息 + */ +@ExtensionService("dsMessageCallback") +@Slf4j +public class DsMessageCallbackService extends SPIBaseService implements ExtensionServiceHandler> { + + @Override + public BaseResponse> handle(BaseRequest req) { + // ----参数校验---- + PlatformAuthCallBackRequestDTO fields = req.getData(); + log.info("receive callback: " + JSON.toJSONString(fields)); + + // ----逻辑校验---- + + // ----业务处理---- + + // ----结果返回---- + return R.ok(CommonTool.successResult()); + } +} diff --git a/ms-biz/src/main/java/com/ms/api/spi/common/CallBackMessageService.java b/ms-biz/src/main/java/com/ms/api/spi/callback/MemberAuthCallback.java similarity index 81% rename from ms-biz/src/main/java/com/ms/api/spi/common/CallBackMessageService.java rename to ms-biz/src/main/java/com/ms/api/spi/callback/MemberAuthCallback.java index 7d630223..1a1baf32 100644 --- a/ms-biz/src/main/java/com/ms/api/spi/common/CallBackMessageService.java +++ b/ms-biz/src/main/java/com/ms/api/spi/callback/MemberAuthCallback.java @@ -1,4 +1,4 @@ -package com.ms.api.spi.common; +package com.ms.api.spi.callback; import com.alibaba.fastjson.JSON; import com.jinritemai.cloud.base.api.BaseRequest; @@ -16,9 +16,9 @@ import java.util.Map; /** * 获取授权1688授权回调地址 */ -@ExtensionService("callBackMessage") +@ExtensionService("memberAuthCallBack") @Slf4j -public class CallBackMessageService extends SPIBaseService implements ExtensionServiceHandler> { +public class MemberAuthCallback extends SPIBaseService implements ExtensionServiceHandler> { @Override public BaseResponse> handle(BaseRequest req) { diff --git a/ms-biz/src/main/java/com/ms/api/spi/callback/OpenMsgConsumerService.java b/ms-biz/src/main/java/com/ms/api/spi/callback/OpenMsgConsumerService.java new file mode 100644 index 00000000..5d8d3c56 --- /dev/null +++ b/ms-biz/src/main/java/com/ms/api/spi/callback/OpenMsgConsumerService.java @@ -0,0 +1,31 @@ +package com.ms.api.spi.callback; + +import com.alibaba.fastjson.JSON; +import com.jinritemai.cloud.base.api.BaseRequest; +import com.jinritemai.cloud.base.api.BaseResponse; +import com.jinritemai.cloud.base.api.ExtensionService; +import com.jinritemai.cloud.base.api.ExtensionServiceHandler; +import com.ms.api.common.R; +import com.ms.api.common.SPIBaseService; +import com.ms.api.dto.auth.PlatformAuthCallBackRequestDTO; +import lombok.extern.slf4j.Slf4j; + +import java.util.List; + +/** + * 抖店消息推送,固定的key:CloudOpenMsgConsumer + */ +@ExtensionService("CloudOpenMsgConsumer") +@Slf4j +public class OpenMsgConsumerService extends SPIBaseService implements ExtensionServiceHandler, Void> { + + @Override + public BaseResponse handle(BaseRequest> req) { + // ----参数校验---- + + // ----逻辑校验---- + + // ----业务处理---- + return R.ok(); + } +} diff --git a/ms-biz/src/main/java/com/ms/api/spi/callback/ShopAuthCallbackService.java b/ms-biz/src/main/java/com/ms/api/spi/callback/ShopAuthCallbackService.java new file mode 100644 index 00000000..00da691a --- /dev/null +++ b/ms-biz/src/main/java/com/ms/api/spi/callback/ShopAuthCallbackService.java @@ -0,0 +1,77 @@ +package com.ms.api.spi.callback; + +import com.alibaba.fastjson.JSON; +import com.doudian.open.api.token_create.TokenCreateRequest; +import com.doudian.open.api.token_create.TokenCreateResponse; +import com.doudian.open.api.token_create.data.TokenCreateData; +import com.doudian.open.api.token_create.param.TokenCreateParam; +import com.jinritemai.cloud.base.api.BaseRequest; +import com.jinritemai.cloud.base.api.BaseResponse; +import com.jinritemai.cloud.base.api.ExtensionService; +import com.jinritemai.cloud.base.api.ExtensionServiceHandler; +import com.ms.api.common.R; +import com.ms.api.common.SPIBaseService; +import com.ms.api.dto.auth.PlatformAuthCallBackRequestDTO; +import com.ms.api.service.ShopService; +import com.ms.api.tool.CommonTool; +import com.ms.dal.entity.Shop; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; + +import java.util.Map; + +/** + * 抖店授权回调地址 + */ +@ExtensionService("shopAuthCallback") +@Slf4j +public class ShopAuthCallbackService extends SPIBaseService implements ExtensionServiceHandler> { + + @Autowired + private ShopService shopService; + + @Override + public BaseResponse> handle(BaseRequest req) { + // ----参数校验---- + log.info("receive callback: " + JSON.toJSONString(req)); + Object fields = req.getData(); + log.info("receive callback: " + JSON.toJSONString(fields)); + + + // ----逻辑校验---- + TokenCreateRequest request = new TokenCreateRequest(); + TokenCreateParam param = request.getParam(); + param.setCode("df020f1c-37ed-41b5-8341-85d3d3b02250"); + param.setGrantType("authorization_code"); + log.info("receive callback: " + JSON.toJSONString(param)); + TokenCreateResponse response = request.execute(); + TokenCreateData data = new TokenCreateData(); + data = response.getData(); + Long shopId = data.getShopId(); + String accessToken = data.getAccessToken(); + Long expiresIn = data.getExpiresIn(); + String shopName = data.getShopName(); + String refreshToken = data.getRefreshToken(); + Shop shop = shopService.getDetailById(shopId); + if (shop == null) { + shop = new Shop(); + shop.setShopId(shopId); + // shop.setAccessToken(accessToken); // 加密 + // shop.setRefreshToken(refreshToken); // 加密 + shop.setExpiresIn(expiresIn.toString()); + shop.setShopName(shopName); + shopService.insert(shop); + } else { + // shop.setAccessToken(accessToken); // 加密 + // shop.setRefreshToken(refreshToken); // 加密 + shopService.updateByPrimaryKey(shop); + } + + + // log.info("receive callback: " + JSON.toJSONString(response.getData())); + // ----业务处理---- + + // ----结果返回---- + return R.ok(CommonTool.successResult()); + } +} diff --git a/ms-biz/src/main/java/com/ms/api/tool/DsJsonRequestTemplate.java b/ms-biz/src/main/java/com/ms/api/tool/DsJsonRequestTemplate.java index 533c371a..1e290a73 100644 --- a/ms-biz/src/main/java/com/ms/api/tool/DsJsonRequestTemplate.java +++ b/ms-biz/src/main/java/com/ms/api/tool/DsJsonRequestTemplate.java @@ -2,17 +2,16 @@ package com.ms.api.tool; import cn.hutool.crypto.SecureUtil; import com.alibaba.fastjson.JSON; -import com.ms.api.common.UniqueKeyMultiValueMap; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.http.HttpHeaders; import org.springframework.http.MediaType; import org.springframework.stereotype.Component; -import org.springframework.util.MultiValueMap; import org.springframework.util.StringUtils; import java.util.Arrays; +import java.util.HashMap; import java.util.Set; /** @@ -61,7 +60,7 @@ public class DsJsonRequestTemplate { headers.set("x-app-name", "msddMicro"); // 使用json方式更符合外部服务管理 headers.setContentType(MediaType.APPLICATION_JSON); - MultiValueMap params = (UniqueKeyMultiValueMap)body; + HashMap params = (HashMap)body; // 构建签名 Set keySet = params.keySet(); String[] keyArray = keySet.toArray(new String[0]); @@ -69,7 +68,7 @@ public class DsJsonRequestTemplate { StringBuilder sb = new StringBuilder(); sb.append(dsToken); for (String s : keyArray) { - sb.append(s).append(JSON.toJSONString(params.getFirst(s))); + sb.append(s).append(JSON.toJSONString(params.get(s))); } sb.append(dsToken); String sign = SecureUtil.md5(sb.toString());