1.注册deepseek并新建密钥

调用接口,需要消耗token,所以充值。为了测试充1块好了

2.curl调用

<?php

$question = "2025年上半年lpr会降吗";
$datas=  ['model'=>'deepseek-chat',
		  'messages'=>[
			['role'=>'user','content'=>$question]
		  ],
		  'stream'=>false
		 ];
send('https://api.deepseek.com/chat/completions',$datas);

function send(string $url,$postdata){
	$curl = curl_init();
 
	curl_setopt($curl, CURLOPT_URL, $url);
	curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); // 返回结果而不是直接输出
	 
	$headers = [
		"Content-Type: application/json", // 设置内容类型为JSON
		"Authorization: Bearer sk-69eae**********d9d" // 设置认证头信息,例如Bearer Token
	];
	curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); // 设置头信息
	curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); 
	curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($postdata));
	
	 
	$response = curl_exec($curl); // 执行请求并获取响应
	if ($response === false) {
		echo 'Curl error: ' . curl_error($curl); // 检查是否有错误发生
	}else{
		echo 'data:'.$response;
	}
	 
	curl_close($curl); // 关闭cURL会话
}



这里打星号的是你自己的api key

Logo

有“AI”的1024 = 2048,欢迎大家加入2048 AI社区

更多推荐