java110
2022-01-17 28e7d3937f819a3486b22bfa1c84aee172aaccb4
service-job/src/main/java/com/java110/job/adapt/fee/ReturnPayFeeToPlutusAdapt.java
@@ -4,8 +4,9 @@
import com.alibaba.fastjson.JSONObject;
import com.java110.core.client.FtpUploadTemplate;
import com.java110.core.client.OssUploadTemplate;
import com.java110.core.factory.CommunitySettingFactory;
import com.java110.core.factory.PlutusFactory;
import com.java110.dto.file.FileDto;
import com.java110.core.log.LoggerFactory;
import com.java110.dto.onlinePay.OnlinePayDto;
import com.java110.dto.smallWeChat.SmallWeChatDto;
import com.java110.entity.order.Business;
@@ -18,17 +19,14 @@
import com.java110.utils.cache.MappingCache;
import com.java110.utils.constant.WechatConstant;
import com.java110.utils.util.BeanConvertUtil;
import com.java110.utils.util.OSSUtil;
import com.java110.utils.util.PayUtil;
import com.java110.utils.util.StringUtil;
import org.bouncycastle.util.encoders.Base64;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;
import java.util.ArrayList;
import java.util.List;
/**
@@ -69,7 +67,7 @@
    @Autowired
    private RestTemplate outRestTemplate;
    public static final String wechatReturnUrl = "https://api.mch.weixin.qq.com/secapi/pay/refund";
    public static final String wechatReturnUrl = "https://api.plutuspay.com/open/v2/refund";
    private static Logger logger = LoggerFactory.getLogger(ReturnPayFeeMoneyAdapt.class);
@@ -116,14 +114,23 @@
        SmallWeChatDto smallWeChatDto = new SmallWeChatDto();
        smallWeChatDto.setMchId(onlinePayDtos.get(0).getMchId());
        smallWeChatDto.setAppId(onlinePayDtos.get(0).getAppId());
//        List<SmallWeChatDto> smallWeChatDtos = smallWeChatInnerServiceSMOImpl.querySmallWeChats(smallWeChatDto);
//        if (smallWeChatDto == null || smallWeChatDtos.size() <= 0) {
//            payPassword = MappingCache.getValue(WechatConstant.WECHAT_DOMAIN, "key");
//            certData = MappingCache.getRemark(WechatConstant.WECHAT_DOMAIN, "cert");
//        } else {
//            payPassword = smallWeChatDtos.get(0).getPayPassword();
//            certData = smallWeChatDtos.get(0).getRemarks();
//        }
        List<SmallWeChatDto> smallWeChatDtos = smallWeChatInnerServiceSMOImpl.querySmallWeChats(smallWeChatDto);
        String privateKey = "";
        String devId = "";
        String payPassword = "";
        String publicKey = "";
        if (smallWeChatDtos == null || smallWeChatDtos.size() < 1) {
            privateKey = MappingCache.getRemark(WechatConstant.WECHAT_DOMAIN, "PLUTUS_PRIVATE_KEY");
            devId = MappingCache.getValue(WechatConstant.WECHAT_DOMAIN, "PLUTUS_DEV_ID");
            payPassword = MappingCache.getValue(WechatConstant.WECHAT_DOMAIN, "key");
            publicKey = MappingCache.getRemark(WechatConstant.WECHAT_DOMAIN, "PLUTUS_PUBLIC_KEY");
        } else {
            privateKey = CommunitySettingFactory.getRemark(smallWeChatDtos.get(0).getObjId(), "PLUTUS_PRIVATE_KEY");
            devId = CommunitySettingFactory.getValue(smallWeChatDto.getObjId(), "PLUTUS_DEV_ID");
            payPassword = smallWeChatDtos.get(0).getPayPassword();
            publicKey = CommunitySettingFactory.getRemark(smallWeChatDtos.get(0).getObjId(), "PLUTUS_PUBLIC_KEY");
        }
        JSONObject parameters = new JSONObject();
        parameters.put("sn", onlinePayDtos.get(0).getMchId());//商户号
@@ -131,7 +138,8 @@
        parameters.put("outRefundId", onlinePayDtos.get(0).getPayId());//我们自己设定的退款申请号,约束为UK
        parameters.put("refundAmount", PayUtil.moneyToIntegerStr(Double.parseDouble(onlinePayDtos.get(0).getTotalFee())));//订单金额 单位为分!!!这里稍微注意一下
        String param = PlutusFactory.Encryption(parameters.toJSONString());
        String param = PlutusFactory.Encryption(parameters.toJSONString(), privateKey, payPassword, devId);
        System.out.println(param);
        String str = PlutusFactory.post(wechatReturnUrl, param);
@@ -142,16 +150,18 @@
        String signature = json.getString("signature");
        String content = json.getString("content");
        //验签
        Boolean verify = PlutusFactory.verify256(content, org.bouncycastle.util.encoders.Base64.decode(signature));
        Boolean verify = PlutusFactory.verify256(content, Base64.decode(signature), publicKey);
        //验签成功
        if (!verify) {
            throw new IllegalArgumentException("支付失败签名失败");
        }
        //解密
        byte[] bb = PlutusFactory.decrypt(Base64.decode(content), PlutusFactory.SECRET_KEY);
        byte[] bb = PlutusFactory.decrypt(Base64.decode(content), payPassword);
        //服务器返回内容
        String paramOut = new String(bb);
        System.out.println(paramOut);
        JSONObject paramObj = JSONObject.parseObject(paramOut);
@@ -165,7 +175,7 @@
    private void doUpdateOnlinePay(String orderId, String state, String message) {
        OnlinePayPo onlinePayPo = new OnlinePayPo();
        onlinePayPo.setMessage(message.length() > 1000 ? message.substring(0, 1000) : message);
        onlinePayPo.setMessage(!StringUtil.isEmpty(message) && message.length() > 1000 ? message.substring(0, 1000) : message);
        onlinePayPo.setOrderId(orderId);
        onlinePayPo.setState(state);
        onlinePayV1InnerServiceSMOImpl.updateOnlinePay(onlinePayPo);