How to use php soap instead of nusoap - php

I've got an specification web app that uses nusoap extension. But on our server runs php 5.5.
I tried to rewrite this example below but its beyond my capabilities...
Here is the script i want to rewrite to use soap in php without nusoap:
<?php
require_once('lib/nusoap.php');
$Client = new nusoap_client( 'https://letsgo-test.org', array( 'encoding'=>'UTF-8' ) );
$Client -> soap_defencoding = 'utf-8';
$Client -> decode_utf8 = FALSE;
$CMsg = array( 'user_name' => 'letsgo', 'user_password' => '123' );
$bClient = $Client->call( 'Login', $CMsg );
$szSession = $bClient[ 'session' ];
$bCPrep = array(
'rname1' => 'Lets',
'rname2' => 'Go',
'rcountry' => 'ORG',
'rzipcode' => '00-770',
);
$CMsg = array( 'session' => $szSession, 'consign_prep_data' => $bCPrep );
$bClient = $Client->call( 'adePreparingBox_Insert', $CMsg );
print_r( $bClient );
$CMsg = array( 'session' => $szSession );
$bClient = $Client->call( 'Logout', $CMsg );
?>
I will be gratefull for any help!!!.

Yep! I found solution!
Its not that hard as i thought,
Some of declarations looks diffrent:
$szSession = $bClient[ 'session' ];
changed to
$szSession = $bClient->session;
instead of "call" you need to use "__soapCall"
So thats what you need to do to free from nusoap.php
I guess there are more things to change but its enought for me.
Best Regards!

Related

Facebook Ads SDK - Unsupported Post Request

I got some example scripts from Facebook App Management to use the Marketing API. When I run the script, I just get this error by curl:
'Unsupported post request. Object with ID \'105101623679981\' does not exist, cannot be loaded due to missing permissions, or does not support this operation.
I already tried to deactivate the Sandbox Mode and go public, tried many different scripts in different languages and also other keys.
Any Ideas?
This is the Script:
<?php
//Add all those Uses and the autoloader
$access_token = '<my_very_long_accessToken';
$ad_account_id = '<my_account_id>'; //<-- This is the Object in the Error Code
$app_secret = '<my_app_secret>';
$page_id = '<my_page_id>';
$app_id = '<my_app_is>';
$api = Api::init($app_id, $app_secret, $access_token);
$api->setLogger(new CurlLogger());
$fields = array(
);
$params = array(
'objective' => 'PAGE_LIKES',
'status' => 'PAUSED',
'buying_type' => 'AUCTION',
'name' => 'My Campaign',
);
$campaign = (new AdAccount($ad_account_id))->createCampaign(
$fields,
$params
);
$campaign_id = $campaign->id;
echo 'campaign_id: ' . $campaign_id . "\n\n";
$fields = array(
);
$params = array(
'status' => 'PAUSED',
'targeting' => array('geo_locations' => array('countries' => array('US'))),
'daily_budget' => '1000',
'billing_event' => 'IMPRESSIONS',
'bid_amount' => '20',
'campaign_id' => $campaign_id,
'optimization_goal' => 'PAGE_LIKES',
'promoted_object' => array('page_id' => $page_id),
'name' => 'My AdSet',
);
//...
Yeah. I got it. It has to be "act_"
So bad. The Script is really crappy. So many Errors. And it's created by facebook!

Php: Create web push notification

I want to create a web push notification in Php but I don't have the exact procedure for it. Following is the code I found, but it is not working.
<?php
require __DIR__ . '/../vendor/autoload.php';
use Minishlink\WebPush\WebPush;
$subscription = json_decode(file_get_contents('php://input'), true);
$auth = array(
'VAPID' => array(
'subject' => '`enter code here`',
'publicKey' => '**********',
'privateKey' => '***********',
),
);
$webPush = new WebPush($auth);
$res = $webPush->sendNotification(
$subscription['endpoint'],
"Hello!",
$subscription['key'],
$subscription['token'],
true
);
Please suggest the correct steps.
I spent some time my self figuring this out. I'm posting the code as it works for me. Generate the keys from here https://web-push-codelab.glitch.me/
<?php
require_once './vendor/autoload.php';
use Minishlink\WebPush\WebPush;
// array of notifications
$notifications = array(
array(
'endpoint' => 'https://fcm.googleapis.com/fcm/send/abcd........', // Chrome
'payload' => 'Hello',
'userPublicKey' => 'BFHh..........',
'userAuthToken' => 'DI............',
)
);
$auth = array(
'GCM' => 'AAAAKTK8bp4..............', // deprecated and optional, it's here only for compatibility reasons
'VAPID' => array(
'subject' => 'Some Text', // can be a mailto: or your website address
'publicKey' => 'BGsm2vrV2AMpT.............', // (recommended) uncompressed public key P-256 encoded in Base64-URL
'privateKey' => 'a89H............', // (recommended) in fact the secret multiplier of the private key encoded in Base64-URL
),
);
$defaultOptions = array(
'TTL' => 300, // defaults to 4 weeks
'urgency' => 'normal', // protocol defaults to "normal"
'topic' => 'push', // not defined by default - collapse_key
);
$webPush = new WebPush($auth, $defaultOptions);
$vr = $webPush->sendNotification(
$notifications[0]['endpoint'],
$notifications[0]['payload'], // optional (defaults null)
$notifications[0]['userPublicKey'], // optional (defaults null)
$notifications[0]['userAuthToken'], // optional (defaults null)
true // optional (defaults false)
);

