项目效果预览

1. 准备工作
- PHP环境:确保你的开发环境中安装了PHP。
- DeepSeek API密钥:注册并获取DeepSeek API的访问密钥。
2. 创建PHP文件,编写API调用脚本
创建一个PHP脚本(api.php),用于调用DeepSeek API。假设API密钥为YOUR_API_KEY。
<?php
header('Content-Type: application/json');
function callDeepSeekAPI($message) {
$apiKey = 'YOUR_API_KEY';
$url = 'https://api.deepseek.com/chat/completions';
$data = [
"model" => "deepseek-chat",
'messages' => [
["role" => "system", "content" => "You are a helpful assistant."],
["role" => "user", "content" => $message]
],
'stream'=>false
];
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Content-Type: application/json',
'Authorization: Bearer ' . $apiKey
]);
$response = curl_exec($ch);
if (curl_errno($ch)) {
$error_msg = curl_error($ch);
curl_close(

最低0.47元/天 解锁文章
1284

被折叠的 条评论
为什么被折叠?



