| | |
| | | import com.oying.utils.enums.PayTypeEnum; |
| | | import lombok.RequiredArgsConstructor; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.dom4j.DocumentException; |
| | | import org.springframework.dao.DataIntegrityViolationException; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.io.IOException; |
| | | import java.util.HashMap; |
| | | import java.util.Map; |
| | | |
| | |
| | | } |
| | | } |
| | | response.getWriter().write(respString); |
| | | } catch (DataIntegrityViolationException e) { |
| | | log.error("汇旺财退款回调数据异常失败:{} {}", map.toString(), e.getMessage()); |
| | | } catch (DocumentException e) { |
| | | log.error("汇旺财退款回调XML转码失败:{} {}", map.toString(), e.getMessage()); |
| | | } catch (IOException e) { |
| | | log.error("汇旺财退款回调写入流失败:{} {}", map.toString(), e.getMessage()); |
| | | } catch (Exception e) { |
| | | log.error("汇旺财支付回调失败:{}", map.toString()); |
| | | log.error("汇旺财退款回调失败:{} {}", map.toString(), e.getMessage()); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void returnNotify(HttpServletRequest request, HttpServletResponse response) { |
| | | Map<String, String> map = new HashMap<>(); |
| | | Map<String, String> map = new HashMap<>(); |
| | | try { |
| | | String resString = XmlUtils.parseRequest(request); |
| | | String respString = "error"; |
| | |
| | | } |
| | | } |
| | | response.getWriter().write(respString); |
| | | } catch (DataIntegrityViolationException e) { |
| | | log.error("汇旺财退款回调数据异常失败:{} {}", map.toString(), e.getMessage()); |
| | | } catch (DocumentException e) { |
| | | log.error("汇旺财退款回调XML转码失败:{} {}", map.toString(), e.getMessage()); |
| | | } catch (IOException e) { |
| | | log.error("汇旺财退款回调写入流失败:{} {}", map.toString(), e.getMessage()); |
| | | } catch (Exception e) { |
| | | log.error("汇旺财退款回调失败:{}", map.toString()); |
| | | log.error("汇旺财退款回调失败:{} {}", map.toString(), e.getMessage()); |
| | | } |
| | | } |
| | | } |
| | |
| | | /** |
| | | * 对返回参数的验证签名 |
| | | */ |
| | | public static boolean verifySign(String sign, String signType, Map<String, String> resultMap, SwiftPassProperties properties, PayTypeEnum status) throws Exception { |
| | | public static boolean verifySign(String sign, String signType, Map<String, String> resultMap, |
| | | SwiftPassProperties properties, PayTypeEnum status) { |
| | | if ("RSA_1_256".equals(signType)) { |
| | | Map<String, String> params = SignUtils.paraFilter(resultMap); |
| | | StringBuilder builder = new StringBuilder((params.size() + 1) * 10); |
| | |
| | | /** |
| | | * RSA_1_256 验证签名 |
| | | */ |
| | | public static boolean verifySign(String preStr, String sign, String signType, String platPublicKey) throws Exception { |
| | | public static boolean verifySign(String preStr, String sign, String signType, String platPublicKey) { |
| | | // 调用这个函数前需要先判断是MD5还是RSA |
| | | // 商户的验签函数要同时支持MD5和RSA |
| | | RSAUtil.SignatureSuite suite; |
| | |
| | | } else if ("RSA_1_256".equals(signType)) { |
| | | suite = RSAUtil.SignatureSuite.SHA256; |
| | | } else { |
| | | throw new Exception("不支持的签名方式"); |
| | | throw new BadRequestException("不支持的签名方式"); |
| | | } |
| | | return RSAUtil.verifySign(suite, preStr.getBytes(StandardCharsets.UTF_8), Base64.decodeBase64(sign.getBytes(StandardCharsets.UTF_8)), |
| | | platPublicKey); |
| | |
| | | /** |
| | | * RSA_1_256生成不同的sign |
| | | */ |
| | | public static String sign(String preStr, String signType, String mchPrivateKey) throws Exception { |
| | | public static String sign(String preStr, String signType, String mchPrivateKey) { |
| | | RSAUtil.SignatureSuite suite; |
| | | if ("RSA_1_1".equals(signType)) { |
| | | suite = RSAUtil.SignatureSuite.SHA1; |
| | | } else if ("RSA_1_256".equals(signType)) { |
| | | suite = RSAUtil.SignatureSuite.SHA256; |
| | | } else { |
| | | throw new Exception("不支持的签名方式"); |
| | | throw new BadRequestException("不支持的签名方式"); |
| | | } |
| | | byte[] signBuf = RSAUtil.sign(suite, preStr.getBytes(StandardCharsets.UTF_8), |
| | | mchPrivateKey); |
| | |
| | | |
| | | import com.oying.exception.BadRequestException; |
| | | import org.dom4j.Document; |
| | | import org.dom4j.DocumentException; |
| | | import org.dom4j.Element; |
| | | import org.dom4j.io.SAXReader; |
| | | import org.xml.sax.InputSource; |
| | |
| | | /** |
| | | * 转XML map |
| | | */ |
| | | public static Map<String, String> toMap(byte[] xmlBytes, String charset) throws Exception { |
| | | public static Map<String, String> toMap(byte[] xmlBytes, String charset) throws DocumentException { |
| | | SAXReader reader = new SAXReader(false); |
| | | InputSource source = new InputSource(new ByteArrayInputStream(xmlBytes)); |
| | | source.setEncoding(charset); |
| | |
| | | |
| | | import com.alibaba.fastjson2.JSON; |
| | | import com.oying.exception.BadRequestException; |
| | | import com.oying.modules.message.common.MesTypeEnum; |
| | | import com.oying.modules.message.common.MsgStatusEnum; |
| | | import com.oying.modules.message.service.MesMsgRecordService; |
| | | import com.oying.modules.sh.domain.OrderOperationLog; |
| | |
| | | resources.setOperationTime(time); |
| | | orderOperationLogMapper.insert(resources); |
| | | if (msgStatusEnum != null){ |
| | | mesMsgRecordService.insertOrderMsg(response.getOrder(), msgStatusEnum, MesTypeEnum.ORDER); |
| | | // mesMsgRecordService.insertOrderMsg(response.getOrder(), msgStatusEnum, MesTypeEnum.ORDER); |
| | | } |
| | | orderMapper.updateOrderStatus(response.getOrder().getOrderNum(), statusEnum.getKey(), statusEnum.getValue()); |
| | | } |