Whatsapp API php code request - php

Following is my code to CodeRequest.
$username = "91xxxxxxxxxx";
$identity = strtolower(urlencode(sha1($username, true)));
$w = new WhatsProt($username, $identity, "test", true);
$r = $w->codeRequest();
print_r($r);
It gives the response as
stdClass Object ( [status] => sent [length] => 6 [method] => sms [retry_after] => 1805 )
But I'm not receiving message. Any suggestions please.
My other questions.
Is there any restriction to request code.(Every time I use new mobile number).?
For example I request a code for mobile number xxx with user agent galaxys3 shall i request another code with mobile number yyy using the same user agent?
I'm using WhatsAPI-Official

Finally I received code to mobile.
$username = "91xxxxxxxxxx";
$identity = "myIdentity";
$w = new WhatsProt($username, $identity, "test", true);
$r = $w->codeRequest('sms',$carrier);
(or)
$r = $w->codeRequest('voice',$carrier); //Voice service is fast compared to sms
$carrier is getting from networkinfo.csv file.
carrier is nothing but mobile network operator(Airtel,Idea etc.,) according to your mobile country code(mcc) and mobile network code (mnc).
You can get the mnc and mcc codes from mobile-network-codes-country-codes
Get mcc and mnc codes with your location and operation match them with networkinfo.csv to get carrier name.
Eg: My number is 919xxxxxx
country - india ( Andhra Pradesh )
operator - Idea
For above link mcc and mnc are for my number is 404 & 7
Now check those codes in networkinfo.csv file
i.e
404,1028,007,7,in,India,91,Idea Cellular Ltd.4
Here 404 -> mcc
and 007 -> mnc
My carrier name is Idea Cellular Ltd.4
If you send correct carrier name you will get sms/call to mobile.

Try this piece of code.
$destinationPhone = 'xxxxxxxxxxxx';
$w = new WhatsProt($userPhone, $userIdentity, $userName, $debug);
$w->Connect();
$w->LoginWithPassword($password);
$w->Message($destinationPhone, $argv[1]);
or more info refer this link..
http://blog.philippheckel.com/2013/07/07/send-whatsapp-messages-via-php-script-using-whatsapi/#Send-WhatsApp-messages

Related

Dhru Api - getting customer input

I try to make dhru api based on this code https://github.com/dhru/dhru-fusion-api-standards .
My problem is to get customer input on web which is sent by dhru web in parameters.
I already determinated what exacly website send to my API:
[username] => login
[apiaccesskey] => pass
[action] => placeimeiorder
[requestformat] => JSON
[parameters] => <PARAMETERS><ID>100</ID><CUSTOMFIELD>eyJ1ZGlkIjoiMDAwMDgwMjAtMDAxQzM0MTIyNjgxMDAyRSJ9</CUSTOMFIELD><MODELID></MODELID><PROVIDERID></PROVIDERID><NETWORK></NETWORK><PIN></PIN><KBH></KBH><MEP></MEP><PRD></PRD><TYPE></TYPE><LOCKS></LOCKS><REFERENCE></REFERENCE><IMEI>423545675567658</IMEI><udid>00008020-001C34122681002E</udid></PARAMETERS>
But i'm unable to get any value from this parameters.
I already tried all of this but nothing work:
1) $udid = json_decode($parameters['udid'],true);
2) $udid = $parameters['udid'];
3) $imei = $parameters['IMEI'];
4) $udid = (string)$parameters['udid'];
Can somebody give me advice?

Bing Ads Offline Conversion confusion after proper OATH process

