PC SOFT

FORUMS PROFESSIONNELS
WINDEVWEBDEV et WINDEV Mobile

Accueil → WINDEV Mobile 2024 → How to get MobileID store properly in MySQL using PHP?
How to get MobileID store properly in MySQL using PHP?
Débuté par Yogi Yang, 14 juin 2017 12:57 - 11 réponses
Membre enregistré
19 messages
Popularité : +2 (2 votes)
Posté le 14 juin 2017 - 12:57
Hello,

I have build the following table structure in MySQL to store MobileID:
--
-- Table structure for table `push_service`
--

CREATE TABLE `push_service` (
`ps_id` int(11) NOT NULL,
`ps_mobile_id` text CHARACTER SET latin1 NOT NULL,
`ps_service_type` int(11) NOT NULL,
`ps_custom_info` text NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;


I have the following PHP script which is responsible for storing the MobielID in MySQL table:
$ps_mobile_id  = $_REQUEST['ps_mobile_id'];
$ps_service_type = $_REQUEST['ps_service_type'];
$ps_custom_info = $_REQUEST['ps_custom_info'];
$get_result = mysql_query("SELECT ps_mobile_id FROM push_service WHERE ps_mobile_id = '".$ps_mobile_id."'", $con);

$totalRows = mysql_num_rows($get_result);

if($totalRows == 0) {
   //If MobilID does not exist in DB then insert it
   $insert =  mysql_query("INSERT INTO push_service (`ps_mobile_id`, `ps_service_type`, `ps_custom_info`)
    VALUES ('".$ps_mobile_id."', '".$ps_service_type."', '".$ps_custom_info."')", $con) 
    or die(mysql_error($link));
}


In my WinDev Mobile I am using the following code in ActivatePushNotif global procedure and calling the above PHP script to store MobileID in MySQL database:
sRegURL is string

IF Length(bufIdentifier) > 0 THEN
sRegURL = "http://xxxx.xxx.xxx/ws/mob_reg.php?ps_mobile_id=%1&ps_service_type=1&ps_custom_info=Mobile"
sRegURL = StringBuild(sRegURL,bufIdentifier)

HTTPRequest(sRegURL)
ELSE
// Returns the error returned by the service
Error("Registration error: ", sError)
END


But what gets stored in the Table in MySQL on the serve is completely unreadable and looks something like this:
偁㥁戱升偬灨瑈煕䭌到瀶伹噮灵䥁特䕰㡇奃奰䍆獣晥彡䵒䉶敋㐭浒爳䥈奧桓剦兢䱵㑮灩偶䙄剱ど㕖佩慧朷浘単坡晌伸㕁奷䅈浰ⵖ摲呂楟剶漰湫汪お䍱䕖㈳ㅕ㝲佨㍣䐰昶䭭慤畦核ぬ砱丹䅄


If I use an Android app built using Google Studio the MobileID comes up as Alphanumberic number instead of unreadable text.

What wrong am I doing here please guide me.

TIA

Yogi Yang

--

Yogi Yang
Membre enregistré
19 messages
Popularité : +2 (2 votes)
Posté le 15 juin 2017 - 06:54
Hello,

The error message that I am receiving from GCM is:
{"multicast_id":6094092220796655173,"success":0,"failure":1,"canonical_ids":0,"results":[{"error":"InvalidRegistration"}]}{"multicast_id":6642743728341667119,"success":0,"failure":1,"canonical_ids":0,"results":[{"error":"InvalidRegistration"}]}


This I think means that the MobileID that is getting stored in the DB is in wrong format.

How can we get the sanitized MobileID from WinDev generate android apk?

Please help solve this problem.

TIA

--

Yogi Yang
Membre enregistré
123 messages
Popularité : +46 (46 votes)
Posté le 15 juin 2017 - 23:21
Hi Yogi, please, Look at these project properties, I use the same method as you, And the result for me is this

f4Ecdl_-3Xc:APA91bGGlFLXJ1JFm9Bh23e2CSzekIQZ9thPz_nPZmi3QUNqwo21XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX





--
Atte. Willian Fernando
Membre enregistré
19 messages
Popularité : +2 (2 votes)
Posté le 16 juin 2017 - 11:23
Hello Willian,

Thanks for the hint but setting the whole project to ANSI is not possible as in other parts of the app all the data that comes from remote server is in UNICODE.

Any other way besides this?

I tried to convert UNICODE to ANSI using UnicodeToAnsi that gives me a blank string.

TIA

--

Yogi Yang
Membre enregistré
19 messages
Popularité : +2 (2 votes)
Posté le 16 juin 2017 - 12:10
Hello Willian,

Update to my previous post.

I changed the configuration from UNICODE to ANSI. Now the MobileID that gets generated is Alphanumeric..!!!

I am using following PHP code to send Push notification on server but I am not able to receive any Push notification on my mobile phones. Google's server response is success but...

$androidAuthKey = "AIzaSyACY_XXXXXXXXXxxxxxxxxxxxxxxxxXXXXXXXXXX";

$data = array( 
                'registration_ids' => array($registration_id),
                'data' => array( 
'WX_PUSH_EXT_VERSION' => '1.0',                                
'WX_PROP_CONTENU' => $params["msg"],
'WX_PROP_MESSAGE' => $params["msg"],
'WX_PROP_SECONDARYMESSAGE' => 'Send from Web Server',
'WX_PROP_TITRE' => 'Pushti Marg Test',
'WX_PROP_ACTIVEAPPLICATION' => 'true',
'WX_PROP_TYPE' => '1'
)
                );
        $headers = array( 
        "Content-Type:application/json",  
        "Authorization:key=".$this->androidAuthKey   
        ); 
                  
        $ch = curl_init(); 
        
curl_setopt($ch, CURLOPT_URL, "https://gcm-http.googleapis.com/gcm/send"); 
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); 
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); 
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); 
        curl_setopt($ch, CURLOPT_POST, true); 
        curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data)); 
        $result = curl_exec($ch); 

