-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
45f79d3
commit d6d45e6
Showing
5 changed files
with
110 additions
and
6 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
# Wechat AES | ||
|
||
提供接收和推送给微信公众平台消息的加解密接口 | ||
|
||
参见微信开放平台->第三方平台->[消息加解密接入指引](https://open.weixin.qq.com/cgi-bin/showdocument?action=dir_list&t=resource/res_list&verify=1&id=open1419318479&token=&lang=zh_CN) |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package wechataes | ||
|
||
import ( | ||
"crypto/sha1" | ||
"encoding/hex" | ||
"sort" | ||
"strings" | ||
) | ||
|
||
func SHA1(token, timestamp, nonce, encrypt string) string { | ||
array := []string{token, timestamp, nonce, encrypt} | ||
sort.Strings(array) | ||
str := strings.Join(array, "") | ||
|
||
hash := sha1.New() | ||
hash.Write([]byte(str)) | ||
sum := hash.Sum(nil) | ||
sumHex := make([]byte, hex.EncodedLen(len(sum))) | ||
hex.Encode(sumHex, sum) | ||
return string(sumHex) | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package wechataes | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
var expectSHA1 = "82c962d39941aa48552f90ef55aa323dc620cc10" | ||
|
||
func TestSHA1(t *testing.T) { | ||
sha1 := SHA1(token, timestamp, nonce, afterAesEncrypt) | ||
if expectSHA1 != sha1 { | ||
t.Error("no异常") | ||
} | ||
} |