//重置密码调用
public function putim_curl($mobile, $param = "", $header = "") {
    if (empty($param)) { return false; }
    $str = "/v1/users/".$mobile."/password";
    $putUrl = "https://api.im.jpush.cn".$str;

    $ch = curl_init();  //初始化curl
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");

    curl_setopt($ch, CURLOPT_URL,$putUrl);                 //目标网页

//    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);            //要求结果为字符串且输出到屏幕上
    
    curl_setopt($ch, CURLOPT_HTTPHEADER,$header);           // 增加 HTTP Header(头)里的字段
    
    curl_setopt($ch, CURLOPT_POSTFIELDS, $param);

    $data = curl_exec($ch);                                 //运行curl

    curl_close($ch);
    return $data;
}

//重置密码
public function putResetPassword(){
    $mobile = $_REQUEST['mobile'];
    $newpass = $_REQUEST['new_pass'];
    if(empty($mobile) || empty($newpass)){
        return FALSE;
    }  else {
        $str = $this->app_key.":".$this->master_secret;
        $base64=base64_encode($str);
   
        $header[] = 'Content-Type:application/json';
        $header[] = 'Authorization: Basic '.$base64;
        
        
        $data = array(
            "new_password"=>$newpass
        );
        
        $data = json_encode($data);
        
        $res = $this->putim_curl($mobile,$data,$header);
    print_r($res);
        if($res[0]){       //得到返回值--成功已否后面判断
            var_dump($res);
        }else{          //未得到返回值--返回失败
            //return false;
            echo 0;
        }
    } 
}

出处!http://my.csdn.net/shenqiongniujiahui

最后由 巴巴爸爸 编辑于2017年09月21日 17:32