I'm working on an application that sends SMS to the customers we got.
I'm currently looking the doc (https://docs.ovh.com/fr/sms/envoyer_des_sms_avec_lapi_ovh_en_php/) => it's in french.
They're using a PHP Wrapper, but I really don't know how I can integrate the API to my Laravel Project.
Does someone know how it's working ?
First of all, install the package
composer require ovh/php-ovh-sms
Then, on the controller, you can use the API easily as stated in the documentation.
use \Ovh\Sms\SmsApi;
// Informations about your application
// You may set them to 'NULL' if you are using
// a configuraton file
$applicationKey = "your_app_key";
$applicationSecret = "your_app_secret";
$consumerKey = "your_consumer_key";
$endpoint = 'ovh-eu';
// Init SmsApi object
$Sms = new SmsApi( $applicationKey, $applicationSecret, $endpoint, $consumerKey );
// Get available SMS accounts
$accounts = $Sms->getAccounts();
dd($accounts);
There is a Laravel notification channel specifically for this provider, this will make the whole process much easier, it will allow you to use Laravel's built in notifications functionality without having to write provider specific code.
http://laravel-notification-channels.com/ovh-sms/
Related
How do we authenticate the app to the Firestore? (not using service account), because when service account have conflicts when security rules which needs authenticate. When I'm switching to production mode and perform a query I got this message
This is the rules that is set in the production mode
match /{document=**} {
allow read, write: if request.auth!=null;
}
match /projects/{document=**} {
allow read, write;
}
And this is my code. This code only works in the test mode how do I make this work in the production mode?
public function __construct(){
global $key;
$this->firestore = new FirestoreClient([
'keyFilePath' => $key,
'projectId' => 'test-4c1ff'
]);
}
If you are using https://github.com/kreait/firebase-php/, the documentation shows how to initialize Firebase Authentication, and then sign-in with one of the many supported providers.
Once you're signed in, the authentication information is securely passed with your requests to the database and you can then access it as request.auth in your security rules as shown here.
You need to authenticate your PHP app first to the Firebase in order your App to make a request.
To do that, follow this quick solution which I recently discovered.
First You must create your own authentication email and password in your Firebase Authenticate Console.
Install this package on your App:
composer require kreait/firebase-php
Once you are done installing the package, you may proceed here.
use Kreait\Firebase\Factory;
use Kreait\Firebase\Auth;
use Kreait\Firebase\Auth\SignInResult;
$key = ""
$factory = (new Factory)
->withServiceAccount($key)
->withDatabaseUri('Your Firebase Database URi');
$auth = $factory->createAuth();
$email = "Your Email";
$password = "Your Password";
$signInResult = $auth->signInWithEmailAndPassword($email, $password);
note: Remember, this is only static and you have to make the entire function to make this more dynamic.
Now you can make a request to the firebase without getting block by the security rules.
Reference:
I'm trying to configure the google-api-php-client library in my project.
I've already created a custom google app engine project that consists in a cloud endpoint. The project is called 'set-core', the service is called 'vrp API', version 'v1' and the method vrp.vrp.getSolution().
Now in my PHP code i'm following this example:
https://developers.google.com/api-client-library/php/start/get_started#building-and-calling-a-service
The problem is that in this example there's no mention how to connect to any custom service, outside Google's ones.
My PHP code is:
$client = new Google_Client();
$client->setApplicationName("set-core");
$client->setDeveloperKey("AIzaSyByd8cRJNGYC4szFLbr3**************");
$client->isAppEngine(true);
$service = new Google_Service_Appengine_Service($client);
$results = $service->vrp->vrp.vrp.getSolution($stringVehicles, $stringServices, $stringDepot);
Unfortunately, on the last line, PHP warns me:
Notice: Trying to get property of non-object (I assume it's $service).
The problem is that I don't really know how to set up all the client's params and which Service type use.
You are going to want to create an authorized HTTP client and then request your API endpoint directly with it. The AppEngine service classes you're manipulating above are not meant for this use case. Something like this should work:
$client = new Google_Client();
$client->useApplicationDefaultCredentials();
$httpClient = $client->authorize();
$response = $httpClient->request('GET', 'https://myapp.appspot.com/vrp/getSolution');
The $httpClient class is an instance of GuzzleHttp\Client, but with your Google authentication already added to it. See the documentation for making a request with Guzzle.
I hope this helps!
Our iOS app should receive push notification. Following this tutorial I implemented these methods in application delegate:
didRegisterForRemoteNotificationsWithDeviceToken
and
didFailToRegisterForRemoteNotificationsWithError
which are called by didFinishLaunchingWithOptions and it seems that the device is correctly registered in our MySQL service. Moreover, I have just created a pem sandbox certification that I will use for testing. Now, I need to know what I should do at the backend in PHP. Which code is required? We are using Zend framework so I should implement function preparetosend_apple()in my mapper and sendtoappleAction() in our controller but I don't know where to start from and how to test it. Thank you!
First thing is sending push notification directly from application is not a good idea as this call can be blocking one (means the rest of the codeblock will wait for its completion). So I suggest using background processor/message queuing services (like gearman, zero mq, etc.).
Secondly easiest solution will be using Parse like services. Parse allows registering the app using the certificates you mentioned and has SDK for php (composer based).
In the background service you just call the API from SDK. Like:
use Parse\ParseClient;
use Parse\ParseInstallation;
use Parse\ParsePush;
ParseClient::initialize($appId, $restKey, $masterKey, $curlDebug);
...
...
...
Using channel in parse
$response = ParsePush::send(array(
"channels" => ["channel-$userId"],
"data" => $data,
));
OR using custom query
$query = ParseInstallation::query();
$query->equalTo('userId', "user-$userId");
$response = ParsePush::send(array(
"where" => $query,
"data" => $data,
));
The best part of using parse - I will say using other interesting features like -- broadcast messages, device listings, etc.
Hope this may help you.
I am following this guide (http://www.lornajane.net/posts/2013/oauth-middleware-for-slim) to setup oAuth2 with php SLIM.
I dont't understand this part:
$auth = new \Service\Mysql\AuthService($this->mysql, $this->config);
$validated_user_id = $auth->verifyOAuth($authHeader);
$this->app->user_id = $validated_user_id;
Where can I take the class \Service\Mysql\AuthService and what is the variable config ?
Otherwise is there another guide with more details also without direct SLIM implementation ?
Thanks
That's the service class that will actually do the loading and storing of user details.
Then you should put your own class.
This could be useful: https://github.com/alexbilbie/oauth2-example-resource-server
This is making me crazy. I've been trying out all sorts of things but I just can't figure this out. LinkedIn's documentation is horrible...
All I need to do is simple: I need to search for a company (using a keyword) and retrieve the company id. I have issues with setting up the OAuth request and with making the request. Any advice on how to do this, especially without installing any PHP libraries?
FYI, my code: I got the OAuth.php from here.
require_once 'OAuth.php';
$base_url = 'http://api.linkedin.com/v1/company-search';
$consumer = new OAuthConsumer('mykey', 'mysecret');
$token = new OAuthToken('tokenkey', 'tokensecret');
$parameters = array (keyword => 'Apple');
$request = OAuthRequest::from_consumer_and_token($consumer, $token, "GET", $base_url, $parameters);
print_r($request);
Thanks
You're using a good OAuth library that I do recommend, but it seems to me you're missing on the Linkedin Library, or at least you haven't included the full code.
In any case, try using the simple-linkedinphp library, which uses your oauth library above. I had to use a few libraries in the past, and this is one of the best, particuarly if you're going to use Faceted search. Make sure you also check the quick start guide, it will help you a lot, as well as the class reference. The company search API function could be found here.
You could always use the raw() function for any custom calls not supported by the above function. I had to use that for some calls.