Skip to content

Instantly share code, notes, and snippets.

@barisesen
Created June 11, 2018 20:27
Show Gist options
  • Save barisesen/e14a2281e9a978804d9572ff7d1cf411 to your computer and use it in GitHub Desktop.
Save barisesen/e14a2281e9a978804d9572ff7d1cf411 to your computer and use it in GitHub Desktop.
package main
import (
"crypto/hmac"
"crypto/md5"
"encoding/hex"
"fmt"
"sort"
"strconv"
)
func main() {
mm := map[string]string{
"BACK_REF": "http://www.backref.com.tr",
"BILL_ADDRESS": "Birinci Adres satır",
"BILL_ADDRESS2": "İkinci Adres satırı",
"BILL_CITY": "ISTANBUL",
"BILL_COUNTRYCODE": "TR",
"BILL_EMAIL": "[email protected]",
"BILL_FAX": "02129003711",
"BILL_FNAME": "Ad",
"BILL_LNAME": "Soyad",
"BILL_PHONE": "02129003711",
"BILL_STATE": "Ayazağa",
"BILL_ZIPCODE": "34000",
"CC_CVV": "000",
"CC_NUMBER": "4355084355084358",
"CC_OWNER": "Ad Soyad",
"CLIENT_IP": "127.0.0.1",
"DELIVERY_ADDRESS": "Birinci Adres satırı",
"DELIVERY_ADDRESS2": "İkinci Adres satırı",
"DELIVERY_CITY": "ISTANBUL",
"DELIVERY_COMPANY": "PayU Ödeme Kuruluşu A.Ş.",
"DELIVERY_COUNTRYCODE": "Ayazağa",
"DELIVERY_EMAIL": "[email protected]",
"DELIVERY_FNAME": "Ad",
"DELIVERY_LNAME": "Soyad",
"DELIVERY_PHONE": "02129003711",
"DELIVERY_STATE": "TR",
"DELIVERY_ZIPCODE": "34000",
"EXP_MONTH": "12",
"EXP_YEAR": "2018",
"LANGUAGE": "TR",
"MERCHANT": "OPU_TEST",
"ORDER_DATE": "2017-10-04 11:10:23",
"ORDER_PCODE0": "Test Kodu",
"ORDER_PCODE1": "Test Kodu-2",
"ORDER_PINFO0": "Test Açıklaması",
"ORDER_PINFO1": "Test Açıklaması-2",
"ORDER_PNAME0": "Test Ürünü",
"ORDER_PNAME1": "Test Ürünü-2",
"ORDER_PRICE0": "5",
"ORDER_PRICE1": "15",
"ORDER_PRICE_TYPE0": "NET",
"ORDER_PRICE_TYPE1": "GROSS",
"ORDER_QTY0": "1",
"ORDER_QTY1": "3",
"ORDER_REF": "3245",
"ORDER_SHIPPING": "5",
"ORDER_VAT0": "18",
"ORDER_VAT1": "24",
"PAY_METHOD": "CCVISAMC",
"PRICES_CURRENCY": "TRY",
}
keys := make([]string, 0, len(mm))
for k := range mm {
keys = append(keys, k)
}
sort.Strings(keys)
resp := ""
for _, k := range keys {
resp += strconv.Itoa(len(mm[k]))
resp += mm[k]
}
fmt.Println(resp)
// resp olusturdugumuz string
key := []byte("secret key buraya gelecek")
sig := hmac.New(md5.New, key)
sig.Write([]byte(resp))
fmt.Println("Response hex! -> ", hex.EncodeToString(sig.Sum(nil)))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment