如题,线上调用deepseek接口正常,但本地调用接口时报以下错误:Error:SSL certificate problem: unable to get local issuer certificate。
问了下豆包,得知是缺少本地证书的问题。然后用小P配置了ssl证书用https访问依旧不行,
报错不变:
解决办法:
调用curl函数时添加以下配置项:
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);//忽略SSL证书的合法性检查。
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
deepseek接口的具体调用方法如下:
$apiKey = 'sk-176******'; // 替换为你的API密钥
$url = 'https://api.deepseek.com/chat/completions'; // DeepSeek API端点 https://api.deepseek.com/v1/chat/completions
$data = [
'model' => 'deepseek-chat', // 或其他可用模型
'messages' => [
['role' => 'user', 'content' => '你好,请介绍一下你自己']
],
'temperature' => 0.7,
'max_tokens' => 1000
];
$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_SSL_VERIFYPEER, false);//关闭本地证书
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);//关闭本地证书
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Content-Type: application/json',
'Authorization: Bearer ' . $apiKey
]);
$response = curl_exec($ch);
//echo "res:".$response;
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
} else {
$decodedResponse = json_decode($response, true);
// echo 'ok';
// print_r($decodedResponse);
// 处理响应
if (isset($decodedResponse['choices'][0]['message']['content'])) {
echo $decodedResponse['choices'][0]['message']['content'];
} else {
print_r($decodedResponse); // 查看完整响应以调试
}
}
curl_close($ch);