【极光推送】

版权声明:咔咔 来自https://blog.csdn.net/fangkang7 https://blog.csdn.net/fangkang7/article/details/90748288

author:咔咔

wechat:fagnkangfk

/**
 * author:咔咔
 *
 * 极光推送
 */
function jpushMessage($data){

    $app_key = config('systemConst.appKey');//填入自己的key
    $master_secret = config('systemConst.masterSecret');//填入自己的secret
    $client =new \JPush\Client($app_key, $master_secret);

    try {
        $response = $client->push()
            ->setPlatform('all')
            ->addAllAudience()
            ->setNotificationAlert($data)
            ->options(array(
                'apns_production' => config('systemConst.apns_production'),
            ))
            ->send();

        if($response['http_code'] == 200){
            $data = [
                'code' => 1,
                'msg'  => '推送成功'
            ];

            return $data;
        }

    } catch (\JPush\Exceptions\APIConnectionException $e) {
        // try something here
        print $e;
    } catch (\JPush\Exceptions\APIRequestException $e) {
        // try something here
        print $e;
    }
}

猜你喜欢

转载自blog.csdn.net/fangkang7/article/details/90748288