Huanxin user imports PHP

Source: Internet
Author: User
Huanxin user imports PHP
$ Hxurl =" https://a1.easemob.com/51xxx/aaaa/ ";/*** Batch delete users ** description: Delete a specified number of email accounts under an app. The above url can delete 300 users at a time. The value can be modified. we recommend that the value be between and, not too large ** @ param $ limit = "300" The default value is 300 * @ param $ ql deletion conditions * such as ql = order + by + created + desc sort by creation time (descending) */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 ;} /*** change user nickname * @ param [string] $ username [user name] * @ param [string] $ nickname [user 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 ;} /*** authorization registration mode | batch registration ** @ param $ options ['username'] username * @ param $ options ['password'] password * batch registration to upload a two-dimensional array */function accreditRegister ($ options) {global $ hxurl; $ formgettoken = $ hxurl. "users"; $ header = array (_ get_token (); $ result = _ curl_request ($ formgettoken, json_encode ($ options), $ header); return $ result ;} // authorization registration mode 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 ;} // reset the user password 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 ;}

// Obtain the app administrator token POST/{org_name}/{app_name}/tokenfunction _ get_token () {global $ hxurl; $ formgettoken = $ hxurl. "token"; $ body = array ("grant_type" => "client_credentials", "client_id" => "xxxxxxxxxxxxxxxxx", "client_secret" => "xxxxxxxxxxxxxxxxxxxxxxxx "); $ 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/100'); 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); // Set the returned status code curl_close ($ ch); // clear_object ($ ch ); // clear_object ($ body); // clear_object ($ header); if ($ err) {return $ err;} return $ ret ;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.