Tolong pilih kategori sesuai, jenis posting (pertanyaan atau bukan) dan sertakan tag/topik yang sesuai misal komputer, php, mysql, dll.
Promosi atau posting tidak pada tempatnya akan kami hapus.
Mencantumkan kode program di posting Anda, tolong ikuti aturan yang sesuai, baca http://diskusiweb.com/discussion/39204/aturan-cara-menyisipkan-kode-program-di-diskusiweb

Baca cara posting gambar/image di post Anda: http://www.diskusiweb.com/discussion/47345/cara-menyisipkan-menyertakan-image-pada-posting/p1

help php, menampilkan hasil web service

salam hormat utk semua master2 :)
sy lagi belaajr mengambil data dari web service, dlm hal ini bpjs.
setelah googling bbrp hari akhirnya bisa juga narik data.
sekaerang mau tampilkan hasilnya pd web browser secara normal.
yg sekrang hasilnya masih format xml array spt ini:

X-cons-id: 10000
X-timestamp:1482453990
X-signature: WjxoyUkoufzuey37VQeBLDYosr3MjWQKb/BRUo3B0eo=

Array
(
[peserta] => Array
(
[informasi] => Array
(
[dinsos] =>
[iuran] =>
[noSKTM] =>
[prolanisPRB] =>
)

[jenisPeserta] => Array
(
[kdJenisPeserta] => 3
[nmJenisPeserta] => PNS DAERAH
)

[kelasTanggungan] => Array
(
[kdKelas] => 2
[nmKelas] => KELAS II
)

[nama] => IWAN MUH TAHIR
[nik] =>
[noKartu] => 000019447xxxx
[noMr] =>
[pisa] => 2
[provUmum] => Array
(
[kdCabang] =>
[kdProvider] => 1819U923
[nmCabang] =>
[nmProvider] => POLI PEG KTR GUBERNUR SULBAR
)

[sex] => L
[statusPeserta] => Array
(
[keterangan] => AKTIF
[kode] => 0
)

[tglCetakKartu] => 2016-12-23
[tglLahir] => 1969-04-24
[tglTAT] => 2069-04-24
[tglTMT] => 2010-08-23
[umur] => Array
(
[umurSaatPelayanan] =>
[umurSekarang] => 47 tahun ,4 bulan ,1 hari
)

)

)

Yang harapkan dapat tampil normal seperti ini:

Nama : IWAN MUH TAHIR
NIk :
tglLahir : 24-04-1969
No Kartu : 000019447xxxx

Kelas : KELAS II
umur Sekarang : 47 tahun ,4 bulan ,1 hari

Ini kode sy yg diatas:

<?php

$data = "10000";
$secretKey = "12456789";
$url = "http://dvlp.bpjs-kesehatan.go.id:8081/devWsLokalRest/Peserta/Peserta/";
$nik = "000019447xxxx";

date_default_timezone_set('UTC');
$tStamp = strval(time()-strtotime('1970-01-01 00:00:00'));
$signature = hash_hmac('sha256', $data."&".$tStamp, $secretKey, true);
$encodedSignature = base64_encode($signature);
$urlencodedSignature = urlencode($encodedSignature);

echo "X-cons-id: " .$data ."<br>";
echo "X-timestamp:" .$tStamp ."
";
echo "X-signature: " .$encodedSignature."
";

$opts = array(
'http'=>array(
'method'=>"GET",
'header'=>"Host: dvlp.bpjs-kesehatan.go.id:8081\r\n".
"Connection: close\r\n".
"X-timestamp: ".$tStamp."\r\n".
"X-signature: ".$encodedSignature."\r\n".
"User-Agent: Mozilla/5.0 (Windows NT 6.3; Win64; x64)\r\n".
"X-cons-id: ".$data."\r\n".
"Accept: application/json\r\n"
)
);

$context = stream_context_create($opts);

