|
@@ -0,0 +1,56 @@
|
|
|
|
+package com.zswl.cloud.springBtach.server.core.api.xiaoju;
|
|
|
|
+
|
|
|
|
+import com.xiaoju.open.oil.commons.config.OilConfig;
|
|
|
|
+import com.xiaoju.open.oil.core.QueryClient;
|
|
|
|
+import com.xiaoju.open.oil.core.QueryClientFactory;
|
|
|
|
+import com.xiaoju.open.oil.interfaces.request.QueryTokenRequest;
|
|
|
|
+import com.xiaoju.open.oil.interfaces.response.QueryTokenResponse;
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
|
+
|
|
|
|
+import javax.crypto.Cipher;
|
|
|
|
+import javax.crypto.spec.IvParameterSpec;
|
|
|
|
+import javax.crypto.spec.SecretKeySpec;
|
|
|
|
+import java.util.Base64;
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+@Component
|
|
|
|
+public class XiaoJuApi {
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ OilConfig oilConfig;
|
|
|
|
+
|
|
|
|
+ public String queryToken(){
|
|
|
|
+
|
|
|
|
+ QueryTokenRequest queryTokenRequest = new QueryTokenRequest();
|
|
|
|
+ queryTokenRequest.setAppSecret(oilConfig.getAppSecret());
|
|
|
|
+ QueryClient queryClient = QueryClientFactory.create(oilConfig);
|
|
|
|
+ QueryTokenResponse queryTokenResponse = queryClient.api().queryToken(queryTokenRequest);
|
|
|
|
+ return queryTokenResponse.getAccessToken();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public static String encrypt(String data, String dataSecret, String dataSecretIv) {
|
|
|
|
+ try {
|
|
|
|
+ if (dataSecret == null) {
|
|
|
|
+ System.out.print("Key为空null");
|
|
|
|
+ return null;
|
|
|
|
+ } else if (dataSecret.length() != 16) {
|
|
|
|
+ System.out.print("Key长度不是16位");
|
|
|
|
+ return null;
|
|
|
|
+ } else {
|
|
|
|
+ byte[] raw = dataSecret.getBytes("UTF-8");
|
|
|
|
+ SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES");
|
|
|
|
+ Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
|
|
|
|
+ IvParameterSpec iv = new IvParameterSpec(dataSecretIv.getBytes());
|
|
|
|
+ cipher.init(1, skeySpec, iv);
|
|
|
|
+ byte[] encrypted = cipher.doFinal(data.getBytes());
|
|
|
|
+ String str = Base64.getEncoder().encodeToString(encrypted);
|
|
|
|
+ str = str.replaceAll("\r", "");
|
|
|
|
+ str = str.replaceAll("\n", "");
|
|
|
|
+ return str;
|
|
|
|
+ }
|
|
|
|
+ } catch (Exception var9) {
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+}
|