From e7393ef75b7df2799f627b4707cd8bc4b9d555e2 Mon Sep 17 00:00:00 2001 From: liurunyu <lry9898@163.com> Date: 星期三, 23 十月 2024 16:54:17 +0800 Subject: [PATCH] Merge branch 'master' of http://8.140.179.55:20000/r/pipIrr-SV --- pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/util/AES.java | 38 +++++++++ /dev/null | 30 ------- pipIrr-platform/pipIrr-web/pipIrr-web-sell/src/main/java/com/dy/pipIrrSell/wechatpay/PaymentSv.java | 19 ---- pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/wechatpay/PaymentCtrl.java | 70 +++++++++++++++-- pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/wechatpay/PaymentSv.java | 28 ++++++- pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/wechatpay/PayInfo.java | 12 +- pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/daoFi/WebFileMapper.java | 1 pipIrr-platform/pipIrr-web/pipIrr-web-sell/src/main/java/com/dy/pipIrrSell/wechatpay/PaymentCtrl.java | 27 ------ pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/wechatpay/dto/Wechatpay.java | 6 9 files changed, 132 insertions(+), 99 deletions(-) diff --git a/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/util/AES.java b/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/util/AES.java new file mode 100644 index 0000000..aa65eb8 --- /dev/null +++ b/pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/util/AES.java @@ -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瀵圭О鍔犲瘑瑙e瘑 + */ +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); + } +} diff --git a/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/daoFi/WebFileMapper.java b/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/daoFi/WebFileMapper.java index a2f3307..ef492f3 100644 --- a/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/daoFi/WebFileMapper.java +++ b/pipIrr-platform/pipIrr-global/src/main/java/com/dy/pipIrrGlobal/daoFi/WebFileMapper.java @@ -18,5 +18,4 @@ int updateByPrimaryKey(WebFile record); - } \ No newline at end of file diff --git a/pipIrr-platform/pipIrr-web/pipIrr-web-file/src/main/java/com/dy/pipIrrWebFile/get/GetFileCtrl.java b/pipIrr-platform/pipIrr-web/pipIrr-web-file/src/main/java/com/dy/pipIrrWebFile/get/GetFileCtrl.java deleted file mode 100644 index 3518c3a..0000000 --- a/pipIrr-platform/pipIrr-web/pipIrr-web-file/src/main/java/com/dy/pipIrrWebFile/get/GetFileCtrl.java +++ /dev/null @@ -1,72 +0,0 @@ -package com.dy.pipIrrWebFile.get; - -import com.dy.common.aop.SsoAop; -import com.dy.common.webUtil.BaseResponse; -import com.dy.common.webUtil.BaseResponseUtils; -import com.dy.pipIrrGlobal.dyFile.FileOperate; -import com.dy.pipIrrGlobal.dyFile.FileRestVo; -import com.dy.pipIrrGlobal.pojoFi.WebFile; -import com.dy.pipIrrGlobal.voFi.VoPhoto; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RestController; - -/** - * @author ZhuBaoMin - * @date 2024-10-22 15:26 - * @LastEditTime 2024-10-22 15:26 - * @Description 鑾峰彇鏂囦欢鎺у埗绫� - */ - -@Slf4j -@RestController -@RequestMapping(path = "get") -@RequiredArgsConstructor -public class GetFileCtrl { - private final GetFileSv getFileSv; - - @Autowired - private FileOperate fileOp ; - - @Value("${dy.webFile.fmUrl}") - private String fmUrl ; - - /** - * 鏍规嵁鍥剧墖ID鑾峰彇鍥剧墖璺緞 - * @param photoId - * @return - */ - @GetMapping(path = "/getPhotoFile") - @SsoAop() - public BaseResponse<VoPhoto> getPhotoFile(@RequestParam("photoId") Long photoId) { - try { - - // 鏍规嵁鍥剧墖ID鑾峰彇鍥剧墖鏂囦欢瀵硅薄锛屼粠鍥剧墖鏂囦欢瀵硅薄涓幏鍙栨枃浠惰矾寰勩�佹墿灞曞悕銆佺缉鐣ュ浘鏂囦欢璺緞 - WebFile webFile = getFileSv.getWebFileById(photoId); - if(webFile == null) { - return BaseResponseUtils.buildErrorMsg("鍥炬爣ID閿欒"); - } - String filePath = webFile.getFilePath(); - String extName = webFile.getExtName(); - String filePathZip = filePath.substring(0, filePath.indexOf('.')) + "_." + extName; - - FileRestVo frVo = fileOp.parseHashcode(fmUrl, webFile.hash); - - VoPhoto photo = new VoPhoto(); - photo.setDownloadPath(frVo.fileWebDownloadPath + photoId); - photo.setWebPath(frVo.fileWebUrl + filePath); - photo.setWebPathZip(frVo.fileWebUrl + filePathZip); - - return BaseResponseUtils.buildSuccess(photo); - } catch (Exception e) { - log.error("鑾峰彇鍥剧墖鏂囦欢寮傚父", e); - return BaseResponseUtils.buildException(e.getMessage()); - } - } - -} diff --git a/pipIrr-platform/pipIrr-web/pipIrr-web-file/src/main/java/com/dy/pipIrrWebFile/get/GetFileSv.java b/pipIrr-platform/pipIrr-web/pipIrr-web-file/src/main/java/com/dy/pipIrrWebFile/get/GetFileSv.java deleted file mode 100644 index d0aea44..0000000 --- a/pipIrr-platform/pipIrr-web/pipIrr-web-file/src/main/java/com/dy/pipIrrWebFile/get/GetFileSv.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.dy.pipIrrWebFile.get; - -import com.dy.pipIrrGlobal.daoFi.WebFileMapper; -import com.dy.pipIrrGlobal.pojoFi.WebFile; -import lombok.extern.slf4j.Slf4j; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; - -/** - * @author ZhuBaoMin - * @date 2024-10-22 15:27 - * @LastEditTime 2024-10-22 15:27 - * @Description - */ - -@Slf4j -@Service -public class GetFileSv { - @Autowired - private WebFileMapper webFileMapper; - - /** - * 鏍规嵁ID鑾峰彇鏂囦欢瀵硅薄 - * @param fileId - * @return - */ - public WebFile getWebFileById(Long fileId) { - return webFileMapper.selectByPrimaryKey(fileId); - } -} diff --git a/pipIrr-platform/pipIrr-web/pipIrr-web-sell/src/main/java/com/dy/pipIrrSell/wechatpay/PaymentCtrl.java b/pipIrr-platform/pipIrr-web/pipIrr-web-sell/src/main/java/com/dy/pipIrrSell/wechatpay/PaymentCtrl.java index bb69aa9..49b6ef7 100644 --- a/pipIrr-platform/pipIrr-web/pipIrr-web-sell/src/main/java/com/dy/pipIrrSell/wechatpay/PaymentCtrl.java +++ b/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) ; - } } diff --git a/pipIrr-platform/pipIrr-web/pipIrr-web-sell/src/main/java/com/dy/pipIrrSell/wechatpay/PaymentSv.java b/pipIrr-platform/pipIrr-web/pipIrr-web-sell/src/main/java/com/dy/pipIrrSell/wechatpay/PaymentSv.java index deddebf..4ac249f 100644 --- a/pipIrr-platform/pipIrr-web/pipIrr-web-sell/src/main/java/com/dy/pipIrrSell/wechatpay/PaymentSv.java +++ b/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); - } } diff --git a/pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/wechatpay/PayInfo.java b/pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/wechatpay/PayInfo.java index a07604b..4db0467 100644 --- a/pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/wechatpay/PayInfo.java +++ b/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 /* * 鍟嗘埛骞冲彴璁剧疆鐨勫瘑閽ey */ - public static String key = "DaYuJieShuiYanJiuYuan20230412ABC"; + public static String key = ""; //DaYuJieShuiYanJiuYuan20230412ABC /** * 鍟嗘埛API璇佷功搴忓垪鍙� */ - public static String serial_no = "52D65AA66405C738670377F467178F4C950E1606"; + public static String serial_no = ""; //52D65AA66405C738670377F467178F4C950E1606 /* * 缁堢IP锛岃皟鐢ㄥ井淇℃敮浠楢PI鐨勬満鍣↖P diff --git a/pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/wechatpay/PaymentCtrl.java b/pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/wechatpay/PaymentCtrl.java index 622d58d..e757992 100644 --- a/pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/wechatpay/PaymentCtrl.java +++ b/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("灏忕▼搴忓敮涓�鏍囪瘑閿欒鎴栧叾淇℃伅涓嶅瓨鍦�"); + } + + } } \ No newline at end of file diff --git a/pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/wechatpay/PaymentSv.java b/pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/wechatpay/PaymentSv.java index 50edb2b..d69cccd 100644 --- a/pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/wechatpay/PaymentSv.java +++ b/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; /** * 鏍规嵁鐧诲綍鎬両D鑾峰彇鐧诲綍鎬佸璞� @@ -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); + } } \ No newline at end of file diff --git a/pipIrr-platform/pipIrr-web/pipIrr-web-sell/src/main/java/com/dy/pipIrrSell/wechatpay/dto/Wechatpay.java b/pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/wechatpay/dto/Wechatpay.java similarity index 89% rename from pipIrr-platform/pipIrr-web/pipIrr-web-sell/src/main/java/com/dy/pipIrrSell/wechatpay/dto/Wechatpay.java rename to pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/wechatpay/dto/Wechatpay.java index d9d0e5c..147a1fb 100644 --- a/pipIrr-platform/pipIrr-web/pipIrr-web-sell/src/main/java/com/dy/pipIrrSell/wechatpay/dto/Wechatpay.java +++ b/pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/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 寰俊鏀粯浼犲叆瀵硅薄 */ -- Gitblit v1.8.0