// 个推鉴权 public function doAuth($cid){ $curl = curl_init(); $headers = array("Content-type: application/json;charset=UTF-8","Accept: application/json","Cache-Control: no-cache", "Pragma: no-cache"); curl_setopt($curl, CURLOPT_URL, PUSH_URL.APPID.'/auth'); curl_setopt($curl,CURLOPT_RETURNTRANSFER,1); //将接口返回内容放到变量中而不是直接输出 curl_setopt($curl, CURLOPT_POST, 1); // post传参 $timestamp = $this->msectime(); // 毫秒 $str = APPKEY.$timestamp.MASTERSECRET; $fields = [ 'sign' => hash("sha256", $str), 'timestamp' => $timestamp, 'appkey' => APPKEY ]; curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($fields)); curl_setopt($curl, CURLOPT_HTTPHEADER, $headers ); //设置请求头 // curl_setopt($curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); $res = curl_exec($curl); curl_close($curl); $res = json_decode($res); //对返回的错误信息进行自定义 if($res->code == 0){ $user = new UserModel; $user->token = $res->data->token; $user->save(); // 鉴权成功,进行推送 $this -> doPush($cid, $res->data->token); }else{ $this->return_msg(400,'鉴权失败!'.$res->msg); } }执行之后输出的结果:
在Post中添加了curl_error($curl)发现错误“SSL certificate problem: unable to get local issuer certificate”:
SSL验证出了问题,跳过SSL证书验证就好了,在Post中添加:
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);