zhubaomin
2024-10-23 004391089df2fda26b9c514d76bac1c329cad750
2024-10-23 朱宝民 可同时支持多个微信小程序
1 文件已重命名
1个文件已添加
5个文件已修改
200 ■■■■■ 已修改文件
pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/util/AES.java 38 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pipIrr-platform/pipIrr-web/pipIrr-web-sell/src/main/java/com/dy/pipIrrSell/wechatpay/PaymentCtrl.java 27 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pipIrr-platform/pipIrr-web/pipIrr-web-sell/src/main/java/com/dy/pipIrrSell/wechatpay/PaymentSv.java 19 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/wechatpay/PayInfo.java 12 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/wechatpay/PaymentCtrl.java 70 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/wechatpay/PaymentSv.java 28 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/wechatpay/dto/Wechatpay.java 6 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/util/AES.java
New file
@@ -0,0 +1,38 @@
package com.dy.common.util;
import javax.crypto.Cipher;
import javax.crypto.spec.SecretKeySpec;
import java.util.Base64;
/**
 * @author ZhuBaoMin
 * @date 2024-10-23 14:32
 * @LastEditTime 2024-10-23 14:32
 * @Description AES对称加密解密
 */
public class AES {
    private static final String ALGORITHM = "AES";
    private static final String TRANSFORMATION = "AES";
    // 16-byte secret key
    private static final String SECRET_KEY = "YanJiuYuanSecret";
    public static String encrypt(String input) throws Exception {
        SecretKeySpec keySpec = new SecretKeySpec(SECRET_KEY.getBytes(), ALGORITHM);
        Cipher cipher = Cipher.getInstance(TRANSFORMATION);
        cipher.init(Cipher.ENCRYPT_MODE, keySpec);
        byte[] encryptedBytes = cipher.doFinal(input.getBytes());
        return Base64.getEncoder().encodeToString(encryptedBytes);
    }
    public static String decrypt(String input) throws Exception {
        SecretKeySpec keySpec = new SecretKeySpec(SECRET_KEY.getBytes(), ALGORITHM);
        Cipher cipher = Cipher.getInstance(TRANSFORMATION);
        cipher.init(Cipher.DECRYPT_MODE, keySpec);
        byte[] decodedBytes = Base64.getDecoder().decode(input);
        byte[] decryptedBytes = cipher.doFinal(decodedBytes);
        return new String(decryptedBytes);
    }
}
pipIrr-platform/pipIrr-web/pipIrr-web-sell/src/main/java/com/dy/pipIrrSell/wechatpay/PaymentCtrl.java
@@ -517,31 +517,4 @@
        return  result;
    }
    @PostMapping(path = "add_wechatpay", consumes = MediaType.APPLICATION_JSON_VALUE)
    @Transactional(rollbackFor = Exception.class)
    @SsoAop()
    public BaseResponse<Boolean> addWechatpay(@RequestBody @Valid Wechatpay po, BindingResult bindingResult) {
        if(bindingResult != null && bindingResult.hasErrors()){
            return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage());
        }
        if(paymentSv.getWechatpayByAppId(po.getAppId()) != null) {
            return BaseResponseUtils.buildErrorMsg("该微信支付信息已经存在");
        }
        SeWechatpay seWechatpay = new SeWechatpay();
        seWechatpay.setAppId(po.getAppId());
        seWechatpay.setAppSecret(po.getAppSecret());
        seWechatpay.setMchId(po.getMchId());
        seWechatpay.setMchKey(po.getMchKey());
        seWechatpay.setSerialNo(po.getSerialNo());
        seWechatpay.setNotifyUrl(po.getNotifyUrl());
        seWechatpay.setRemarks(po.getRemarks());
        Long rec = Optional.ofNullable(paymentSv.addWechatpay(seWechatpay)).orElse(0L);
        if(rec == 0) {
            return BaseResponseUtils.buildFail("添加微信支付信息失败");
        }
        return BaseResponseUtils.buildSuccess(true) ;
    }
}
pipIrr-platform/pipIrr-web/pipIrr-web-sell/src/main/java/com/dy/pipIrrSell/wechatpay/PaymentSv.java
@@ -5,7 +5,6 @@
import com.dy.pipIrrGlobal.daoSe.SeWechatpayMapper;
import com.dy.pipIrrGlobal.pojoSe.SeOpenId;
import com.dy.pipIrrGlobal.pojoSe.SeVcRecharge;
import com.dy.pipIrrGlobal.pojoSe.SeWechatpay;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@@ -48,22 +47,4 @@
        return po.getId();
    }
    /**
     * 添加微信支付信息
     * @param po
     * @return
     */
    Long addWechatpay(SeWechatpay po) {
        seWechatpayMapper.insert(po);
        return po.getId();
    }
    /**
     * 根据AppId获取微信支付对象
     * @param appId
     * @return
     */
    SeWechatpay getWechatpayByAppId(String appId) {
        return seWechatpayMapper.getWechatpayByAppId(appId);
    }
}
pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/wechatpay/PayInfo.java
@@ -65,14 +65,12 @@
    /*
     * 小程序唯一标识
     */
    //public static String appid = "wxbc2b6a00dd904ead";
    public static String appid = "wxf773810cd5643196";
    public static String appid = "";    //wxf773810cd5643196
    /*
     * 小程序的 app secret
     */
    //public static String secret = "796ffe3e9921f756db0499e80d6ed0cd";
    public static String secret = "080d4f947095551e988cfe9338e27f15";
    public static String secret = "";   //080d4f947095551e988cfe9338e27f15
    /*
     * 小程序的授权类型,登录凭证校验使用
@@ -82,17 +80,17 @@
    /*
     * 商户号(微信支付分配的商户号)
     */
    public static String mchid = "1640721520";
    public static String mchid = "";    //1640721520
    /*
     * 商户平台设置的密钥key
     */
    public static String key = "DaYuJieShuiYanJiuYuan20230412ABC";
    public static String key = "";  //DaYuJieShuiYanJiuYuan20230412ABC
    /**
     * 商户API证书序列号
     */
    public static String serial_no = "52D65AA66405C738670377F467178F4C950E1606";
    public static String serial_no = "";    //52D65AA66405C738670377F467178F4C950E1606
    /*
     * 终端IP,调用微信支付API的机器IP
pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/wechatpay/PaymentCtrl.java
@@ -3,6 +3,7 @@
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import com.dy.common.multiDataSource.DataSourceContext;
import com.dy.common.util.AES;
import com.dy.common.webUtil.BaseResponse;
import com.dy.common.webUtil.BaseResponseUtils;
import com.dy.common.webUtil.ResultCodeMsg;
@@ -17,10 +18,7 @@
import com.dy.pipIrrWechat.virtualCard.dto.DtoVirtualCard;
import com.dy.pipIrrWechat.virtualCard.enums.LastOperateENUM;
import com.dy.pipIrrWechat.virtualCard.enums.RefundItemStateENUM;
import com.dy.pipIrrWechat.wechatpay.dto.Code2Session;
import com.dy.pipIrrWechat.wechatpay.dto.DtoOrder;
import com.dy.pipIrrWechat.wechatpay.dto.NotifyResource;
import com.dy.pipIrrWechat.wechatpay.dto.OrderNotify;
import com.dy.pipIrrWechat.wechatpay.dto.*;
import com.dy.pipIrrWechat.wechatpay.enums.RefundStatusENUM;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
@@ -48,10 +46,7 @@
import java.security.SignatureException;
import java.security.spec.InvalidKeySpecException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.*;
/**
 * @author ZhuBaoMin
@@ -535,4 +530,63 @@
        result.put("message", "成功");
        return  result;
    }
    /**
     * 添加微信支付信息
     * @param po
     * @param bindingResult
     * @return
     */
    @PostMapping(path = "add_wechatpay", consumes = MediaType.APPLICATION_JSON_VALUE)
    public BaseResponse<Boolean> addWechatpay(@RequestBody @Valid Wechatpay po, BindingResult bindingResult) throws Exception {
        if(bindingResult != null && bindingResult.hasErrors()){
            return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage());
        }
        if(paymentSv.getWechatpayByAppId(po.getAppId()) != null) {
            return BaseResponseUtils.buildErrorMsg("该微信支付信息已经存在");
        }
        SeWechatpay seWechatpay = new SeWechatpay();
        seWechatpay.setAppId(AES.encrypt(po.getAppId()));
        seWechatpay.setAppSecret(AES.encrypt(po.getAppSecret()));
        seWechatpay.setMchId(AES.encrypt(po.getMchId()));
        seWechatpay.setMchKey(AES.encrypt(po.getMchKey()));
        seWechatpay.setSerialNo((AES.encrypt(po.getSerialNo())));
        seWechatpay.setNotifyUrl(AES.encrypt(po.getNotifyUrl()));
        seWechatpay.setRemarks(po.getRemarks());
        Long rec = Optional.ofNullable(paymentSv.addWechatpay(seWechatpay)).orElse(0L);
        if(rec == 0) {
            return BaseResponseUtils.buildFail("添加微信支付信息失败");
        }
        return BaseResponseUtils.buildSuccess(true) ;
    }
    /**
     * 初始化微信支付信息
     * @param appId
     * @return
     */
    @PostMapping(path = "init_wechatpay")
    public BaseResponse<Boolean> initWechatpay(@RequestParam("appId") String appId) throws Exception {
        if(appId == null || appId.trim().length() == 0) {
            return BaseResponseUtils.buildErrorMsg("小程序唯一标识不能为空");
        }
        appId = AES.encrypt(appId);
        SeWechatpay seWechatpay = paymentSv.getWechatpayByAppId(appId);
        if(seWechatpay != null) {
            PayInfo.appid = AES.decrypt(seWechatpay.getAppId());
            PayInfo.secret = AES.decrypt(seWechatpay.getAppSecret());
            PayInfo.mchid = AES.decrypt(seWechatpay.getMchId());
            PayInfo.key = AES.decrypt(seWechatpay.getMchKey());
            PayInfo.serial_no = AES.decrypt(seWechatpay.getSerialNo());
            PayInfo.notifyUrl = AES.decrypt(seWechatpay.getNotifyUrl());
            return BaseResponseUtils.buildSuccess(true) ;
        }else {
            return BaseResponseUtils.buildErrorMsg("小程序唯一标识错误或其信息不存在");
        }
    }
}
pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/wechatpay/PaymentSv.java
@@ -1,12 +1,10 @@
package com.dy.pipIrrWechat.wechatpay;
import com.dy.pipIrrGlobal.daoSe.SeClientMapper;
import com.dy.pipIrrGlobal.daoSe.SeOpenIdMapper;
import com.dy.pipIrrGlobal.daoSe.SeVcOperateMapper;
import com.dy.pipIrrGlobal.daoSe.SeVcRechargeMapper;
import com.dy.pipIrrGlobal.daoSe.*;
import com.dy.pipIrrGlobal.pojoSe.SeClient;
import com.dy.pipIrrGlobal.pojoSe.SeOpenId;
import com.dy.pipIrrGlobal.pojoSe.SeVcRecharge;
import com.dy.pipIrrGlobal.pojoSe.SeWechatpay;
import com.dy.pipIrrGlobal.voSe.VoClient;
import com.dy.pipIrrWechat.virtualCard.SeClientToVoClient;
import lombok.extern.slf4j.Slf4j;
@@ -34,6 +32,9 @@
    @Autowired
    private SeVcOperateMapper seVcOperateMapper;
    @Autowired
    private SeWechatpayMapper seWechatpayMapper;
    /**
     * 根据登录态ID获取登录态对象
@@ -94,4 +95,23 @@
    //    seVcOperateMapper.insert(po);
    //    return po.getId();
    //}
    /**
     * 添加微信支付信息
     * @param po
     * @return
     */
    Long addWechatpay(SeWechatpay po) {
        seWechatpayMapper.insert(po);
        return po.getId();
    }
    /**
     * 根据AppId获取微信支付对象
     * @param appId
     * @return
     */
    SeWechatpay getWechatpayByAppId(String appId) {
        return seWechatpayMapper.getWechatpayByAppId(appId);
    }
}
pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/wechatpay/dto/Wechatpay.java
File was renamed from pipIrr-platform/pipIrr-web/pipIrr-web-sell/src/main/java/com/dy/pipIrrSell/wechatpay/dto/Wechatpay.java
@@ -1,12 +1,12 @@
package com.dy.pipIrrSell.wechatpay.dto;
package com.dy.pipIrrWechat.wechatpay.dto;
import lombok.Data;
import org.apache.logging.log4j.core.config.plugins.validation.constraints.NotBlank;
/**
 * @author ZhuBaoMin
 * @date 2024-10-22 11:31
 * @LastEditTime 2024-10-22 11:31
 * @date 2024-10-23 11:16
 * @LastEditTime 2024-10-23 11:16
 * @Description 微信支付传入对象
 */