先贴出PHP代码:
$string = "1234";
$key = "abcd";
$signature = hash_hmac('sha256', $string, $key);
然后是Golang:
package main
import (
"crypto/hmac"
"crypto/sha256"
"encoding/hex"
"fmt"
)
func main() {
s := []byte("1234")
key := []byte("abcd")
m := hmac.New(sha256.New, key )
m.Write( s )
signature := hex.EncodeToString(m.Sum(nil))
fmt.Print(signature + "\n\r")
}
得出签名都是:d219a3dd877f943be0ee65ef6a34129778d2fd0568ce2d9a8f37fea9d7fcaca3