tp集成极光推送
有哪位大神做过极光推送? 麻烦有没有代码可以给我研究一下。。
在网上找了一个大神发的源码 但是不知道怎么放到tp框架中。。稍后奉上代码 哪位能指导一下 先谢谢了
另:我想问一下 假如我自己写了一个函数 叫jpush.php 那我如何在控制器中调用它? 这个文件要放到哪个文件夹下?
jpush.php
/**
* 极光推送
* @author 晨曦
* @Email jakehu1991@163.com
* @Website http://www.jakehu.me/
* @version 20130706
*/
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
/**
* 极光推送
* @author 晨曦
* @Email jakehu1991@163.com
* @Website http://www.jakehu.me/
* @version 20130706
*/
include('jpush.php');
$n_title = '1231232';
$n_content = '12312321231232123123212312321231232';
$appkeys='123123212312321231232';
$masterSecret='1231232123123212312321231232';
$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();
?>
回复讨论(解决方案)
有哪位大神能指导一下。。。
sdk中的类文件放到vendor目录
自定义函数知道在哪吧...
在自定义函数里tp的函数vendor('jiguang.jpush')引入
实例化时需要$a = new \jpush();

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Laravel simplifies handling temporary session data using its intuitive flash methods. This is perfect for displaying brief messages, alerts, or notifications within your application. Data persists only for the subsequent request by default: $request-

The PHP Client URL (cURL) extension is a powerful tool for developers, enabling seamless interaction with remote servers and REST APIs. By leveraging libcurl, a well-respected multi-protocol file transfer library, PHP cURL facilitates efficient execution of various network protocols, including HTTP, HTTPS, and FTP. This extension offers granular control over HTTP requests, supports multiple concurrent operations, and provides built-in security features.

Laravel provides concise HTTP response simulation syntax, simplifying HTTP interaction testing. This approach significantly reduces code redundancy while making your test simulation more intuitive. The basic implementation provides a variety of response type shortcuts: use Illuminate\Support\Facades\Http; Http::fake([ 'google.com' => 'Hello World', 'github.com' => ['foo' => 'bar'], 'forge.laravel.com' =>

Do you want to provide real-time, instant solutions to your customers' most pressing problems? Live chat lets you have real-time conversations with customers and resolve their problems instantly. It allows you to provide faster service to your custom

Article discusses late static binding (LSB) in PHP, introduced in PHP 5.3, allowing runtime resolution of static method calls for more flexible inheritance.Main issue: LSB vs. traditional polymorphism; LSB's practical applications and potential perfo

PHP logging is essential for monitoring and debugging web applications, as well as capturing critical events, errors, and runtime behavior. It provides valuable insights into system performance, helps identify issues, and supports faster troubleshoot

Laravel simplifies HTTP verb handling in incoming requests, streamlining diverse operation management within your applications. The method() and isMethod() methods efficiently identify and validate request types. This feature is crucial for building

The Storage::download method of the Laravel framework provides a concise API for safely handling file downloads while managing abstractions of file storage. Here is an example of using Storage::download() in the example controller:
