· 7 years ago · Nov 23, 2018, 07:14 AM
1public function store(Request $request)
2 {
3 $usr = $request->username;
4 $pwd = $request->password;
5 $secretKey = 'ZHNvOnd2c2RuMGRicDQ5bzZieDV6dWtxdnRrdnlrNnA5cw==';
6
7 $postData = "username=".
8 $usr."&password=".
9 $pwd."&grant_type=password";
10
11 // API START HERE
12 $url = "https://api.zoomin.id/v1/login";
13 $request_headers = array(
14 'content-type: application/x-www-form-urlencoded',
15 'Authorization: Basic ' . $secretKey
16 );
17
18 $ch = curl_init();
19 curl_setopt($ch, CURLOPT_URL, $url);
20 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
21 curl_setopt($ch, CURLOPT_TIMEOUT, 60);
22 curl_setopt($ch, CURLOPT_HTTPHEADER, $request_headers);
23 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
24 // curl_setopt($ch, CURLOPT_POST, count($postData));
25 curl_setopt($ch, CURLOPT_POST, 1);
26 curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
27 $data = curl_exec($ch);
28 if (curl_errno($ch))
29 {
30 print "Error: " . curl_error($ch);
31 }
32 else
33 {
34 $transaction = json_decode($data, FALSE);
35 }
36 curl_close($ch);
37 if ($transaction->code == 200) {
38 foreach ($transaction->data as $tkn){
39 $acc_token = $tkn;
40 }
41 // API REQUEST START
42 $url = "http://api.zoomin.id/v1/profiles/me";
43 $request_headers = array(
44 'content-type: application/x-www-form-urlencoded',
45 'Authorization: Bearer ' . $acc_token
46 );
47 $ch = curl_init();
48 curl_setopt($ch, CURLOPT_URL, $url);
49 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
50 curl_setopt($ch, CURLOPT_TIMEOUT, 60);
51 curl_setopt($ch, CURLOPT_HTTPHEADER, $request_headers);
52 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
53 // curl_setopt($ch, CURLOPT_POST, 1);
54 // curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
55 $data = curl_exec($ch);
56 if (curl_errno($ch))
57 {
58 print "Error: " . curl_error($ch);
59 }
60 else
61 {
62 $rslt = json_decode($data, FALSE);
63 }
64 curl_close($ch);
65 Session::put('token',$acc_token);
66 Session::put('username',$rslt->data->profiles->username);
67 Session::put('name',$rslt->data->profiles->name);
68 return redirect('blog');
69 // $data = array(
70 // 'username' => $rslt->data->profiles->username,
71 // 'name' => $rslt->data->profiles->name,
72 // );
73 // dd($rslt);
74 } else {
75 print_r($transaction);
76 }
77
78 }