"jiguang/jmessage": "~1.1"
composer下载
注意post数据要json_encode,不然数据格式报错,其余的接口看下文档就ok了
文档
http://docs.jiguang.cn/jmessage/server/rest_api_im/#_61
https://github.com/jpush/jmessage-api-php-client/blob/master/docs/GUIDE.md#%E8%AF%81%E4%B9%A6%E9%97%AE%E9%A2%98
"mager",
"password" => "mager",
"nickname" => "mager",
"avatar" => "mager",
],
];
$url = "https://api.im.jpush.cn/v1/users/";
$post_arr = json_encode($user_arr);
$return_arr = jg_curl($url, $post_arr);
return $return_arr;
}
/**
* 极光修改用户密码
*/
function jg_update_pwd($username = '', $new_pwd = '') {
$url = "https://api.im.jpush.cn/v1/users/" . $username . "/password";
$new_pwd_arr = [];
$new_pwd_arr = [
"new_password" => $new_pwd,
];
$post_arr = json_encode($new_pwd_arr);
$return_arr = put_jg_send($url, $post_arr);
return $return_arr;
}
/**
* 极光curl
* @param type $temp_url
* @param type $temp_post_arr
* @return type
*/
function jg_curl($temp_url, $temp_post_arr = []) {
$push_appkey = Config::get("site.push_appkey");
$push_secret = Config::get("site.push_secret");
$arr_header = [];
$arr_header[] = "Content-Type: application/json";
$arr_header[] = "Authorization: Basic " . base64_encode($push_appkey . ":" . $push_secret);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $temp_url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
if (!empty($arr_header)) {
curl_setopt($ch, CURLOPT_HTTPHEADER, $arr_header);
}
if ($temp_post_arr) {
curl_setopt($ch, CURLOPT_POST, 1);
// $temp_post_arr = http_build_query( $temp_post_arr );
curl_setopt($ch, CURLOPT_POSTFIELDS, $temp_post_arr);
}
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$push_ret = curl_exec($ch);
curl_close($ch);
// echo "";var_dump($push_ret);die;
$push_ret_arr = json_decode($push_ret, true);
return $push_ret_arr;
}
/**
* PUT请求
* @param type $url
* @param type $data
* @return type
*/
function put_jg_send($url, $data) {
$push_appkey = Config::get("site.push_appkey");
$push_secret = Config::get("site.push_secret");
$arr_header = [];
$arr_header[] = "Content-Type: application/json";
$arr_header[] = "Authorization: Basic " . base64_encode($push_appkey . ":" . $push_secret);
$ch = curl_init(); //初始化CURL句柄
curl_setopt($ch, CURLOPT_URL, $url); //设置请求的URL
if (!empty($arr_header)) {
curl_setopt($ch, CURLOPT_HTTPHEADER, $arr_header);
}
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //设为TRUE把curl_exec()结果转化为字串,而不是直接输出
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT"); //设置请求方式
curl_setopt($ch, CURLOPT_POSTFIELDS, $data); //设置提交的字符串
$output = curl_exec($ch);
// echo "";var_dump($output);die;
curl_close($ch);
return json_decode($output, true);
}
/*
* 极光创建聊天室
* 先引入极光组建
use JMessage\IM\ChatRoom;
use JMessage\JMessage;
*/
function jg_create_room_by_composer() {
$client = new JMessage($this->push_appkey, $this->push_secret);
$room = new ChatRoom($client);
$com_ret = $room->create("测试聊天室", "admin", $members = [], $description = null);
}
?>