线上正常,本地调用deepseek接口报错:Error:SSL certificate problem: unable to get local issuer certificate

如题,线上调用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);

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值