Unable to log in or create users in MediaWiki

I am unable to log in / create a New user in a MediaWiki wiki.
It throws the error:
Account creation error: Incorrect password entered. Please try again.
Or when I try to log in:
Log-in error :Incorrect password entered. Please try again.
Based on the help documents in MediaWiki added the below code in the localsettings.php file.
I have also added the php-ldap service though command prompt in my local ubuntu machine.
LDAP Settings in Local Settings.php
require_once 'extensions/LdapAuthentication/LdapAuthentication.php';
require_once 'includes/AuthPlugin.php';
$wgAuth = new LdapAuthenticationPlugin();
$wgLDAPDomainNames = array(
'MDomain',
);
$wgLDAPServerNames = array(
'MDomain.local' => '10.10.1.6','MDomain-C02.MDomain','MDomain01.MDomain.local',
);
$wgLDAPUseLocal = false;
$wgLDAPEncryptionType = array(
'MDomain.LOCAL' => 'tls',
);
$wgLDAPPort = array(
'openldap_example_com' => 389,
);
$wgLDAPProxyAgent = array(
'MDomain.local' => 'cn=wikimedia-service,dc=MDomain,dc=LOCAL',
);
$wgLDAPProxyAgentPassword = array(
'MDomain.local' => 'XXXX',
);
$wgLDAPSearchAttributes = array(
'MDomain.local' => 'sAMAccountName'
);
$wgLDAPBaseDNs = array(
'MDomain.local' => 'ou=MDomain,dc=MDomain,dc=local',
);
# To pull e-mail address from LDAP
$wgLDAPPreferences = array(
'MDomain.local' => array( 'email' => 'mail')
);
# Group based restriction
$wgLDAPGroupUseFullDN = array( "MDomain.local"=>false );
$wgLDAPGroupObjectclass = array( "MDomain.local"=>"Group" );
$wgLDAPGroupAttribute = array( "MDomain.local"=>"memberuid" );
$wgLDAPGroupSearchNestedGroups = array( "MDomain.local"=>true );
$wgLDAPGroupNameAttribute = array( "MDomain.local"=>"cn" );
$wgLDAPRequiredGroups = array( "MDomain.local"=>array("cn=wikimedia-service,dc=MDomain,dc=local"));
$wgLDAPLowerCaseUsername = array(
'MDomain.local' => true,
);
Can you please let me know if i am missing anything.

Fedex Web Services: ERROR 9040 - Can't pull up tracking

