支付宝正扫支付API
This commit is contained in:
parent
b79756a488
commit
98fb2c2530
|
|
@ -0,0 +1,55 @@
|
||||||
|
package com.ghy.web.controller.pay;
|
||||||
|
|
||||||
|
import com.ghy.common.adapay.AdapayService;
|
||||||
|
import com.ghy.common.adapay.callback.PayCallback;
|
||||||
|
import com.ghy.common.core.controller.BaseController;
|
||||||
|
import com.ghy.common.core.domain.AjaxResult;
|
||||||
|
import com.ghy.order.domain.OrderMaster;
|
||||||
|
import com.ghy.order.service.OrderMasterService;
|
||||||
|
import com.huifu.adapay.core.exception.BaseAdaPayException;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 支付宝支付API
|
||||||
|
*
|
||||||
|
* @author HH 2022/5/10
|
||||||
|
*/
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("pay/ali")
|
||||||
|
public class AlipayController extends BaseController {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private PayCallback payCallback;
|
||||||
|
@Resource
|
||||||
|
private AdapayService adapayService;
|
||||||
|
@Resource
|
||||||
|
private OrderMasterService orderMasterService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 支付宝正扫支付
|
||||||
|
*/
|
||||||
|
@PostMapping("qr")
|
||||||
|
public AjaxResult qrPay(String orderMasterCode) {
|
||||||
|
List<OrderMaster> orderMasters = orderMasterService.selectOrderMasterList(new OrderMaster(orderMasterCode));
|
||||||
|
if (orderMasters.isEmpty()) {
|
||||||
|
return AjaxResult.error("订单不存在");
|
||||||
|
}
|
||||||
|
OrderMaster orderMaster = orderMasters.get(0);
|
||||||
|
Map<String, Object> map;
|
||||||
|
try {
|
||||||
|
// TODO 订单里需要补充支付金额、tittle、简要描述、分账信息、description
|
||||||
|
map = adapayService.alipayQrPay(payCallback, orderMaster.getCode(), "orderMaster.get支付金额",
|
||||||
|
"orderMaster.getTittle()", "orderMaster.get简要描述", "orderMaster.getDivMember", "orderMaster.getDescription");
|
||||||
|
} catch (BaseAdaPayException e) {
|
||||||
|
logger.error("获取微信用户信息失败", e);
|
||||||
|
return AjaxResult.error();
|
||||||
|
}
|
||||||
|
return AjaxResult.success(map);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -2,8 +2,8 @@ package com.ghy.web.controller.pay;
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import com.ghy.common.adapay.AdapayService;
|
import com.ghy.common.adapay.AdapayService;
|
||||||
|
import com.ghy.common.adapay.callback.PayCallback;
|
||||||
import com.ghy.common.adapay.callback.model.WxLiteExpend;
|
import com.ghy.common.adapay.callback.model.WxLiteExpend;
|
||||||
import com.ghy.common.adapay.callback.reply.WxPubPayCallBack;
|
|
||||||
import com.ghy.common.config.WxConfig;
|
import com.ghy.common.config.WxConfig;
|
||||||
import com.ghy.common.core.controller.BaseController;
|
import com.ghy.common.core.controller.BaseController;
|
||||||
import com.ghy.common.core.domain.AjaxResult;
|
import com.ghy.common.core.domain.AjaxResult;
|
||||||
|
|
@ -34,7 +34,12 @@ public class WxPayController extends BaseController {
|
||||||
private AdapayService adapayService;
|
private AdapayService adapayService;
|
||||||
@Resource
|
@Resource
|
||||||
private OrderMasterService orderMasterService;
|
private OrderMasterService orderMasterService;
|
||||||
|
@Resource
|
||||||
|
private PayCallback payCallback;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 微信小程序支付
|
||||||
|
*/
|
||||||
@PostMapping("lite")
|
@PostMapping("lite")
|
||||||
public AjaxResult litePay(HttpServletRequest request) {
|
public AjaxResult litePay(HttpServletRequest request) {
|
||||||
String code = request.getParameter("code");
|
String code = request.getParameter("code");
|
||||||
|
|
@ -58,7 +63,7 @@ public class WxPayController extends BaseController {
|
||||||
Map<String, Object> map;
|
Map<String, Object> map;
|
||||||
try {
|
try {
|
||||||
// TODO 订单里需要补充支付金额、tittle、简要描述、分账信息、description
|
// TODO 订单里需要补充支付金额、tittle、简要描述、分账信息、description
|
||||||
map = adapayService.wxPubPay(new WxPubPayCallBack(), expend, orderMaster.getCode(), "orderMaster.get支付金额",
|
map = adapayService.wxPubPay(payCallback, expend, orderMaster.getCode(), "orderMaster.get支付金额",
|
||||||
"orderMaster.getTittle()", "orderMaster.get简要描述", "orderMaster.getDivMember", "orderMaster.getDescription");
|
"orderMaster.getTittle()", "orderMaster.get简要描述", "orderMaster.getDivMember", "orderMaster.getDescription");
|
||||||
} catch (BaseAdaPayException e) {
|
} catch (BaseAdaPayException e) {
|
||||||
logger.error("获取微信用户信息失败", e);
|
logger.error("获取微信用户信息失败", e);
|
||||||
|
|
@ -90,7 +95,7 @@ public class WxPayController extends BaseController {
|
||||||
//调用adapay微信公众号支付.
|
//调用adapay微信公众号支付.
|
||||||
WxLiteExpend expend = new WxLiteExpend();
|
WxLiteExpend expend = new WxLiteExpend();
|
||||||
expend.setOpen_id(openId);
|
expend.setOpen_id(openId);
|
||||||
Map<String, Object> map = adapayService.wxPubPay(new WxPubPayCallBack(), expend, "wxPay123456" + Math.ceil(Math.random() * 100), "1.00",
|
Map<String, Object> map = adapayService.wxPubPay(payCallback, expend, "wxPay123456" + Math.ceil(Math.random() * 100), "1.00",
|
||||||
"测试商品", "测试商品detail", null, "description");
|
"测试商品", "测试商品detail", null, "description");
|
||||||
//拼接消息给前端.前端通过JSAPI调用微信支付
|
//拼接消息给前端.前端通过JSAPI调用微信支付
|
||||||
map.forEach((key, value) -> {
|
map.forEach((key, value) -> {
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,34 @@
|
||||||
|
package com.ghy.web.core;
|
||||||
|
|
||||||
|
import com.ghy.common.adapay.callback.PayCallback;
|
||||||
|
import com.ghy.common.adapay.callback.model.PayReply;
|
||||||
|
import com.ghy.order.service.OrderDetailService;
|
||||||
|
import com.ghy.order.service.OrderMasterService;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户支付后
|
||||||
|
*/
|
||||||
|
@Configuration
|
||||||
|
public class AfterPay {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
OrderMasterService orderMasterService;
|
||||||
|
@Resource
|
||||||
|
OrderDetailService orderDetailService;
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public PayCallback payCallback() {
|
||||||
|
return new PayCallback() {
|
||||||
|
@Override
|
||||||
|
public void onReply(PayReply reply) {
|
||||||
|
// TODO 修改 OrderMaster 订单状态
|
||||||
|
// TODO 修改 OrderDetail 订单状态
|
||||||
|
// TODO 保存支付结果到MySQL
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,15 +0,0 @@
|
||||||
package com.ghy.common.adapay.callback.reply;
|
|
||||||
|
|
||||||
import com.ghy.common.adapay.callback.PayCallback;
|
|
||||||
import com.ghy.common.adapay.callback.model.PayReply;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
|
|
||||||
@Slf4j
|
|
||||||
public class WxPubPayCallBack implements PayCallback {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onReply(PayReply reply) {
|
|
||||||
// 更新工单状态
|
|
||||||
log.info("wx pub pay response is : " + reply.toString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Loading…
Reference in New Issue