laravel webservice response returns null value - laravel

plz find the below code
Client
public function index()
{
$username = Session::get('username');
$password = Session::get('password');
$url = url('/languagesService');
$data = json_encode(array("username" => $username,"password" => $password));
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_HEADER,false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$response = CURL_EXEC($ch);
$data = json_decode($response,true);
return $data;//return $response tried both.
}
Server
public function index()
{
$user = array(
'username' => Input::get('username'),
'password' => Input::get('password')
);
if ( Auth::attempt($user) ) {
$data = languages::all();
}else {
$data = array("invalid" => "Invalid username and password");
}
$response = Response::json($data,200);
return $response;
//return View::make("languages.index")->with("languages",$languages);
}
when accessing the server directly, it outputs the response in json format. but accessing via client, it responds nothing. Getting blank output. Tried trying with hard coded response, still the same blank output. Am i missing something tat is important?

Related

Push notification from Laravel using google firebase

I am trying to send push notification using google firebase , but notification is not coming to phone
public function pushNotificationToUsersTest(){
$apikey = env('FCM_SERVER_KEY');
$deviceToken = array("deviceTocken_1,deviceTocken_2");
$url = 'https://fcm.googleapis.com/fcm/send';
$message = "Message from server";
foreach ($deviceToken as $key => $Token) {
$preview_message = "ACTIONABLE";
$sound = "default";
$fields = array(
'to' => $Token,
'data' => array(
'message' => $message,
'notification_type' => "message_type",
'message_content' => "message_content",
'chat_type' => "chat_type",
'badge' => 10,
'category' => $preview_message,
'sound' => $sound,
)
);
//header with content_type api key
$headers = array(
'Content-Type:application/json',
'Authorization:key='.$apikey
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
$result = curl_exec($ch);
curl_close($ch);
}
print_r($result);
}
When I print Result I am getting like this
{"multicast_id":1610930223174111380,"success":1,"failure":0,"canonical_ids":0,"results":[{"message_id":"0:1657873770379569%73be5013f9fd7ecd"}]}1
When I checked respose code
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
It gives output 400.
Don't know what the issue

Laravel Curl to send multiple SMS

I am developing a small script and I am bit messed up.
I'm parsing csv file as list of phone Nos to receive bulk SMS notification.
The csv file record is in the form of 1 phone No column contains all phone Nos
the app is first allow the user to upload csv file then it shows them to the user in order to prepare a text message to be sent.
The app is working but no SMS received.
I wish if some help me with phone No array.
(code from comment 1)
if (count($data) > 0) {
if ($request->has('header')) {
$csv_header_fields = [];
foreach ($data[0] as $key => $value) {
$csv_header_fields[] = $key;
}
}
$csv_data = $data;
$csv_data_file = CsvData::create([
'csv_filename' => request->file('csv_file')->getClientOriginalName(),
'csv_header' => $request->has('header'),
'csv_data' => json_encode($data)
]);
} else {
return redirect()->back();
}
(code from comment 2)
$json = array();
$mobile_phone = $data;
$message = $notes ." \Hello";
$mobile_phone_array = str_split($mobile_phone);
$sms = array( 'number' => $mobile_phone, 'message' => $message, 'key' => '123' );
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_URL, '10.192.100.180/NoranAPI/default.aspx');
curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Content-Type: application/json'));
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($sms));
$result_sms = curl_exec($ch);

how to update payment status in database after payment successful using instamojo with codigniter

i am using instamojo payment integration with codeigniter,i am faceing below error
payment request data inserted correctly but i want to update payment
status after payment successful.
not woking webhook url in library
instamojo webhook code wrote in CI controller like this:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Welcome extends CI_Controller {
public function __construct()
{
parent::__construct();
$this->load->helper('url'); // helper load
}
public function payment_webhook(){
$data = $_POST;
$mac_provided = $data['mac'];
unset($data['mac']);
$ver = explode('.', phpversion());
$major = (int) $ver[0];
$minor = (int) $ver[1];
if($major >= 5 and $minor >= 4){
ksort($data, SORT_STRING | SORT_FLAG_CASE);
}
else{
uksort($data, 'strcasecmp');
}
$mac_calculated = hash_hmac("sha1", implode("|", $data), "our Salt key updated here");
if($mac_provided == $mac_calculated){
if($data['status'] == "Credit"){
echo "successful";
}
else{
echo "unsuccessful";
}
}
else{
echo "MAC mismatch";
}
}
}
instamojo library : webhook not working here
public function pay_payment($purpose,$amount,$member_name,$member_mobile,$member_email,$redirect_url){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://test.instamojo.com/api/1.1/payment-requests/');
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_HTTPHEADER,
array("X-Api-Key:test_our_key",
"X-Auth-Token:test_our_token"));
$payload = Array(
'purpose' => $purpose,
'amount' => $amount,
'phone' => $member_mobile,
'buyer_name' => $member_name,
'redirect_url' => $redirect_url,
'send_email' => true,
'webhook' => base_url().'Welcome/payment_webhook', // not redirect to given url
'send_sms' => true,
'email' => $member_email,
'allow_repeated_payments' => false
);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($payload));
$response = curl_exec($ch);
curl_close($ch);
$data = json_decode($response, TRUE);
if(isset($data['success']) && $data['success'] === true)
{
$transaction=$data['payment_request'];
$result=$this->CI->db->insert('ag_payment',$transaction);
// if($result==="TRUE"){
$site = $data['payment_request']['longurl'];
redirect($site, 'refresh');
// }
}
}

