Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function store(Request $request)
- {
- $usr = $request->username;
- $pwd = $request->password;
- $secretKey = 'ZHNvOnd2c2RuMGRicDQ5bzZieDV6dWtxdnRrdnlrNnA5cw==';
- $postData = "username=".
- $usr."&password=".
- $pwd."&grant_type=password";
- // API START HERE
- $url = "https://api.zoomin.id/v1/login";
- $request_headers = array(
- 'content-type: application/x-www-form-urlencoded',
- 'Authorization: Basic ' . $secretKey
- );
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($ch, CURLOPT_TIMEOUT, 60);
- curl_setopt($ch, CURLOPT_HTTPHEADER, $request_headers);
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
- // curl_setopt($ch, CURLOPT_POST, count($postData));
- curl_setopt($ch, CURLOPT_POST, 1);
- curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
- $data = curl_exec($ch);
- if (curl_errno($ch))
- {
- print "Error: " . curl_error($ch);
- }
- else
- {
- $transaction = json_decode($data, FALSE);
- }
- curl_close($ch);
- if ($transaction->code == 200) {
- foreach ($transaction->data as $tkn){
- $acc_token = $tkn;
- }
- // API REQUEST START
- $url = "http://api.zoomin.id/v1/profiles/me";
- $request_headers = array(
- 'content-type: application/x-www-form-urlencoded',
- 'Authorization: Bearer ' . $acc_token
- );
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($ch, CURLOPT_TIMEOUT, 60);
- curl_setopt($ch, CURLOPT_HTTPHEADER, $request_headers);
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
- // curl_setopt($ch, CURLOPT_POST, 1);
- // curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
- $data = curl_exec($ch);
- if (curl_errno($ch))
- {
- print "Error: " . curl_error($ch);
- }
- else
- {
- $rslt = json_decode($data, FALSE);
- }
- curl_close($ch);
- Session::put('token',$acc_token);
- Session::put('username',$rslt->data->profiles->username);
- Session::put('name',$rslt->data->profiles->name);
- return redirect('blog');
- // $data = array(
- // 'username' => $rslt->data->profiles->username,
- // 'name' => $rslt->data->profiles->name,
- // );
- // dd($rslt);
- } else {
- print_r($transaction);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement