how to convert a json response to a text output.? - php

I am using a platforme call ideamart to create some sms based applications.
They provide a api called subscription api.
deatils about ideamart subscription API
Guid to work with subscription API
I use below first code to request BaseSize details.is that code is correct.?
can I Display response using PHP echo() Function .? or any other way.?
<?php
include_once "definitions.php";
include_once "subscription.php";
$sub = new Subscription();
$AppId = "APP_00001";
$Password = "yuhst345";
$baseSize = $sub->getBaseSize($AppId,$Password);
?>
here is the getBaseSize function that includes in subscription.php
public function getBaseSize($applicationId, $password){
$arrayField = array(
"applicationId" => $applicationId,
"password" => $password);
$jsonObjectFields = json_encode($arrayField);
$resp=$this->sendBaseRequest($jsonObjectFields);
$response = json_decode($resp, true);
$statusDetail = $response['statusDetail'];
$statusCode = $response['statusCode'];
$status =$response['baseSize'];
return $status;
}

So, it looks like your getBaseSize() is returning an simply the base size. So, you should be able to do a
print $baseSize;
OR
echo $baseSize;
And you'll print out the string.

Related

Basic authorization on PHP soapClient

I am trying to call a function on a web service defined on a Tomcat server, but I can not make the call due to a credentials failure.
The structure of this web service asks for a Basic Authorization embedded on the envelope (not the header itself). Using the SOAPui tool I have no problem to make this call entering the username and password. But using the PHP client is not possible to access the web service.
I have already tried to use nusoal library which actually works, but it doesn't help with the parameters because I can not filter the query. I mean is like this call doesn't use the parameters at all returning all the results.
I would like to give it a try with the default soapClient.
<?php
$username = "user";
$password = "pass";
$wsdl = 'http://192.168.1.185:8080/msw/gestionSolicitudes?wsdl';
$options = array(
'Username' => $username,
'Password' => $password,
);
$client = new SoapClient($wsdl, $options);
$parametros = array("statusId"=>2, "startDate"=>'2019-01-01', "endDate"=>'2019-09-01', "name"=>'Maria');
$result = $client->__soapCall('getSolicitudesLista', $parametros);
foreach ($result as &$valor) {
foreach ($valor as &$solicitud) {
if (is_object($solicitud)) {
echo nl2br (">>>Solicitud init ============================================\r\n");
....
} else {
echo nl2br (">>>Result ============================================\r\n\r\n");
var_dump($solicitud);
echo nl2br (">>>Result ============================================\r\n\r\n");
}
}
}
?>

How to create an "Application Signed Request" with Sinch using PHP

I am trying to use the Sinch Rest API with PHP to mute and unmute specific participants from Conference calls but have not been able to find an example of how to send an application signed request with PHP. I have been trying to work off of this documentation from Sinch here https://www.sinch.com/docs/voice/rest/index.html#muteunmuteconfparticipant
My initial guesses are that this would require the use of CURL and that I would also need to use similar pieces of this example to sign my application but I"m not sure how to combine the two. https://github.com/sinch/php-auth-ticket
Any help appreciated. Thanks!
edit: #cjensen I added this code snippet I've been working on to try and use as the signed request maker. It's very similar to that github link above
<?php
class SinchTicketGenerator
{
private $applicationKey;
private $applicationSecret;
public function __construct($applicationKey, $applicationSecret)
{
$this->applicationKey = $applicationKey;
$this->applicationSecret = $applicationSecret;
}
public function generateTicket()
{
$request = [
'command' => 'mute',
];
$requestJson = preg_replace('/\s+/', '', json_encode($request));
$requestBase64 = $this->base64Encode($requestJson);
$digest = $this->createDigest($requestJson);
$signature = $this->base64Encode($digest);
$requestSigned = $requestBase64.':'.$signature;
return $requestSigned;
}
private function base64Encode($data)
{
return trim(base64_encode($data));
}
private function createDigest($data)
{
return trim(hash_hmac('sha256', $data, base64_decode($this->applicationSecret), true));
}
}
$generator = new SinchTicketGenerator('app-key', 'app-secret');
$signedrequest = $generator->generateTicket();
echo $signedrequest;
?>

How to avoid getting page number as a string using slim framework?

I am using slim 2.x framework for developing a web service. When I use 'get' request method its working fine but all the parameters getting are string. I want 'page' parameter as a numeric value. How to change this in slim. Below is my code.
$app->get('/listings','getListings');
/* Run the application */
$app->run();
function getListings(){
global $api_obj;//api obj
$response = array();//array
$app = \Slim\Slim::getInstance();
$req = $app->request;
$page = $req->get('page');
$response = $api_obj->api_Listings($page); //return
echoResponse(200, $response);
}
You can use a simple cast to get the integer from it:
$page = (int)$req->get('page');
//or
$page = intval($req->get('page'));
Ex: https://3v4l.org/cUqVA

