Skip to content

Commit 6354def

Browse files
committed
add receive API
1 parent f1fea6c commit 6354def

File tree

3 files changed

+38
-5
lines changed

3 files changed

+38
-5
lines changed

lib/jpush_api_php_client.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,9 @@ public function sendCustomMesByAppkey($app_key, $sendno, $send_description,
186186
*/
187187
public function getReceivedApi($app_key, $msg_ids)
188188
{
189-
$
190-
189+
$baseClent = new BaseClent();
190+
$auth = $baseClent->getBase64_code($app_key, $this->masterSecret);
191+
return $baseClent->getReceiedData($auth, $msg_ids, $app_key);
191192
}
192193

193194
/**

lib/jpush_api_php_client/baseClient.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
*/
99
class BaseClent
1010
{
11-
private $API_URL = "http://api.jpush.cn:8800/v2/push";
11+
private $SEND_API_URL = "http://api.jpush.cn:8800/v2/push";
12+
private $RECEIVE_API_URL = "http://api.jpush.cn:8800/v2/push";
1213

1314
/**
1415
* 构造函数
@@ -39,7 +40,7 @@ public function send($sendno, $app_key, $receiver_type, $receiver_value, $verifi
3940
$params = $this->getParams($sendno, $app_key, $receiver_type, $receiver_value, $verification_code,
4041
$msg_type, $msg_content, $send_description, $platform, $time_to_live, $override_msg_id);
4142
$httpPostClient = new HttpPostClient();
42-
return $httpPostClient->request_post($this->API_URL, $params);
43+
return $httpPostClient->request_post($this->SEND_API_URL, $params);
4344
}
4445

4546
/**
@@ -69,6 +70,12 @@ private function getParams($sendno, $app_key, $receiver_type, $receiver_value, $
6970
return $params;
7071
}
7172

73+
protected function getReceiedData($auth, $msg_ids, $app_key)
74+
{
75+
$url = $this->RECEIVE_API_URL."?app_key=".$app_key."&&msg_ids=".$msg_ids;
76+
$httpPostClient = new HttpPostClient();
77+
return $httpPostClient->request_get($this->RECEIVE_API_URL, $auth);
78+
}
7279

7380
/**
7481
* 消息发送体
@@ -113,7 +120,8 @@ public function getVerification_code($sendno, $receiver_type, $receiver_value)
113120

114121
protected function getBase64_code($app_key, $masterSecret)
115122
{
116-
123+
$data = $app_key.":".$masterSecret;
124+
return rtrim(strtr(base64_encode($data), '+/', '-_'), '=');
117125
}
118126
}
119127
?>

lib/jpush_api_php_client/httpPostClient.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,30 @@ function request_post($remote_server, $post_string)
2626
$data = file_get_contents($remote_server, false, $stream_context);
2727
return $data;
2828
}
29+
30+
/**
31+
* get提交
32+
* 使用方法:
33+
* $post_string = "app=request&version=beta";
34+
* request_by_other('http://facebook.cn/restServer.php',$post_string);
35+
*/
36+
function request_get($remote_server, $auth)
37+
{
38+
$context = array(
39+
'http' => array(
40+
'method' => 'GET',
41+
'header' => 'Connection:Keep-Alive'.
42+
'\r\n'.'Charset: UTF-8' .
43+
'\r\n'.'Authorization: Basic '.$auth.
44+
'\r\n'.'Content-type: application/x-www-form-urlencoded'.
45+
'\r\n')
46+
);
47+
//echo $post_string;
48+
$stream_context = stream_context_create($context);
49+
//echo $stream_context;
50+
$data = file_get_contents($remote_server, false, $stream_context);
51+
return $data;
52+
}
2953

3054

3155
}

0 commit comments

Comments
 (0)