|
|
|
@ -1,6 +1,7 @@
|
|
|
|
|
package com.ms.api.spi.callback;
|
|
|
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
|
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;
|
|
|
|
@ -16,65 +17,67 @@ 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.api.tool.SecurityTool;
|
|
|
|
|
import com.ms.dal.entity.Shop;
|
|
|
|
|
import lombok.Data;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
|
|
|
|
|
|
|
import java.util.Date;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
import java.util.Objects;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 抖店授权回调地址
|
|
|
|
|
*/
|
|
|
|
|
@ExtensionService("shopAuthCallback")
|
|
|
|
|
@Slf4j
|
|
|
|
|
public class ShopAuthCallbackService extends SPIBaseService implements ExtensionServiceHandler<Object, Ret> {
|
|
|
|
|
public class ShopAuthCallbackService extends SPIBaseService implements ExtensionServiceHandler<CallBackRequest, String> {
|
|
|
|
|
|
|
|
|
|
@Value("${cloud.app.secret}")
|
|
|
|
|
private String cloudAppSecret;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private ShopService shopService;
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public BaseResponse<Ret> handle(BaseRequest<Object> req) {
|
|
|
|
|
// initHandle(req);
|
|
|
|
|
public BaseResponse<String> handle(BaseRequest<CallBackRequest> req) {
|
|
|
|
|
// ----参数校验----
|
|
|
|
|
log.info("receive callback: " + JSON.toJSONString(req));
|
|
|
|
|
Object fields = req.getData();
|
|
|
|
|
log.info("receive callback: " + JSON.toJSONString(fields));
|
|
|
|
|
String url = req.getData().getUrl();
|
|
|
|
|
String reqBody = req.getData().getBody();
|
|
|
|
|
String key = cloudAppSecret.replaceAll("-", "");
|
|
|
|
|
reqBody = SecurityTool.decryptDoudianCallback(reqBody, key);
|
|
|
|
|
log.info("receive callback body: ", reqBody);
|
|
|
|
|
|
|
|
|
|
JSONObject bodyObj = JSONObject.parseObject(reqBody);
|
|
|
|
|
Integer msgType = bodyObj.getInteger("msg_type");
|
|
|
|
|
if (msgType == 2) { // 授权消息
|
|
|
|
|
String msg = bodyObj.getString("msg");
|
|
|
|
|
JSONObject msgObj = JSONObject.parseObject(msg);
|
|
|
|
|
Long shopId = msgObj.getLong("shop_id");
|
|
|
|
|
|
|
|
|
|
Shop shop = shopService.getDetailById(shopId);
|
|
|
|
|
if (Objects.isNull(shop)) {
|
|
|
|
|
shop = new Shop();
|
|
|
|
|
shop.setShopId(shopId);
|
|
|
|
|
shop.setGmtCreate(new Date());
|
|
|
|
|
shop.setGmtModified(new Date());
|
|
|
|
|
shopService.insert(shop);
|
|
|
|
|
|
|
|
|
|
throw new MSException("预留接口,看返回结构");
|
|
|
|
|
// // ----逻辑校验----
|
|
|
|
|
// 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());
|
|
|
|
|
// TODO 创建素材文件夹
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 按照三方平台的规范返回成功或失败的body值
|
|
|
|
|
String respBody = "{\"success\":true,\"code\":0}";
|
|
|
|
|
return BaseResponse.<String>builder().success(true).code("0").data(respBody).build();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Data
|
|
|
|
|
class CallBackRequest {
|
|
|
|
|
private String url;
|
|
|
|
|
private String body;
|
|
|
|
|
}
|
|
|
|
|