leutu
2024-06-25 12aae5acd8449d896278e4274c245b4a9a69aafb
src/main/java/com/yb/util/OkHttpUtil.java
@@ -1,8 +1,11 @@
package com.yb.util;
import com.alibaba.fastjson.JSON;
import com.google.gson.Gson;
import com.yb.entity.ResponseEntity;
import okhttp3.*;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RestController;
@@ -78,12 +81,14 @@
        return  null ;
    }
    @Async
    public String requesFast(String message){
        OkHttpClient client = new OkHttpClient();
        System.out.println("fastgpt:"+message) ;
       OkHttpClient client = new OkHttpClient();
        Response response = null ;
        // 创建请求头(Headers)
        okhttp3.Headers headers = new okhttp3.Headers.Builder()
                .add("Authorization", "Bearer fastgpt-rML09d7nyx8Bn2Al3UipZia3Q8FNuXdekU1nyMlgCfHNwS8NN1giSPNZ1y6Wmt")
                .add("Authorization", "Bearer "+apikey)
                .build();
        /*
@@ -105,7 +110,7 @@
        // 构建请求体(RequestBody),这里使用的是字符串类型的请求数据
        HashMap<String,Object> hashMap = new HashMap<>() ;
        hashMap.put("chatId",""+Math.random()*100000);
        hashMap.put("chatId","1111");
        hashMap.put("stream","false");
        hashMap.put("detail","false");
        List<HashMap<String,String>> list = new ArrayList<>();
@@ -130,7 +135,15 @@
            if (response.isSuccessful()) {
                //System.out.println("Success: " + response.body().string());
                String rep = response.body().string();
                return rep ;
                if( rep.indexOf("flowResponses") > 0) {
                    int index = rep.indexOf("flowResponses");
                    int index_s = rep.indexOf("data", index);
                    String data = rep.substring(index_s + 5);
                    System.out.println("data is ok....");
                    return data;
                }else{
                    return rep ;
                }
            } else {
                System.out.println("Error: " + response.code() + " " + response.message());
            }
@@ -139,15 +152,15 @@
        }
         return response != null?response.body().toString():"null" ;
         return null ;
    }
    public String requesFast_kl(String parentId){
    public String requesFast_kl(){
        OkHttpClient client = new OkHttpClient();
        Response response = null ;
        // 创建请求头(Headers)
        okhttp3.Headers headers = new okhttp3.Headers.Builder()
                .add("Authorization", "Bearer fastgpt-rML09d7nyx8Bn2Al3UipZia3Q8FNuXdekU1nyMlgCfHNwS8NN1giSPNZ1y6Wmt")
                .add("Authorization", "Bearer "+apikey)
                .build();
        /*
@@ -159,7 +172,7 @@
        // 创建请求(Request)
        if( parentId != null ) fastgpt_kl = fastgpt_kl+"?parentId="+parentId;
        okhttp3.Request.Builder builder = new okhttp3.Request.Builder()
                .url(fastgpt_kl)
                .headers(headers) ;
@@ -171,7 +184,8 @@
            response = client.newCall(request).execute();
            if (response.isSuccessful()) {
                //System.out.println("Success: " + response.body().string());
                String rep = response.body().string();
                String rep = response.body().toString();
                return rep ;
            } else {
                System.out.println("Error: " + response.code() + " " + response.message());