|
|
|
@ -6,6 +6,9 @@ import com.gitee.sop.websiteserver.sign.AlipaySignature; |
|
|
|
|
import com.gitee.sop.websiteserver.util.UploadUtil; |
|
|
|
|
import lombok.Data; |
|
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
|
import okhttp3.Headers; |
|
|
|
|
import okhttp3.Response; |
|
|
|
|
import okhttp3.ResponseBody; |
|
|
|
|
import org.apache.commons.io.IOUtils; |
|
|
|
|
import org.apache.commons.lang.StringUtils; |
|
|
|
|
import org.apache.http.NameValuePair; |
|
|
|
@ -25,6 +28,7 @@ import org.springframework.web.bind.annotation.RestController; |
|
|
|
|
import org.springframework.web.multipart.MultipartFile; |
|
|
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest; |
|
|
|
|
import javax.servlet.http.HttpServletResponse; |
|
|
|
|
import java.io.IOException; |
|
|
|
|
import java.text.SimpleDateFormat; |
|
|
|
|
import java.util.Collection; |
|
|
|
@ -59,7 +63,10 @@ public class SandboxController { |
|
|
|
|
, @RequestParam String version |
|
|
|
|
, @RequestParam String bizContent |
|
|
|
|
, @RequestParam(defaultValue = "get") String httpMethod |
|
|
|
|
, HttpServletRequest request) throws AlipayApiException { |
|
|
|
|
, @RequestParam(defaultValue = "false") boolean isDownloadRequest |
|
|
|
|
, HttpServletRequest request |
|
|
|
|
, HttpServletResponse response |
|
|
|
|
) throws AlipayApiException { |
|
|
|
|
|
|
|
|
|
Assert.isTrue(StringUtils.isNotBlank(appId), "AppId不能为空"); |
|
|
|
|
Assert.isTrue(StringUtils.isNotBlank(privateKey), "PrivateKey不能为空"); |
|
|
|
@ -110,7 +117,21 @@ public class SandboxController { |
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
String responseData; |
|
|
|
|
if (!CollectionUtils.isEmpty(files)) { |
|
|
|
|
if (isDownloadRequest) { |
|
|
|
|
Response resp = httpTool.requestForResponse(url, params, Collections.emptyMap(), HttpTool.HTTPMethod.GET); |
|
|
|
|
Headers respHeaders = resp.headers(); |
|
|
|
|
ResponseBody body = resp.body(); |
|
|
|
|
if (body == null) { |
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
respHeaders |
|
|
|
|
.names() |
|
|
|
|
.forEach(name -> response.setHeader(name, respHeaders.get(name))); |
|
|
|
|
|
|
|
|
|
IOUtils.copy(body.byteStream(), response.getOutputStream()); |
|
|
|
|
response.flushBuffer(); |
|
|
|
|
return null; |
|
|
|
|
} else if (!CollectionUtils.isEmpty(files)) { |
|
|
|
|
responseData = httpTool.requestFile(url, params, Collections.emptyMap(), files); |
|
|
|
|
} else { |
|
|
|
|
responseData = httpTool.request(url, params, Collections.emptyMap(), HttpTool.HTTPMethod.fromValue(httpMethod)); |
|
|
|
@ -118,6 +139,7 @@ public class SandboxController { |
|
|
|
|
result.apiResult = responseData; |
|
|
|
|
return result; |
|
|
|
|
} catch (Exception e) { |
|
|
|
|
log.error("请求失败", e); |
|
|
|
|
throw new RuntimeException("请求失败"); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|