leutu
2024-06-24 3f1ea1e3240f045412189619d7e4021d5f26a4f2
src/main/java/com/yb/util/OkHttpUtil.java
@@ -1,6 +1,8 @@
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.stereotype.Component;
@@ -79,11 +81,12 @@
    }
    public String requesFast(String message){
        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 +108,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 +133,15 @@
            if (response.isSuccessful()) {
                //System.out.println("Success: " + response.body().string());
                String rep = response.body().string();
                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);
                    return data;
                }else{
                return rep ;
                }
            } else {
                System.out.println("Error: " + response.code() + " " + response.message());
            }
@@ -139,15 +150,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 +170,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 +182,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());