I am using https://github.com/BingAds/BingAds-PHP-SDK to send offline conversion data to Bing. I am successfully able to connect and call different service using OATH. But when I am trying to send offline conversion request I am failed. Bing SOAP request's example for Offline conversion requests https://msdn.microsoft.com/en-us/library/bing-ads-campaign-management-applyofflineconversions.aspx
Now, I need help from you guys, If I want to send ApplyOfflineConversionsRequest what approach should I use SoapVar and then CampaignManagement ApplyOfflineConversions? I am asking this because I am not very well known about the Bing API v11.
After my proper OATH process
//Setting the account id as CustomerAccountId in the header element as per Bing API Doc
$GLOBALS['AuthorizationData']->AccountId = $obj->Id;
//send offline conversion
$offline = new OfflineConversion();
$offline->ConversionCurrencyCode = 'USD';
$offline->ConversionName = 'OfflineConversionSellOfRentals';
$offline->ConversionTime = date('Y-m-d\TH:i:s', strtotime('-7 days'));
$offline->ConversionValue = 2.5;
$offline->MicrosoftClickId = '8349a6501442491186ce602ca56881fe';
$offline_response = new SoapVar($offline, SOAP_ENC_OBJECT, 'OfflineConversion', $GLOBALS['CampaignProxy']->GetNamespace());
$request[] = $offline_response;
$offline_response = CampaignManagementHelper::ApplyOfflineConversions($request);
print_r($offline_response);
I have created a static method inside CampaignManagementHelper.php file because I didn't find any implementation of AddOfflineConversion method on the Bing API SDK.
static function AddOfflineConversion($offline){
$GLOBALS['Proxy'] = $GLOBALS['CampaignProxy'];
$request = new ApplyOfflineConversionsRequest();
$request->OfflineConversions[] = $offline;
return $GLOBALS['CampaignProxy']->GetService()->ApplyOfflineConversions($request);
}
I am able to import offline CSV conversion that means My UET Tags and Conversion Goal are enabled.
I am having a hard time because I didn't get any sample example for how to request for offline conversion requests.
Response from Bing API call:
stdClass Object
(
[PartialErrors] => stdClass Object
(
)
)

Issues with twilio sms module in PhP

I am trying to test the twilio sms reminder library with a trial account I created for this purpose. The problem is that when I launch the file from my XAMPP "webroot" folder that also contains the "Twilio" folder I see nothing, just a blank page on Mozilla Firefox while on IE the error code 500 is up. Please find my code below thank you.
<?php
require $_SERVER['DOCUMENT_ROOT']."/openemr/twilio/Services/Twilio.php";
// Step 2: set our AccountSid and AuthToken from www.twilio.com/user/account
$AccountSid = "yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy";
$AuthToken = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
// Step 3: instantiate a new Twilio Rest Client
$client = new Services_Twilio($AccountSid, $AuthToken);
// Step 4: make an array of people we know, to send them a message.
// Feel free to change/add your own phone number and name here.
$people = array(
"+14158675309" => "Curious George",
"+14158675310" => "Boots",
"+14158675311" => "Virgil",
);
// Step 5: Loop over all our friends. $number is a phone number above, and
// $name is the name next to it
foreach ($people as $number => $name) {
$sms = $client->account->messages->sendMessage(
// Step 6: Change the 'From' number below to be a valid Twilio number
// that you've purchased, or the (deprecated) Sandbox number
"+12057198157",
// the number we are sending to - Any phone number
$number,
// the sms body
"Hey $name, Monkey Party at 6PM. Bring Bananas!"
);
// Display a confirmation message on the screen
echo "Sent message to $name";
}

How do I submit an address to Paypal Express Checkout?

