New file |
| | |
| | | package com.kidgrow.oprationcenter.service.impl; |
| | | |
| | | import com.alipay.api.AlipayClient; |
| | | import com.alipay.api.domain.AlipayTradePrecreateModel; |
| | | import com.alipay.api.request.AlipayTradePrecreateRequest; |
| | | import com.alipay.api.response.AlipayTradePrecreateResponse; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.kidgrow.common.utils.QRCodeUtil; |
| | | import com.kidgrow.common.utils.StringUtils; |
| | | import com.kidgrow.oprationcenter.alipay.AlipayProperties; |
| | | import com.kidgrow.oprationcenter.model.SaasClientPay; |
| | | import com.kidgrow.oprationcenter.service.AlipayService; |
| | | import com.kidgrow.oprationcenter.service.ISaasClientPayService; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.context.annotation.Lazy; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | @Slf4j |
| | | @Service |
| | | public class AlipayServiceImpl implements AlipayService { |
| | | @Resource |
| | | private AlipayProperties alipayProperties; |
| | | @Resource |
| | | private AlipayClient alipayClient; |
| | | @Autowired |
| | | @Lazy |
| | | private ISaasClientPayService saasClientPayService; |
| | | @Override |
| | | public String getCode(SaasClientPay saasClientPay) throws Exception { |
| | | AlipayTradePrecreateModel model = new AlipayTradePrecreateModel(); |
| | | model.setProductCode("FACE_TO_FACE_PAYMENT"); //销售产品码 |
| | | model.setOutTradeNo(saasClientPay.getOutTradeNo()); //商户订单号 |
| | | model.setSubject(saasClientPay.getChildName()+"的支付"); //订单标题 |
| | | double l = Double.parseDouble(saasClientPay.getPayPrice().toString()) / 100; |
| | | model.setTotalAmount(l+""); //订单总金额 单位为元 |
| | | AlipayTradePrecreateRequest request = new AlipayTradePrecreateRequest(); |
| | | request.setBizModel(model); |
| | | //兼容pkcs1 编码; |
| | | java.security.Security.addProvider( |
| | | new org.bouncycastle.jce.provider.BouncyCastleProvider() |
| | | ); |
| | | request.setNotifyUrl(alipayProperties.getNotifyUrl()); |
| | | request.setReturnUrl(alipayProperties.getReturnUrl()); |
| | | AlipayTradePrecreateResponse alipayTradePrecreateResponse = alipayClient.execute(request); |
| | | if (StringUtils.isBlank(alipayTradePrecreateResponse.getQrCode())) { |
| | | return null; |
| | | } |
| | | String content = alipayTradePrecreateResponse.getQrCode(); |
| | | String base64 = QRCodeUtil.creatRrCode(content, 200, 200, 0).replaceAll("\n", "").replaceAll("\r", ""); |
| | | return base64; |
| | | } |
| | | |
| | | @Override |
| | | public String notify(Map<String, String> requestMap) { |
| | | log.error("eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee"); |
| | | log.error(requestMap.toString()); |
| | | log.error("eeeeeeeeeeeeeeeewwwwwwwwwwww:"+requestMap.toString()); |
| | | if(requestMap.get("trade_status").equals("TRADE_SUCCESS")){ |
| | | QueryWrapper queryWrapper = new QueryWrapper(); |
| | | queryWrapper.eq("out_trade_no",requestMap.get("out_trade_no")); |
| | | queryWrapper.eq("pay_status",0); |
| | | List<SaasClientPay> list = saasClientPayService.list(queryWrapper); |
| | | if(!list.isEmpty()){ |
| | | SaasClientPay saasClientPay = list.get(0); |
| | | saasClientPay.setPayTime(new Date()); |
| | | saasClientPay.setPayStatus(2); |
| | | saasClientPay.setPayMethod(1); |
| | | saasClientPay.setTradeNo(requestMap.get("trade_no")); |
| | | boolean b = saasClientPayService.updateById(saasClientPay); |
| | | } |
| | | return "success"; |
| | | }else { |
| | | return "fail"; |
| | | } |
| | | } |
| | | } |