Laravel send notification to android using firebase

i am sending notification to android using backend as laravel through firebase but i get error as "append .json to your request URI to use the REST API." Using Postman i am runing this api
This is function which is used to get notification in json in my controller
public function sendNotification(Request $req)
{
$fcmUrl = 'https://playout-52d1f.firebaseio.com';
$token=$req->input('token');
$title=$req->input('title');
$notification = [
'title' => $title,
'sound' => true,
];
$extraNotificationData = ["message" => $notification,"moredata" =>'dd'];
$fcmNotification = [
//'registration_ids' => $tokenList, //multple token array
'to' => $token, //single token
'notification' => $notification,
'data' => $extraNotificationData
];
$headers = [
'Authorization: key=AIzaSyDF4_rqij_Bt4zC3GNEVbNFvwX1HHxy5Mo',
'Content-Type: application/json'
];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$fcmUrl);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fcmNotification));
$result = curl_exec($ch);
curl_close($ch);
dd($result );
}

Mailchimp API "Marketing permission ID '' does not exist." while passing valid id

I use the Mailchimp API to first get the marketing_permission_id for my list. The response looks like this
[marketing_permission_id] => f878932739
This value is then used in a second api call to update the settings for a specific user. However, I get the error:
string(227)
"{"type":"http://developer.mailchimp.com/documentation/mailchimp/guides/error-glossary/","title":"Bad
Request","status":400,"detail":"Marketing permission ID '' does not
exist.", [...]
I double checked the data that is being send in the second call and it has the correct marketing_permission_id in there:
{"marketing_permissions":{"marketing_permission_id":"f878932739","enabled":true}}
I followed the format from https://developer.mailchimp.com/documentation/mailchimp/reference/lists/members/#%20.
I don't understand what's going wrong. Hopefully someone here does.. :)
Just leaving this for future reference - there're not many hints on google for mailchimp API with marketing permissions...
This is the basic function i use for adding a contact to a list.
function syncMailchimp($userdata,
$apiKey, $listId)
{
$dataCenter = substr($apiKey,
strpos($apiKey, '-') +
1);
$url = 'https://'.$dataCenter.
'.api.mailchimp.com/3.0/lists/'
.$listId.
'/members/';
// This is the interesting part //
$json = json_encode([
'email_address' => $userdata[
'email'],
'status' => $userdata['status'], // "subscribed","unsubscribed","cleaned","pending"
'merge_fields' => [
'FNAME' => $userdata[
'firstname'
],
'LNAME' => $userdata['lastname']
],
'tags' => [
'added'
],
// How to build the Array -->
'marketing_permissions' =>
array(
0 =>
array(
'marketing_permission_id' =>
'1e5142bbce',
'enabled' =>
true,
),
),
]);
$ch = curl_init($url);
curl_setopt($ch,
CURLOPT_HTTPAUTH,
CURLAUTH_BASIC);
$headers = array(
'Content-Type:application/json',
'Authorization: apikey '
.$apiKey
);
curl_setopt($ch,
CURLOPT_HTTPHEADER,
$headers);
curl_setopt($ch,
CURLOPT_RETURNTRANSFER,
true);
curl_setopt($ch,
CURLOPT_TIMEOUT, 10);
curl_setopt($ch,
CURLOPT_CUSTOMREQUEST,
'POST');
curl_setopt($ch,
CURLOPT_SSL_VERIFYPEER,
false);
curl_setopt($ch,
CURLOPT_POSTFIELDS,
$json);
$result = curl_exec($ch);
$httpCode = curl_getinfo($ch,
CURLINFO_HTTP_CODE);
curl_close($ch);
return $result;
}

Resources