magento : how to add parameter with soap request

I am new to Magento I tried calling a category level using the Magento SOAP API with parent category id. I used the following code:
<?php
$proxy = new SoapClient('http://domain/index.php/api/soap/?wsdl');
$session = $proxy->login('user', 'password');
$result = $proxy->call($session,'catalog_category.level');
echo json_encode($result);
?>
For the above code "Default Category" details are coming, I tried to call some other category by using the following code:
$result = $proxy->call($session,'catalog_category.level',12);
This is not working:
$arguments = array( 'parentCategory' => 12);
$result = $proxy->call($session,'catalog_category.level',$arguments);
This is also not working:
Then I tried calling category tree using following code:
<?php
$proxy = new SoapClient('http://domain/index.php/api/soap/?wsdl');
$session = $proxy->login('user', 'password');
$result = $proxy->call($session,'catalog_category.tree');
echo json_encode($result);
?>
It shows the entire category tree so it means API is working but whenever I try to pass an argument it shows server not found error.
Can anyone please tell me how to pass arguments with the request.
You will need to call it like
$proxy->call($sessionId, 'category.level', array(null, null, 12));
For more information about the function check class
Mage_Catalog_Model_Category_Api
function level($website = null, $store = null, $categoryId = null)
If you want to pass particular website and store you can pass it instead of null parameter.
i manage to get output using soapv2. but it is slow compare to soapv1 but it is giving the required out put. the code i use to pass parameter is given as below.
<?php
$proxy = new SoapClient('http://domain/index.php/api/v2_soap/?wsdl=1');
$session = $proxy->login((object)array('username' => 'user', 'apiKey' => 'password'));
$result = $proxy->catalogCategoryTree((object)array('sessionId' => $session->result, 'parentId' => '12'));
echo json_encode($result);
?>

SOAP error. Not getting correct structure returned

I have a website that contains a form that makes various SOAP requests at certain points. One of these requests gets a list of induction times returned and displays them to the user in order for them to pick one.
I am getting results returned fine from the SOAP service but unfortunately it seems to be not showing information correctly and even not displaying returned object keys at all.
I have liased with one of the devs at the SOAP end and he says the service is fine and spitting out the cirrect information. He has provided a screentshot:
Here is my code to pull call the method I need for this information:
public function getInductionTimes($options) {
$client = $this->createSoapRequest();
$inductionTimes = $client->FITinductionlist($options);
//die(print_r($inductionTimes));
return $inductionTimes;
}
private function createSoapRequest() {
$url = 'https://fitspace.m-cloudapps.com:444/FITSPACE/MHservice.asmx?WSDL';
$options["connection_timeout"] = 25;
$options["location"] = $url;
$options['trace'] = 1;
$options['style'] = SOAP_RPC;
$options['use'] = SOAP_ENCODED;
$client = new SoapClient($url, $options);
//die(print_R($client->__getFunctions()));
return $client;
}
As you can see I print_r the code right after I have received it to check what I am getting returned and it is this:
As you can see this IDdtstring field is getting completely ignored.
Does anyone have any ideas as to why this may be happening? Is it something to do with encoding? I can't seem to get anywhere on this issue!
Thanks
I was able to retrieve the fields correctly, including IDdtstring, using your basic code. Perhaps you are not sending the parameters correctly?
function getInductionTimes($options) {
$client = createSoapRequest();
$inductionTimes = $client->FITinductionlist($options);
die(print_r($inductionTimes));
return $inductionTimes;
}
function createSoapRequest() {
$url = 'https://fitspace.m-cloudapps.com:444/FITSPACE/MHservice.asmx?WSDL';
$options["connection_timeout"] = 25;
$options["location"] = $url;
$options['trace'] = 1;
$options['style'] = SOAP_RPC;
$options['use'] = SOAP_ENCODED;
$client = new SoapClient($url, $options);
//die(print_R($client->__getFunctions()));
return $client;
}
getInductionTimes(array("IDDate" => "2013-06-28T13:00:00+01:00", "GYMNAME" => "Bournemouth"));
I managed to solve this issue by adding the line of code into my SOAP options array which I then presume was an issue with my WSDL being cached in PHP:
$options['cache_wsdl'] = WSDL_CACHE_NONE;

Categories