I'm having issues attempting to pull up tracking info using Fedex's Web Services. I am using a valid tracking number and I'm able to view the details on Fedex's site. However, I get an error 9040 "No information for the following shipments has been received by our system yet. Please try again or contact Customer Service at 1.800.Go.FedEx(R) 800.463.3339." Am I leaving something out?
My code:
<?php
$path_to_wsdl = "URL_TO_WSDL";
ini_set("soap.wsdl_cache_enabled", "0");
$client = new SoapClient($path_to_wsdl, array('trace' => 1));
$request['WebAuthenticationDetail'] = array(
'UserCredential' =>array(
'Key' => 'MY_KEY',
'Password' => 'MY_PASSWORD'
)
);
$request['ClientDetail'] = array(
'AccountNumber' => 'MY_ACCT',
'MeterNumber' => 'MY_METER'
);
$request['TransactionDetail'] = array('CustomerTransactionId' => 'ActiveShipping');
$request['Version'] = array(
'ServiceId' => 'trck',
'Major' => '5',
'Intermediate' => '0',
'Minor' => '0'
);
$request['PackageIdentifier'] = array(
'Value' => 'TRACKING#',
'Type' => 'TRACKING_NUMBER_OR_DOORTAG');
$response = $client->track($request);
var_dump($response);
?>
Got it!
Call the web services departement and they told me to remove 'beta' from the wsdl file. This appears to be a different address than what I found in responses to this problem before. On line 1507 of the wsdl file, make the following change:
From:
<s1:address location="https://wsbeta.fedex.com:443/web-services/track"/>
To
<s1:address location="https://ws.fedex.com:443/web-services/track"/>
I changed the rest of my code slightly, but that shouldn't have made the difference. To be on the safe side, here it is:
<?php
$path_to_wsdl = "PATH_TO_WSDL_FILE";
$client = new SoapClient($path_to_wsdl, array('trace' => 1));
$trackRequest = array(
'WebAuthenticationDetail' => array(
'UserCredential' => array(
'Key' => 'MY_KEY',
'Password' => 'MY_PASSWORD'
)
),
'ClientDetail' => array(
'AccountNumber' => 'MY_ACCT_#',
'MeterNumber' => 'MY_METER_#'
),
'Version' => array(
'ServiceId' => 'trck',
'Major' => '5',
'Intermediate' => '0',
'Minor' => '0'
),
'PackageIdentifier' => array(
'Type' => 'TRACKING_NUMBER_OR_DOORTAG',
'Value' => 'THE_TRACKING_#',
),
'CustomerTrasactionId',
'IncludeDetailedScans' => 1
);
$response = $client->track($trackRequest);
var_dump($response);
?>
I'm also working on this same problem. I'm trying several things and you can see if anything works for you. Try including ShipDateRangeBegin and End elements, your test account/payer numbers or destination info. I've found here that switching to xml and ssl post requests supposedly solve the problem, but it's not an option for me. Maybe it will help you?
I have same problem when use xml-request. I solved the problem this way:
$endpointurl = "https://gatewaybeta.fedex.com:443/xml"; // remove word "beta"
$endpointurl = "https://gateway.fedex.com:443/xml";
...
$request = stream_context_create($form);
$browser = fopen($endpointurl , 'rb' , false , $request);
$response = stream_get_contents($browser);
...

PHP Soap non-WSDL call: how do you pass parameters?

I'm trying to make a non-WSDL call in PHP (5.2.5) like this. I'm sure I'm missing something simple. This call has one parameter, a string, called "timezone":
$URL = 'http://www.nanonull.com/TimeService/TimeService.asmx';
$client = new SoapClient(null, array(
'location' => $URL,
'uri' => "http://www.Nanonull.com/TimeService/",
'trace' => 1,
));
// First attempt:
// FAILS: SoapFault: Object reference not set to an instance of an object
$return = $client->__soapCall("getTimeZoneTime",
array(new SoapParam('ZULU', 'timezone')),
array('soapaction' => 'http://www.Nanonull.com/TimeService/getTimeZoneTime')
);
// Second attempt:
// FAILS: Generated soap Request uses "param0" instead of "timezone"
$return = $client->__soapCall("getTimeZoneTime",
array('timezone'=>'ZULU' ),
array('soapaction' => 'http://www.Nanonull.com/TimeService/getTimeZoneTime')
);
Thanks for any suggestions
-Dave
Thanks. Here's the complete example which now works:
$URL = 'http://www.nanonull.com/TimeService/TimeService.asmx';
$client = new SoapClient(null, array(
'location' => $URL,
'uri' => "http://www.Nanonull.com/TimeService/",
'trace' => 1,
));
$return = $client->__soapCall("getTimeZoneTime",
array(new SoapParam('ZULU', 'ns1:timezone')),
array('soapaction' => 'http://www.Nanonull.com/TimeService/getTimeZoneTime')
);
#Dave C's solution didn't work for me. Looking around I came up with another solution:
$URL = 'http://www.nanonull.com/TimeService/TimeService.asmx';
$client = new SoapClient(null, array(
'location' => $URL,
'uri' => "http://www.Nanonull.com/TimeService/",
'trace' => 1,
));
$return = $client->__soapCall("getTimeZoneTime",
array(new SoapParam(new SoapVar('ZULU', XSD_DATETIME), 'timezone')),
array('soapaction' => 'http://www.Nanonull.com/TimeService/getTimeZoneTime')
);
Hope this can help somebody.
The problem lies somewhere in the lack of namespace information in the parameter. I used the first case of your example since it was closest to what I came up with.
If you change the line:
array(new SoapParam('ZULU', 'timezone')),
to:
array(new SoapParam('ZULU', 'ns1:timezone')),
it should give you the result you expected.
You could try to add another array() call around your params like this:
$params = array('timezone'=>'ZULU' );
$return = $client->__soapCall("getTimeZoneTime",
array($params),
array('soapaction' => 'http://www.Nanonull.com/TimeService/getTimeZoneTime')
);
I can't test this, but you could.

Categories