本文整理匯總了PHP中Ajax::error方法的典型用法代碼示例。如果您正苦於以下問題:PHP Ajax::error方法的具體用法?PHP Ajax::error怎麽用?PHP Ajax::error使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Ajax
的用法示例。
在下文中一共展示了Ajax::error方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: getItems4Client
function getItems4Client()
{
$DB = new PDO('mysql:host=' . DB_HOST . ';dbname=' . DB_NAME, DB_USERNAME, DB_PASSWORD);
$table = DB_TABLE;
//檢查一下是否存在表
$sql = "SHOW TABLES LIKE '%{$table}%';";
$rc = $DB->query($sql)->rowCount();
if (!$rc) {
$sqlFile = file_get_contents('items.sql');
$DB->exec($sqlFile);
}
$sql = "SELECT * FROM `{$table}` LIMIT 0,10";
$query = $DB->query($sql);
$query->setFetchMode(PDO::FETCH_ASSOC);
$rt = $query->fetchAll();
if ($rt) {
$items = array();
foreach ($rt as $item) {
$tmp = array();
$tmp['openid'] = $item['tb_item_id'];
$tmp['iid'] = $item['tb_iid'];
$tmp['price'] = $item['price'] ? $item['price'] / 100 : $item['reserve_price'] / 100;
$tmp['name'] = $item['name'];
$tmp['pic'] = $item['pic'];
$tmp['itemType'] = $item['is_mall'] + 1;
// 客戶端判斷是 1:集市店,2:天貓店
$items[] = $tmp;
}
Ajax::go($items);
} else {
Ajax::error('數據查詢失敗.');
}
}
示例2: sendGoogleCloudMessage
public function sendGoogleCloudMessage($data)
{
// GCM url
$url = 'https://android.googleapis.com/gcm/send';
// Message goes here
$msg = array('message' => array('name' => $data['name'], 'message' => $data['message'], 'location' => $data['location']));
// Device id where we want to send notification
$ids = array($data['apid']);
$post = array('registration_ids' => $ids, 'data' => $msg, 'time_to_live' => 15);
// Applicaiton registration key
$headers = array('Authorization: key=' . $this->apikey, 'Content-Type: application/json');
// Hiting GCM api via CURL..
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($post));
$result = curl_exec($ch);
if (curl_errno($ch)) {
Ajax::error(curl_errno($ch));
}
print_r($ch);
curl_close($ch);
}
示例3: justDemo
function justDemo()
{
/*
* 第一步: 接收頁麵提交上來的參數,簡單校驗一下
*/
// $itemUrl = $_REQUEST['itemUrl'];
// $appKey = $_REQUEST['appKey'];
// $appSecret = $_REQUEST['appSecret'];
$itemUrl = 'https://detail.tmall.com/item.htm?id=520360573194&skuId=3101727199054';
$appKey = '23285002';
$appSecret = '0559365a08a6c5c71c321df373591512';
if (empty($itemUrl) && empty($appKey) && empty($appSecret)) {
Ajax::error('請求參數錯誤!');
}
$itemId = getIdInUrl($itemUrl);
if (empty($itemId)) {
Ajax::error('url錯誤,未能獲取到商品id!');
}
/*
* 第二步: 調用top接口拿到商品數據
* 接口說明文檔地址:
* http://api.taobao.com/apidoc/api.htm?path=scopeId:11471-apiId:23731
*/
$c = new TopClient();
$c->appkey = $appKey;
$c->secretKey = $appSecret;
$req = new TaeItemsListRequest();
$req->setFields('num,title,nick,pic_url,location,cid,price,post_fee,promoted_service');
$req->setNumIids($itemId);
$resp = $c->execute($req);
if (!isset($resp['items'])) {
//缺少權限包,則跳轉到權限申請頁麵
if (isset($resp['msg']) && isset($resp['sub_code']) && $resp['msg'] == 'Insufficient isv permissions' && $resp['sub_code'] == 'isv.permission-api-package-limit') {
Ajax::error('isv.permission-api-package-limit');
}
Ajax::error('top接口獲取商品失敗');
}
/*
* 第三步: 整理數據入庫
*/
$DB = new PDO('mysql:host=' . DB_HOST . ';dbname=' . DB_NAME, DB_USERNAME, DB_PASSWORD);
$table = DB_TABLE;
if (isset($resp['items']) && isset($resp['items']['x_item']) && isset($resp['items']['x_item'][0])) {
$tmp = $resp['items']['x_item'][0];
}
//檢查一下是否存在表
$sql = "SHOW TABLES LIKE '%{$table}%';";
$rc = $DB->query($sql)->rowCount();
if (!$rc) {
$sqlFile = file_get_contents('items.sql');
$DB->exec($sqlFile);
}
//檢查是否存在該商品
$openId = $tmp['open_auction_iid'];
$sql = "SELECT * FROM `{$table}` WHERE `tb_item_id` LIKE '{$openId}'";
$query = $DB->query($sql);
$query->setFetchMode(PDO::FETCH_ASSOC);
$rs = $query->fetchAll();
if ($rs) {
Ajax::error('已經存在該商品.');
} else {
$sql = "INSERT INTO `{$table}`\n (`id`, `pic`, `reserve_price`, `price`, `tb_item_id`,`tb_iid`, `name`, `is_mall`)\n VALUES\n (NULL,\n '" . $tmp['pic_url'] . "',\n '" . $tmp['reserve_price'] * 100 . "',\n '" . $tmp['price'] * 100 . "',\n '" . $tmp['open_auction_iid'] . "',\n '" . $itemId . "',\n '" . $tmp['title'] . "',\n '" . ($tmp['mall'] ? 1 : 0) . "');";
$rs = $DB->exec($sql);
if (!$rs) {
Ajax::error('數據入庫失敗.');
}
}
/*
* 最後: 返回數據,前端可以通過控製台查看數據結果.
*/
Ajax::go($resp);
}