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

支付接口调整

上级 8cf85d8e
...@@ -6,6 +6,7 @@ import cn.ibizlab.core.pay.domain.PayOpenAccess; ...@@ -6,6 +6,7 @@ import cn.ibizlab.core.pay.domain.PayOpenAccess;
import cn.ibizlab.core.pay.domain.PayTrade; import cn.ibizlab.core.pay.domain.PayTrade;
import cn.ibizlab.core.pay.service.IPayOpenAccessService; import cn.ibizlab.core.pay.service.IPayOpenAccessService;
import cn.ibizlab.util.errors.BadRequestAlertException; import cn.ibizlab.util.errors.BadRequestAlertException;
import com.alibaba.fastjson.JSONObject;
import com.alipay.api.AlipayClient; import com.alipay.api.AlipayClient;
import com.alipay.api.DefaultAlipayClient; import com.alipay.api.DefaultAlipayClient;
import com.alipay.api.request.*; import com.alipay.api.request.*;
...@@ -68,17 +69,18 @@ public class PayCoreService { ...@@ -68,17 +69,18 @@ public class PayCoreService {
* @param trade * @param trade
* @return * @return
*/ */
public boolean preCreate(PayTrade trade){ public JSONObject preCreate(PayTrade trade){
JSONObject rs=new JSONObject();
PayOpenAccess openAccess=getOpenAccess(trade); PayOpenAccess openAccess=getOpenAccess(trade);
switch (openAccess.getOpenType()){ switch (openAccess.getOpenType()){
case "aliyun": case "aliyun":
aliPayPreCreate(openAccess,trade); // qrcode=aliPayPreCreate(openAccess,trade);
break; break;
case "wechat": case "wechat":
wechatPreCreate(openAccess,trade); rs= wechatPreCreate(openAccess,trade);
break; break;
} }
return true; return rs;
} }
/** /**
...@@ -86,17 +88,18 @@ public class PayCoreService { ...@@ -86,17 +88,18 @@ public class PayCoreService {
* @param trade * @param trade
* @return * @return
*/ */
public boolean query(PayTrade trade){ public JSONObject query(PayTrade trade){
JSONObject rs=new JSONObject();
PayOpenAccess openAccess=getOpenAccess(trade); PayOpenAccess openAccess=getOpenAccess(trade);
switch (openAccess.getOpenType()){ switch (openAccess.getOpenType()){
case "aliyun": case "aliyun":
aliPayQuery(openAccess,trade); // aliPayQuery(openAccess,trade);
break; break;
case "wechat": case "wechat":
wechatPayQuery(openAccess,trade); rs=wechatPayQuery(openAccess,trade);
break; break;
} }
return true; return rs;
} }
/** /**
...@@ -104,17 +107,18 @@ public class PayCoreService { ...@@ -104,17 +107,18 @@ public class PayCoreService {
* @param trade * @param trade
* @return * @return
*/ */
public boolean cancel(PayTrade trade){ public JSONObject cancel(PayTrade trade){
JSONObject rs=new JSONObject();
PayOpenAccess openAccess=getOpenAccess(trade); PayOpenAccess openAccess=getOpenAccess(trade);
switch (openAccess.getOpenType()){ switch (openAccess.getOpenType()){
case "aliyun": case "aliyun":
aliPayCancel(openAccess,trade); // aliPayCancel(openAccess,trade);
break; break;
case "wechat": case "wechat":
wechatPayCancel(openAccess,trade); rs=wechatPayCancel(openAccess,trade);
break; break;
} }
return true; return rs;
} }
/** /**
...@@ -184,7 +188,8 @@ public class PayCoreService { ...@@ -184,7 +188,8 @@ public class PayCoreService {
* @param trade * @param trade
*/ */
@SneakyThrows @SneakyThrows
private void wechatPreCreate(PayOpenAccess openAccess,PayTrade trade) { private JSONObject wechatPreCreate(PayOpenAccess openAccess,PayTrade trade) {
JSONObject rs=new JSONObject();
WechatPayConfig config = getWechatPayConfig(openAccess); WechatPayConfig config = getWechatPayConfig(openAccess);
WXPay wxpay = new WXPay(config); WXPay wxpay = new WXPay(config);
Map<String, String> data = new HashMap<String, String>(); Map<String, String> data = new HashMap<String, String>();
...@@ -197,8 +202,11 @@ public class PayCoreService { ...@@ -197,8 +202,11 @@ public class PayCoreService {
data.put("notify_url", openAccess.getRedirectUri()); data.put("notify_url", openAccess.getRedirectUri());
data.put("trade_type", "NATIVE"); // 此处指定为扫码支付 data.put("trade_type", "NATIVE"); // 此处指定为扫码支付
// data.put("product_id", "12"); // data.put("product_id", "12");
Map<String, String> resp = wxpay.unifiedOrder(data); Map resp = wxpay.unifiedOrder(data);
System.out.println(resp); if(resp!=null){
rs=new JSONObject(resp);
}
return rs;
} }
/** /**
...@@ -206,13 +214,17 @@ public class PayCoreService { ...@@ -206,13 +214,17 @@ public class PayCoreService {
* @param trade * @param trade
*/ */
@SneakyThrows @SneakyThrows
private void wechatPayQuery(PayOpenAccess openAccess,PayTrade trade) { private JSONObject wechatPayQuery(PayOpenAccess openAccess,PayTrade trade) {
JSONObject rs=new JSONObject();
WechatPayConfig config = getWechatPayConfig(openAccess); WechatPayConfig config = getWechatPayConfig(openAccess);
WXPay wxpay = new WXPay(config); WXPay wxpay = new WXPay(config);
Map<String, String> data = new HashMap<String, String>(); Map<String, String> data = new HashMap<String, String>();
data.put("out_trade_no", trade.getOutTradeNo()); data.put("out_trade_no", trade.getOutTradeNo());
Map<String, String> resp = wxpay.orderQuery(data); Map resp = wxpay.orderQuery(data);
System.out.println(resp); if(resp!=null){
rs=new JSONObject(resp);
}
return rs;
} }
/** /**
...@@ -220,13 +232,17 @@ public class PayCoreService { ...@@ -220,13 +232,17 @@ public class PayCoreService {
* @param trade * @param trade
*/ */
@SneakyThrows @SneakyThrows
private void wechatPayCancel(PayOpenAccess openAccess,PayTrade trade) { private JSONObject wechatPayCancel(PayOpenAccess openAccess,PayTrade trade) {
JSONObject rs=new JSONObject();
WechatPayConfig config = getWechatPayConfig(openAccess); WechatPayConfig config = getWechatPayConfig(openAccess);
WXPay wxpay = new WXPay(config); WXPay wxpay = new WXPay(config);
Map<String, String> data = new HashMap<String, String>(); Map<String, String> data = new HashMap<String, String>();
data.put("out_trade_no", trade.getOutTradeNo()); data.put("out_trade_no", trade.getOutTradeNo());
Map<String, String> resp = wxpay.closeOrder(data); Map resp = wxpay.closeOrder(data);
System.out.println(resp); if(resp!=null){
rs=new JSONObject(resp);
}
return rs;
} }
/** /**
......
...@@ -3,6 +3,7 @@ package cn.ibizlab.api.rest.extensions; ...@@ -3,6 +3,7 @@ package cn.ibizlab.api.rest.extensions;
import cn.ibizlab.api.dto.PayTradeDTO; import cn.ibizlab.api.dto.PayTradeDTO;
import cn.ibizlab.api.mapping.PayTradeMapping; import cn.ibizlab.api.mapping.PayTradeMapping;
import cn.ibizlab.core.extensions.service.PayCoreService; import cn.ibizlab.core.extensions.service.PayCoreService;
import com.alibaba.fastjson.JSONObject;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy; import org.springframework.context.annotation.Lazy;
...@@ -27,19 +28,19 @@ public class PayCoreResource { ...@@ -27,19 +28,19 @@ public class PayCoreResource {
@ApiOperation(value = "预下单获取二维码", tags = {"获取二维码" }, notes = "预下单获取二维码") @ApiOperation(value = "预下单获取二维码", tags = {"获取二维码" }, notes = "预下单获取二维码")
@RequestMapping(method = RequestMethod.POST,value = "/trade/precreate") @RequestMapping(method = RequestMethod.POST,value = "/trade/precreate")
public ResponseEntity<Boolean> preCreate(@Validated @RequestBody PayTradeDTO dto){ public ResponseEntity<JSONObject> preCreate(@Validated @RequestBody PayTradeDTO dto){
return ResponseEntity.status(HttpStatus.OK).body(payCoreService.preCreate(payTradeMapping.toDomain(dto))); return ResponseEntity.status(HttpStatus.OK).body(payCoreService.preCreate(payTradeMapping.toDomain(dto)));
} }
@ApiOperation(value = "查询订单", tags = {"查询订单" }, notes = "查询订单") @ApiOperation(value = "查询订单", tags = {"查询订单" }, notes = "查询订单")
@RequestMapping(method = RequestMethod.POST,value = "/trade/query") @RequestMapping(method = RequestMethod.POST,value = "/trade/query")
public ResponseEntity<Boolean> query(@Validated @RequestBody PayTradeDTO dto){ public ResponseEntity<JSONObject> query(@Validated @RequestBody PayTradeDTO dto){
return ResponseEntity.status(HttpStatus.OK).body(payCoreService.query(payTradeMapping.toDomain(dto))); return ResponseEntity.status(HttpStatus.OK).body(payCoreService.query(payTradeMapping.toDomain(dto)));
} }
@ApiOperation(value = "取消订单", tags = {"取消订单" }, notes = "取消订单") @ApiOperation(value = "取消订单", tags = {"取消订单" }, notes = "取消订单")
@RequestMapping(method = RequestMethod.POST,value = "/trade/cancel") @RequestMapping(method = RequestMethod.POST,value = "/trade/cancel")
public ResponseEntity<Boolean> cancel(@Validated @RequestBody PayTradeDTO dto){ public ResponseEntity<JSONObject> cancel(@Validated @RequestBody PayTradeDTO dto){
return ResponseEntity.status(HttpStatus.OK).body(payCoreService.cancel(payTradeMapping.toDomain(dto))); return ResponseEntity.status(HttpStatus.OK).body(payCoreService.cancel(payTradeMapping.toDomain(dto)));
} }
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册