| ÎļþÃû´Ó sandu-common/src/main/java/com/sandu/common/third/pay/wx/WxFastPayService.java ÐÞ¸Ä |
| | |
| | | package com.sandu.common.third.pay.wx; |
| | | package com.sandu.ximon.admin.pay.wx; |
| | | |
| | | import cn.hutool.core.codec.Base64; |
| | | import cn.hutool.crypto.SecureUtil; |
| | |
| | | import com.github.binarywang.wxpay.service.WxPayService; |
| | | import com.sandu.common.execption.BusinessException; |
| | | import com.sandu.common.util.IpUtil; |
| | | import com.sandu.common.util.ResponseUtil; |
| | | import com.sandu.ximon.admin.pay.wxpay.UsrWxPayConfigService; |
| | | import com.sandu.ximon.dao.domain.WxConfigEntity; |
| | | import lombok.AllArgsConstructor; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.util.Map; |
| | | import java.util.Set; |
| | | import java.util.SortedMap; |
| | | import java.util.TreeMap; |
| | | import java.text.DecimalFormat; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.*; |
| | | |
| | | /** |
| | | * @author chenjiantian |
| | |
| | | @AllArgsConstructor |
| | | public class WxFastPayService { |
| | | |
| | | private final com.github.binarywang.wxpay.service.WxPayService wxPayService; |
| | | //private final WxPayProperties wxPayProperties; |
| | | public static final String WECHAT_ORDER_PAY_CALLBACK_URL = "http://49.235.239.118:20012/callback/pay/wechatCallback"; |
| | | |
| | | /** |
| | | * appæ¯ä» |
| | |
| | | * @param callbackUrl |
| | | * @return |
| | | */ |
| | | public boolean refundOrder(WxPayService wxPayService, String orderId,String refundSn, Integer refundFee, String callbackUrl) { |
| | | public boolean refundOrder(WxPayService wxPayService, String orderId, String refundSn, Integer refundFee, String callbackUrl) { |
| | | WxPayRefundRequest refundRequest = new WxPayRefundRequest(); |
| | | refundRequest.setOutTradeNo(orderId); |
| | | refundRequest.setOutRefundNo(refundSn); |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * çæäºç»´ç 仿¬¾ |
| | | */ |
| | | public String generateQRCodePay(WxPayService wxPayService, String body, |
| | | String orderId, int totalFee, String callbackUrl) { |
| | | String orderId, int totalFee, String callbackUrl) { |
| | | WxPayUnifiedOrderRequest wxPayUnifiedOrderRequest = new WxPayUnifiedOrderRequest(); |
| | | wxPayUnifiedOrderRequest.setBody(body); |
| | | wxPayUnifiedOrderRequest.setOutTradeNo(orderId); |
| | |
| | | throw new BusinessException("微信æ¯ä»å¤±è´¥ï¼" + e.getErrCodeDes()); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 鿬¾ |
| | | * @param totalAmount |
| | | * @param refundAmount |
| | | * @param outTradeNo |
| | | * @param poleId |
| | | * @return |
| | | */ |
| | | public boolean refund(Double totalAmount, Double refundAmount, String outTradeNo, Long poleId) { |
| | | WxConfigEntity wxConfig = UsrWxPayConfigService.getBean().getConfigByPoleId(poleId); |
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss"); |
| | | String refundNo = sdf.format(new Date()); |
| | | WxPayRefundRequest refundRequest = new WxPayRefundRequest(); |
| | | refundRequest.setOutTradeNo(outTradeNo); |
| | | refundRequest.setOutRefundNo(refundNo); |
| | | refundRequest.setTotalFee(Integer.valueOf(parseWxAmount((totalAmount + "")))); |
| | | refundRequest.setRefundFee(Integer.valueOf(parseWxAmount((refundAmount + "")))); |
| | | try { |
| | | WxPayRefundResult wxPayRefundResult = wxPayService.refund(refundRequest); |
| | | if (WxPayConstants.ResultCode.SUCCESS.equals(wxPayRefundResult.getResultCode())) { |
| | | return true; |
| | | } else { |
| | | log.error("å¾®ä¿¡éæ¬¾å¤±è´¥ï¼{}", wxPayRefundResult.getErrCodeDes()); |
| | | throw new BusinessException("å¾®ä¿¡éæ¬¾å¤±è´¥ï¼" + wxPayRefundResult.getErrCodeDes()); |
| | | } |
| | | } catch (WxPayException e) { |
| | | log.error("å¾®ä¿¡éæ¬¾å¤±è´¥ï¼{}", e.getErrCodeDes()); |
| | | throw new BusinessException("å¾®ä¿¡éæ¬¾å¤±è´¥ï¼" + e.getErrCodeDes()); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 转æ¢ä¸ºå¾®ä¿¡éé¢(å) |
| | | * |
| | | * @param normalAmount 0.01å
|
| | | * @return |
| | | */ |
| | | public static String parseWxAmount(String normalAmount) { |
| | | // ä¿ç2ä½å°æ° |
| | | double totalAmountDouble = Double.parseDouble(new DecimalFormat("#.00").format( |
| | | Double.parseDouble(normalAmount))); |
| | | String amount = (totalAmountDouble * 100) + ""; |
| | | amount = amount.substring(0, amount.indexOf(".")); |
| | | return amount; |
| | | } |
| | | |
| | | } |