package com.miniso.robot.feign;
import cn.hutool.json.JSON;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.miniso.robot.bean.Message;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
@Component
@FeignClient(name = "robotWebHookFeign",url = "${robot.webhook.url}",configuration = RobotFeignConfig.class)
public interface RobotFeign {
@RequestMapping(value = "/upload_media", method = RequestMethod.POST, consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
String uploadFile(@RequestParam(name="key") String robotKey,@RequestParam(name="type")String type,@RequestPart("file") MultipartFile file);
default String uploadFile(String robotKey,MultipartFile file){
JSONObject jsonObject = JSONUtil.parseObj(uploadFile(robotKey, "file", file));
if( 0 ==jsonObject.get("errcode",Integer.class)){
return jsonObject.get("media_id",String.class);
}
return null;
}
}