yml文件
package com.umh.medicalbookingplatform.api.service
import com.umh.medicalbookingplatform.api.model.*
import com.umh.medicalbookingplatform.core.model.user.User
import com.umh.medicalbookingplatform.core.model.user.UserRepository
import com.umh.medicalbookingplatform.core.model.user.UserToken
import com.umh.medicalbookingplatform.core.security.model.AuthenticationRequest
import com.umh.medicalbookingplatform.core.service.TokenService
import com.umh.medicalbookingplatform.core.service.UserTokenService
import io.swagger.v3.oas.annotations.Operation
import org.slf4j.LoggerFactory
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.data.repository.findByIdOrNull
import org.springframework.stereotype.Service
import java.util.*
import com.google.firebase.FirebaseApp
import com.google.auth.oauth2.GoogleCredentials
import com.google.firebase.FirebaseOptions
import com.google.firebase.auth.FirebaseAuth
import com.umh.medicalbookingplatform.core.properties.ApplicationProperties
import org.springframework.security.crypto.codec.Utf8
import java.io.*
/**
* @Description :
* @Author xiaomh
* @create 2021/9/14 11:37
*/
@Service
class ApiMemberService {
@Autowired
private lateinit var apiGPInvokeService: ApiGPInvokeService
private val logger = LoggerFactory.getLogger(this.javaClass)
@Autowired
private lateinit var tokenUtils: TokenService
@Autowired
private lateinit var userTokenService: UserTokenService
@Autowired
private lateinit var apiMemberService: ApiMemberService
@Autowired
private lateinit var userRepository: UserRepository
@Autowired
private lateinit var appProperties: ApplicationProperties
@Operation(summary = "第三方登录接口", description = "第三方登录接口")
fun socialMediaLogin(/*authenticationRequest: AuthenticationRequest, requestIp: String*/): String {
//这里的需求是要把yml里的base64编码拿过来进行解码
//base64转string
val decoder = Base64.getDecoder()
val decoded = decoder.decode(appProperties.firebaseAdminSdk)
val decodedStr = String(decoded, Charsets.UTF_8)
//val jsonObject = JSONObject.parseObject(decodedStr)
//val serviceAccount = FileInputStream("C:/Users/sendi/Desktop/serviceAccountKey.json")
//往文本里面写入字符串内容,firebaseAccountKey.json为名字
val file = File("firebaseAccountKey.json")
file.writeText(decodedStr)
println(file)
//测试
val test = FileOutputStream("C:/Users/sendi/Desktop/test.json")
test.write(decodedStr.toByteArray())
test.close()
val serviceAccount = FileInputStream(file)
val options = FirebaseOptions.builder()
.setCredentials(GoogleCredentials.fromStream(serviceAccount))
//.setCredentials(GoogleCredentials.getApplicationDefault())
//.setDatabaseUrl("https://<DATABASE_NAME>.firebaseio.com/")
.build()
FirebaseApp.initializeApp(options)
val idToken = "eyJhbGciOiJSUzI1NiIsImtpZCI6ImYwNTM4MmFlMTgxYWJlNjFiOTYwYjA1Yzk3ZmE0MDljNDdhNDQ0ZTciLCJ0eXAiOiJKV1QifQ.eyJuYW1lIjoi5Y2i5pm66ZSLIiwicGljdHVyZSI6Imh0dHBzOi8vbGgzLmdvb2dsZXVzZXJjb250ZW50LmNvbS9hL0FBVFhBSndqUnc1UjJsdFlJVy1vX2xWXzZqTGF6X19yeXFIRVdGdDBVRFJUPXM5Ni1jIiwiaXNzIjoiaHR0cHM6Ly9zZWN1cmV0b2tlbi5nb29nbGUuY29tL3VtaC1hcHAtdWF0IiwiYXVkIjoidW1oLWFwcC11YXQiLCJhdXRoX3RpbWUiOjE2MzQwMDIwODcsInVzZXJfaWQiOiJ2aGFsbU40S084UFFHSFNSbGtiYXBiRVdVNm8xIiwic3ViIjoidmhhbG1ONEtPOFBRR0hTUmxrYmFwYkVXVTZvMSIsImlhdCI6MTYzNDAwMjA4NywiZXhwIjoxNjM0MDA1Njg3LCJlbWFpbCI6Imx1emZAZ3pzZW5kaS5jbiIsImVtYWlsX3ZlcmlmaWVkIjp0cnVlLCJmaXJlYmFzZSI6eyJpZGVudGl0aWVzIjp7Imdvb2dsZS5jb20iOlsiMTAwMTcwNzI2Njc2NzM5ODY4NzYyIl0sImVtYWlsIjpbImx1emZAZ3pzZW5kaS5jbiJdfSwic2lnbl9pbl9wcm92aWRlciI6Imdvb2dsZS5jb20ifX0.F-HBiaBArWKQ_B5xzmrthbWfqp7KqVvpBkmcK6g_Nnmjhu-OwrbUeRZRuuhJatHNQmxdMUUSIpV7jjgd-fDCKtma_sZi5bg7_GFTmNgsLD3lxqio5OSTIB-b6V79rDgsVmBKbFJZZNKIH6U8zvwma6yr7u1GYF1bV5Qw67oPQuSSIt5MpjPl-Ihs9TKkULiEJce3-T9JCrt-MdUX_3r1nBdRsyqzasg9DFVNzjTz6xq4EBWeShJXw46HHg0wUdWC4PX1VQr3dnJRTHgEu08YiKD5pd-6XsyVFv0AZW1GXrcKstqj_AqdShlRw0td-qjxGy_x2JEpYKO"
val decodedToken = FirebaseAuth.getInstance().verifyIdToken(idToken)
val uid = decodedToken.uid
return uid
}
}
@Test
void getTest() {
// String filePath = System.getProperty("user.home") + "/Desktop/yourfile.txt";
String filePath = "D:/nonGame/快捷桌面/项目/ykt/一卡通09-01es数据.txt";
//D:/nonGame/快捷桌面/项目/ykt/一卡通09-01es数据.txt
try {
// 创建文件对象
File file = new File(filePath);
// 使用BufferedReader来读取文件内容
BufferedReader reader = new BufferedReader(new FileReader(file));
StringBuilder stringBuilder = new StringBuilder();
String line;
// 逐行读取文件内容并追加到StringBuilder中
while ((line = reader.readLine()) != null) {
stringBuilder.append(line).append("\n");
}
// 关闭文件读取器
reader.close();
// 将读取的内容转换为字符串
String fileContent = stringBuilder.toString();
// 打印读取的内容
// System.out.println("文件内容:\n" + fileContent);
ObjectMapper objectMapper = new ObjectMapper();
try {
// 将JSON数据解析为TravelItinerary数组
ItineraryVisualizationDocument[] travelItineraries = objectMapper.readValue(fileContent, ItineraryVisualizationDocument[].class);
int totalTouristCount = 0;
int groupBill = 0;
int touristCountForeach = 0;
for (ItineraryVisualizationDocument travelItinerary : travelItineraries) {
// System.out.println("===1");
// System.out.println(travelItinerary.getDeleted());
// System.out.println(travelItinerary.getStatus());
// System.out.println(travelItinerary.getIsTemplate());
if (travelItinerary.getDeleted().equals(true)
|| travelItinerary.getStatus() == null
|| travelItinerary.getStatus().equals(1)
|| travelItinerary.getStatus().equals(11)
|| travelItinerary.getIsTemplate().equals(true)) {
continue;
}
int size = travelItinerary.getNestedTouristVisualizationBoList().size();
int touristCount = travelItinerary.getTouristCount();
if (size != touristCount) {
System.out.println("touristCount与nestedTouristVisualizationBoList.size不相同的oid为:");
System.out.println("oid:::" + travelItinerary.getOid());
System.out.println("itineraryNo:::" + travelItinerary.getItineraryNo());
System.out.println("touristCount:::" + touristCount);
System.out.println("size:::" + size);
}
touristCountForeach += size;
totalTouristCount += touristCount;
groupBill += 1;
}
// List<String> stringList = new ArrayList<>();
//
// // 将两个字符串添加到列表中
// stringList.add("你好");
// stringList.add("世界");
// System.out.println("测试size" +stringList.size() );
System.out.println("09-01,txt数据如下");
System.out.println("团单数量为:::" + groupBill);
System.out.println("touristCount字段计算的总数:::" + totalTouristCount);
System.out.println("根据nestedTouristVisualizationBoList.size获得的游客数量为:::" + touristCountForeach);
// return Arrays.asList(travelItineraries);
} catch (IOException e) {
e.printStackTrace();
}
} catch (IOException e) {
// 处理文件读取异常
e.printStackTrace();
}
// return new ArrayList<>();
}
@Test
void Test2() {
String filePath = "C:/Users/37798/Desktop/测试2.png";
try {
String base64String = encodeImageToBase64(filePath);
saveBase64StringToFile(base64String, "C:/Users/37798/Desktop/base64Output.txt");
System.out.println("Base64 encoded string: " + base64String);
} catch (IOException e) {
e.printStackTrace();
}
}
@Test
void Test3() throws IOException {
String filePath = "C:/Users/37798/Desktop/base64Output.txt";
// 创建文件对象
File file = new File(filePath);
// 使用BufferedReader来读取文件内容
BufferedReader reader = new BufferedReader(new FileReader(file));
StringBuilder stringBuilder = new StringBuilder();
String line;
// 逐行读取文件内容并追加到StringBuilder中
while ((line = reader.readLine()) != null) {
stringBuilder.append(line).append("\n");
}
// 关闭文件读取器
reader.close();
// 将读取的内容转换为字符串
String fileContent = stringBuilder.toString();
saveBase64StringToFile(fileContent, "C:/Users/37798/Desktop/stringOutput.txt");
}
@Test
void test4() throws IOException {
StringBuilder stringBuilder = new StringBuilder();
for (int i = 0; i < 138; i++) {
try {
int prefix = 0;
if (i != 0 && i <= 122) {
prefix = 1;
} else if (i > 122){
prefix = 2;
}
String filePath = "C:/Users/37798/Desktop/天使/" + prefix + "-" + i + ".txt";
//String filePath = "C:/Users/37798/Desktop/0-0.txt";
System.out.println("filePath:" + filePath);
// 创建文件对象
File file = new File(filePath);
// 使用BufferedReader来读取文件内容
BufferedReader reader = new BufferedReader(new InputStreamReader(Files.newInputStream(file.toPath()), StandardCharsets.UTF_16LE));
String line;
// 逐行读取文件内容并追加到StringBuilder中
while ((line = reader.readLine()) != null) {
stringBuilder.append(line).append("\n");
}
// 关闭文件读取器
reader.close();
} catch (IOException e) {
e.printStackTrace();
}
}
String outputFilePath = "C:/Users/37798/Desktop/天使.txt";
File outputFile = new File(outputFilePath);
try (FileOutputStream outputStream = new FileOutputStream(outputFile)) {
// 写入Base64字符串到文件
outputStream.write(stringBuilder.toString().getBytes(Charset.forName("UTF-8")));
outputStream.close();
}
}
private static String encodeImageToBase64(String imagePath) throws IOException {
File imageFile = new File(imagePath);
byte[] imageBytes = Files.readAllBytes(imageFile.toPath());
// 使用Base64编码
//return Base64.getEncoder().encodeToString(imageBytes);
return Arrays.toString(imageBytes);
}
private static void saveBase64StringToFile(String base64String, String outputFilePath) throws IOException {
File outputFile = new File(outputFilePath);
try (FileOutputStream outputStream = new FileOutputStream(outputFile)) {
// 写入Base64字符串到文件
outputStream.write(base64String.getBytes());
outputStream.close();
}
}