获取长效令牌 (API 云合同)

网友投稿 625 2022-11-14

获取长效令牌 (API 云合同)

获取长效令牌 (API 云合同)

从服务品返回的token值 不在response中,是返回在响应头里的(respond.header)

第一步:获得服务器返回的数据

//获取长效令牌 $appId="201804dfsfs200018";//应用APPID $appKey="qvedqG0fsfsqDei"; $curl = curl_init(); curl_setopt_array($curl, array( CURLOPT_URL => " CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => "", CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 30, CURLOPT_SSL_VERIFYPEER => false, CURLOPT_SSL_VERIFYHOST => false, //CURLOPT_HEADER => true, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => "POST", CURLOPT_POSTFIELDS => "{\n\"appId\":\"$appId\",\n\"appKey\":\"$appKey\"\n}", CURLOPT_HTTPHEADER => array( "cache-control: no-cache", "content-type: APPlication/json", "postman-token: 5f1ca675-edb1-d414-b5da-cd967bd882ee" ), )); $response = curl_exec($curl); $err = curl_error($curl); curl_close($curl); if ($err) { echo "cURL Error #:" . $err; } else { echo $response; // $arr = json_decode($response, true);// $code = $arr['code'];//code=200 说明成功// $msg = $arr['msg'];// //$token = $arr['token'];// echo $msg; }

返回这个值说明成功获取token值

第一步:获得token值

是返回在响应头里的(respond.header),所以要输出header信息,然后取得token值

完整代码

//获取长效令牌 $appId="20180454400018";//应用APPID $appKey="qverttrjqG0qDei"; $curl = curl_init(); curl_setopt_array($curl, array( CURLOPT_URL => " CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => "", CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 30, CURLOPT_SSL_VERIFYPEER => false, CURLOPT_SSL_VERIFYHOST => false, CURLOPT_HEADER => true, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => "POST", CURLOPT_POSTFIELDS => "{\n\"appId\":\"$appId\",\n\"appKey\":\"$appKey\"\n}", CURLOPT_HTTPHEADER => array( "cache-control: no-cache", "content-type: application/json", "postman-token: 5f1ca675-edb1-d414-b5da-cd967bd882ee" ), )); $response = curl_exec($curl); $err = curl_error($curl); curl_close($curl); if ($err) { echo "cURL Error #:" . $err; } else { //echo $response; $headArr = explode("\r\n", $response); foreach ($headArr as $loop) { if(strpos($loop, "token") !== false){ $token = trim(substr($loop, 10)); } } }print_r($token); 增加

要增加这段代码:

输出中包含header

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:jQuery插件封装(单个插件含多个分支函数)
下一篇:人脸识别:在警察领域高级人脸识别技术的一致性
相关文章

 发表评论

暂时没有评论,来抢沙发吧~