setAppKeyToken($appKeyToken) ->setUserKeyToken($userKeyToken); $this->apiInstance = new DefaultApi( new GuzzleHttp\Client(), $config ); } public function test() { $data =input(); $id=$data['ids']; $wheres['id']=$id; $one_push = Db::name('message')->where($wheres)->find(); if (empty($one_push)) { echo '没有查到推送队列'; exit; } $result =$this->sendTest($one_push); $this->success('',$result); } function createNotification($one_push){ $template_dsc =$one_push['template_dsc']; $title =$one_push['template_name']; $type =$one_push['type']; $url =$one_push['para']; $content = new StringMap(); $content->setEn($template_dsc); $notification = new Notification(); $notification->setContents($content); $notification->setIosBadgeType('Increase'); $notification->setIosBadgeCount(1); $notification->setIsIos(true); $notification->setContentAvailable(true); $data['push_para']=$url; $data['push_type']=$type; $data['title']=$title; $data['message_id']=$one_push['id']; $notification->setData($data); $notification->setMutableContent(true); $apns_alert['title']=$title; $notification->setApnsAlert($apns_alert); if($one_push['template_image']){ $request = Request::instance(); $domain=$request->domain(); $images['id'] = $domain.$one_push['template_image']; $notification->setIosAttachments($images); } return $notification; } public function sendTest($one_push){ $appId =$this->getAppId(); $notification = $this->createNotification($one_push); $notification->setAppId($appId); $notification->setIncludedSegments(['TestUsers']); return $this->apiInstance->createNotification($notification); } public function getAppId(){ $url = $_SERVER['HTTP_HOST']; if (strpos($url, 'westkiss') !== false) { $appId ='6bbd561f-4d8e-4d04-a6c4-dbef1bf99694'; }elseif (strpos($url, 'asteriahair') !== false) { $appId ='618fe580-bc97-4bf4-b2bb-5039f9dbbc82'; }else{ $appId ='b3124d44-7bc7-4965-95dc-0ecb502fdaea'; } return $appId; } }