// 接口密码$code =,只能填一个
分类:热门新闻

$loginname = ; // 接口帐号$pass = ; // 接口密码$code = ;$subid = ;$sender = ;$receivers = ; // 接收号码,多个号码间用 ; 分隔$settimer = ; // 定时发送时间 格式:YYYY-MM-DD HH:MM$message = urlencode();$cmd = send;$allowforward = ;$recordid_client = ; // 短信的客户端记录号$http = _sms_url.ajax;$file = $$loginname.pass=.$pass.code=.$code.subid=.$subid.sender=.$sender.receivers=.$receivers.settimer=.$settimer.message=.$message.cmd=.$cmd.allowforward=.$allowforward.recordid_client=.$recordid_client;$xml = new XMLReader();$xml-open($file);$xml-setParserProperty(2,true);while ($xml-read()) {switch ($xml-name) {case Success: $xml-read();$Success = $xml-value;$xml-read();break;case Fail: $xml-read();$Fail = $xml-value;$xml-read();break;case RetCode: $xml-read();$RetCode = $xml-value;$xml-read();break;case SmsRemain: $xml-read();$SmsRemain = $xml-value;$xml-read();break;case ErrPhones: $xml-read();$ErrPhones = $xml-value;$xml-read();break;}}$xml-close();// $Success 发送成功条数// $Fail 发送失败条数// $RetCode 发送状态值// $SmsRemain 接口帐号余额// $ErrPhones 发送失败号码

HTML

<div id="wrap"><a href="<{:U('Push/pushData')}>">推送</a></div>

 

Jpush类

<?php
class Jpush_send{
private $app_key = '618208e20d4ae27510680d5b'; //待发送的应用程序(appKey),只能填一个。
private $master_secret = 'a7388142bec3b6696996167b'; //主密码
private $url = ""; //推送的地址
public function __construct($app_key=null, $master_secret=null,$url=null) {
if ($app_key) $this->app_key = $app_key;
if ($master_secret) $this->master_secret = $master_secret;
if ($url) $this->url = $url;
}
public function send_pub($receive,$content,$m_type,$m_txt,$m_time){

$m_time = '86400';//离线保留时间

$message="";//存储推送状态
$result = $this->push($receive,$content,$m_type,$m_txt,$m_time);
if($result){
$res_arr = json_decode($result, true);
if(isset($res_arr['error'])){ //如果返回了error则证明失败
echo $res_arr['error']['message']; //错误信息
$error_code=$res_arr['error']['code']; //错误码
switch ($error_code) {
case 200:
$message= '发送成功!';
威尼斯登录首页,break;
case 1000:
$message= '失败(系统内部错误)';
break;
case 1001:
$message = '失败(只支持 HTTP Post 方法,不支持 Get 方法)';
break;
case 1002:
$message= '失败(缺少了必须的参数)';
break;
case 1003:
$message= '失败(参数值不合法)';
break;
case 1004:
$message= '失败(验证失败)';
break;
case 1005:
$message= '失败(消息体太大)';
break;
case 1008:
$message= '失败(appkey参数非法)';
break;
case 1020:
$message= '失败(只支持 HTTPS 请求)';
break;
case 1030:
$message= '失败(内部服务超时)';
break;
default:
$message= '失败(返回其他状态,目前不清楚额,请联系开发人员!)';
break;
}
}else{
$message="发送成功!";
}
}else{
$message='接口调用失败或无响应';
}
echo "<script>alert('推送信息:{$message}')</script>";
}

public function push($receiver='all',$content='',$m_type='',$m_txt='',$m_time='86400'){
$base64=base64_encode("$this->app_key:$this->master_secret");
$header=array("Authorization:Basic $base64","Content-Type:application/json");
$data = array();
$data['platform'] = 'all'; //目标用户终端手机的平台类型android,ios,winphone
$data['audience'] = $receiver; //目标用户

$data['notification'] = array(
//统一的模式--标准模式
"alert"=>$content,
//安卓自定义
"android"=>array(
"alert"=>$content,
"title"=>"",
"builder_id"=>1,
"extras"=>array("type"=>$m_type, "txt"=>$m_txt)
),
//ios的自定义
"ios"=>array(
"alert"=>$content,
"badge"=>"1",
"sound"=>"default",
"extras"=>array("type"=>$m_type, "txt"=>$m_txt)
)
);

//苹果自定义---为了弹出值方便调测
$data['message'] = array(
"msg_content"=>$content,
"extras"=>array("type"=>$m_type, "txt"=>$m_txt)
);

//附加选项
$data['options'] = array(
"sendno"=>time(),
"time_to_live"=>$m_time, //保存离线时间的秒数默认为一天
"apns_production"=>false, //布尔类型 指定 APNS 通知发送环境:0开发环境,1生产环境。或者传递false和true
);
$param = json_encode($data);
$res = $this->push_curl($param,$header);

if($res){ //得到返回值--成功已否后面判断
return $res;
}else{ //未得到返回值--返回失败
return false;
}
}

//推送的Curl方法
public function push_curl($param="",$header="") {
if (empty($param)) { return false; }
$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;
}
}
?>

 

PushController.class.php

<?php

namespace Plutocontroller;

use CommonControllerBaseController;

class PushController extends BaseController {

public function pushDataAction() {
import("Pluto.controller.Jpush_send"); //引入Jpush_send类文件
$fetion = new Jpush_send();
$receive = 'all';//全部
//$receive = array('alias'=>array('2'),'alias'=>array('1'));//别名
$content = '我要推送';
$m_type = 'tb';
$m_txt = '891';
$m_time = '600'; //离线保留时间
$res=$fetion->send_pub($receive, $content ,$m_type, $m_txt ,$m_time);
}

}

* *

本文由威尼斯在线注册平台发布于热门新闻,转载请注明出处:// 接口密码$code =,只能填一个

上一篇://将1-n只猴子顺序编号 入数组中 for($i= 1 下一篇:没有了
猜你喜欢
热门排行
精彩图文