I'm in the process of writing some code that will submit an order to Paypal Express Checkout. Unforunately I can't seem to get the whole address thing to work, and I also can't seem to find much info on it in the API docs. Here's my code so far.
$config = array (
'mode' => 'sandbox' ,
'acct1.UserName' => '****removed*****',
'acct1.Password' => '******removed*******',
'acct1.Signature' => '*********removed***********'
);
$paypalService = new PayPal\Service\PayPalAPIInterfaceServiceService($config);
$paymentDetails= new PayPal\EBLBaseComponents\PaymentDetailsType();
// Dummy shipping address
// Obviously, in the final version, this would be passed in from a form
$shipping_address = new PayPal\EBLBaseComponents\AddressType();
$shipping_address->Name = "John Smith";
$shipping_address->Street1 = "123 Market Street";
$shipping_address->Street2 = "";
$shipping_address->CityName = "Columbus";
$shipping_address->StateOrProvince = "OH";
$shipping_address->PostalCode = "43017";
$shipping_address->Country = "US";
// A dummy item
// Once again, in a final version this would be passed in
$itemDetails = new PayPal\EBLBaseComponents\PaymentDetailsItemType();
$itemDetails->Name = 'Electro Lettuce Feeders';
$itemAmount = 1250.00;
$itemDetails->Amount = $itemAmount;
$itemQuantity = 1;
$itemDetails->Quantity = $itemQuantity;
// Add all items to the list
$paymentDetails->PaymentDetailsItem[0] = $itemDetails;
// The company is in NYS, so in the final version the
// sales tax rate will be passed in (NYS is destination-based)
$sales_tax_rate = 0.07;
// Order sub-total
$itemTotal = new PayPal\CoreComponentTypes\BasicAmountType();
$itemTotal->currencyID = 'USD';
$itemTotal->value = ($itemAmount * $itemQuantity);
// Shipping total
$shippingTotal = new PayPal\CoreComponentTypes\BasicAmountType();
$shippingTotal->currencyID = 'USD';
$shippingTotal->value = 2.00;
// Tax total
$taxTotal = new PayPal\CoreComponentTypes\BasicAmountType();
$taxTotal->currencyID = 'USD';
$taxTotal->value = $itemTotal->value * $sales_tax_rate;
// Order total
$orderTotal = new PayPal\CoreComponentTypes\BasicAmountType();
$orderTotal->currencyID = 'USD';
$orderTotal->value = $itemTotal->value + $taxTotal->value + $shippingTotal->value;
$paymentDetails->TaxTotal = $taxTotal;
$paymentDetails->ItemTotal = $itemTotal;
$paymentDetails->ShippingTotal = $shippingTotal;
$paymentDetails->OrderTotal = $orderTotal;
$paymentDetails->PaymentAction = 'Sale';
// ***** Is the address from this object passed to Paypal?
$paymentDetails->ShipToAddress = $shipping_address;
$setECReqDetails = new PayPal\EBLBaseComponents\SetExpressCheckoutRequestDetailsType();
$setECReqDetails->PaymentDetails[0] = $paymentDetails;
$setECReqDetails->CancelURL = 'https://devtools-paypal.com/guide/expresscheckout/php?cancel=true';
$setECReqDetails->ReturnURL = 'https://devtools-paypal.com/guide/expresscheckout/php?success=true';
// ***** Or is this the address that will be passed to Paypal?
$setECReqDetails->Address = $shipping_address;
// ***** And can you choose to not pass in the billing address? Or is it required? *****
$setECReqDetails->BillingAddress = $shipping_address;
// ***** If this is set to 0, will the previously provided shipping address be shown
// ***** at all? Or will it just be "modify-able" unless you set this to 1?
$setECReqDetails->AddressOverride = 1;
$setECReqType = new PayPal\PayPalAPI\SetExpressCheckoutRequestType();
$setECReqType->Version = '104.0';
$setECReqType->SetExpressCheckoutRequestDetails = $setECReqDetails;
$setECReq = new PayPal\PayPalAPI\SetExpressCheckoutReq();
$setECReq->SetExpressCheckoutRequest = $setECReqType;
$setECResponse = $paypalService->SetExpressCheckout($setECReq);
//var_dump($setECResponse);
$redirect_url = "https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=".$setECResponse->Token;
return $app->redirect($redirect_url);
Summed up...
You'll see my questions distributed throughout the code, but here they are all summed up.
Both PaymentDetailsType() and SetExpressCheckoutRequestType() have address-ish properties. Which one will be passed on to Paypal?
Does the API require that you pass in a billing address if you pass in a shipping address?
If you don't set AddressOverride to 1, should it show the address that you passed in at all?
But in the end, I most importantly just want to know how to get address passing to work. =). Right now I can't seem to get any address to pass to Paypal no matter what I try.
It would help more to see the raw API requests getting generated as opposed to the code generating the requests. The library you're using should give you some way to see that. Then you just need to make sure the address parameters are getting passed correctly in DoExpressCheckoutPayment.
If you like, you might want to take a look at my PHP class library for PayPal. Might kinda suck to start over with another library, but it makes it very quick and easy. It has files prepared with all the parameters and everything ready to go so all you need to do is fill in the values and it'll work every time. :)
After some furious research, I was able to figure out the problem using Paypal's API explorer. As it turns out, setting ->Address on the SetExpressCheckoutRequestType() object is deprecated. The correct method is to set ->ShipToAddress for your PaymentDetailsType() object.
In my case, however, the reason that nothing was working was because I had my address wrong [slaps palm into forehead]. My zip, while in the region of Columbus, OH is technically in Dublin, OH. So, Paypal was generating an error.
Paypal wasn't showing me error information, however, so I had no way to know what in particular was causing the error. This is where the API explorer came in handy; I filled in the API explorer and tried my request--and it gave me detailed error information.
Since then, I've also found out that I can see detailed error information simply by using:
var_dump($setECResponse);

sending multiple messages using clickatell gateway

I used php server side to connect with clickatell messages service , i used the soap api technique to make the connection . it is working .but in my code , i can send just one message at the same time , here is the code :
function actionSendSMS(){
$msgModel = new Messages();
$settModel = new Settings();
$setRows = $settModel->findAll();
$usr=$setRows[0]->clickatell_usr;
$pwdRows = $settModel->findAll();
$pwd=$pwdRows[0]->clickatell_pwd;
$api_idRows = $settModel->findAll();
$api_id=$api_idRows[0]->clickatell_api_id;
$msgModel->findAllBySql("select * from messages where is_sent=0 and
send_date=".date("m/d/Y"));
$client = new SoapClient("http://api.clickatell.com/soap/webservice.php?WSDL");
$params = array('api_id' => $api_id,'user'=> $usr,'password'=> $pwd);
$result = $client->auth($params['api_id'],$params['user'],$params['password']);
$sessionID = substr($result,3);
$callback=6;
// echo $result."<br/>";
// echo $sessionID;
$params2 = array('session_id'=>$sessionID, 'api_id' => $api_id,'user'=>
$usr,'password'=>$pwd,
'to'=>array('962xxxxxxx'), 'from'=>"thetester",'text'=>'this is a sample test
message','callback'=>$callback);
$result2 = $client->sendmsg($params2['session_id'],
$params['api_id'],$params['user'],$params['password'],
$params2['to'],$params2['from'],$params2['text'],$params2['callback']);
print_r( $result2)."<br/>";
$apimsgid= substr($result2[0],4);
$rowsx=Messages::model()->findAllBySql("select * from messages where is_sent=0 and
send_date='".date("m/d/Y")."'");
for($i=0;$i<count($rowsx);$i++)
{
$rowsx[$i]->clickatell_id=$apimsgid;
$rowsx[$i]->save();
}
//echo $apimsgid."<br/>";
if (substr($result2[0], 0,3)==='ERR' && (!(substr($result2[0], 0,2)==='ID'
) ))
{
echo 'Connot Routing Message';
}
.... now you see that this code will send one message at the same time , forget about the id , its for personal purpose , now this service i have to modify it , to send multiple messages at the same time , and i will give every message an unique ID , so now my problem is : is there any one knows if there is a service to send multiple sms at the same time ;
as in my code i fill the information for one message ,but i need a service to send multiple sms , does any body can give me a link to this service , i made many searches but there is no answer i have found
Try startbatch command to send multiple messages at the same time (it also supports personalized). However, it is not based soap, it is based http api.
Have you tried
$params2 = array('session_id'=>$sessionID, 'api_id' => $api_id,'user'=> $usr,'password'=>$pwd, 'to'=>array('962xxxxxxx', '962xxxxxxx', '962xxxxxxx'), 'from'=>"thetester",'text'=...
or
$params2 = array('session_id'=>$sessionID, 'api_id' => $api_id,'user'=> $usr,'password'=>$pwd, 'to'=>array('962xxxxxxx,962xxxxxxx,962xxxxxxx'), 'from'=>"thetester",'text'=...

Categories