This file contains hidden or 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
/** payload data **/ | |
payload := &NotificationPayload{} | |
_, err = jwt.ParseWithClaims(tokenStr, payload, func(token *jwt.Token) (interface{}, error) { | |
return extractPublicKeyFromToken(tokenStr) | |
}) | |
/** transaction info **/ | |
transactionInfo := &TransactionInfo{} |
This file contains hidden or 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
// Notification signed payload | |
type NotificationPayload struct { | |
jwt.StandardClaims | |
NotificationType string `json:"notificationType"` | |
Subtype string `json:"subtype"` | |
NotificationUUID string `json:"notificationUUID"` | |
NotificationVersion string `json:"notificationVersion"` | |
Data NotificationData `json:"data"` | |
} |
This file contains hidden or 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
func extractPublicKeyFromToken(tokenStr string) (*ecdsa.PublicKey, error) { | |
certStr, err := extractHeaderByIndex(tokenStr, 0) // get certificate from X5c[0] header | |
if err != nil { | |
return nil, err | |
} | |
cert, err := x509.ParseCertificate(certStr) // parse certificate | |
if err != nil { | |
return nil, err |
This file contains hidden or 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
func verifyCert(certByte []byte, intermediateCert []byte) error { | |
roots := x509.NewCertPool() // new empty set of certificate pool | |
ok := roots.AppendCertsFromPEM([]byte(APP_STORE_NOTIFICATION_ROOT_CERT)) // parse and append app store certificate to certPool | |
if !ok { | |
return errors.New("failed to parse root certificate") | |
} | |
interCert, err := x509.ParseCertificate(intermediateCert) // parse and append intermediate X5c certificate |
This file contains hidden or 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
// prepare header structure contains algorithm and token type | |
type NotificationHeader struct { | |
Alg string `json:"alg"` | |
X5c []string `json:"x5c"` | |
} | |
// extract header from given JWS formatted token | |
func extractHeaderByIndex(tokenStr string, index int) ([]byte, error) { | |
tokenArr := strings.Split(tokenStr, ".") // get header from token |
This file contains hidden or 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
<?php | |
$text = "\xE0"; | |
echo utf8_decode($text); | |
# output : ? | |
?> |
This file contains hidden or 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
<?php | |
$text = "\xE0"; | |
echo utf8_encode($text); | |
# output : à | |
?> |
This file contains hidden or 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
<?php | |
# encode | |
echo str_rot13("We celebrate differences!!"); | |
# Output 1 : Jr pryroengr qvssreraprf!! | |
# decode |
This file contains hidden or 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
<?php | |
# Example 1 (Associative array) | |
$users = '[{"id":"1","name":"John"},{"id":"2","name":"Michel"}]'; | |
var_dump(json_decode($users)); | |
/* | |
output: array(2) { [0]=> object(stdClass)#1 (2) { ["id"]=> string(1) "1" ["name"]=> string(4) "John" } | |
[1]=> object(stdClass)#2 (2) { ["id"]=> string(1) "2" ["name"]=> string(6) "Michel" } |
This file contains hidden or 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
<?php | |
# Example 1 (Associative array) | |
$users = array(array("id"=>"1", "name"=>"John"), array("id"=>"2", "name"=>"Michel")); | |
echo json_encode($users); | |
# output: [{"id":"1","name":"John"},{"id":"2","name":"Michel"}] | |