wangchaoxu 1 year ago
commit 3c1e018649

@ -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\",\"\":\"\"}"
}'

@ -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<ItemDTO
@Override
public BaseResponse<String> handle(BaseRequest<ItemDTO> req) {
MultiValueMap<String, Object> params = new UniqueKeyMultiValueMap<>();
HashMap<String, Object> params = new HashMap<>();
// List arrayString = new ArrayList<String>();
// arrayString.add("arrayString1");
// arrayString.add("arrayString2");
// params.add("arrayString", JSON.toJSONString(arrayString));
List<String> arrayString = new ArrayList<>();
arrayString.add("arrayString1");
arrayString.add("arrayString2");
params.put("arrayString", arrayString);
HashMap<String, Object> mapStringString = new HashMap<>();
HashMap<String, String> mapStringString = new HashMap<>();
mapStringString.put("A","mapStringString1");
mapStringString.put("B","mapStringString2");
params.add("mapStringString", mapStringString);
//
// List arrayInt64 = new ArrayList<Integer>();
// 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<Integer> 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<Object> arrayStruct = new LinkedList<>();
arrayStruct.add(new GetCurrentShopMoveSettingRequestDTO());
arrayStruct.add(new GetMoveHistoryProductListRequestDTO());
arrayStruct.add(new SaveBatchMoveTaskRequestDTO());
params.put("arrayStruct", arrayStruct);
Map<String,Object> 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 {

@ -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<PlatformAuthCallBackRequestDTO, Map<String, String>> {
@Override
public BaseResponse<Map<String, String>> handle(BaseRequest<PlatformAuthCallBackRequestDTO> req) {
// ----参数校验----
PlatformAuthCallBackRequestDTO fields = req.getData();
log.info("receive callback: " + JSON.toJSONString(fields));
// ----逻辑校验----
// ----业务处理----
// ----结果返回----
return R.ok(CommonTool.successResult());
}
}

@ -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<PlatformAuthCallBackRequestDTO, Map<String, String>> {
public class MemberAuthCallback extends SPIBaseService implements ExtensionServiceHandler<PlatformAuthCallBackRequestDTO, Map<String, String>> {
@Override
public BaseResponse<Map<String, String>> handle(BaseRequest<PlatformAuthCallBackRequestDTO> req) {

@ -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<List<String>, Void> {
@Override
public BaseResponse<Void> handle(BaseRequest<List<String>> req) {
// ----参数校验----
// ----逻辑校验----
// ----业务处理----
return R.ok();
}
}

@ -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<Object, Map<String, String>> {
@Autowired
private ShopService shopService;
@Override
public BaseResponse<Map<String, String>> handle(BaseRequest<Object> 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());
}
}

@ -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<String,Object> params = (UniqueKeyMultiValueMap<String,Object>)body;
HashMap<String,Object> params = (HashMap<String,Object>)body;
// 构建签名
Set<String> 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());

Loading…
Cancel
Save