Im working on SMS integration for Opencart I have purchased SMS's from a company. Now I have API like this :
http://smst.abcd.co.in/submitsms.jsp?user=ABCDEF&key=12c7ca6975XX&mobile=+911234567890&message=test%20sms&senderid=ABCDEF&accusage=1
Im looking for some extension where i would able to put this integration, if anybody have any ideas, please let me know. thanks alot in advance.
Create a library for SMS gateway and place it in your system/library folder..
class SendSMS{
public $user = 'ABCDEF';
public $key = '12c7ca6975XX';
public function send($mobile,$message,$senderid,$accusage) {
$service_url = 'http://smst.abcd.co.in/submitsms.jsp?user=' . $user . '&key=' . $key . '&mobile=' . $mobile . '&message=' . $message . '&senderid=' . $senderid . '&accusage=' . $accusage;
$curlObj = curl_init($service_url);
curl_setopt($curlObj, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($curlObj);
curl_close($curlObj);
if($response === false) {
return 'failed';
} else {
return 'success';
}
}
}
Then call this library function from your controller..
$sms = new SendSMS();
$sms->send('+911234567890','test%20sms','ABCDEF',1);
Related
I'm trying to use Facebook's PHP SDK. The code that makes a call to Facebook to retrieve user's information is saved in a file called fbcall.php. The fbcall.php page is called through an href link from another page called index.php
The Entire Code (index.php):
<?php
echo "Login Here";
?>
Index.php is also my FacebookRedirectLoginHelper redirect url.
The question I have is that I'm not seeing an output for the following statement in the fbcall.php file and I'm not sure why?
echo "Name: " . $user_profile->getName();
I get the sense that my sessions isn't initiated but I'm sure how to validate this. And if it isn't initiated then I'm not sure what i'm doing wrong considering I'm following Facebook's guidelines here (or atleast I think I am).
The Entire Code (fbcall.php):
<?php
session_start();
// Make sure to load the Facebook SDK for PHP via composer or manually
require_once 'autoload.php';
//require 'functions.php';
use Facebook\FacebookSession;
use Facebook\FacebookRedirectLoginHelper;
use Facebook\FacebookRequest;
use Facebook\FacebookResponse;
use Facebook\FacebookSDKException;
use Facebook\FacebookRequestException;
use Facebook\FacebookAuthorizationException;
use Facebook\GraphObject;
use Facebook\Entities\AccessToken;
use Facebook\HttpClients\FacebookCurlHttpClient;
use Facebook\HttpClients\FacebookHttpable;
// add other classes you plan to use, e.g.:
// use Facebook\FacebookRequest;
// use Facebook\GraphUser;
// use Facebook\FacebookRequestException;
FacebookSession::setDefaultApplication('AM USING MY APP ID HERE','AM USING MY SECRET KEY HERE');
$helper = new FacebookRedirectLoginHelper('http://localhost/facebook/index.php');
$params = array('email','public_profile', 'user_status', 'user_friends');
$loginUrl = $helper->getLoginUrl($params);
try {
$session = $helper->getSessionFromRedirect();
// var_dump($session);
} catch(FacebookRequestException $ex) {
} catch(\Exception $ex) {
}
if (isset($session)) {
var_dump($session);
}
else
{
$loginUrl = $helper->getLoginUrl();
header("location:".$loginUrl);
exit;
}
$request = new FacebookRequest($session, 'GET', '/me');
$response = $request->execute();
$graphObject = $response->getGraphObject();
if(isset($session)) {
try {
$user_profile = (new FacebookRequest(
$session, 'GET', '/me'
))->execute()->getGraphObject(GraphUser::className());
echo "Name: " . $user_profile->getName();
} catch(FacebookRequestException $e) {
echo "Exception occured, code: " . $e->getCode();
echo " with message: " . $e->getMessage();
}
}
?>
Once the user grant your permissions, he/she will be redirected to index.php (because of your redirect_uri).
So there is two solutions:
- change you're redirect_uri to be fbcall.php
- move all fbcall.php logic to index.php, and change header("location:".$loginUrl); by echo "Login Here";
I am trying to do a simple soap call to a weather service and I keep getting Invalid ZIP error. Can someone tell me what I am doing wrong below is my code.
Thanks
require_once 'SOAP/Client.php';
$client = new Soap_Client('http://wsf.cdyne.com/WeatherWS/Weather.asmx?WSDL');
$method = 'GetCityWeatherByZIP';
$params = array('ZIP' => '07108');
$result = $client->call($method, $params);
if (PEAR::isError($result)) {
echo $result->getMessage();
} else {
print_r($result);
}
Use PHP's in-built SOAP client. The one in PEAR was written at a time PHP did not have one itself.
Their service is no SOAP service. The wiki states:
$url = "http://wsf.cdyne.com/WeatherWS/Weather.asmx/GetCityForecastByZIP";
$url .= "?ZIP=" . $this->ZipCode;
$this->response = simplexml_load_file($url) or die("ERROR");
I've read the facbeook blog post about how to handle expired access tokens here: https://developers.facebook.com/blog/post/2011/05/13/how-to--handle-expired-access-tokens/
But a few things are not clear to me and it's making it difficult for me to progress. I've listed both the sample code from the blog, and my own php code. I'd mostly like to know just what changes I need to make to my code so the code from the blog will work in my own. I also have some questions about specific code from the blog. For starters where is $_REQUEST["code"] is coming from?
If you look at my code you'll see that I'm trying to send a notification to a user, I get the app access token before hand, and make the api call that sends the the access token along with it; but in the sample code the graph call gets made with curl_file_get_contents() instead of $facebook->api, what do I do about that? Does $facebook->api return the same kind of response as curl_file_get_contents()? Because the sample code checks that response for errors and redirects if there is one.
//PHP SAMPLE CODE FROM THE BLOG
<?php
$app_id = "YOUR_APP_ID";
$app_secret = "YOUR_APP_SECRET";
//IS THIS SUPPOSED TO BE MY CANVAS APP URL?
$my_url = "YOUR_POST_LOGIN_URL";
// known valid access token stored in a database
$access_token = "YOUR_STORED_ACCESS_TOKEN";
//WHERE IS THIS $CODE VARIABLE COMING FROM?
$code = $_REQUEST["code"];
if (isset($code)) {
$token_url="https://graph.facebook.com/oauth/access_token?client_id="
. $app_id . "&redirect_uri=" . urlencode($my_url)
. "&client_secret=" . $app_secret
. "&code=" . $code . "&display=popup";
$response = file_get_contents($token_url);
$params = null;
parse_str($response, $params);
$access_token = $params['access_token'];
}
// ATTEMPT TO QUERY THE GRAPH
$graph_url = "https://graph.facebook.com/me?"
. "access_token=" . $access_token;
$response = curl_get_file_contents($graph_url);
$decoded_response = json_decode($response);
//CHECK FOR ERRORS
if ($decoded_response->error) {
// check to see if this is an oAuth error:
if ($decoded_response->error->type== "OAuthException") {
// Retrieving a valid access token.
$dialog_url= "https://www.facebook.com/dialog/oauth?"
. "client_id=" . $app_id
. "&redirect_uri=" . urlencode($my_url);
echo("<script> top.location.href='" . $dialog_url
. "'</script>");
}
else {
echo "other error has happened";
}
}
else {
// success
echo("success" . $decoded_response->name);
echo($access_token);
}
// note this wrapper function exists in order to circumvent PHP’s
//strict obeying of HTTP error codes. In this case, Facebook
//returns error code 400 which PHP obeys and wipes out
//the response.
function curl_get_file_contents($URL) {
$c = curl_init();
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($c, CURLOPT_URL, $URL);
$contents = curl_exec($c);
$err = curl_getinfo($c,CURLINFO_HTTP_CODE);
curl_close($c);
if ($contents) return $contents;
else return FALSE;
}
?>
//MY PHP
$token_url ="https://graph.facebook.com/oauth/access_token?" .
"client_id=" . $APP_ID .
"&client_secret=" . $APP_SECRET .
"&grant_type=client_credentials";
$app_token = file_get_contents($token_url);
$app_token = str_replace("access_token=", "", $app_token);
$data = array(
'href'=> 'https://apps.facebook.com/thebringernetwork/',
'access_token'=> $app_token,
'template'=> 'test'
);
// HOW DO I USE THAT ERROR CHECKING CODE AT THIS POINT?
$facebook->api('/16xxxxx3/notifications', 'post', $data);
I am using the following script from facebook example:
The script grabs the e-mail fine but hometown and location trigger a 500 error on my server. I need to grab the data for statistics.
<?php
$app_id = "API_ID_GOES_HERE";
$app_secret = "SECRET_GOES_HERE";
$my_url = "REDIRECT_URL_GOES_HERE";
$permissions ="user_hometown,user_location,email";
session_start();
$code = $_REQUEST["code"];
if(empty($code)) {
$_SESSION['state'] = md5(uniqid(rand(), TRUE)); //CSRF protection
$dialog_url = "http://www.facebook.com/dialog/oauth?client_id="
. $app_id . "&redirect_uri=" . urlencode($my_url) . "&scope=".$permissions.
"&state="
. $_SESSION['state'];
echo("<script> top.location.href='" . $dialog_url . "'</script>");
}
if($_REQUEST['state'] == $_SESSION['state']) {
$token_url = "https://graph.facebook.com/oauth/access_token?"
. "client_id=" . $app_id . "&redirect_uri=" . urlencode($my_url)
. "&scope=".$permissions. "&client_secret=" . $app_secret . "&code=" . $code;
$response = file_get_contents($token_url);
$params = null;
parse_str($response, $params);
$graph_url = "https://graph.facebook.com/me?access_token="
. $params['access_token'];
$user = json_decode(file_get_contents($graph_url));
echo("Hello " . $user->name);
echo ("Location ". $user->location);
}
else {
echo("The state does not match. You may be a victim of CSRF.");
}
?>
I found the answer. Using this $user->hometown->name Will get the Hometown array and the Name object.
EX. [hometown] => stdClass Object ( [id] => 111806898837603 [name] => San Antonio, Texas )
$user->hometown->name
OUTPUT:
San Antonio, Texas
I would take the URLs you are creating to get the user info off the graph api (i.e. $graph_url) and paste them into your browser to inspect the data facebook is returning, and go from there. If the URL's are returning proper information, then you know you are getting the right data back. Use the Graph API Explorer (https://developers.facebook.com/tools/explorer) to test the URL's you are creating for the graph API. You can see what results look like with different permissions granted and code accordingly for the response. Hope that helps!
Am doing one project ,
For that my client asked amazon payment gateway ,
So now i started exploring amazon payment gateway ,
This is the first time am looking the amazon payment gateway ,
I have registered in amazon payment gateway,
Please tell me PHP CODE snippet for amazon payment gateway ,
Thanks
Amazon has different payment products. Checkout by Amazon is their usual product, but it works best for products that you actually ship by mail. SimplePay is probably best for electronic goods and services - which I discovered too late. Make sure you sign up for the right thing. :)
Here's the PHP code for a "Pay Now" button for one item using a POST form submission:
// Key from Amazon
$merchant_id = 'your_id';
$aws_access_key_id = 'your_access_key';
$aws_secret_access_key = 'your_secret_access_key';
// Set up cart
$form['aws_access_key_id'] = $aws_access_key_id;
$form['currency_code'] = 'USD';
$form['item_merchant_id_1'] = $merchant_id;
$form['item_price_1'] = $price;
$form['item_quantity_1'] = $quantity;
$form['item_sku_1'] = $sku;
$form['item_title_1'] = $item_name;
ksort($form);
// Encode order as string and calculate signature
$order = '';
foreach ($form as $key => $value) {
$order .= $key . "=" . rawurlencode($value) . "&";
}
$form['merchant_signature'] = base64_encode(hash_hmac('sha1', $order, $aws_secret_access_key, true));
// Return string with Amazon javascript and HTML form
// Assumes you already have jQuery loaded elsewhere on page
// URL's link to live site, not sandbox!
$amazon_order_html =
'<script type="text/javascript" src="https://images-na.ssl-images-amazon.com/images/G/01/cba/js/widget/widget.js"></script>
<form method="post" action="https://payments.amazon.com/checkout/' . $merchant_id . '">';
foreach ( $form as $key => $value ) {
$amazon_order_html .= '<input type="hidden" name="' . $key . '" value="' . $value . '" />';
}
$amazon_order_html .= '<input alt="Checkout with Amazon Payments" src="https://payments.amazon.com/gp/cba/button?ie=UTF8&color=orange&background=white&cartOwnerId=' . $merchant_id . '&size=large" type="image"></form>';
return $amazon_order_html;
For simple pay when account is created, user will be given a sandbox access in which you find the "Merchant code" at this URL : https://sandbox.simplepay.hu/admin/partner/account/id(partnerid)