本文整理汇总了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);
}