首先用composer 安装
composer require shaozeming/laravel-getui -v
然后在config\app.php的providers
在config\app.php的aliases
用php加载一下
php artisan vendor:publish --provider=ShaoZeMing\\GeTui\\GeTuiServiceProvider
想直接引用个推
在bootstrap/app.php中加入
$app->register(ShaoZeMing\GeTui\GeTuiServiceProvider::class);
将 vendor/ShaoZeMing/laravel-getui/src/config/getui.php 拷贝到项目根目录/config目录下,并将文件名改成getui.php。
// config/getui.php
// APP_EVN 你的项目当前环境 测试、生产
//可以换成env('appid)
'app_env' => env('APP_ENV') == 'production' ? 'production' : 'development',
// The default default_client name which configured in `development` or `production` section
//默认推送的客户端
'default_client' => 'client_1',
//在个推平台自己创建的appid和appkey
//如果是uniapp,请开通unipush 这里放unipush里面的appid和appkey
'development' => [
'client_1' => [
'gt_appid' => 'WAqyXNcLpS8OLg4jBywS48',
'gt_appkey' => 'FkxUuibQsT75FX5Tt5jteA',
'gt_appsecret' => 'jWtd0iUzdmAvVPhKorrtW1',
'gt_mastersecret' => '4uCfJsfME99oaF5sT1ZjO',
'gt_domainurl' => 'http://sdk.open.api.igexin.com/apiex.htm',
],
'client_2' => [
'gt_appid' => 'SeldZ6X0Iq8hpj5rGvqAk8',
'gt_appkey' => '93MPU2THwl9okpeNf4lNI4',
'gt_appsecret' => 'kzZuSXVMm29M7owpvId979',
'gt_mastersecret' => '0QCmCdVZSi8lcyMFXLB4e',
'gt_domainurl' => 'http://sdk.open.api.igexin.com/apiex.htm',
],
// other client_3 ......
],
'production' => [
'client_1' => [
'gt_appid' => '6V95sH0t3W6Du1MTiU3679',
'gt_appkey' => 'n6q8NSAshP77ImKxdhuHV6',
'gt_appsecret' => '01hGwR1Jdl6vuwBcnvfyD3',
'gt_mastersecret' => 'daw4hbkFj4Ah3kBlPFfIh2',
'gt_domainurl' => 'http://sdk.open.api.igexin.com/apiex.htm',
],
'client_2' => [
'gt_appid' => 'iB7DfaXV6bAf8zlJ0L59A8',
'gt_appkey' => 'DKKp54s2knA2MaeGBXuF01',
'gt_appsecret' => 'exTKWC0M1K6O2Bgig5RiC8',
'gt_mastersecret' => '0cojzBC7yB86mhOiOVHBuA',
'gt_domainurl' => 'http://sdk.open.api.igexin.com/apiex.htm',
],
// other client_3 ......
],
后端代码 api接口
namespace App\Http\Controllers\Api;
use App\Http\Controllers\Controller;
use App\Http\Controllers\Api\BaseContorller;
use Dingo\Api\Console\Command\Cache;
use Illuminate\Http\Request;
use Session;
use DB, Validator;
use Log,GeTui;
class GeTuiController extends Controller
{
//个推
public function test(){
//$deviceId = 'a1f3e7c11ca97924be6f291f2c09714b';
//前端获取的cid
$deviceId = 'db8fb2e75bd81557f352f8adfa4abe75';
// 多个push对象device_id 用数组传入
// $deviceId = [
// 'a1f3e7c11ca97924be6f291f2c09714b',
// 'ea34a4715b08b1b8d77aabf36c977cba',
// ];
$data = [
'url' => 'http://test.4d4k.com/push',
'type' => '点击查看\(^o^)/~',
'title' => 'ceshi',
'content' => '1111111111',
'id' => '3a92y3GR1neZ',
'merchant_name' => '测试',
'big_cat' => 'PHP',
'full_address' => '山东省潍坊市奎文区泰华A1508',
];
$res = GeTui::push($deviceId, $data,true); //Using default default_client
print_r($res);
}
}
//
前端 //获取了cid跟用户绑定存储 按照这个id给指定用户推送
let pinf = plus.push.getClientInfo();
let cid = pinf && pinf.clientid || ''; //客户端标识
这样就可以推送了
关于透传推送的问题,第一个模板,前端接收不到值,第二个就可以接收到了,没有了下拉栏的推送。问题还没找到。
/
use GeTui;
//针对单个或者多个用户推送
GeTui::push($deviceId, $data,true) //Using default default_client 推送给默认的客户端
GeTui::toClient('CLIENT NAME')->push($deviceId, $data) // CLIENT NAME is key name of `development` or `production` configuration. //自定义发送的客户端
// 针对整个app所有人推送
GeTui::pushToApp($data,true) Using default default_client
GeTui::toClient('CLIENT NAME')->pushToApp($data) // GATEWAY NAME is key name of `development` or `production` configuration.
/
$deviceId = 'b2e5b64931f06f617e363b74c8057cf6';
// 多个push对象device_id 用数组传入
$deviceId = [
'ea34a4715b08b1b8d77aabf36c977cba',
'ea34a4715b08b1b8d77aabf36c977cba',
];
$data = [
'url' => 'http://test.4d4k.com/push',
'type' => '点击查看\(^o^)/~',
'title' => '23232323fdf',
'content' => '今天天气真好',
'id' => '3a92y3GR1neZ',
'merchant_name' => '泽明科技',
'big_cat' => '电视机',
'full_address' => '北京市海淀区五道口清华大学',
];
$res = \GeTui::push($deviceId, $data,true); //Using default default_client
print_r($res);
/