This repository has been archived by the owner on Nov 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
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
Showing
10 changed files
with
54 additions
and
50 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
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
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
File renamed without changes.
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,12 +1,43 @@ | ||
package epay | ||
|
||
import ( | ||
"crypto/subtle" | ||
"fmt" | ||
"sort" | ||
"strings" | ||
|
||
"github.com/AH-dark/bytestring" | ||
"github.com/samber/lo" | ||
|
||
"github.com/AH-dark/epay-cli/pkg/utils" | ||
) | ||
|
||
// GenerateParams 生成加签参数 | ||
func GenerateParams(params map[string]string, secret string) map[string]string { | ||
params["sign"] = utils.CalculateEPaySign(params, secret) | ||
params["sign"] = bytestring.BytesToString(CalculateEPaySign(params, secret)) | ||
params["sign_type"] = "MD5" | ||
return params | ||
} | ||
|
||
func CalculateEPaySign(mapData map[string]string, secret string) []byte { | ||
// sort keys | ||
keys := lo.Keys(mapData) | ||
sort.Strings(keys) | ||
|
||
combinedData := "" | ||
for _, k := range keys { | ||
if k == "sign" || k == "sign_type" || lo.IsEmpty(mapData[k]) { | ||
continue | ||
} | ||
|
||
combinedData += fmt.Sprintf("%s=%s&", k, mapData[k]) | ||
} | ||
|
||
combinedData = strings.TrimSuffix(combinedData, "&") | ||
|
||
return utils.MD5(combinedData + secret) | ||
} | ||
|
||
func CheckEPaySign(mapData map[string]string, secret string, sign []byte) bool { | ||
return subtle.ConstantTimeCompare(CalculateEPaySign(mapData, secret), sign) == 1 | ||
} |
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 was deleted.
Oops, something went wrong.