Compare commits
3 Commits
619f0dac67
...
1eec59a4c3
Author | SHA1 | Date |
---|---|---|
胡锐 | 1eec59a4c3 | 11 months ago |
胡锐 | 72e3cb2f01 | 11 months ago |
胡锐 | 378b392427 | 11 months ago |
@ -0,0 +1,14 @@ |
||||
package com.hfkj.channel.llg.config; |
||||
|
||||
/** |
||||
* 零零购 |
||||
* @className: LLGConfig |
||||
* @author: HuRui |
||||
* @date: 2023/12/19 |
||||
**/ |
||||
public class LLGConfig { |
||||
|
||||
public static final String requestUrl = "https://abcd.zjdt.cc"; |
||||
public static final String key = "BMKp20Omcv9u7TqGAhydCw63"; |
||||
|
||||
} |
@ -0,0 +1,92 @@ |
||||
package com.hfkj.channel.llg.service; |
||||
|
||||
import com.alibaba.fastjson.JSONObject; |
||||
import com.hfkj.channel.llg.config.LLGConfig; |
||||
import com.hfkj.channel.llg.util.AesUtil; |
||||
import com.hfkj.common.utils.HttpsUtils; |
||||
|
||||
import java.math.BigDecimal; |
||||
import java.net.HttpURLConnection; |
||||
import java.net.URL; |
||||
import java.util.HashMap; |
||||
import java.util.Map; |
||||
|
||||
/** |
||||
* 零零购分期 |
||||
* 交易订单业务 |
||||
* @className: LLGOrderService |
||||
* @author: HuRui |
||||
* @date: 2023/12/19 |
||||
**/ |
||||
public class LLGOrderService { |
||||
|
||||
/** |
||||
* 获取银行列表 |
||||
* @param merId 商户号 |
||||
* @param period 分期期数 |
||||
* @return |
||||
* @throws Exception |
||||
*/ |
||||
public static JSONObject getBanks(String merId,Integer period) { |
||||
return HttpsUtils.doGet(LLGConfig.requestUrl + "/v3/openapi/banks?merId=" + merId + "&period=" + period); |
||||
} |
||||
|
||||
/** |
||||
* 创建订单 |
||||
* @return 分期支付地址 |
||||
* @throws Exception |
||||
*/ |
||||
public static String createOrder() throws Exception { |
||||
Map<String,Object> param = new HashMap<>(); |
||||
param.put("merId", "109"); |
||||
param.put("marketId", "135"); |
||||
param.put("pkgId", "54"); |
||||
param.put("bankId", "52"); |
||||
param.put("orderId", System.currentTimeMillis()); |
||||
param.put("nickPrice", "100"); |
||||
param.put("payType", "02"); |
||||
param.put("period", "06"); |
||||
param.put("phoneName", "测试"); |
||||
param.put("backUrl", false); // 回调地址
|
||||
param.put("frontUrl", false); // 前端跳转地址
|
||||
param.put("qrcode", false); |
||||
|
||||
String dataStr = AesUtil.aesEncrypt(LLGConfig.key, JSONObject.toJSONString(param)); |
||||
URL url = new URL(LLGConfig.requestUrl + "/v3/openapi/order/create?data="+ dataStr); |
||||
HttpURLConnection connection = (HttpURLConnection) url.openConnection(); |
||||
// GET请求方式
|
||||
connection.setRequestMethod("GET"); |
||||
// 设置不使用缓存, 默认为 true 使用缓存
|
||||
connection.setUseCaches(false); |
||||
// 设置单次请求是否支持重定向,默认为 setFollowRedirects 方法设置的值
|
||||
connection.setInstanceFollowRedirects(false); |
||||
// 设置是否进行重定向,注意此处为 静态方法,表示所有的请求都不支持重定向,默认为true
|
||||
connection.setFollowRedirects(false); |
||||
|
||||
connection.getContent(); |
||||
// 获取重定向地址
|
||||
return "https:" + connection.getHeaderField("Location"); |
||||
} |
||||
|
||||
/** |
||||
* 创建订单 |
||||
* @return 分期支付地址 |
||||
* @throws Exception |
||||
*/ |
||||
public static JSONObject createOrder(Long merId, String orderId, String payType, BigDecimal txnAmt) throws Exception { |
||||
Map<String,Object> param = new HashMap<>(); |
||||
param.put("merId", merId); |
||||
param.put("orderId", orderId); |
||||
param.put("payType", payType); |
||||
param.put("txnAmt", txnAmt); |
||||
|
||||
String dataStr = AesUtil.aesEncrypt(LLGConfig.key, JSONObject.toJSONString(param)); |
||||
JSONObject response = HttpsUtils.doGet(LLGConfig.requestUrl + "/v3/openapi/order/paycheck?data=" + dataStr); |
||||
if (response == null) { |
||||
|
||||
} |
||||
|
||||
return response; |
||||
} |
||||
|
||||
} |
@ -0,0 +1,105 @@ |
||||
package com.hfkj.channel.llg.util; |
||||
|
||||
import javax.crypto.Cipher; |
||||
import javax.crypto.spec.IvParameterSpec; |
||||
import javax.crypto.spec.SecretKeySpec; |
||||
|
||||
/** |
||||
* @className: AesUtil |
||||
* @author: HuRui |
||||
* @date: 2023/12/19 |
||||
**/ |
||||
public class AesUtil { |
||||
|
||||
private static final String CHARSET = "UTF-8"; |
||||
private static final String KEY_ALGORITHM = "AES"; |
||||
/**默认的加密算法 aes-192-cbc*/ |
||||
private static final String DEFAULT_CIPHER_ALGORITHM = "AES/CBC/PKCS5Padding"; |
||||
//private static final String IV_PARAMETER_SPEC_STRING = "0000000000000000";
|
||||
//对应nodejs的buffer.alloc(16,0)
|
||||
private static final byte[] IV_PARAMETER_SPEC_BYTE = new byte[]{00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00}; |
||||
private static final Integer RADIX = 16; |
||||
|
||||
public static void main(String[] args) { |
||||
String testStr =""; |
||||
String aesKey = "BMKp20Omcv9u7TqGAhydCw63";//密钥
|
||||
try { |
||||
/* String aesEncrypt = aesEncrypt(aesKey, testStr); |
||||
System.out.println("========success:===488944dc7dca74786f21fe9b98420038=================="); |
||||
System.out.println(aesEncrypt);*/ |
||||
String aesEncryptStr = "61be322b8f6afb254888109c67cc39619214e9a62eccca1dfee72461e025b9a4"; |
||||
String aesDecrypt = aesDecrypt(aesKey, aesEncryptStr); |
||||
System.out.println(aesDecrypt); |
||||
} catch (Exception e) { |
||||
e.printStackTrace(); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* AES 加密操作 |
||||
* |
||||
* @param aesKey 密钥 |
||||
* @param data 待加密内容 |
||||
* @return 加密数据 |
||||
*/ |
||||
public static String aesEncrypt(String aesKey, String data) throws Exception { |
||||
return byte2HexString(encrypt(aesKey.getBytes(CHARSET), data.getBytes(CHARSET))); |
||||
} |
||||
|
||||
/** |
||||
* AES 解密操作 |
||||
* |
||||
* @param aesKey 密钥 |
||||
* @param data 待解密内容 |
||||
* @return 解密数据 |
||||
*/ |
||||
public static final String aesDecrypt(String aesKey, String data) throws Exception { |
||||
return new String(decrypt(aesKey.getBytes(CHARSET), hexString2Byte(data)), CHARSET); |
||||
} |
||||
|
||||
private static byte[] decrypt(byte[] key, byte[] data) throws Exception { |
||||
SecretKeySpec secretKeySpec = new SecretKeySpec(key, KEY_ALGORITHM); |
||||
Cipher cipher = Cipher.getInstance(DEFAULT_CIPHER_ALGORITHM); |
||||
IvParameterSpec iv = new IvParameterSpec(IV_PARAMETER_SPEC_BYTE); |
||||
cipher.init(Cipher.DECRYPT_MODE, secretKeySpec, iv); |
||||
return cipher.doFinal(data); |
||||
} |
||||
|
||||
private static byte[] hexString2Byte(String hexString) { |
||||
hexString = hexString.toUpperCase(); |
||||
int length = hexString.length() / 2; |
||||
char[] hexChars = hexString.toCharArray(); |
||||
byte[] b = new byte[length]; |
||||
for (int i = 0; i < length; i++) { |
||||
int pos = i * 2; |
||||
b[i] = (byte) (charToByte(hexChars[pos]) << 4 | charToByte(hexChars[pos + 1])); |
||||
} |
||||
return b; |
||||
} |
||||
|
||||
private static String byte2HexString(byte[] src) { |
||||
StringBuilder sb = new StringBuilder(); |
||||
for (int i = 0; i < src.length; i++) { |
||||
int v = src[i] & 0xff; |
||||
String hv = Integer.toHexString(v); |
||||
if (hv.length() < 2) { |
||||
sb.append("0"); |
||||
} |
||||
sb.append(hv); |
||||
} |
||||
return sb.toString(); |
||||
} |
||||
|
||||
private static byte charToByte(char c) { |
||||
return (byte) "0123456789ABCDEF".indexOf(c); |
||||
} |
||||
|
||||
private static byte[] encrypt(byte[] key, byte[] data) throws Exception { |
||||
SecretKeySpec secretKeySpec = new SecretKeySpec(key, KEY_ALGORITHM); |
||||
Cipher cipher = Cipher.getInstance(DEFAULT_CIPHER_ALGORITHM); |
||||
IvParameterSpec iv = new IvParameterSpec(IV_PARAMETER_SPEC_BYTE); |
||||
cipher.init(Cipher.ENCRYPT_MODE, secretKeySpec, iv); |
||||
return cipher.doFinal(data); |
||||
} |
||||
|
||||
} |
Loading…
Reference in new issue