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