error_reporting
(E_ALL^E_NOTICE);
class
ApipostAction{
private
$_appkeys
=
'f722b1337ded85********'
;
private
$_masterSecret
=
'bd267a37c30**********'
;
function
request_post(
$url
=
""
,
$param
=
""
) {
if
(
empty
(
$url
) ||
empty
(
$param
)) {
return
false;
}
$postUrl
=
$url
;
$curlPost
=
$param
;
$ch
= curl_init();
curl_setopt(
$ch
, CURLOPT_URL,
$postUrl
);
curl_setopt(
$ch
, CURLOPT_HEADER, 0);
curl_setopt(
$ch
, CURLOPT_RETURNTRANSFER, 1);
curl_setopt(
$ch
, CURLOPT_POST, 1);
curl_setopt(
$ch
, CURLOPT_POSTFIELDS,
$curlPost
);
$data
= curl_exec(
$ch
);
curl_close(
$ch
);
return
$data
;
}
function
send(
$sendno
= 15,
$receiver_type
= 1,
$receiver_value
=
""
,
$msg_type
= 1,
$msg_content
=
""
,
$platform
=
'android'
)
{
$url
=
'http://api.jpush.cn:8800/sendmsg/v2/sendmsg'
;
$param
=
''
;
$param
.=
'&sendno='
.
$sendno
;
$appkeys
=
$this
->_appkeys;
$param
.=
'&app_key='
.
$appkeys
;
$param
.=
'&receiver_type='
.
$receiver_type
;
$param
.=
'&receiver_value='
.
$receiver_value
;
$masterSecret
=
$this
->_masterSecret;
$verification_code
= md5(
$sendno
.
$receiver_type
.
$receiver_value
.
$masterSecret
);
$param
.=
'&verification_code='
.
$verification_code
;
$param
.=
'&msg_type='
.
$msg_type
;
$param
.=
'&msg_content='
.
$msg_content
;
$param
.=
'&platform='
.
$platform
;
$res
=
$this
->request_post(
$url
,
$param
);
$res_arr
= json_decode(
$res
, true);
print_r(
$res_arr
);
}
}
$platform
=
'android,ios'
;
$msg_content
= json_encode(
array
(
'n_builder_id'
=>1,
'n_title'
=>
'标题'
,
'n_content'
=>
'内容'
,
'n_extras'
=>
array
(
'fromer'
=>
'发送者'
,
'fromer_name'
=>
'发送者名字'
,
'fromer_icon'
=>
'发送者头像'
,
'image'
=>
'发送图片链接'
,
'sound'
=>
'发送音乐链接'
)));
$jpush
=
new
ApipostAction();
$jpush
->send(16,4,
""
,1,
$msg_content
,
$platform
);