function makeRequest()
 {
     $request = $this->client->createRequest('GET', $this->apiRequestUrl);
     $request->setHeader('Content-Type', 'application/xml');
     //$request->setHeader('Cache-Control: no-cache');
     $request->setHeader('Fk-Affiliate-Id', $this->fkAffiliateToken);
     $request->setHeader('Fk-Affiliate-Token', $this->fkAffiliateToken);
     $response = $this->client->send($request);
     $responseCode = $response->getStatusCode();
     if ($responseCode == 410 || $responseCode == 403 || $responseCode == 401) {
         returnApiError();
     }
     //echo $response->xml();
     print_r($response->xml());
 }
Example #2
0
        break;
    }
}
if ($isExist == false) {
    returnApiError('no exist this id');
    exit('');
}
$dataArr[$upIndex]['name'] = $name;
$dataArr[$upIndex]['age'] = $age;
$dataArr[$upIndex]['sex'] = $sex;
$dataArr = array_filter($dataArr);
//去删除数组中的空元素
$json_string = json_encode($dataArr);
$ifSuccess = file_put_contents('data.json', $json_string);
if ($ifSuccess != false) {
    returnApiSuccess($ifSuccess);
} else {
    returnApiError('file put fail');
}
function returnApiSuccess($msg = null)
{
    //执行成功时返回
    $result = array('flag' => 'success', 'msg' => $msg);
    print json_encode($result);
}
function returnApiError($msg = null)
{
    //执行失败时返回
    $result = array('flag' => 'error', 'msg' => $msg);
    print json_encode($result);
}
Example #3
0
        $beginSearchIndex = $indexTable_array[$i - 1]['maxIndex'];
        $endSearchIndex = $indexTable_array[$i]['maxIndex'];
        break;
    }
}
$dataArr = json_decode($dataFile_json_string, true);
//将相应的文件json字符串转为数组
for ($j = $beginSearchIndex; $j <= $endSearchIndex; $j++) {
    //通过用户传入的key,找到相对应的下标
    if (intval($id) == intval($dataArr[$j]['key'])) {
        $isExist = true;
        break;
    }
}
if ($isExist == false) {
    returnApiError('no exist this id');
    exit('');
}
for ($i = $beginSearchIndex; $i <= $endSearchIndex; $i++) {
    if ($id == $dataArr[$i]['key']) {
        //当数组中的key与用户请求的id相等时
        returnApiSuccess($dataArr[$i]);
        break;
    }
}
function returnApiSuccess($data = array())
{
    //请求成功时调用,返回数据。
    $result = array('flag' => 'success', 'data' => array('id' => $data['key'], 'name' => $data['name'], 'sex' => $data['sex'], 'age' => $data['age']));
    print json_encode($result);
}
Example #4
0
}
for ($k = count($dataArr) + 1; $k > $insertIndex - 1; $k--) {
    $dataArr[$k] = $dataArr[$k - 1];
}
$dataArr[$insertIndex] = $newStu;
$dataArr = array_filter($dataArr);
//删除数组中的空元素
$dataArr = array_values($dataArr);
//去除键
$json_string = json_encode($dataArr);
$ifSuccess = file_put_contents('data.json', $json_string);
if ($ifSuccess != false) {
    newTable($dataArr);
    returnApiSuccess($ifSuccess);
} else {
    returnApiError();
}
function returnApiSuccess($msg = null)
{
    //请求成功时调用,返回数据。
    $result = array('flag' => 'success', 'msg' => $msg);
    print json_encode($result);
    exit('');
}
function returnApiError($msg = null)
{
    //请求失败时调用,返回失败信息
    $result = array('flag' => 'error', 'msg' => $msg);
    print json_encode($result);
    exit('');
}