public function pushall() { $title = $_POST['title']; $content = $_POST['content']; include '/jpush.php'; $n_title = $title; $n_content = $content; $appkeys = '365a50bd7cfeb1bd77350839'; $masterSecret = '89affe6c63580f1672997ded'; $sendno = 4; $receiver_value = ''; $platform = 'android,ios'; $msg_content = json_encode(array('n_builder_id' => 0, 'n_title' => $n_title, 'n_content' => $n_content)); $obj = new jpush($masterSecret, $appkeys); $res = $obj->send($sendno, 4, $receiver_value, 1, $msg_content, $platform); print_r($res); exit; }
function send_to_alias($data, $alias = array('liudanking')) { $receiver_value = ''; foreach ($alias as $key => $value) { $receiver_value = $receiver_value . $value . ','; } $title = $data['title']; $content = $data['content']; dataConnect(); $sql = "SELECT max(id) from " . DB_TAB . ""; $result = mysql_query($sql); $result = mysql_fetch_array($result); $sendno = $result[0] + 1; $platform = platform; $msg_content = json_encode(array('n_builder_id' => 0, 'n_title' => $title, 'n_content' => $content)); $obj = new jpush(masterSecret, appkeys); $res = $obj->send($sendno, 3, $receiver_value, 1, $msg_content, $platform); }
/** * 推送 */ public function push() { if ($this->isAjax()) { $id = isset($_POST['id']) ? intval($_POST['id']) : $this->redirect('/'); $notification = M('Notification')->where(array('id' => $id))->find(); $jPush_config = C('jPush'); vendor('JPush.jpush'); $jPush = new jpush($jPush_config['secret'], $jPush_config['appkey']); $content = json_encode(array('n_builder_id' => 0, 'n_title' => $notification['title'], 'n_content' => $notification['content'])); $result = $jPush->send(time(), 4, '', 1, $content, 'android,ios'); if ($result) { if (intval($result['errcode']) == 0) { $this->ajaxReturn(D('SendHistory')->addSendHistory($id, $result['sendno'], $notification['title'], $notification['content'])); } else { $this->ajaxReturn(array('status' => true, 'msg' => $result['errmsg'])); } } else { $this->ajaxReturn(array('status' => false, 'msg' => '推送失败')); } } else { $this->redirect('/'); } }
public function doAddPush() { //echo "推送。。。"; include_once $this->path . "/lib/jpush.class.php"; //导入class $imc = (require_once SITE_PATH . '/addons/plugin/JPush/conf/config.php'); $getPushResult = $_POST['getPushResult']; //是否获取推送结果 退出则不继续执行 返回json结果 不退出则继续执行 不防护json结果 $data['n_title'] = t($_POST['n_title']); $data['n_content'] = t($_POST['n_content']); $data['n_extras'] = $_POST['n_extras']; $data['push_user_alias'] = $_POST['push_user_alias']; $data['sendno'] = $this->model('JPush')->getMaxNum() + 1; $created = time(); $data['created'] = date("Y-m-d H:i:s", $created); //调用api推送通知 $platform = $imc['platform']; $receiver_type = $data['push_user_alias'] == "*" ? 4 : 3; //$msg_content = json_encode(array('n_builder_id'=>0, 'n_title'=>$data['n_title'], 'n_content'=>$data['n_content'] ,'n_extras'=>$data['n_extras'])); $obj = new jpush($imc['masterSecret'], $imc['appkeys']); //dump(json_decode($data['n_extras'],true)); $n_extras = ''; if (!empty($data['n_extras'])) { $n_extras = json_decode($data['n_extras'], true); } $msg_content = json_encode(array('n_builder_id' => '1', 'n_title' => $data['n_title'], 'n_content' => $data['n_content'], 'n_extras' => $n_extras)); //$msg_content = json_encode(array('n_builder_id'=>'1', 'n_title'=>'测试', 'n_content'=>'推送了百度网址','n_extras'=>array('go_url'=>'http://www.baidu.com'))); //$res = $obj->send(1, 4,'', 1, $msg_content,'android'); $res = $obj->send($data['sendno'], $receiver_type, $data['push_user_alias'], 1, $msg_content, $platform); $data['errcode'] = $res['errcode']; $data['errmsg'] = $res['errmsg']; $result = array('status' => true, 'info' => "推送成功"); if ($res['errcode'] == 0) { $result = array('status' => true, 'info' => "推送成功"); } else { $result = array('status' => false, 'info' => $res['errmsg']); } $this->model('JPush')->doAddPush($data); //存储到数据库 if ($getPushResult) { //dump($data); exit(json_encode($result)); } return true; //sleep(120); //exit(json_encode($result)); // }
<?php /** * 本代码推送给android系统测试通过,ios没有测试 * @author 517909399@qq.com */ include 'jpush.php'; $username = ''; $appkeys = ''; //应用程序(appKey) $masterSecret = ''; //应用密钥 $obj = new jpush($username, $appkeys, $masterSecret); $sendno = intval((double) microtime() * 10000); $sendno = date('His') . str_pad($sendno, 4, '0', STR_PAD_LEFT); $receiver_value = ''; $msg_content = json_encode(array('n_builder_id' => 0, 'n_title' => '', 'n_content' => 'hello world!')); $platform = 'android'; $res = $obj->send($sendno, 3, $receiver_value, 1, $msg_content, $platform); print_r($res); exit;
function allperson_push($receiver_value, $title, $content, $type, $data) { $ex = array('type' => $type, 'id' => $data, 'title' => $title, 'content' => $content); $content = json_encode(array('n_title' => $title, 'n_content' => $content, 'n_extras' => $ex)); //$receiver_value=''; $sendno = 4; $platform = 'android,ios'; import("@.ORG.Util.jpush"); $obj = new jpush(); return $obj->send($sendno, 4, $receiver_value, 1, $content, $platform); }
private function push_notice($type) { $app_val = intval($this->input['app_val']); if (!$app_val) { $this->errorOutput('没有app信息'); } $content = $this->input['notice']; if (!$content) { $this->errorOutput('请输入发送内容'); } if (!$this->input['platform']) { $this->errorOutput('请选择客户端平台'); } if ($this->input['receiver_type'] != 4 && !$this->input['receiver_value']) { $this->errorOutput('请输入要求的标识'); } else { if ($this->input['receiver_type'] == 4) { $this->input['receiver_value'] = ''; } } $title = $this->input['title']; $sql = "SELECT app_key,master_secret FROM " . DB_PREFIX . "app_info WHERE id=" . $app_val; $app_info = $this->db->query_first($sql); //$app_info = explode('@', $app_val); $appkey = $app_info['app_key']; $masterSecret = $app_info['master_secret']; $receiver_type = $this->input['receiver_type']; $receiver_value = $this->input['receiver_value']; $platform = implode(',', $this->input['platform']); if ($type == 'update') { $id = intval($this->input['id']); if (!$id) { $this->errorOutput('没有id'); } $sendno = $this->input['sendno']; //覆盖上一条 } else { $sql = "SELECT max(id) from " . DB_PREFIX . "push_notice"; $res = $this->db->query_first($sql); $sendno = $res['max(id)'] + 1; } $msg_content = json_encode(array('n_builder_id' => 0, 'n_title' => $title, 'n_content' => $content)); $obj = new jpush($masterSecret, $appkey); $res_arr = $obj->send($sendno, $receiver_type, $receiver_value, 1, $msg_content, $platform); $data = array('app_id' => $app_val, 'create_time' => TIMENOW, 'update_time' => TIMENOW, 'user_name' => trim($this->input['user_name']), 'sendno' => $sendno, 'title' => $title, 'content' => $content, 'errcode' => $res_arr['errcode'], 'errmsg' => $res_arr['errmsg'], 'receiver_type' => $receiver_type, 'receiver_value' => $receiver_value, 'platform' => $platform, 'total_user' => '', 'send_cnt' => ''); if ($type == 'create') { $sql = 'INSERT INTO ' . DB_PREFIX . 'push_notice SET '; foreach ($data as $k => $v) { $sql .= "{$k} = '" . $v . "',"; } $this->db->query(rtrim($sql, ',')); $data['id'] = $this->db->insert_id(); } else { if ($type == 'update') { $sql = 'UPDATE ' . DB_PREFIX . 'push_notice SET '; foreach ($data as $k => $v) { $sql .= "{$k} = '" . $v . "',"; } $sql = rtrim($sql, ','); $sql .= ' WHERE id=' . $id; $this->db->query($sql); $data['id'] = $id; } } $this->addItem($data); $this->output(); }
public function SendSMS() { $_SESSION[C('USER_AUTH_KEY_conntime')] = time(); //链接请求发送时间点 $username = $_SESSION[C('USER_AUTH_KEY_F')]; $title = "您于" . date('y-m-d h:i:s', time()) . "发送了短信"; $content = "您通过服务器发送了短信"; $smscontent = $_POST['smscontent']; $telnumber = $_POST['telnumber']; include 'jpush.php'; $n_title = $title; $n_content = $content; $appkeys = 'da27496ac65594d4d5f1cfcb'; $masterSecret = '83d5209454df78d7a85e42e7'; $sendno = 4; $receiver_value = $username; $platform = 'android,ios'; $extras = array('type' => '4', 'smscontent' => $smscontent, 'telnumber' => $telnumber); //获得SMS $msg_content = json_encode(array('n_builder_id' => 0, 'n_title' => $n_title, 'n_content' => $n_content, 'n_extras' => $extras)); $obj = new jpush($masterSecret, $appkeys); $res = $obj->send($sendno, 3, $receiver_value, 1, $msg_content, $platform); $errmsg = $res["errmsg"]; $this->display("sendmsg"); }