2021与蓝度共同重构项目,服务端
liuhaonan
2022-03-29 bcabde9dfb31d649454c4a9774f3ba3afd01b124
ximon-admin/src/main/java/com/sandu/ximon/admin/pay/wx/WxFastPayService.java
@@ -2,6 +2,8 @@
import cn.dreampie.encription.EncriptionKit;
import cn.hutool.core.codec.Base64;
import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSON;
import com.github.binarywang.wxpay.bean.notify.WxPayOrderNotifyResult;
import com.github.binarywang.wxpay.bean.notify.WxPayRefundNotifyResult;
import com.github.binarywang.wxpay.bean.request.WxPayRefundRequest;
@@ -13,6 +15,8 @@
import com.github.binarywang.wxpay.service.WxPayService;
import com.sandu.common.execption.BusinessException;
import com.sandu.common.util.IpUtil;
import com.sandu.ximon.admin.dto.YSY_AccessTokenDto;
import com.sandu.ximon.admin.dto.wxquery.WxOrderDto;
import com.sandu.ximon.admin.pay.wxpay.UsrWxPayConfigService;
import com.sandu.ximon.dao.domain.WxConfigEntity;
import lombok.AllArgsConstructor;
@@ -34,18 +38,25 @@
    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";
    public static final String WECHAT_ORDER_PAY_CALLBACK_URL = "http://49.235.239.118:20012/callback/pay/wechatCallback";
    //微信订单状态查询
    public static final String WECHAT_ORDER_QUETY_URL = "https://api.mch.weixin.qq.com/v3/pay/transactions/out-trade-no/";
    public static final String WECHAT_ORDER_QUETY = "?mchid=";
    private final UsrWxPayConfigService wxPayConfigService;
    /**
     * app支付
     *
     * @param body     商品描述
     * @param orderId  订单id
     * @param
     * @param totalFee 支付金额(分)
     * @return
     */
    public SortedMap<Object, Object> appPay(String body, String orderSn, int totalFee,Long poleId) {
    public SortedMap<Object, Object> appPay(String body, String orderSn, int totalFee, Long poleId) {
        WxConfigEntity wxConfig = wxPayConfigService.getConfigByPoleId(poleId);
        WxPayUnifiedOrderRequest wxPayUnifiedOrderRequest = new WxPayUnifiedOrderRequest();
        wxPayUnifiedOrderRequest.setBody(body);
@@ -94,21 +105,39 @@
        }
    }
/*    private String createSign(SortedMap<Object, Object> parameters) {
        StringBuffer sb = new StringBuffer();
        Set es = parameters.entrySet();// 所有参与传参的参数按照accsii排序(升序)
        for (Object e : es) {
            Map.Entry entry = (Map.Entry) e;
            String k = (String) entry.getKey();
            Object v = entry.getValue();
            if (null != v && !"".equals(v) && !"sign".equals(k) && !"key".equals(k)) {
                sb.append(k + "=" + v + "&");
    /*    private String createSign(SortedMap<Object, Object> parameters) {
            StringBuffer sb = new StringBuffer();
            Set es = parameters.entrySet();// 所有参与传参的参数按照accsii排序(升序)
            for (Object e : es) {
                Map.Entry entry = (Map.Entry) e;
                String k = (String) entry.getKey();
                Object v = entry.getValue();
                if (null != v && !"".equals(v) && !"sign".equals(k) && !"key".equals(k)) {
                    sb.append(k + "=" + v + "&");
                }
            }
            sb.append("key=" + wxPayProperties.getMchKey());
            System.out.println("字符串拼接后是:" + sb.toString());
            return SecureUtil.md5(sb.toString()).toUpperCase();
        }*/
    /**
     * 微信订单状态查询
     * @param poleId
     * @param outTradeNo
     * @return
     */
    private Object WxOrderQuery(Long poleId,String outTradeNo){
        WxConfigEntity wxConfig = wxPayConfigService.getConfigByPoleId(poleId);
        if(wxConfig==null){
            throw new BusinessException("获取微信支付配置失败");
        }
        sb.append("key=" + wxPayProperties.getMchKey());
        System.out.println("字符串拼接后是:" + sb.toString());
        return SecureUtil.md5(sb.toString()).toUpperCase();
    }*/
        String s = HttpUtil.get(WECHAT_ORDER_QUETY_URL + outTradeNo + WECHAT_ORDER_QUETY + wxConfig.getMchId());//WxOrderDto
        WxOrderDto wxOrderDto = JSON.parseObject(s, WxOrderDto.class);
        return  wxOrderDto.getTrade_state();
    }
    /**
     * @param parameters