} return $sJSONPayload; } } date_default_timezone_set('PRC'); echo "we are young,test apns. -" . date('Y-m-d h:i:s', time()); static $count = 0; $rootpath = 'entrust_root_certification_authority.pem'; //ROOT证书地址 $cp = 'ck.pem'; //provider证书地址 $apns = new APNS(1, $cp); try { $countStr = (string) $count++; //$apns->setRCA($rootpath); //设置ROOT证书 $apns->connect(); //连接 $apns->addDT('e373de841e841616ee23027aa74afcedd014a8b0b6b29b403cb7ba40fc452748'); //加入deviceToken $apns->setText('刘老二: 今天天气不是很好啊' . $countStr); //发送内容 $apns->setBadge(1); //设置图标数 $apns->setSound(); //设置声音 $apns->setExpiry(3600); //过期时间 $apns->setCP('custom operation', array('type' => '1', 'url' => 'http://www.google.com.hk')); //自定义操作 $apns->send(); //发送
public function add_info() { switch ($_POST['info_type']) { case "app": $table = "app"; $icon = $_POST['icon']; if ($_POST['isicontext'] == "yes") { $savebase = '/resource/cusicon/' . date("YmdHis") . '_' . $_SESSION['userid'] . '.'; $savefile = $_SERVER['DOCUMENT_ROOT'] . $savebase; $color = array("red" => 255, "green" => 255, "blue" => 255); if ($icon == "/resource/icon/6.png") { $color = array("red" => 0, "green" => 0, "blue" => 0); } $font_size = 13; $x = 10; $y = 10; $icon_text = $_POST['icontext']; switch (mb_strlen($icon_text, 'UTF8')) { case 1: $font_size = 36; $x = 6; $y = 48; break; case 2: $font_size = 18; $x = 6; $y = 40; break; case 3: $font_size = 12; $x = 4; $y = 35; break; case 4: $font_size = 18; $x = 6; $y = 20; $icon_text = mb_substr($icon_text, 0, 2) . "\n" . mb_substr($icon_text, 2, 2); break; } $ext = $this->mark_text($_SERVER['DOCUMENT_ROOT'] . $icon, $font_size, $x, $y, $color, $icon_text, $savefile); $icon = $savebase . $ext; } $info = array("name_app" => $_POST['name'], "icon_app" => $icon, "icon_text_app" => $_POST['isicontext'] == "yes" ? $_POST['icontext'] : "", "cat_app" => $_POST['category'], "state_app" => 1, "desc_app" => $_POST['description'], "merchant_id_app" => $_SESSION['userid'], "launch_app" => $_POST['launch'], "template_app" => $_POST['template'], "skin_app" => $_POST['skin'], "skincolor_app" => $_POST['skincolor'], "create_time_app" => date("Y-m-d H:i:s"), "update_time_app" => date("Y-m-d H:i:s"), "download_time_app" => 0); $log = "添加APP【" . $_POST['name'] . "】"; break; case "register": $table = "merchant"; if (!$this->check_unique("merchant", $_POST['username'])) { echo json_encode(array("result" => "notunique", "message" => "该用户名已经存在")); return false; } $info = array("username_merchant" => $_POST['username'], "pwd_merchant" => MD5("kmkj" . $_POST['pwd']), "grade_merchant" => 1, "reg_time_merchant" => date("Y-m-d H:i:s")); $log = "【" . $_POST['username'] . "】注册"; break; case "nav": $table = "nav"; $info = array("app_id_nav" => $_POST['appid'], "icon_nav" => $_POST['icon'], "name_nav" => $_POST['name'], "order_nav" => $_POST['order']); $log = "添加id为" . $_POST['appid'] . "的APP的导航【" . $_POST['name'] . "】"; break; case "slider": $table = "homeslider"; $info = array("appid_homeslider" => $_POST['appid'], "src_homeslider" => $_POST['src'], "ordernum_homeslider" => $_POST['order']); $log = "添加id为" . $_POST['appid'] . "的APP的滚动图【" . $_POST['src'] . "】"; break; case "essay": $table = "essay"; $info = array("navid_essay" => $_POST['navid'], "title_essay" => $_POST['title'], "summary_essay" => $_POST['summary'], "text_essay" => $_POST['content'], "thumbnail_essay" => json_encode($_POST['thumbnail']), "state_essay" => $_POST['draft'], "time_essay" => date("Y-m-d H:i:s"), "lasttime_essay" => date("Y-m-d H:i:s")); $log = "添加文章【" . $_POST['title'] . "】"; break; case "product": $table = "product"; $info = array("navid_product" => $_POST['navid'], "catid_product" => isset($_POST['catid']) && is_numeric($_POST['catid']) ? $_POST['catid'] : 0, "unit_product" => $_POST['unit'], "price_product" => $_POST['price'], "oriprice_product" => $_POST['oriPrice'], "name_product" => $_POST['title'], "summary_product" => $_POST['summary'], "description_product" => $_POST['content'], "thumbnail_product" => json_encode($_POST['thumbnail']), "state_product" => $_POST['draft'], "collect_product" => 0, "time_product" => date("Y-m-d H:i:s"), "lasttime_product" => date("Y-m-d H:i:s")); $log = "添加商品【" . $_POST['title'] . "】"; break; case "previewimg": $table = "previewimg"; $info = array("appid_previewimg" => $_POST['appid'], "src_previewimg" => $_POST['src'], "ordernum_previewimg" => $_POST['order']); $log = "添加id为" . $_POST['appid'] . "的APP的预览图【<img width='50' height='100' src='" . $_POST['src'] . "'>】"; break; case "message": $table = "message"; $byMerchantId = isset($_SESSION['Fuserid']) && $_SESSION['Fuserid'] != "" ? $_SESSION['Fuserid'] : $_SESSION['userid']; $info = array("type_message" => $_POST["type"], "from_message" => $byMerchantId, "to_message" => $_POST["to"] != "" && is_numeric($_POST["to"]) ? $_POST["to"] : 0, "device_message" => $_POST["device"], "title_message" => $_POST["title"], "msg_message" => $_POST["msg"], "time_message" => date("Y-m-d H:i:s"), "appid_message" => $_POST["app"], "check_message" => 0); if ($_POST["type"] == '2' && $_POST["device"] != '1' && false) { $this->load->helper("apns"); $rootpath = 'entrust_root_certification_authority.pem'; //ROOT证书地址 $cp = 'production_push_certificates.pem'; //provider证书地址 $apns = new APNS(0, $cp); try { $apns->setRCA($rootpath); //设置ROOT证书 $apns->connect(); //连接 $apns->addDT('b9d98721b5586b61a00fbfa0d61a033954e1bfb8faaae3dfc5a1382xxxxxx'); //加入deviceToken $apns->setText($_POST["title"]); //发送内容 $apns->setBadge(1); //设置图标数 $apns->setSound(); //设置声音 $apns->setExpiry(3600); //过期时间 $apns->setCP('fljt', array('type' => '1', 'url' => 'http://www.google.com.hk')); //自定义操作 $apns->send(); //发送 } catch (Exception $e) { echo $e; } } $log = "推送消息【" . $_POST['title'] . "】"; break; } $this->log($log); $result = $this->dbHandler->insertdata($table, $info); if ($result == 1) { echo json_encode(array("result" => "success", "message" => "信息写入成功")); } else { echo json_encode(array("result" => "failed", "message" => "信息写入失败")); } }