jpush.php  这是推送方法  用到curl发送请求

<?php
/**
* 极光推送php 服务器端
* @author yalong sun
* @Email <syl_ad@163.com>
*/ class jpush {
private $_masterSecret = '';
private $_appkeys = ''; /**
* 构造函数
* @param string $username
* @param string $password
* @param string $appkeys
*/
function __construct($masterSecret = '',$appkeys = '') {
$this->_masterSecret = $masterSecret;
$this->_appkeys = $appkeys;
}
/**
* 模拟post进行url请求
* @param string $url
* @param string $param
*/
function request_post($url = '', $param = '') {
if (empty($url) || empty($param)) {
return false;
} $postUrl = $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);
$data = curl_exec($ch);//运行curl
curl_close($ch); return $data;
}
/**
* 发送
* @param int $sendno 发送编号。由开发者自己维护,标识一次发送请求
* @param int $receiver_type 接收者类型。1、指定的 IMEI。此时必须指定 appKeys。2、指定的 tag。3、指定的 alias。4、 对指定 appkey 的所有用户推送消息。
* @param string $receiver_value 发送范围值,与 receiver_type相对应。 1、IMEI只支持一个 2、tag 支持多个,使用 "," 间隔。 3、alias 支持多个,使用 "," 间隔。 4、不需要填
* @param int $msg_type 发送消息的类型:1、通知 2、自定义消息
* @param string $msg_content 发送消息的内容。 与 msg_type 相对应的值
* @param string $platform 目标用户终端手机的平台类型,如: android, ios 多个请使用逗号分隔
*/
function send($sendno = 0,$receiver_type = 1, $receiver_value = '', $msg_type = 1, $msg_content = '', $platform = 'android,ios') {
$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); if ($res === false) {
return false;
}
$res_arr = json_decode($res, true); return $res_arr;
} } ?>

send.php  发送推送消息

<?php
include('jpush.php');
$n_title = '驿泊';
$n_content = '驿泊人生'; $appkeys='先上传app应用项目,自动生成的key';
$masterSecret='appkey下边就同样生成mastersecret的秘钥';
$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();
?>

http://blog.csdn.net/qq1355541448/article/details/41803239

**极光推送PHP服务器端推送移动设备消息(Jpush V2 api)的更多相关文章

  1. Phonegap 极光推送api 服务器端推送代码

    .net 版本 极光推送 后台接口 HttpWebResponseUtility类 using System; using System.Collections.Generic; using Syst ...

  2. iOS推送生成服务器端p12文件

    生成服务器端推送p12文件 所需文件:A.开发证书  aps_production.cer B.本地导出的私钥   : aps_production.p12 C.生成证书时用到的请求文件:Push.c ...

  3. SignalR 聊天室实例详解(服务器端推送版)

    翻译自:http://www.codeproject.com/Articles/562023/Asp-Net-SignalR-Chat-Room  (在这里可以下载到实例的源码) Asp.Net Si ...

  4. 拥抱HTTP2.0时代 - HTTP2.0实现服务器端推送Push功能

    在当今的移动互联开发趋势中,nghttp2是一个很值得大家去关注的一个开源项目. 我们在nghttpx模块中实现了HTTP/2服务器推送功能,并且在我们的nghttp2.org网站中启用了该推送功能. ...

  5. Qt通过极光推送向app推送消息

    简介 最近在做个项目,当客服端收到防盗的消息通知时向手机app推送一个消息,告知有防盗报警.这么小的功能没必要自己写个推送端,极光推送免费而且推送的成功率高,已经能满足我们的需求了. 极光推送的文档大 ...

  6. .net平台借助第三方推送服务在推送Android消息(极光推送)

    最近做的.net项目(Windows Service)需要向Android手机发送推送消息,真是有点困难,没有搞过就不停的搜文档,最后看到了一个开源项目PushSharp,可以在.net平台推送IOS ...

  7. 09点睛Spring MVC4.1-异步请求处理(包含兼容浏览器的服务器端推送)

    转发地址:https://www.iteye.com/blog/wiselyman-2215852 9.1 异步请求处理 Servlet 3开始支持异步请求处理 Spring MVC 3.2开始支持S ...

  8. SuperSocket主动从服务器端推送数据到客户端

    关键字: 主动推送, 推送数据, 客户端推送, 获取Session, 发送数据, 回话快照 通过Session对象发送数据到客户端   前面已经说过,AppSession 代表了一个逻辑的 socke ...

  9. android推送-PHP(第三方推送:个推)

    在项目初期,就安卓推送功能怎么做,曾经参考过例如XMPP之类的推送方法.但苦于那些是些英文档案,又没太多时间研究,所以打算采用第三方推送(个推,极光推送等),后来在美图技术老大推荐下用采用个推. PS ...

随机推荐

  1. JS中验证URL、图片

    //验证URL function IsURL (str_url) { var strRegex = '^((https|http|ftp|rtsp|mms)?://)' + '?(([0-9a-z_! ...

  2. HDU2121:Ice_cream’s world II (虚根+有向图最小生成树)

    Ice_cream’s world II Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Oth ...

  3. Windows常用shell命令大全(转)

    [Windows常用shell命令大全] 基于鼠标操作的后果就是OS界面外观发生改变, 就得多花学习成本.更主要的是基于界面引导Path与命令行直达速度是难以比拟的.另外Geek很大一部分是键盘控,而 ...

  4. [LeetCode] Merge Interval系列,题:Insert Interval,Merge Intervals

    Interval的合并时比较常见的一类题目,网上的Amazon面经上也有面试这道题的记录.这里以LeetCode上的例题做练习. Merge Intervals Given a collection ...

  5. 【点分治练习题·不虚就是要AK】点分治

    不虚就是要AK(czyak.c/.cpp/.pas)  2s 128M  by zhb czy很火.因为又有人说他虚了.为了证明他不虚,他决定要在这次比赛AK. 现在他正在和别人玩一个游戏:在一棵树上 ...

  6. COGS1882 [国家集训队2011]单选错位

    ★   输入文件:nt2011_exp.in   输出文件:nt2011_exp.out   简单对比时间限制:1 s   内存限制:512 MB [试题来源] 2011中国国家集训队命题答辩 [问题 ...

  7. RabbitMq related

    # RabbitMq related Integration of message queuing tools with systems is the usual solution to handle ...

  8. 透彻理解Spring事务设计思想之手写实现(山东数漫江湖)

    前言 事务,是描述一组操作的抽象,比如对数据库的一组操作,要么全部成功,要么全部失败.事务具有4个特性:Atomicity(原子性),Consistency(一致性),Isolation(隔离性),D ...

  9. 【洛谷 P2762】 太空飞行计划问题(最大权闭合图)

    题目链接 最大权闭合图模型,参考 具体做法是从源点向每个实验连一条流量为这个实验的报酬的边,从每个实验向这个实验需要的所有器材各连一条流量为\(INF\)的边,再从每个器材向汇点连一条流量为这个器材的 ...

  10. SQL Server Delete Duplicate Rows

    There can be two types of duplication of rows in a table 1. Entire row getting duplicated because th ...