java110
2022-01-17 b48cc4f6b0b711c4e408274ff4737cc7a19ed3de
service-api/src/main/java/com/java110/api/smo/payment/adapt/plutuspay/PlutusPayNotifyAdapt.java
@@ -15,20 +15,23 @@
 */
package com.java110.api.smo.payment.adapt.plutuspay;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.java110.api.properties.WechatAuthProperties;
import com.java110.api.smo.DefaultAbstractComponentSMO;
import com.java110.api.smo.payment.adapt.IPayNotifyAdapt;
import com.java110.core.factory.CommunitySettingFactory;
import com.java110.core.factory.PlutusFactory;
import com.java110.core.factory.WechatFactory;
import com.java110.dto.smallWeChat.SmallWeChatDto;
import com.java110.utils.constant.CommonConstant;
import com.java110.utils.util.BeanConvertUtil;
import com.java110.utils.util.DateUtil;
import com.java110.utils.util.PayUtil;
import org.apache.commons.codec.digest.DigestUtils;
import org.bouncycastle.util.encoders.Base64;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.java110.core.log.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
@@ -77,25 +80,42 @@
     * @throws Exception
     */
    public String confirmPayFee(String param, String wId) {
        JSONObject resJson = new JSONObject();
        resJson.put("errCode", "INTERNAL_ERROR");
        resJson.put("errMsg", "失败");
        JSONObject json = JSON.parseObject(param);
        String signature = json.getString("signature");
        String content = json.getString("content");
        String appId = WechatFactory.getAppId(wId);
        SmallWeChatDto smallWeChatDto = getSmallWechat(appId);
        if (smallWeChatDto == null) {
            throw new IllegalArgumentException("未配置公众号或者小程序信息");
        }
        String publicKey = CommunitySettingFactory.getRemark(smallWeChatDto.getObjId(),"PLUTUS_PUBLIC_KEY");
        //验签
        Boolean verify = PlutusFactory.verify256(param, org.bouncycastle.util.encoders.Base64.decode(signature),publicKey);
        //验签成功
        if (!verify) {
            throw new IllegalArgumentException("支付失败签名失败");
        }
        //解密
        byte[] bb = PlutusFactory.decrypt(Base64.decode(content), smallWeChatDto.getPayPassword());
        //服务器返回内容
        String paramOut = new String(bb);
        try {
            JSONObject map = JSONObject.parseObject(param);
            JSONObject map = JSONObject.parseObject(paramOut);
            logger.info("【银联支付回调】 回调数据: \n" + map);
            //更新数据
            int result = confirmPayFee(map, wId);
            if (result > 0) {
                //支付成功
                resJson.put("errCode", "SUCCESS");
                resJson.put("errMsg", "成功");
                return "SUCCESS";
            }
        } catch (Exception e) {
            logger.error("通知失败", e);
            resJson.put("result_msg", "鉴权失败");
            return "ERROR";
        }
        return resJson.toJSONString();
        return "ERROR";
    }
@@ -122,20 +142,12 @@
            paramMap.put(key, map.get(key).toString());
        }
        //String sign = PayUtil.createChinaUmsSign(paramMap, smallWeChatDto.getPayPassword());
        String preSign = map.getString("preSign");
        String text = preSign + smallWeChatDto.getPayPassword();
        System.out.println("待签名字符串:" + text);
        String sign = DigestUtils.sha256Hex(getContentBytes(text)).toUpperCase();
        if (!sign.equals(map.get("sign"))) {
            throw new IllegalArgumentException("鉴权失败");
        }
        //JSONObject billPayment = JSONObject.parseObject(map.getString("billPayment"));
        String outTradeNo = map.get("merOrderId").toString();
        String outTradeNo = map.get("outTransId").toString();
        //查询用户ID
        JSONObject paramIn = new JSONObject();
        paramIn.put("oId", outTradeNo.substring(4));
        paramIn.put("oId", outTradeNo);
        String url = "fee.payFeeConfirm";
        responseEntity = this.callCenterService(getHeaders("-1"), paramIn.toJSONString(), url, HttpMethod.POST);