搜索

首页  >  问答  >  正文

javascript - 最近在做乐橙的监控设备,第一步通过http post json获取accessToken都失败了,请问如何解决?

网址:乐橙应用开发指南


现在我第一步的获取accessToken都获取不到,我的代码如下:

function http_post_json($url, $jsonStr){
    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonStr);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array(
            'Content-Type: application/json; charset=utf-8',
            'Content-Length: ' . strlen($jsonStr)
        )
    );

    $response = curl_exec($ch);
    $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    curl_close($ch);
 
    return array($httpCode, $response);
}
 
$url = "https://openapi.lechange.cn:443/openapi/accessToken";
$jsonStr = json_encode(array('phone' => '18600000000'));
echo $jsonStr;
list($returnCode, $returnContent) = http_post_json($url, $jsonStr);

运行结果:

为情所困为情所困2749 天前492

全部回复(2)我来回复

  • phpcn_u1582

    phpcn_u15822017-05-16 13:18:43

    我认为你postfield应该是这个

    $data = array(
        "params" => array(
            "phone" => "1xxxxxxxxxx"    
        ),    
    );

    回复
    0
  • 習慣沉默

    習慣沉默2017-05-16 13:18:43

    你这个上传的数据,按照手册上的来,
    $data = array(

    "params" => array(
        "phone" => "1xxxxxxxxxx"    
    ),    

    );
    也可以问一下客服,多试试

    回复
    0
  • 取消回复