1 2 3 4 5 6 7 |
$key = null; $key = array_search($s->id, array_column($user_array, 'id')); if ($key !== false) { }else{ } |
Kategori: php
phpstorm remove comment line
ctrl + r
1 |
<!--.*?--> |
replace all
php wise.com api kullanımı & wise.com api example
An english support is available for this project. You can have an english support for this work. Thus, you may send an e-mail to info@alicancanpolat.com. I don’t have an excellent english but i think we’ll get along.
bu api ile bir hesaptan bir hesaba dolar, euro veya tl her ne isterseniz gönderebiliyorsunuz. bir nevi banka gibi oluyorsunuz.
nerede bir göt göt api var beni bulur. avrupada halı saha & jigola merkezi ödemesinde kullanılmak üzere wise.com üzerinden bir api yazmam gerekiyordu. bunu yaptık fakat canımız çıktı. şimdi sırayla anlatıyorum, anlamayabilirsiniz, anlamadığınız yerleri mutlaka sorunuz.
api token alıyoruz bir tane wise.comdan.
1.adım – hangi para biriminden hangisine atacağımızı bildiriyoruz.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
$url = "https://api.transferwise.com/v2/quotes"; $curl = curl_init($url); curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_POST, true); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); $headers = array( "Authorization: Bearer $api_token", "Content-Type: application/json", ); curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); $data = <<<DATA { "sourceCurrency": "USD", "targetCurrency": "USD", "sourceAmount": 10, "targetAmount": null, "profile": PROFILEID } DATA; curl_setopt($curl, CURLOPT_POSTFIELDS, $data); curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); $resp = curl_exec($curl); curl_close($curl); |
1.adımdan aldığın quoteUuid değerini tut.
2.adım – göndereceğin kişinin banka hesabı yok ise oluştur, var ise zaten sana aynı sonucu döndürüyor.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
$url = "https://api.transferwise.com/v1/accounts"; $curl = curl_init($url); curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_POST, true); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); $headers = array( "Authorization: Bearer $api_token", "Content-Type: application/json", ); curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); $data = <<<DATA { "profile": 26112760, "accountHolderName": "$name", "currency": "USD", "type": "aba", "details": { "legalType": "PRIVATE", "abartn": "", "accountNumber": "", "accountType": "", "address" : { "country": "US", "state": "AZ", "city": "New York", "postCode": "10025", "firstLine": "45 Sunflower Ave" } } } DATA; curl_setopt($curl, CURLOPT_POSTFIELDS, $data); curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); $resp = curl_exec($curl); curl_close($curl); |
buradan yine ID değeri döndürecek. O senin bank_account_id değerin. bunu da yaz bi kenara
3.aşama
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
$guid = (string) Str::uuid(); // https://www.uuidgenerator.net/api/guid create $url = "https://api.transferwise.com/v1/transfers"; $curl = curl_init($url); curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_POST, true); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); $headers = array( "Authorization: Bearer $api_token", "Content-Type: application/json", ); curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); $data = <<<DATA { "targetAccount": $bank_account_id, "quoteUuid": "$quoteUuid", "customerTransactionId": "$guid" } DATA; curl_setopt($curl, CURLOPT_POSTFIELDS, $data); curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); $resp = curl_exec($curl); curl_close($curl); |
artık paramızı, birimini, hangi kişiye olduğunu sisteme tanıttık.
burası bok gibi. try için değil fakat eur, usd için çift taraflı doğrulama istiyor bunu nasıl yapacağız.
Strong Customer Authentication dedikleri bi olay var. private ve public.pem diye bir dosya oluşturuyorsun. openssl ile oluştur.
1 2 |
$ openssl genrsa -out private.pem 2048 $ openssl rsa -pubout -in private.pem -out public.pem |
https://github.com/robclark56/TransferWise_PHP_SimpleAPIclass/blob/master/README.md
public.pem ‘i api ayarları bölümünden yüklüyorsun. Private sende kalıyor. Şimdi son aşamayı iki defa gönderiyorsun.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
$url = "https://api.transferwise.com/v1/transfers"; $curl = curl_init($url); curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_POST, true); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); $headers = array( "Authorization: Bearer $api_token", "Content-Type: application/json", ); curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); $data = <<<DATA { "targetAccount": $bank_account_id, "quoteUuid": "$quoteUuid", "customerTransactionId": "$guid" } DATA; curl_setopt($curl, CURLOPT_POSTFIELDS, $data); curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); $resp = curl_exec($curl); curl_close($curl); |
transferi başlattın. son aşama kaldı, transferi kendi bakiyenden düşmek.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
$url = "https://api.transferwise.com/v3/profiles/26112760/transfers/$transfer_id/payments"; $curl = curl_init($url); curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_POST, true); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); $headers = array( "Authorization: Bearer $api_token", "Content-Type: application/json", ); curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); $data = <<<DATA { "type":"BALANCE" } DATA; curl_setopt($curl, CURLOPT_POSTFIELDS, $data); curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($curl, CURLOPT_HEADER,true); $resp = curl_exec($curl); curl_close($curl); list($headers, $content) = explode("\r\n\r\n",$resp,2); $k = 0; foreach (explode("\r\n",$headers) as $hdr){ $search_result=strstr($hdr,"x-2fa-approval: "); if($search_result){ $ott = $hdr; $k = 1; } } $ott = str_replace("x-2fa-approval: ","",$ott); |
1 2 3 4 5 6 7 8 9 10 11 12 13 |
HTTP/1.1 403 Forbidden Date: Fri, 03 Jan 2020 12:34:56 GMT Content-Type: application/json;charset=UTF-8 x-2fa-approval-result: REJECTED x-2fa-approval: be2f6579-9426-480b-9cb7-d8f1116cc8b9 ... { "timestamp": "2020-01-03T12:34:56.789+0000", "status": 403, "error": "Forbidden", "message": "You are forbidden to send this request", "path": "/v3/profiles/{profileId}/transfers/{transferId}/payments" } |
hemen header bölümüne bakıyorsun. Gördün mü bak x-2fa-approval diye bir değişken verdi sana. Bu telefonuna gönderilmiş sms gibi. Bunu sana ayarladım ott diye bir değişkende şu an o.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
$url = "https://api.transferwise.com/v3/profiles/26112760/transfers/$transfer_id/payments"; $curl = curl_init($url); curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_POST, true); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); $pkeyid = openssl_pkey_get_private("-----BEGIN RSA PRIVATE KEY----- MIIEowIBAAKCAQEAtc9xJLHWeODKJv5z37tJLkzUHHCsdgTsfYzbmcv5kokkuT+D YWIhs2qPJdjY/9WE/E7tAsWMxnWe78GKKAy+3sh8mFI3E1YeC3f3Fpti2KKjVBaR 12TxZeGntD0BGUHZait0cvZT+zDcB1kQQWNUx8dShbEiWrbpVh MaYbMXQPhhIoaY8sjsUAKuqQQyGxl+SxR7r4v8+fZhJLqFQ7Hrua -----END RSA PRIVATE KEY-----"); openssl_sign($ott, $Xsignature, $pkeyid,OPENSSL_ALGO_SHA256); openssl_free_key($pkeyid); $Xsignature= base64_encode($Xsignature); $headers = array( "Content-Type: application/json", "Authorization: Bearer a17d5ea1-ba36-45d5-9dad-47341227ed5f", "x-2fa-approval: $ott", "X-Signature: $Xsignature", ); curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); $data = '{"type": "BALANCE"}'; curl_setopt($curl, CURLOPT_POSTFIELDS, $data); curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); $resp = curl_exec($curl); curl_close($curl); |
artık çift aşamalı doğrulama da tamam. paramız gitti. bok gibi anlattım ama olsun anladınız. kaynak az zaten.
php baş harfi büyük yapma
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
function ucwords_tr($gelen){ $sonuc=''; $kelimeler=explode(" ", $gelen); foreach ($kelimeler as $kelime_duz){ $kelime_uzunluk=strlen($kelime_duz); $ilk_karakter=mb_substr($kelime_duz,0,1,'UTF-8'); if($ilk_karakter=='Ç' or $ilk_karakter=='ç'){ $ilk_karakter='Ç'; }elseif ($ilk_karakter=='Ğ' or $ilk_karakter=='ğ') { $ilk_karakter='Ğ'; }elseif($ilk_karakter=='I' or $ilk_karakter=='ı'){ $ilk_karakter='I'; }elseif ($ilk_karakter=='İ' or $ilk_karakter=='i'){ $ilk_karakter='İ'; }elseif ($ilk_karakter=='Ö' or $ilk_karakter=='ö'){ $ilk_karakter='Ö'; }elseif ($ilk_karakter=='Ş' or $ilk_karakter=='ş'){ $ilk_karakter='Ş'; }elseif ($ilk_karakter=='Ü' or $ilk_karakter=='ü'){ $ilk_karakter='Ü'; }else{ $ilk_karakter=strtoupper($ilk_karakter); } $digerleri=mb_substr($kelime_duz,1,$kelime_uzunluk,'UTF-8'); $sonuc.=$ilk_karakter.kucuk_yap($digerleri).' '; } $son=trim(str_replace(' ', ' ', $sonuc)); return $son; } function kucuk_yap($gelen){ $gelen=str_replace('Ç', 'ç', $gelen); $gelen=str_replace('Ğ', 'ğ', $gelen); $gelen=str_replace('I', 'ı', $gelen); $gelen=str_replace('İ', 'i', $gelen); $gelen=str_replace('Ö', 'ö', $gelen); $gelen=str_replace('Ş', 'ş', $gelen); $gelen=str_replace('Ü', 'ü', $gelen); $gelen=strtolower($gelen); return $gelen; } |
Error:SSL certificate problem: self signed certificate in certificate chain Hatası Çözümü
Error:SSL certificate problem: self signed certificate in certificate chain hatası alıyoruz bazen curl işlemlerinde. bunu çözmek için aşağıdaki kodu eklemeniz yeterli olacaktır.
1 |
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); |
pdo veritabanı bilgileri
PHP PDO Veritabanına Bağlanma
1 2 3 4 5 |
try { $baglan = new PDO("mysql:host=localhost;dbname=veritabaniadi;charset=utf8", "kullaniciadi", "sifre"); } catch ( PDOException $h ){ print $h->getMessage(); } |
Yukarıdaki kod mysql veritabanı ile bağlantı kurmamızı sağlar. Eğer bağlantı doğru değil ise hata mesajını yakalamak için getMessage fonksiyonunu yazdırdık. Charset ile de utf8 yani Türkçe Karakter sorununu giderdik. Sizde az çok anlamışsınızdır veritabanı adı, kulanıcı adı ve şifrenin nereye girildiğini ben o detaylara girmiyorum. Yukarıdaki kodu anladığınızı düşünüyor ve sonrası kısıma geçiyorum.
Okumaya devam et “pdo veritabanı bilgileri”