極光推送事例

2023-03-16 23:01:20 字數 3026 閱讀 4119

/**** 極光推送**/

defined

('in_phpcms')or

exit

('no permission resources.');

class

jpush

public

function

push

($receiver=''

,$content=''

,$m_type=''

,$message=''

,$title=''

,$m_time

='86400'

,$platform=''

)else

$data

['audience']=

$receiver

;//目標使用者

$data

['notification']=

array

(//統一的模式--標準模式

"alert"

=>

$content

,//安卓自定義

"android"

=>

array

("alert"

=>

$content

,"title"

=>

$title

,"builder_id"

=>1,

"extras"

=>

array

("type"

=>

$m_type

,"message"

=>

$message))

,//ios的自定義

"ios"

=>

array

("alert"

=>

$content

,"title"

=>

$title

,"badge"

=>

"1",

"sound"

=>

"default"

,"extras"

=>

array

("type"

=>

$m_type

,"message"

=>

$message

)// "extras"=>array("type"=>$m_type, "txt"=>$m_txt)),

);//蘋果自定義---為了彈出值方便調測

$data

['message']=

array

("msg_content"

=>

$content

,"extras"

=>

array

("type"

=>

$m_type

,"message"

=>

$message

)//"extras"=>array("type"=>$m_type, "txt"=>$m_txt));

//附加選項

$data

['options']=

array

("sendno"

=>

time()

,//"time_to_live"=>$m_time, //儲存離線時間的秒數預設為一天

"apns_production"

=>0,

//指定 apns 通知傳送環境:0開發環境,1生產環境。);

$param

=json_encode

($data);

$res

=$this

->

push_curl

($param

,$header);

if($res

)else

}//推送的curl方法

public

function

push_curl

($param=""

,$header=""

)$posturl

=$this

->

url;

$curlpost

=$param

;$ch

=curl_init()

;//初始化curl

curl_setopt

($ch

,curlopt_url

,$posturl);

//抓取指定網頁

curl_setopt

($ch

,curlopt_header,0

);//設定header

curl_setopt

($ch

,curlopt_returntransfer,1

);//要求結果為字串且輸出到螢幕上

curl_setopt

($ch

,curlopt_post,1

);//post提交方式

curl_setopt

($ch

,curlopt_postfields

,$curlpost);

curl_setopt

($ch

,curlopt_httpheader

,$header);

// 增加 http header(頭)裡的欄位

curl_setopt

($ch

,curlopt_ssl_verifypeer

,false);

// 終止從服務端進行驗證

curl_setopt

($ch

,curlopt_ssl_verifyhost

,false);

$data

=curl_exec

($ch);

//執行curl

curl_close

($ch);

return

$data

;}