Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // Global Var
- $base_url='http://apollo.gits.id:9000/v1';
- //Get Token
- $client_id='ahs';
- $client_secret='ahs_active';
- $grant_type='password';
- $username='Danone';
- $password='Danone';
- $api_path='/oauth/login';
- $constracttoken=$base_url.$api_path;
- $callAPItoken=CallAPI('POST',$constracttoken,array('client_id'=>$client_id,'client_secret'=>$client_secret,'grant_type'=>$grant_type,'username'=>$username,'password'=>$password));
- $jsdecodetoken=json_decode($callAPItoken);
- $accesstoken=$jsdecodetoken->access_token;
- // echo $accesstoken."<br>";
- //$constract=$base_url.$api_path.'?client_id='.$client_id.'&client_secret='.$client_secret.'&grant_type='.$grant_type.'&username='.$username.'&password='.$password;
- //echo $constract
- //$hitURL=file_get_contents($constract);
- //$response=json_decode($hitURL);
- //echo $hitURL;
- //$test=file_get_contents('http://google.com');
- //echo $test;
- //http://apollo.gits.id:9000/v1/oauth/login?client_id=ahs&client_secret=ahs_active&grant_type=password&username=Danone&password=Danone
- //$hitURL=file_get_contents('http://localhost:90/json/andy.json');
- //Use Token to Get Status
- $status_path='/consumers';
- $constractstatus=$base_url.$status_path;
- $search_type='phone_no';
- // $phone_number='6285224265251';
- // $phone_number='6282138262565';
- $getresponsestatus=file_get_contents($constractstatus.'?accessToken='.$accesstoken.'&search_type='.$search_type.'&search='.$phone_number);
- // echo $getresponsestatus;
- $jsdecodestatus=json_decode($getresponsestatus);
- // $consumerstatuscomplete=$jsdecodestatus->data->consumers[0]->status;
- $consumerstatus=$jsdecodestatus->data->consumers;
- // echo $getresponsestatus."<br>";
- // echo $consumerstatus."<br>";
- /* if ($consumerstatuscomplete="active") {
- echo "true";
- } elseif($consumerstatuscomplete=""){
- echo "false";
- }
- */
- if (!empty($consumerstatus)) {
- //echo 'terdaftar';
- $status='terdaftar';
- } else {
- //echo 'tidak terdaftar';
- $status='tidak terdaftar';
- }
- $showtext_1='{';
- $showtext_2='"messages": [';
- $showtext_3='{"text": "Status kamu adalah"},';
- // $showtext_4='{"text": "'.$status.'"}';
- $showtext_4='{"text": "rahasia"}';
- $showtext_5=']';
- $showtext_6='}';
- $showtext=$showtext_1.$showtext_2.$showtext_3.$showtext_4.$showtext_5.$showtext_6;
- $jsonencode=json_encode($showtext);
- $patterns = array();
- $patterns[0] = '/\\\\\"/';
- $replacements = array();
- $replacements[2] = "\"";
- $jsonencode= preg_replace($patterns, $replacements, $jsonencode);
- $jsonencode=trim($jsonencode, '"');
- echo $jsonencode;
- /* // Evaluates as true because $var is set
- if (isset($consumerstatus)) {
- if ($consumerstatuscomplete="active") {
- echo 'terdaftar';
- }
- }
- */
- //Reformat to Chatbot Client
- //New Function
- // Method: POST, PUT, GET etc
- // Data: array("param" => "value") ==> index.php?param=value
- function CallAPI($method, $url, $data = false)
- {
- $curl = curl_init();
- switch ($method)
- {
- case "POST":
- curl_setopt($curl, CURLOPT_POST, 1);
- if ($data)
- curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
- break;
- case "PUT":
- curl_setopt($curl, CURLOPT_PUT, 1);
- break;
- default:
- if ($data)
- $url = sprintf("%s?%s", $url, http_build_query($data));
- case "GET":
- curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
- if ($data)
- curl_setopt($curl, CURLOPT_RETURNTRANSFER, $data);
- break;
- }
- // Optional Authentication:
- curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
- curl_setopt($curl, CURLOPT_USERPWD, "username:password");
- curl_setopt($curl, CURLOPT_URL, $url);
- curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
- $result = curl_exec($curl);
- curl_close($curl);
- return $result;
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement