Created
December 25, 2022 10:11
-
-
Save mcihad/066d7f440f6856ec323e2988e23f2c32 to your computer and use it in GitHub Desktop.
Soap Servislerinden Go Programlama Dili İle Kimlik Doğrulama
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"bytes" | |
"encoding/xml" | |
"fmt" | |
"io/ioutil" | |
"net/http" | |
"text/template" | |
) | |
type TCKimlik struct { | |
TCKimlik uint64 | |
Ad string | |
Soyad string | |
DogumYili int | |
} | |
type Body struct { | |
XMLName xml.Name `xml:"Body"` | |
Result bool `xml:"TCKimlikNoDogrulaResponse>TCKimlikNoDogrulaResult"` | |
} | |
type Response struct { | |
XMLName xml.Name `xml:"Envelope"` | |
Body Body `xml:"Body"` | |
} | |
var getTemplate = `<?xml version="1.0" encoding="utf-8"?> | |
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope"> | |
<soap12:Body> | |
<TCKimlikNoDogrula xmlns="http://tckimlik.nvi.gov.tr/WS"> | |
<TCKimlikNo>{{.TCKimlik}}</TCKimlikNo> | |
<Ad>{{.Ad}}</Ad> | |
<Soyad>{{.Soyad}}</Soyad> | |
<DogumYili>{{.DogumYili}}</DogumYili> | |
</TCKimlikNoDogrula> | |
</soap12:Body> | |
</soap12:Envelope>` | |
var contentType = "application/soap+xml; charset=utf-8" | |
func KimlikValid(tckimlik uint64, ad string, soyad string, dogumyili int) bool { | |
t := template.Must(template.New("get").Parse(getTemplate)) | |
var b bytes.Buffer | |
t.Execute(&b, TCKimlik{tckimlik, ad, soyad, dogumyili}) | |
resp, err := http.Post("https://tckimlik.nvi.gov.tr/Service/KPSPublic.asmx", contentType, &b) | |
if err != nil { | |
fmt.Println(err) | |
return false | |
} | |
defer resp.Body.Close() | |
body, err := ioutil.ReadAll(resp.Body) | |
if err != nil { | |
fmt.Println(err) | |
return false | |
} | |
var response Response | |
xml.Unmarshal(body, &response) | |
return response.Body.Result | |
} | |
func main() { | |
println(KimlikValid(11111111111, "GOLANG", "RUSTLANG", 2000)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment