Find us on facebook

Showing posts with label Web Services. Show all posts
Showing posts with label Web Services. Show all posts

Sep 6, 2014

sending json encoded data in web service iOS/Android

in chrome-extension://hgmloofddffdnphfgcellkdfbfbjeloo/RestClient.html
delivery_type=2&table=20&total_value=200&person_id=18&isEdited=false&os=android&data={"items":[{"itemId":61,"itemPrice":"234","isEdited":false,"orderdetails_id":0,"chair":0,"hasNote":"false","itemQty":1},{"itemId":62,"itemPrice":"234","isEdited":false,"orderdetails_id":0,"chair":0,"hasNote":"false","itemQty":1}]}

In PHP Catching
$items = $_POST['data'];
$items = CJSON::decode($items);
foreach ($items as $key=>$value) {
foreach ($value as $value1) {
$isEdited = $value1['isEdited'];
}
}

Jul 7, 2014

Push data to GCM server

public function sentToGcm($id, $devid, $oid, $ost) {

$response["success"] = 1;
$devid = $devid;
$registatoin_ids = array($devid);
$msgall = $ost;

$msg = array("message" => $msgall, "o_id" => $oid, 'type' => 'order_st');
$url = 'https://android.googleapis.com/gcm/send';
$fields = array('registration_ids' => $registatoin_ids, 'data' => $msg);
$headers = array('Authorization: key =AIzaSyD8E0T0h49MBYBST2aj_RuOCNxKReciCZA', 'Content-Type: application/json');

$data = json_encode($fields);
$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_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
$result = curl_exec($ch);
curl_close($ch);
//$ss = Yii::app()->curl->post($url, $data);

echo $result;
}

Jun 25, 2014

Web Service to send user profile details to Android IOS - YII

public function actionGetUserProfileData() {
   
 $this -> layout = false;
 header('Content-type: application/json');

  $uid = $_GET['uid'];
 
   $profiles = Profiles::model()->findByPk($uid);
    $userProfileData = array(
    'firstname'    => $profiles->firstname,
    'street_address'  => $profiles->street_address,
    'city'     => $profiles->city,
    'contact_no'   => $profiles->contact_no,
    'country_code'   => $profiles->country_code,
   
   );



 echo CJSON::encode($userProfileData);
 Yii::app() -> end();


}

Web Service to update data in DB with Android or IOS - YII

public function actionGetGcm() {

try {

if ((isset($_POST['token'])) && !empty($_POST['token'])&&(isset($_POST['customer_id'])) && !empty($_POST['customer_id'])) {

$token = $_POST['token'];
$customer_id = $_POST['customer_id'];
$Pda = new Pda;
$Pda -> gcm_token = $token;
$Pda -> customer_id = $customer_id;
$Pda -> save();
if($Pda->save()){
$msg = CJSON::encode(array( array('success' => "success", 'message' => 'exception','pda_id'=>$Pda->id)));
echo $msg;
}else{
$msg = CJSON::encode(array( array('success' => "false", 'message' => 'exception')));
echo $msg;
}
}

} catch (Exception $exc) {
$msg = CJSON::encode(array( array('success' => "false", 'message' => 'exception')));
echo $msg;
}

}

Can test function using  http://www.hurl.it/