print_r($result);
echo "

 

";
        //result sample {"multicast_id":6375780939476727795,"success":1,"failure":0,"canonical_ids":0,"results":[{"message_id":"0:1390531659626943%6cd617fcf9fd7ecd"}]} 
        //http://developer.android.com/google/gcm/http.html  // refer error code 
        curl_close($ch);


If you know PHP please guide me.

--

Yogi Yang
Membre enregistré
123 messages
Popularité : +46 (46 votes)
Posté le 16 juin 2017 - 16:38
Hi Yogi, yes my code PHP is this
//how to use??

sendGCM($device_id_from_DB,$message);

function sendGCM ($device_id, $message){
        // API access key from Google API's Console
        if (!defined('API_ACCESS_KEY')) define( 'API_ACCESS_KEY', 'AAAAW3coln0XXXXXXXXXXXXXXXXxxxxXXXxxxXXxxXXxxXXxxXX' );
        $tokenarray = array($device_id);
        // prep the bundle
        $msg = array
        (
            'WX_PROP_ACTIVEAPPLICATION' => true, /*active or not the app on click in Notification*/
            'WX_PROP_AFFICHAGELED'=> false,
            'WX_PROP_CHRONOMETRE'=> false,
            'WX_PROP_CONTENU' => '',
            'WX_PROP_COULEURLED' => 65280, 
            'WX_PROP_FORMAT' => array('WX_PROP_CONTENU' => '',
                                        'WX_PROP_GRANDEICONE'=> '',
                                        'WX_PROP_TITRE' => '',
                                        'WX_PROP_TYPE' => 1),
            'WX_PROP_GRANDEICONE' => '',
            'WX_PROP_ICONE' => '',
            'WX_PROP_LOCALE' => false,
            'WX_PROP_MESSAGE' => $message,
            'WX_PROP_MESSAGESECONDAIRE' => '',
            'WX_PROP_PRIORITE' => 0,
            'WX_PROP_SON' => 'sound_notif.mp3',/*sound of notification*/
            'WX_PROP_SUPPRIMABLE' => false,
            'WX_PROP_TEXTEDEROULANT' => '',
            'WX_PROP_TITRE' => 'My Custom Title',//Title of Notification
            'WX_PROP_VIBRATION' => true,
            'WX_PUSH_VERSION' => '1.0'


        );
        $fields = array
        (
            'registration_ids'     => $tokenarray,
            'data'            => $msg
        );

        $headers = array
        (
            'Authorization: key=' . API_ACCESS_KEY,
            'Content-Type: application/json'
        );

        $ch = curl_init();
        curl_setopt( $ch,CURLOPT_URL, 'fcm.googleapis.com/fcm/send' );
        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 );
        print_r($result);
}


--
Atte. Willian Fernando
Membre enregistré
123 messages
Popularité : +46 (46 votes)
Posté le 16 juin 2017 - 16:40
I am using WM 22 with Firebase

What you can change is the CURL URL

--
Atte. Willian Fernando
Membre enregistré
19 messages
Popularité : +2 (2 votes)
Posté le 17 juin 2017 - 07:21
Thank you Willian,

Finally I managed to send GCM Push Notification to Android apps!!! :)

TIA

--

Yogi Yang
Membre enregistré
19 messages
Popularité : +2 (2 votes)
Posté le 17 juin 2017 - 11:50
Hello Willian,

You have this line in your code sample:
'WX_PROP_SON' => 'sound_notif.mp3',/*sound of notification*/


This parameter is for playing sound when the notification arrives on phone.

So does specifying a file name here would require me to upload a .mp3 file on my web server or would I need to have this file on users phone?

TIA

--

Yogi Yang
Membre enregistré
123 messages
Popularité : +46 (46 votes)
Posté le 19 juin 2017 - 15:25
Hello Yogi.

The file .MP3 must be embedded in your MOBILE project






--
Atte. Willian Fernando
Membre enregistré
19 messages
Popularité : +2 (2 votes)
Posté le 20 juin 2017 - 06:16
Willian,

Thanks for the clarification.

TIA

--

Yogi Yang
Posté le 28 février 2019 - 18:58
Willian Fernando wrote:
Hi Yogi, yes my code PHP is this
'WX_PROP_FORMAT' => array('WX_PROP_CONTENU' => '',
                                        'WX_PROP_GRANDEICONE'=> '',
                                        'WX_PROP_TITRE' => '',
                                        'WX_PROP_TYPE' => 1),
            'WX_PROP_GRANDEICONE' => '',


--
Atte. Willian Fernando


How can we provide Icon using the parameter: WX_PROP_GRANDEICONE?

Please guide me.