· 7 years ago · Dec 24, 2018, 07:04 AM
1//.....skrip sebelumya
2
3//data dari varible seperti di bawah di create pada skrip sebelumnya
4
5
6 // 'ta_akademik'=>$tahun_akademik,
7 // 'va_kode'=>$va_kode,
8 // 'pin'=>$pin,
9 // 'password'=>$password,
10 // 'nama' =>$nama,
11 // 'no_hp'=>$no_hp,
12 // 'email'=>$email,
13 // 'program_pen'=>$pilihan,
14 // 'tgl_daftar'=>date('Y-m-d'),
15
16require_once APPPATH . "/third_party/BniEnc.php";
17
18/*bgaian mulai data */
19
20$client_id = 'xxxxxx';
21$secret_key = 'xxxxxxxxxxxxx';
22$url = 'https://apibeta.bni-ecollection.com/';
23
24
25function get_content($url, $post = '') {
26 $usecookie = APPPATH . "/views/admin/bank/cookie.txt";
27 $header[] = 'Content-Type: application/json';
28 $header[] = "Accept-Encoding: gzip, deflate";
29 $header[] = "Cache-Control: max-age=0";
30 $header[] = "Connection: keep-alive";
31 $header[] = "Accept-Language: en-US,en;q=0.8,id;q=0.6";
32
33 $ch = curl_init();
34 curl_setopt($ch, CURLOPT_URL, $url);
35 curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
36 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
37 curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
38 curl_setopt($ch, CURLOPT_HEADER, false);
39 curl_setopt($ch, CURLOPT_VERBOSE, false);
40 // curl_setopt($ch, CURLOPT_NOBODY, true);
41 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
42 curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
43 curl_setopt($ch, CURLOPT_ENCODING, true);
44 curl_setopt($ch, CURLOPT_AUTOREFERER, true);
45 curl_setopt($ch, CURLOPT_MAXREDIRS, 5);
46
47 curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.120 Safari/537.36");
48
49 if ($post)
50 {
51 curl_setopt($ch, CURLOPT_POST, true);
52 curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
53 }
54
55 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
56
57 $rs = curl_exec($ch);
58
59 if(empty($rs)){
60 var_dump($rs, curl_error($ch));
61 curl_close($ch);
62 return false;
63 }
64 curl_close($ch);
65 return $rs;
66}
67
68$data_asli = array(
69 'type'=>'createBilling',
70 'client_id' => $client_id,
71 'trx_id' => mt_rand(),
72 'trx_amount' => $biaya,
73 'billing_type' => 'c',
74 'datetime_expired' => '2019-01-31 16:00:00',
75 'virtual_account' =>$va_kode,
76 'customer_name' => $nama,
77 'customer_email' =>$email,
78 'customer_phone' =>$no_hp,
79 'description'=>'Formulir SPMB - Universitas Ekasakti',
80);
81
82$hashed_string = BniEnc::encrypt(
83 $data_asli,
84 $client_id,
85 $secret_key
86);
87
88$data = array(
89 'client_id' => $client_id,
90 'data' => $hashed_string,
91);
92
93$response = get_content($url, json_encode($data));
94$response_json = json_decode($response, true);
95
96if ($response_json['status'] !== '000') {
97 // handling jika gagal
98 var_dump($response_json);
99}
100else {
101 $data_response = BniEnc::decrypt($response_json['data'], $client_id, $secret_key);
102 // $data_response will contains something like this:
103 // array(
104 // 'virtual_account' => 'xxxxx',
105 // 'trx_id' => 'xxx',
106 // );
107 var_dump($data_response);
108}
109
110
111/// permasalahan yang muncul bool(false) string(66) "Could not resolve host: apibeta.bni-ecollection.com; Unknown error" NULL