1. 首先是外层封装的类
// 添加用到的引用
use oppoPush\oppoPush;
class OppoNoti
{
function __construct()
{
$this->appKey = '**申请的appKey**';
$this->mstSecret = ''**申请的Secret**'';
}
//单播消息
public function sendAndroidUnicast($device_tokens,$param=[])
{
try {
//引入类
Vendor('oppopush.autoload');
$client = new oppoPush($this->appKey, $this->mstSecret); // AppKey 与 MasterSecret(非 AppSecret)
$extend = [
'push_id' => $param['push_id'],
'title' => $param['title'],
];
$authToken = $client->getAuthToken(); // 有效期24小时
$client->setTitle($param['title']);
$client->setContent($param['sub']);
$client->setAuthToken($authToken);
$client->getAuthTokenExpiresTime(); // 获取 auth_token 过期时间
$client->setIntent('com.***.****.oppopush'); // 打开应用内页的 intent action,这需要填写自己的应用定义
//$client->setActionUrl('http://www.xxx.com'); // 打开网页
$client->setActionParameters(json_encode($extend)); // 打开应用内页或网页时传递的参数 (数组或json类型)
$client->addRegistrationId($device_tokens); // 添加需要发送设备的 registration_id, 最多 1000 个
//$client->broadcastByRegId(); // registration_id 推送
$result = $client->broadcastByRegId(); // registration_id 推送
if (0 == $result['code']) {
return true;
} else {
return false;
}
} catch (Exception $e) {
print("Caught exception: " . $e->getMessage());
}
}
}
2. 然后是oppo的核心发送SDK,文件结构如下,从网盘上下载了直接引入即可
下载地址:链接:https://pan.baidu.com/s/1RnnpFMwQLHEGg36wWu21gA 密码:b1h0