feat: paypal配置
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
package org.wfc.common.core.utils;
|
||||
|
||||
import org.bouncycastle.jce.provider.BouncyCastleProvider;
|
||||
|
||||
import javax.crypto.Cipher;
|
||||
import javax.crypto.spec.IvParameterSpec;
|
||||
import javax.crypto.spec.SecretKeySpec;
|
||||
import java.security.Security;
|
||||
import java.util.Base64;
|
||||
|
||||
public class AESUtil {
|
||||
// AES密钥算法
|
||||
private static final String KEY_ALGORITHM = "AES";
|
||||
// 加密/解密算法/工作模式/填充方式
|
||||
private static final String CIPHER_ALGORITHM = "AES/CBC/PKCS5Padding";
|
||||
|
||||
private static final String KEY = "EolSdjfd89v2PubN";
|
||||
|
||||
//CBC加密偏移量
|
||||
private static final String IVCODE = "EjlnujOBvlv2PubN";
|
||||
|
||||
/**
|
||||
* AES加密
|
||||
*/
|
||||
public static String encrypt(String data) {
|
||||
try {
|
||||
Security.addProvider(new BouncyCastleProvider());
|
||||
SecretKeySpec secretKeySpec = new SecretKeySpec(KEY.getBytes(), KEY_ALGORITHM);
|
||||
Cipher cipher = Cipher.getInstance(CIPHER_ALGORITHM, "BC");
|
||||
IvParameterSpec iv = new IvParameterSpec(IVCODE.getBytes());
|
||||
cipher.init(Cipher.ENCRYPT_MODE, secretKeySpec, iv);
|
||||
byte[] encryptedBytes = cipher.doFinal(data.getBytes());
|
||||
return Base64.getEncoder().encodeToString(encryptedBytes);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* AES解密
|
||||
*/
|
||||
public static String decrypt(String encryptedData) {
|
||||
try {
|
||||
SecretKeySpec secretKeySpec = new SecretKeySpec(KEY.getBytes(), KEY_ALGORITHM);
|
||||
IvParameterSpec iv = new IvParameterSpec(IVCODE.getBytes());
|
||||
Security.addProvider(new BouncyCastleProvider());
|
||||
byte[] encryptedBytes = javax.xml.bind.DatatypeConverter.parseBase64Binary(encryptedData);
|
||||
Cipher cipher = Cipher.getInstance(CIPHER_ALGORITHM, "BC");
|
||||
cipher.init(Cipher.DECRYPT_MODE, secretKeySpec, iv);
|
||||
byte[] decryptedBytes = cipher.doFinal(encryptedBytes);
|
||||
return new String(decryptedBytes);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// 验证
|
||||
// public static void main(String[] args) throws Exception {
|
||||
// String data = "AfPgwFAmo9K7KCqiiGpNRCyQMSxI6V33eH-nEMnVndJNVEYOEOEn5wSPkHUybfzcjDLnBejt-RKnIfqX";
|
||||
// String encryptedData = encrypt(data); // 加密数据
|
||||
// String decryptedData = decrypt(encryptedData); // 解密数据
|
||||
// System.out.println("加密后的数据: " + encryptedData);
|
||||
// System.out.println("解密后的数据: " + decryptedData);
|
||||
// }
|
||||
}
|
||||
@@ -43,7 +43,7 @@ public class LicenseCheckRunner implements ApplicationRunner {
|
||||
// 启动定时任务
|
||||
public void startTimer() {
|
||||
scheduledFuture = scheduler.scheduleAtFixedRate(this::timer, 0, 30, TimeUnit.SECONDS);
|
||||
scheduler.scheduleAtFixedRate(this::fileTimer, 0, 40, TimeUnit.SECONDS);
|
||||
scheduler.scheduleAtFixedRate(this::fileTimer, 0, 60, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
// 停止定时任务
|
||||
|
||||
@@ -6,6 +6,7 @@ import com.paypal.sdk.authentication.ClientCredentialsAuthModel;
|
||||
import com.paypal.sdk.models.Order;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
@@ -13,6 +14,7 @@ import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
import org.wfc.common.core.domain.R;
|
||||
import org.wfc.common.core.utils.AESUtil;
|
||||
import org.wfc.payment.domain.PayPalBean;
|
||||
import org.wfc.payment.pay.paypal.service.IPayPalService;
|
||||
|
||||
@@ -67,6 +69,12 @@ public class PayPalController {
|
||||
}
|
||||
}
|
||||
|
||||
@GetMapping("/result/one")
|
||||
public R<String> getPaypalConfig()
|
||||
{
|
||||
return R.ok(AESUtil.encrypt(payPalBean.getClientId()));
|
||||
}
|
||||
|
||||
@PostMapping("/orders/{paypalOrderId}/capture/{orderId}")
|
||||
public R<Order> captureOrder(@PathVariable String paypalOrderId, @PathVariable Long orderId) {
|
||||
try {
|
||||
|
||||
@@ -80,4 +80,4 @@ paypal:
|
||||
stripe:
|
||||
secret-key: sk_test_51RHGN8FwutpVO5TqqmAkJNYMlWDPgwj4NVKPxcPKEXMGSPpEZ4yKwpGancV1vyPP74Pk3ETPUdAws0CfiH1jTN9v00kQ64suj5
|
||||
domain: http://192.168.6.222/u
|
||||
endpoint-secret: whsec_rD5GFCx37wIS3Ag67ocPHWoD2WGIfWyC
|
||||
endpoint-secret: whsec_zBaAhDlSc6AdNBlbLzmbT0mfGCikA8IT
|
||||
|
||||
@@ -306,13 +306,15 @@ public class UCdrServiceImpl extends ServiceImpl<UCdrMapper, UCdr> implements IU
|
||||
Long userId = uClient.getUserId();
|
||||
if (userId != null) {
|
||||
UAccount account = accountService.getOne(Wrappers.<UAccount>lambdaQuery().eq(UAccount::getUserId, userId), false);
|
||||
if (AccountUtil.isPackageValidNoUsedBalance(account, new Date())) {
|
||||
uClient.setUseType(UserTypeEnum.PACKAGE.getCode());
|
||||
uClient.setUseId(account.getPackageId());
|
||||
} else if (AccountUtil.isBalanceValid(account)) {
|
||||
uClient.setUseType(UserTypeEnum.BALANCE.getCode());
|
||||
} else {
|
||||
uClient.setUseType(UserTypeEnum.OTHER.getCode());
|
||||
if (account != null) {
|
||||
if (AccountUtil.isPackageValidNoUsedBalance(account, new Date())) {
|
||||
uClient.setUseType(UserTypeEnum.PACKAGE.getCode());
|
||||
uClient.setUseId(account.getPackageId());
|
||||
} else if (AccountUtil.isBalanceValid(account)) {
|
||||
uClient.setUseType(UserTypeEnum.BALANCE.getCode());
|
||||
} else {
|
||||
uClient.setUseType(UserTypeEnum.OTHER.getCode());
|
||||
}
|
||||
}
|
||||
}
|
||||
clientService.updateById(uClient);
|
||||
|
||||
@@ -37,7 +37,7 @@ public class UConfigServiceImpl implements IUConfigService
|
||||
|
||||
private static final String DEFAULT_SYS_PAY_CURRENCY_VALUE = "USD";
|
||||
private static final String DEFAULT_SYS_PAY_CURRENCY_SYMBOL_VALUE = "$";
|
||||
private static final String[] DEFAULT_SYS_PAY_PAYMENT_METHOD_VALUE = {"paypal"};
|
||||
private static final String[] DEFAULT_SYS_PAY_PAYMENT_METHOD_VALUE = {"paypal", "stripe"};
|
||||
|
||||
/**
|
||||
* 项目启动时,初始化参数到缓存
|
||||
|
||||
@@ -14,15 +14,22 @@ import org.wfc.common.core.utils.bean.BeanValidators;
|
||||
import org.wfc.common.security.utils.SecurityUtils;
|
||||
import org.wfc.user.api.domain.URole;
|
||||
import org.wfc.user.api.domain.UUser;
|
||||
import org.wfc.user.domain.UAccount;
|
||||
import org.wfc.user.domain.UPost;
|
||||
import org.wfc.user.domain.UUserPost;
|
||||
import org.wfc.user.domain.UUserRole;
|
||||
import org.wfc.user.mapper.*;
|
||||
import org.wfc.user.mapper.UAccountMapper;
|
||||
import org.wfc.user.mapper.UPostMapper;
|
||||
import org.wfc.user.mapper.URoleMapper;
|
||||
import org.wfc.user.mapper.UUserMapper;
|
||||
import org.wfc.user.mapper.UUserPostMapper;
|
||||
import org.wfc.user.mapper.UUserRoleMapper;
|
||||
import org.wfc.user.service.IUConfigService;
|
||||
import org.wfc.user.service.IUDeptService;
|
||||
import org.wfc.user.service.IUUserService;
|
||||
|
||||
import javax.validation.Validator;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
@@ -61,6 +68,9 @@ public class UUserServiceImpl implements IUUserService
|
||||
@Autowired
|
||||
protected Validator validator;
|
||||
|
||||
@Autowired
|
||||
private UAccountMapper accountMapper;
|
||||
|
||||
/**
|
||||
* 根据条件分页查询用户列表
|
||||
*
|
||||
@@ -276,7 +286,17 @@ public class UUserServiceImpl implements IUUserService
|
||||
@Override
|
||||
public boolean registerUser(UUser user)
|
||||
{
|
||||
return userMapper.insertUser(user) > 0;
|
||||
boolean flag = userMapper.insertUser(user) > 0;
|
||||
try {
|
||||
UAccount account = new UAccount();
|
||||
account.setUserId(user.getUserId());
|
||||
account.setBalance(BigDecimal.ZERO);
|
||||
account.setBalanceUsed(BigDecimal.ZERO);
|
||||
accountMapper.insert(account);
|
||||
} catch (Exception e) {
|
||||
log.error("register add account error {}", e.getMessage());
|
||||
}
|
||||
return flag;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user