$result = file_get_contents($url.$nik, false, $context);
echo "
Respon:";
if ($result === false)
{
echo "Tidak dapat menyambung ke server";
} else {
$resultarr=json_decode($result, true);
@$s=$resultarr['response']['start'];
@$l=$resultarr['response']['limit'];
@$c=$resultarr['response']['count'];

echo "
Ditemukan ".$c." data, tampil mulai dari nomor ".$s." hingga nomor ".$l."
";
for($i=0;$i<$c;$i++){
echo "<h1>Nama: ".$resultarr['response']['list'][$i]['nama']."";
}

echo "
";
print_r($resultarr['response']);
echo "
";
}

?>

sy sd coba pake perintah foreach, tapi masih gagal.

Semoga ada yg bisa bantu, dan terima kasih

Tanggapan

  • $resultarr kalo di print_r hasil nya seperti apa?
  • sudah ada di atas mas. spt ini:

    Array
    (
    [peserta] => Array
    (
    [informasi] => Array
    (
    [dinsos] =>
    [iuran] =>
    [noSKTM] =>
    [prolanisPRB] =>
    )

    [jenisPeserta] => Array
    (
    [kdJenisPeserta] => 3
    [nmJenisPeserta] => PNS DAERAH
    )

    [kelasTanggungan] => Array
    (
    [kdKelas] => 2
    [nmKelas] => KELAS II
    )

    [nama] => IWAN MUH TAHIR
    [nik] =>
    [noKartu] => 000019447xxxx
    [noMr] =>
    [pisa] => 2
    [provUmum] => Array
    (
    [kdCabang] =>
    [kdProvider] => 1819U923
    [nmCabang] =>
    [nmProvider] => POLI PEG KTR GUBERNUR SULBAR
    )

    [sex] => L
    [statusPeserta] => Array
    (
    [keterangan] => AKTIF
    [kode] => 0
    )

    [tglCetakKartu] => 2016-12-23
    [tglLahir] => 1969-04-24
    [tglTAT] => 2069-04-24
    [tglTMT] => 2010-08-23
    [umur] => Array
    (
    [umurSaatPelayanan] =>
    [umurSekarang] => 47 tahun ,4 bulan ,1 hari
    )

    )

    )
  • gak ngerti gw, di print_r yg dikasih gak ada index response,
    tapi di code ente ada index response.

    Bisa lebih rapi lagi hasil print_r nya?

    Contoh print_r array yg rapi:
    Array
    (
    [0] => Array
    (
    [tgl_cuti] => 2016-12-01
    [jml_jam] => 8
    )
     
    [2] => Array
    (
    [tgl_cuti] => 2016-12-15
    [jml_jam] => 8
    )
     
    )

  • Array
    (
    [peserta] => Array
    (
    [informasi] => Array
    (
    [dinsos] =>
    [iuran] =>
    [noSKTM] =>
    [prolanisPRB] =>
    )

    [jenisPeserta] => Array
    (
    [kdJenisPeserta] => 22
    [nmJenisPeserta] => PBI (APBD)
    )

    [kelasTanggungan] => Array
    (
    [kdKelas] => 3
    [nmKelas] => KELAS III
    )

    [nama] => TRI ARNI
    [nik] => 3174016909650001
    [noKartu] => 0001261832477
    [noMr] =>
    [pisa] => 3
    [provUmum] => Array
    (
    [kdCabang] =>
    [kdProvider] => 09020107
    [nmCabang] =>
    [nmProvider] => KEL. MANGGARAI SELATAN
    )

    [sex] => P
    [statusPeserta] => Array
    (
    [keterangan] => AKTIF
    [kode] => 0
    )

    [tglCetakKartu] => 2014-12-17
    [tglLahir] => 1965-09-29
    [tglTAT] => 2050-12-31
    [tglTMT] => 2014-01-09
    [umur] => Array
    (
    [umurSaatPelayanan] =>
    [umurSekarang] => 51 tahun ,3 bulan ,6 hari
    )

    )

    )
  • sudah rapi yaa? :smile:
  • gagal apanya nih?
    bagian ini :
    @$s=$resultarr['response']['start'];
    @$l=$resultarr['response']['limit'];
    @$c=$resultarr['response']['count'];

    itu array start / limit / count dari mana?
    Sementara data dump dari $resultarr['response'] yg lu berikan cuma 'peserta'.
Sign In or Register to comment.