后台效果:
后台代码(html):
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
public function push_msg($ids) { $data = M("push_message")->field('id,description,status')->find($ids); // print_r($data);die; /*if(!empty($data['msg_img'])){ $data['msg_img']=M('picture')->where(array('id'=>$data['msg_img']))->getField('path'); }else{ unset($data['msg_img']); }*/ if ($data['status'] != 0) { $result['result'] = 0; return $result; } $array['type'] = 2; $array['user_data'] = get_user_info(UID,'uid,head_img,nickname'); $array['data'] = $data; $array['time'] = time(); // print_r($array);die; $array = json_encode($array); $result = $this->pushMessageToApp($array, "养生通知"); //print_r($result);die; if ($result['result'] == "ok") { M("push_message")->where(array("id" => $ids))->save(array("status" => 1)); }else{ M('push_message')->where(array("id" => $ids))->save(array("status" => 0)); } $this->ajaxReturn($result); }
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
//推送单个应用(所有用户) private function pushMessageToApp($data, $title) { //print_r($data);die; header("Content-Type: text/html; charset=utf-8"); define('HOST', 'http://sdk.open.api.igexin.com/apiex.htm'); define('APPKEY', ''); define('APPID', '); define('MASTERSECRET', ); import('Common.Lib.GETUI.Push','','.php'); //路径 $igt = new \IGeTui(HOST, APPKEY, MASTERSECRET); // print_r($data);exit; // $template = $this->template($data); $template = $this->IGtTransmissionTemplateDemo($data,$title); $message = new \IGtAppMessage(); $message->set_isOffline(true); $message->set_offlineExpireTime(3600 * 1000 * 2);//离线时间单位为毫秒,例,两个小时离线为3600*1000*2 $message->set_data($template); $appIdList = array(APPID); $message->set_appIdList($appIdList); //$message->set_conditions($cdt->getCondition()); return $igt->pushMessageToApp($message, $title); } function IGtTransmissionTemplateDemo($data,$title){ $template = new \IGtTransmissionTemplate(); $template->set_appId(APPID);//应用appid $template->set_appkey(APPKEY);//应用appkey $template->set_transmissionType(2);//透传消息类型 $template->set_transmissionContent($data);//透传内容 //$template->set_duration(BEGINTIME,ENDTIME); //设置ANDROID客户端在此时间区间内展示消息 // 如下有两个推送模版,一个简单一个高级,可以互相切换使用。此处以高级为例,所以把简单模版注释掉。 //APN简单推送 // $apn = new IGtAPNPayload(); // $alertmsg=new SimpleAlertMsg(); // $alertmsg->alertMsg=""; // $apn->alertMsg=$alertmsg; // $apn->badge=2; // $apn->sound=""; // $apn->add_customMsg("payload","payload"); // $apn->contentAvailable=1; // $apn->category="ACTIONABLE"; // $template->set_apnInfo($apn); //APN高级推送 $apn = new \IGtAPNPayload(); $alertmsg=new \DictionaryAlertMsg(); $alertmsg->body="body"; $alertmsg->actionLocKey="ActionLockey"; $alertmsg->locKey="天天养生通知您"; $alertmsg->locArgs=array("locargs"); $alertmsg->launchImage="launchimage"; // IOS8.2 支持 $alertmsg->title="水培喝水"; $alertmsg->titleLocKey="通知"; $alertmsg->titleLocArgs=array("TitleLocArg"); $apn->alertMsg=$alertmsg; $apn->badge=1; $apn->sound=""; $apn->add_customMsg("payload",$data); // $apn->contentAvailable=1; $apn->category="ACTIONABLE"; $template->set_apnInfo($apn); return $template; }
结果图: