提交 5a3ef6d4 编写于 作者: zhouweidong's avatar zhouweidong

补充阿里网页支付回调业务系统

上级 133bcf31
......@@ -115,9 +115,7 @@ public class DevBootSecurityConfig extends WebSecurityConfigurerAdapter {
.antMatchers("/"+uploadpath).permitAll()
.antMatchers("/"+previewpath+"/**").permitAll()
//开放支付接口
.antMatchers("/trade/pagepay").permitAll()
.antMatchers("/trade/precreate").permitAll()
.antMatchers("/trade/query").permitAll()
.antMatchers("/pay/trade/**").permitAll()
.anyRequest().authenticated()
// 防止iframe 造成跨域
.and().headers().frameOptions().disable();
......
......@@ -120,9 +120,7 @@ public class apiSecurityConfig extends WebSecurityConfigurerAdapter {
.antMatchers("/"+uploadpath).permitAll()
.antMatchers("/"+previewpath+"/**").permitAll()
//开放支付接口
.antMatchers("/trade/pagepay").permitAll()
.antMatchers("/trade/precreate").permitAll()
.antMatchers("/trade/query").permitAll()
.antMatchers("/pay/trade/**").permitAll()
// 所有请求都需要认证
.anyRequest().authenticated()
// 防止iframe 造成跨域
......
......@@ -14,6 +14,7 @@ import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
@RestController
public class PayCoreResource {
......@@ -27,33 +28,33 @@ public class PayCoreResource {
PayTradeMapping payTradeMapping;
@ApiOperation(value = "预下单获取二维码", tags = {"获取二维码" }, notes = "预下单获取二维码")
@RequestMapping(method = RequestMethod.POST,value = "/trade/precreate")
@RequestMapping(method = RequestMethod.POST,value = "/pay/trade/precreate")
public ResponseEntity<JSONObject> preCreate(@Validated @RequestBody PayTradeDTO dto){
return ResponseEntity.status(HttpStatus.OK).body(payCoreService.preCreate(payTradeMapping.toDomain(dto)));
}
@ApiOperation(value = "查询订单", tags = {"查询订单" }, notes = "查询订单")
@RequestMapping(method = RequestMethod.POST,value = "/trade/query")
@RequestMapping(method = RequestMethod.POST,value = "/pay/trade/query")
public ResponseEntity<JSONObject> query(@Validated @RequestBody PayTradeDTO dto){
return ResponseEntity.status(HttpStatus.OK).body(payCoreService.query(payTradeMapping.toDomain(dto)));
}
@ApiOperation(value = "取消订单", tags = {"取消订单" }, notes = "取消订单")
@RequestMapping(method = RequestMethod.POST,value = "/trade/cancel")
@RequestMapping(method = RequestMethod.POST,value = "/pay/trade/cancel")
public ResponseEntity<JSONObject> cancel(@Validated @RequestBody PayTradeDTO dto){
return ResponseEntity.status(HttpStatus.OK).body(payCoreService.cancel(payTradeMapping.toDomain(dto)));
}
@ApiOperation(value = "网页支付", tags = {"网页支付" }, notes = "网页支付")
@RequestMapping(method = RequestMethod.POST,value = "/trade/pagepay")
@RequestMapping(method = RequestMethod.POST,value = "/pay/trade/pagepay")
public ResponseEntity<String> pagePay(@Validated @RequestBody PayTradeDTO dto){
return ResponseEntity.status(HttpStatus.OK).body(payCoreService.pagePay(payTradeMapping.toDomain(dto)));
}
@ApiOperation(value = "网页支付回调", tags = {"网页支付回调" }, notes = "网页支付回调")
@RequestMapping(method = RequestMethod.GET,value = "/trade/pagepaycallback")
public ResponseEntity<String> pagePayCallBack(@Validated @RequestBody PayTradeDTO dto) {
return ResponseEntity.status(HttpStatus.OK).body(payCoreService.pagePayCallBack(payTradeMapping.toDomain(dto)));
@RequestMapping(value = "/pay/trade/pagepay/callback")
public ResponseEntity<String> pagePayCallBack(HttpServletRequest req) {
return ResponseEntity.status(HttpStatus.OK).body(payCoreService.pagePayCallBack(req));
}
}
package cn.ibizlab.util.helper;
import com.alibaba.fastjson.JSONObject;
import org.springframework.core.io.Resource;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.StringHttpMessageConverter;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestTemplate;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.nio.charset.Charset;
/**
* 请求工具类
*/
public class HttpUtils {
private final static String DEFAULT_ENCODING = "UTF-8";
/**
* Post请求
*
* @return
*/
public static String post(String url) {
return post(url,null,null);
}
/**
*Post请求
* @param
* @return
*/
public static String post(String url,JSONObject headerMap,JSONObject paramMap) {
return doRestRequest(url,HttpMethod.POST,headerMap,paramMap);
}
/**
*put请求
* @param
* @return
*/
public static String put(String url, JSONObject headerMap,JSONObject paramMap) {
return doRestRequest(url,HttpMethod.PUT,headerMap,paramMap);
}
/**
* GET请求
*
* @param
* @return
*/
public static String get(String url) throws UnsupportedEncodingException {
return get(url,null,null);
}
/**
* GET请求
*
* @param
* @param
* @return
*/
public static String get(String url, JSONObject headerMap,JSONObject paramMap) throws UnsupportedEncodingException {
if(paramMap !=null){
boolean flag = true;
for(String key : paramMap.keySet()){
if(flag){
url += "?";
}else{
url += "&";
}
flag = false;
url = url + key + "=" + URLEncoder.encode(paramMap.getString(key),DEFAULT_ENCODING);
}
}
return doRestRequest(url,HttpMethod.GET,headerMap,paramMap);
}
/**
* DELETE请求
*
* @param
* @return
*/
public static String delete(String url) {
return delete(url,null,null);
}
/**
* DELETE请求
*
* @param
* @param
* @return
*/
public static String delete(String url, JSONObject headerMap,JSONObject paramMap) {
return doRestRequest(url,HttpMethod.DELETE,headerMap,paramMap);
}
public static String doRestRequest(String url, HttpMethod method, JSONObject headerMap, JSONObject paramMap){
RestTemplate restTemplate = getRestTemplate();
HttpHeaders headers = new HttpHeaders();
if(headerMap!=null){
for(String key : headerMap.keySet()){
headers.add(key,headerMap.getString(key));
}
}
MultiValueMap<String,String> params = new LinkedMultiValueMap<String,String>();
HttpEntity<String> entity;
if(paramMap!=null){
entity = new HttpEntity<>(paramMap.toString(), headers);
}else{
entity = new HttpEntity<>(null, headers);
}
ResponseEntity<String> responseEntity = restTemplate.exchange(url, method, entity, String.class);
return responseEntity.getBody();
}
public static InputStream requestInputStream(String url, JSONObject headerMap, JSONObject paramMap) throws IOException {
RestTemplate restTemplate = getRestTemplate();
HttpHeaders headers = new HttpHeaders();
if(headerMap!=null){
for(String key : headerMap.keySet()){
headers.add(key,headerMap.getString(key));
}
}
MultiValueMap<String,String> params = new LinkedMultiValueMap<String,String>();
HttpEntity<String> entity;
if(paramMap!=null){
entity = new HttpEntity<>(paramMap.toString(), headers);
}else{
entity = new HttpEntity<>(null, headers);
}
ResponseEntity<Resource> responseEntity = restTemplate.exchange(url, HttpMethod.GET, entity, Resource.class);
return responseEntity.getBody().getInputStream();
}
public static RestTemplate getRestTemplate(){
RestTemplate restTemplate = new RestTemplate();
for (HttpMessageConverter<?> httpMessageConverter : restTemplate.getMessageConverters()) {
if (httpMessageConverter instanceof StringHttpMessageConverter) {
((StringHttpMessageConverter) httpMessageConverter).setDefaultCharset(Charset.forName("UTF-8"));
break;
}
}
return restTemplate;
}
}
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册