| | |
| | | package cc.mrbird.febs.pay.controller; |
| | | |
| | | import cc.mrbird.febs.common.entity.FebsResponse; |
| | | import cc.mrbird.febs.pay.model.LaKaLaCreateOrderReqDate; |
| | | import cc.mrbird.febs.pay.properties.AliPayProperties; |
| | | import cc.mrbird.febs.pay.service.IAliPayService; |
| | | import cc.mrbird.febs.pay.service.IPayService; |
| | | import cc.mrbird.febs.pay.service.LaKaLaService; |
| | | import cn.hutool.core.date.DateUtil; |
| | | import cn.hutool.json.JSONObject; |
| | | import cn.hutool.json.JSONUtil; |
| | | import com.alipay.api.AlipayApiException; |
| | | import com.alipay.api.internal.util.AlipaySignature; |
| | | import com.github.binarywang.wxpay.bean.notify.WxPayNotifyResponse; |
| | | import com.github.binarywang.wxpay.bean.notify.WxPayOrderNotifyResult; |
| | | import com.github.binarywang.wxpay.exception.WxPayException; |
| | | import com.github.binarywang.wxpay.service.WxPayService; |
| | | import com.ijpay.alipay.AliPayApi; |
| | | import io.swagger.annotations.Api; |
| | | import lombok.RequiredArgsConstructor; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.web.bind.annotation.GetMapping; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | import me.chanjar.weixin.common.service.WxService; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import javax.annotation.Resource; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import java.util.Date; |
| | | import java.util.HashMap; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | |
| | | @Slf4j |
| | | @RestController |
| | | @RequestMapping(value = "/api/pay") |
| | | @RequiredArgsConstructor |
| | | @Api(value = "PayCallBackController", tags = "回调接口") |
| | | public class PayCallBackController { |
| | | |
| | | @GetMapping("/aliCallBack") |
| | | public FebsResponse aliPayCallBack(HttpServletRequest request) { |
| | | @Autowired |
| | | private IAliPayService payService; |
| | | |
| | | @Autowired |
| | | private IPayService wechatPayService; |
| | | |
| | | @Resource |
| | | private AliPayProperties aliPayProperties; |
| | | |
| | | @Autowired |
| | | private WxPayService wxPayService; |
| | | |
| | | @Autowired |
| | | private LaKaLaService laKaLaService; |
| | | |
| | | @RequestMapping("/aliCallBack") |
| | | public String aliPayCallBack(HttpServletRequest request){ |
| | | log.info("进入支付宝回调"); |
| | | Map<String, String> params = AliPayApi.toMap(request); |
| | | |
| | | for (Map.Entry<String, String> entry : params.entrySet()) { |
| | | log.info("支付宝回调:{}===={}", entry.getKey(), entry.getValue()); |
| | | boolean verifyResult = false; |
| | | try { |
| | | verifyResult = AlipaySignature.verifyV1(params, aliPayProperties.getPublicKey(), "UTF-8", "RSA2"); |
| | | } catch (AlipayApiException e) { |
| | | log.info("=验证失败=:{}", params); |
| | | return "failure"; |
| | | } |
| | | return new FebsResponse().success(); |
| | | |
| | | if (verifyResult) { |
| | | if ("TRADE_SUCCESS".equals(params.get("trade_status")) || "TRADE_FINISHED".equals(params.get("trade_status"))) { |
| | | payService.aliCallback(params); |
| | | return "success"; |
| | | } else { |
| | | log.info("支付失败:{}", params); |
| | | return "failure"; |
| | | } |
| | | } else { |
| | | log.info("验证失败:{}", params); |
| | | return "failure"; |
| | | } |
| | | } |
| | | |
| | | @PostMapping(value = "/wxPayCallBack") |
| | | public String wxPayCallBack(@RequestBody String xmlData) throws WxPayException { |
| | | log.info("=======微信回调:{}========", xmlData); |
| | | WxPayOrderNotifyResult notifyResult = this.wxPayService.parseOrderNotifyResult(xmlData); |
| | | |
| | | wechatPayService.payCallback(notifyResult.toMap()); |
| | | return WxPayNotifyResponse.success("成功"); |
| | | } |
| | | |
| | | @PostMapping(value = "/laKaLaPayCallBack") |
| | | public String laKaLaPayCallBack(@RequestBody String xmlData){ |
| | | log.info("=======拉卡拉回调:{}========", xmlData); |
| | | JSONObject jsonObject = JSONUtil.parseObj(xmlData); |
| | | return laKaLaService.payCallback(jsonObject); |
| | | } |
| | | |
| | | @PostMapping(value = "/laKaLaPayTest") |
| | | public String laKaLaPayTest(){ |
| | | log.info("=======拉卡拉支付:{}========"); |
| | | LaKaLaCreateOrderReqDate laKaLaCreateOrderReqDate = new LaKaLaCreateOrderReqDate(); |
| | | //订单编号 |
| | | String yyyyMMddHHmmss = DateUtil.format(new Date(), "yyyyMMddHHmmss"); |
| | | laKaLaCreateOrderReqDate.setOut_order_no("HLM"+ yyyyMMddHHmmss); |
| | | //订单金额,分计 |
| | | laKaLaCreateOrderReqDate.setTotal_amount(1); |
| | | laKaLaCreateOrderReqDate.setOrder_info("商品"); |
| | | return laKaLaService.verifyCreateOrder(laKaLaCreateOrderReqDate); |
| | | } |
| | | |
| | | public static void main(String[] args) { |
| | | String ss = "{\"channel_id\":\"95\",\"merchant_no\":\"8222900701107M5\",\"order_create_time\":\"20230419144657\",\"order_efficient_time\":\"20230419154657\",\"order_info\":\"测试\",\"order_status\":\"2\",\"order_trade_info\":{\"acc_trade_no\":\"4200001781202304197079597853\",\"acc_type\":\"99\",\"bank_type\":\"OTHERS\",\"busi_type\":\"SCPAY\",\"log_no\":\"66210308040064\",\"pay_mode\":\"WECHAT\",\"payer_amount\":1,\"settle_merchant_no\":\"8222900701107M5\",\"settle_term_no\":\"A1062976\",\"trade_amount\":1,\"trade_no\":\"2023041966210308040064\",\"trade_remark\":\"\",\"trade_status\":\"S\",\"trade_time\":\"20230419144905\",\"trade_type\":\"PAY\",\"user_id1\":\"olpr-0s4UbBnMs_BkbhWQZY0dGS4\",\"user_id2\":\"oUpF8uJz3B57zLzhefnWANjzOjYU\"},\"out_order_no\":\"HLM20230419144657\",\"pay_order_no\":\"23041911012001101011000965795\",\"term_no\":\"A1062976\",\"total_amount\":1,\"trans_merchant_no\":\"8222900701107M5\",\"trans_term_no\":\"A1062976\"}"; |
| | | JSONObject jsonObject = JSONUtil.parseObj(ss); |
| | | System.out.println(jsonObject.get("order_status")); |
| | | System.out.println(jsonObject.get("out_order_no")); |
| | | } |
| | | } |