iOS Question Send a long string over get on server

gerredtor

Active Member
Licensed User
Hello i will send the transactionReceipt to my server, but this is in string a very long string and the httpClient has problems with them or the php backend, iam not sure
 

tufanv

Expert
Licensed User
Longtime User
you must encodebase64 the byte and than send it.

B4X:
    Dim no As NativeObject = Product
    Dim b() As Byte = no.NSDataToArray(no.GetField("transactionReceipt"))

than send this to server

B4X:
su.EncodeBase64(b)
do you send it in string or byte format ?
 
Upvote 0

gerredtor

Active Member
Licensed User
Ok, my string on the server is this then:

B4X:
ewoJInNpZ25hdHVyZSIgPSAiQXlHUU9tVlRXY0VOelBkZ3g0N0krWmNHaHFyUU5uOU54NUdndkVUSm5UNXdsN2pqZWkvcGZ5c0Fnd0ZkRXVyWERVeUtSWVkvQkZyb3kreUQ4RXcyWlQzOEs5a2ZMSHpHNk9UaWN2ajdMK3F0bUZtS2F5bnRwTGc0cHFndFNESVI2cC9HeXhuNTgvSzAwWitMNFVRNTRMb2t4NFZpVlQ2RllFalN0Sm9qYTJHVDQ3QnpFd2dyRlUvUlFZTmZTVFo2ZnlscWREMHc3YmhnNWJCSXJnK0RtbThLYmdFbElnTzBqM2VNclNzejZFc1YweDZqUnFNY0VucGduQ083em9VMFAxdXR5aVVmS1ZWNEZqZ3FJeXNnblgzS1RremlWb0JUTmI3bEFiV2ZBTWViMmQ1d05XWFBtWFVTSHNzZ1hMNUpRUkRXRkIrK2pYenVWM2JheGVDNlhsOEFBQVdBTUlJRmZEQ0NCR1NnQXdJQkFnSUlEdXRYaCtlZUNZMHdEUVlKS29aSWh2Y05BUUVGQlFBd2daWXhDekFKQmdOVkJBWVRBbFZUTVJNd0VRWURWUVFLREFwQmNIQnNaU0JKYm1NdU1Td3dLZ1lEVlFRTERDTkJjSEJzWlNCWGIzSnNaSGRwWkdVZ1JHVjJaV3h2Y0dWeUlGSmxiR0YwYVc5dWN6RkVNRUlHQTFVRUF3dzdRWEJ3YkdVZ1YyOXliR1IzYVdSbElFUmxkbVZzYjNCbGNpQlNaV3hoZEds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TnpneElqc0tDU0p3ZFhKamFHRnpaUzFrWVhSbElpQTlJQ0l5TURFMkxUQTJMVE13SURFd09qSXlPak0zSUVWMFl5OUhUVlFpT3dvSkluQjFjbU5vWVhObExXUmhkR1V0Y0hOMElpQTlJQ0l5TURFMkxUQTJMVE13SURBek9qSXlPak0zSUVGdFpYSnBZMkV2VEc5elgwRnVaMlZzWlhNaU93b0pJbTl5YVdkcGJtRnNMWEIxY21Ob1lYTmxMV1JoZEdVaUlEMGdJakl3TVRZdE1EWXRNekFnTVRBNk1qSTZNemNnUlhSakwwZE5WQ0k3Q24wPSI7CgkiZW52aXJvbm1lbnQiID0gIlNhbmRib3giOwoJInBvZCIgPSAiMTAwIjsKCSJzaWduaW5nLXN0YXR1cyIgPSAiMCI7Cn0=

But this is wrong,
which script you use? to test the receipt
 
Upvote 0

tufanv

Expert
Licensed User
Longtime User
I am having no issues since 2 months . Your base64 seems correct.

Php side function is :
B4X:
function validate_receipt($receipt_data) {

     // $url = "https://sandbox.itunes.apple.com/verifyReceipt/";
       $url = "https://buy.itunes.apple.com/verifyReceipt";

    $ch = curl_init($url);
    $data_string = json_encode(array(
        'receipt-data' => $receipt_data,
        'password'     => 'SHAREDAPPSECRET',
    ));
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array(
        'Content-Type: application/json',
        'Content-Length: ' . strlen($data_string))
    );
    $output   = curl_exec($ch);
    $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    curl_close($ch);
    if (200 != $httpCode) {
        die("Error validating App Store transaction receipt. Response HTTP code $httpCode");
    }
    $decoded = json_decode($output, TRUE);
    return $decoded;
}

than u send the base64 encoded to php and use stg like :

B4X:
 $dekoder = validate_receipt($str);
               if ($dekoder['status']=='0')     {

if status is 0 it means valid purchase.
Dont forget to change the your app scret in function and change to sandbox if you are testing
 
Upvote 0
Top