環信使用者匯入PHP

來源:互聯網
上載者:User
$hxurl = "https://a1.easemob.com/51xxx/aaaa/";/**     * 大量刪除使用者     * 描述:刪除某個app下指定數量的環信帳號。上述url可一次刪除300個使用者,數值可以修改 建議這個數值在100-500之間,不要過大     *     * @param $limit="300" 預設為300條               * @param $ql 刪除條件     *          如ql=order+by+created+desc 按照建立時間來排序(降序)     */    function batchDeleteUser($limit = "300", $ql = '') {        global $hxurl;        $url = $hxurl."users?limit=" . $limit;        if (! empty ( $ql )) {            $url = $hxurl."users?ql=" . $ql . "&limit=" . $limit;        }        $header = array(_get_token());        $result = _curl_request( $url, '', $header, $type = 'DELETE' );        return $result;    }    /**     * 更改使用者暱稱     * @param  [string] $username [使用者名稱稱]     * @param  [string] $nickname [使用者暱稱]     *     */    function editNick($username,$nickname) {        global $hxurl;        $formgettoken = $hxurl."users/" . $username;        $body=array(            "username"=>$username,            "nickname"=>$nickname,        );        $patoken=json_encode($body);        $header = array(_get_token());        $result = _curl_request( $formgettoken, $patoken, $header, $type = 'PUT');        return $result;    }    /**     * 授權註冊模式 || 大量註冊     *     * @param $options['username'] 使用者名稱               * @param $options['password'] 密碼     *          大量註冊傳二維數組     */    function accreditRegister($options) {        global $hxurl;        $formgettoken = $hxurl."users";        $header = array(_get_token());        $result = _curl_request ( $formgettoken, json_encode($options), $header );        return $result;    }//授權註冊模式 POST /{org_name}/{app_name}/usersfunction registerToken($username,$pwd,$nickname=''){    global $hxurl;    $formgettoken=$hxurl."users";    $body=array(        "username"=>$username,        "password"=>$pwd,        'nickname'=>$nickname    );    $patoken=json_encode($body);    $header = array(_get_token());    $res = _curl_request($formgettoken,$patoken,$header);    $arrayResult =  json_decode($res, true);        return $arrayResult ;}//重設使用者密碼 PUT /{org_name}/{app_name}/users/{username}/passwordfunction changePwdToken($nikename,$newpwd){    global $hxurl;    $formgettoken=$hxurl."users/".$nikename."/password";    $body=array(        "newpassword"=>$newpwd,    );    $patoken=json_encode($body);    $header = array(_get_token());    $method = "PUT";    $res = _curl_request($formgettoken,$patoken,$header,$method);    $arrayResult =  json_decode($res, true);        return $arrayResult ;}//刪除 DELETE /{org_name}/{app_name}/users/{username}function delUserToken($nikename){    global $hxurl;    $formgettoken=$hxurl."users/".$nikename;    $body=array();    $patoken=json_encode($body);    $header = array(_get_token());    $method = "DELETE";    $res = _curl_request($formgettoken,$patoken,$header,$method);    $arrayResult =  json_decode($res, true);        return $arrayResult ;}

//先擷取app管理員token POST /{org_name}/{app_name}/tokenfunction _get_token(){    global $hxurl;    $formgettoken=$hxurl."token";    $body=array(    "grant_type"=>"client_credentials",    "client_id"=>"xxxxxxxxxxxxxxxxxxxxx",    "client_secret"=>"xxxxxxxxxxxxxxxxxxxxxx"    );    $patoken=json_encode($body);    $res = _curl_request($formgettoken,$patoken);    $tokenResult = array();        $tokenResult =  json_decode($res, true);    //var_dump($tokenResult);    return "Authorization: Bearer ". $tokenResult["access_token"];  }function _curl_request($url, $body, $header = array(), $method = "POST"){    array_push($header, 'Accept:application/json');    array_push($header, 'Content-Type:application/json');    $ch = curl_init();    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 60);    curl_setopt($ch, CURLOPT_URL, $url);    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);    //curl_setopt($ch, $method, 1);        switch ($method){         case "GET" :             curl_setopt($ch, CURLOPT_HTTPGET, true);        break;         case "POST":             curl_setopt($ch, CURLOPT_POST,true);         break;         case "PUT" :             curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");         break;         case "DELETE":            curl_setopt ($ch, CURLOPT_CUSTOMREQUEST, "DELETE");         break;     }        curl_setopt($ch, CURLOPT_USERAGENT, 'SSTS Browser/1.0');    curl_setopt($ch, CURLOPT_ENCODING, 'gzip');    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 1);    if (isset($body{3}) > 0) {        curl_setopt($ch, CURLOPT_POSTFIELDS, $body);    }    if (count($header) > 0) {        curl_setopt($ch, CURLOPT_HTTPHEADER, $header);    }    $ret = curl_exec($ch);    $err = curl_error($ch);    $err = curl_getinfo($ch,CURLINFO_HTTP_CODE); //設定返回狀態代碼    curl_close($ch);    //clear_object($ch);    //clear_object($body);    //clear_object($header);    if ($err) {        return $err;    }    return $ret;}
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.