php调用国内coze api问答流式示例代码

代码语言:phpcli

所属分类:其他

代码描述:php调用国内coze api问答流式示例代码

代码标签: php 调用 国内 coze api 问答 示例 代码 流式

下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开

<?php

//api申请 https://www.coze.cn/open/api
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.coze.cn/open_api/v2/chat");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);


$_postobj = array(
    "query" => "我第一句问啥了",
    "bot_id" => "73392968860561419",
    "conversation_id" => "29032201862555",
  // "chat_history": {chat_history},
    "user" => "1231",
    "stream" => true
);


curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($_postobj, JSON_UNESCAPED_UNICODE));
$certificate = "/data/wwwroot/default/asset/cacert.pem";
curl_setopt($ch, CURLOPT_CAINFO, $certificate);
curl_setopt($ch, CURLOPT_CAPATH, $certificate);
// curl_setopt($ch, CURLOPT_SSLVERSION, 3);
//curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_POST, 1);

// Set the API key as an HTTP header
$headers = array();
$headers[] = "Content-Type: application/json";
$headers[] = "Authorization: Bearer APIKEY";

curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

curl_setopt($ch, CURLOPT_WRITEFUNCTION, function($curl, $data) {
    // 处理获得的数据
    //  echo $data;

   .........完整代码请登录后点击上方下载按钮下载查看

网友评论0