PC SOFT

GRUPOS DE DISCUSSÃO PROFISSIONAL
WINDEVWEBDEV e WINDEV Mobile

Inicio → WINDEV Mobile 2024 → How to get MobileID store properly in MySQL using PHP?
How to get MobileID store properly in MySQL using PHP?
Iniciado por Yogi Yang, jun., 14 2017 12:57 PM - 11 respostas
Membro registado
19 mensagems
Popularité : +2 (2 votes)
Publicado em junho, 14 2017 - 12:57 PM
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
Membro registado
19 mensagems
Popularité : +2 (2 votes)
Publicado em junho, 15 2017 - 6:54 AM
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
Membro registado
123 mensagems
Popularité : +46 (46 votes)
Publicado em junho, 15 2017 - 11:21 PM
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
Membro registado
19 mensagems
Popularité : +2 (2 votes)
Publicado em junho, 16 2017 - 11:23 AM
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
Membro registado
19 mensagems
Popularité : +2 (2 votes)
Publicado em junho, 16 2017 - 12:10 PM
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
Membro registado
123 mensagems
Popularité : +46 (46 votes)
Publicado em junho, 16 2017 - 4:38 PM
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
Membro registado
123 mensagems
Popularité : +46 (46 votes)
Publicado em junho, 16 2017 - 4:40 PM
I am using WM 22 with Firebase

What you can change is the CURL URL

--
Atte. Willian Fernando
Membro registado
19 mensagems
Popularité : +2 (2 votes)
Publicado em junho, 17 2017 - 7:21 AM
Thank you Willian,

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

TIA

--

Yogi Yang
Membro registado
19 mensagems
Popularité : +2 (2 votes)
Publicado em junho, 17 2017 - 11:50 AM
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
Membro registado
123 mensagems
Popularité : +46 (46 votes)
Publicado em junho, 19 2017 - 3:25 PM
Hello Yogi.

The file .MP3 must be embedded in your MOBILE project






--
Atte. Willian Fernando
Membro registado
19 mensagems
Popularité : +2 (2 votes)
Publicado em junho, 20 2017 - 6:16 AM
Willian,

Thanks for the clarification.

TIA

--

Yogi Yang
Publicado em fevereiro, 28 2019 - 6:58 PM
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.