{"id":212,"date":"2023-03-29T17:03:51","date_gmt":"2023-03-29T09:03:51","guid":{"rendered":"https:\/\/www.aqrboyblog.top\/?p=212"},"modified":"2023-04-03T09:20:16","modified_gmt":"2023-04-03T01:20:16","slug":"chatgpt-phphtml","status":"publish","type":"post","link":"https:\/\/www.aqrboyblog.top\/?p=212","title":{"rendered":"ChatGPT PHP"},"content":{"rendered":"\n<p>1.\u804a\u5929\u6a21\u578b <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$curl = curl_init();\ncurl_setopt_array($curl, array(\n    CURLOPT_URL => \"https:\/\/api.openai.com\/v1\/chat\/completions\",\n    CURLOPT_RETURNTRANSFER => true,\n    CURLOPT_ENCODING => \"\",\n    CURLOPT_MAXREDIRS => 10,\n    CURLOPT_TIMEOUT => 0,\n    CURLOPT_FOLLOWLOCATION => true,\n    CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,\n    CURLOPT_CUSTOMREQUEST => \"POST\",\n    CURLOPT_POSTFIELDS => json_encode(array(\n        \"model\" => \"gpt-3.5-turbo\",\n        'max_tokens' => 2000,\n        \"messages\" => &#91;array(\"role\" => \"user\", \"content\" => $prompt)],\n    )),\n    CURLOPT_HTTPHEADER => array(\n        \"Content-Type: application\/json\",\n        \"Authorization: Bearer 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\",\n    ),\n));\n$response = curl_exec($curl);\ncurl_close($curl);<\/code><\/pre>\n\n\n\n<p>2.\u56fe\u7247\u751f\u6210<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$curl = curl_init();\ncurl_setopt_array($curl, array(\n    CURLOPT_URL => \"https:\/\/api.openai.com\/v1\/images\/generations\",\n    CURLOPT_RETURNTRANSFER => true,\n    CURLOPT_ENCODING => \"\",\n    CURLOPT_MAXREDIRS => 10,\n    CURLOPT_TIMEOUT => 0,\n    CURLOPT_FOLLOWLOCATION => true,\n    CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,\n    CURLOPT_CUSTOMREQUEST => \"POST\",\n    CURLOPT_POSTFIELDS => json_encode(array(\n        \"prompt\" => $prompt,\n        \"n\" => 1,\n        \"size\" => \"1024x1024\",\n        'response_format' => \"b64_json\",\n    )),\n    CURLOPT_HTTPHEADER => array(\n        \"Content-Type: application\/json\",\n        \"Authorization: Bearer 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\",\n    ),\n));\n$response = curl_exec($curl);\ncurl_close($curl);<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p class=\"text-justify\">1.\u804a\u5929\u6a21\u578b 2.\u56fe\u7247\u751f\u6210<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-212","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/www.aqrboyblog.top\/index.php?rest_route=\/wp\/v2\/posts\/212","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.aqrboyblog.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.aqrboyblog.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.aqrboyblog.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.aqrboyblog.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=212"}],"version-history":[{"count":2,"href":"https:\/\/www.aqrboyblog.top\/index.php?rest_route=\/wp\/v2\/posts\/212\/revisions"}],"predecessor-version":[{"id":214,"href":"https:\/\/www.aqrboyblog.top\/index.php?rest_route=\/wp\/v2\/posts\/212\/revisions\/214"}],"wp:attachment":[{"href":"https:\/\/www.aqrboyblog.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=212"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.aqrboyblog.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=212"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.aqrboyblog.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=212"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}