gpt4 book ai didi

php - 如何将api结果添加到mysql

转载 作者:行者123 更新时间:2023-11-29 22:46:12 25 4
gpt4 key购买 nike

我正在开发一个项目,并试图找到一种将我的 api 结果添加到 mysql 的方法。

这里是the page你能找到结果吗?

以下是页面代码:

    <?php
///PLOT PROJECT USER REQUEST

//HELPER FUNCTION TO PRINT TO CONSOLE
function debug_to_console( $data ) {

if ( is_array( $data ) )
$output = "<script>console.log( 'Debug Objects: " . implode( ',', $data) . "' );</script>";
else
$output = "<script>console.log( 'Debug Objects: " . $data . "' );</script>";

echo $output;
}

//PLOT PROJECT REQUEST
$appId = '9fed0c75ca624e86a411b48ab27b3d5a';
$private_token = 'VGjPehPNBa5henSa';
$qry_str = "/api/v1/account/";

$ch = curl_init();
$headers = array(
'Content-Type:application/json',
'Authorization: Basic '. base64_encode($appId.":".$private_token) // <---
);

$geofenceId = '736cb24a1dae442e943f2edcf353ccc7';

curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_URL, 'https://admin.plotprojects.com/api/v1/notification/?geofenceId=' . $geofenceId);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, '3');
curl_setopt($ch, CURLOPT_ENCODING, 'gzip');

$content = trim(curl_exec($ch));
curl_close($ch);
print $content;

?>

最佳答案

您可以使用 json_decode() 解码 JSON 字符串并获取进行查询所需的值。阅读更多内容:

  • http://php.net/manual/en/function.json-decode.php

    <?php

    //The response from http://www.jobsinsac.com/api/api_notification.php

    $json = '{ "success": true, "result": { "data": [{ "placeId": "736cb24a1dae442e943f2edcf353ccc7", "cooldownDays": 0, "triggerTimes": "inherit", "state": "published", "cooldownSeconds": 1, "data": "http://www.illuminatimc.com", "enabled": true, "geofenceId": "736cb24a1dae442e943f2edcf353ccc7", "id": "0cad6b54d225459e85cd8c27567f8b0b", "message": "Get a cold beer, for $2.00, shots for $4.00, come inside, up stairs.", "created": "2015-03-17T18:54:41Z", "timespans": [], "handlerType": "landingPage", "trigger": "enter" }], "total": 1 } }';

    $data = json_decode($json, true);

    print_r($data);

    ?>

    输出:

    Array
    (
    [success] => 1
    [result] => Array
    (
    [data] => Array
    (
    [0] => Array
    (
    [placeId] => 736cb24a1dae442e943f2edcf353ccc7
    [cooldownDays] => 0
    [triggerTimes] => inherit
    [state] => published
    [cooldownSeconds] => 1
    [data] => http://www.illuminatimc.com
    [enabled] => 1
    [geofenceId] => 736cb24a1dae442e943f2edcf353ccc7
    [id] => 0cad6b54d225459e85cd8c27567f8b0b
    [message] => Get a cold beer, for $2.00, shots for $4.00, come inside, up stairs.
    [created] => 2015-03-17T18:54:41Z
    [timespans] => Array
    (
    )

    [handlerType] => landingPage
    [trigger] => enter
    )

    )

    [total] => 1
    )

    )

关于php - 如何将api结果添加到mysql,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29113437/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com