Created
March 14, 2017 13:07
-
-
Save Pittan/be9c22593f4a98a57ae8e2637d8d8d95 to your computer and use it in GitHub Desktop.
Convert
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// AngularでCORSのエラー出て面倒なので(ほんとはちゃんとやりたいけど) | |
header("Access-Control-Allow-Origin: *"); | |
// IPアドレスさすがにアレなので、自分で見つけてきてね | |
$url = "http://XXX.XXX.XXX.XXX:XXXX/dataspider/trigger/path"; | |
$json = file_get_contents($url); | |
// 最終的に返すデータ | |
$response = array(); | |
$twres = array(); | |
$webres = array(); | |
foreach (json_decode($json, true) as $key => $val) { | |
$tmpElements = array(); | |
foreach ($val as $k => $v) { | |
if ($k == "twitterContent" || $k == "webContent") { | |
//この2つだけJSONをパースして改めてオブジェクトとして返す | |
$tmpElements[$k] = json_decode($v); | |
} else { | |
$tmpElements[$k] = $v; | |
} | |
} | |
if ($tmpElements['twitterContent']) array_push($twres, $tmpElements); | |
if ($tmpElements['webContent']) array_push($webres, $tmpElements); | |
} | |
$i = 0; | |
for ($i = 0; $i <30 ; $i++) { | |
if ($i % 2 == 0) { | |
$el = array_shift ($webres); | |
if ($el) array_push($response, $el); | |
} else { | |
$el = array_shift ($twres); | |
if ($el) array_push($response, $el); | |
} | |
} | |
echo json_encode($response, JSON_UNESCAPED_UNICODE); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment