refactor: 重构用户模型和密码验证逻辑 feat(epay): 添加支付类型支持 docs: 添加安装和配置指南文档 fix: 修复优惠券过期检查逻辑 perf: 优化设备解绑缓存清理流程 test: 添加密码验证测试用例 chore: 更新依赖版本
This commit is contained in:
@@ -14,9 +14,10 @@ import (
|
||||
)
|
||||
|
||||
type Client struct {
|
||||
Pid string
|
||||
Url string
|
||||
Key string
|
||||
Pid string
|
||||
Url string
|
||||
Key string
|
||||
Type string
|
||||
}
|
||||
|
||||
type Order struct {
|
||||
@@ -37,11 +38,12 @@ type queryOrderStatusResponse struct {
|
||||
Status int `json:"status"`
|
||||
}
|
||||
|
||||
func NewClient(pid, url, key string) *Client {
|
||||
func NewClient(pid, url, key string, Type string) *Client {
|
||||
return &Client{
|
||||
Pid: pid,
|
||||
Url: url,
|
||||
Key: key,
|
||||
Pid: pid,
|
||||
Url: url,
|
||||
Key: key,
|
||||
Type: Type,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,6 +55,7 @@ func (c *Client) CreatePayUrl(order Order) string {
|
||||
params.Set("notify_url", order.NotifyUrl)
|
||||
params.Set("out_trade_no", order.OrderNo)
|
||||
params.Set("pid", c.Pid)
|
||||
params.Set("type", c.Type)
|
||||
params.Set("return_url", order.ReturnUrl)
|
||||
|
||||
// Generate the sign using the CreateSign function
|
||||
@@ -117,6 +120,7 @@ func (c *Client) structToMap(order Order) map[string]string {
|
||||
result["notify_url"] = order.NotifyUrl
|
||||
result["out_trade_no"] = order.OrderNo
|
||||
result["pid"] = c.Pid
|
||||
result["type"] = c.Type
|
||||
result["return_url"] = order.ReturnUrl
|
||||
return result
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ package epay
|
||||
import "testing"
|
||||
|
||||
func TestEpay(t *testing.T) {
|
||||
client := NewClient("", "http://127.0.0.1", "")
|
||||
client := NewClient("", "http://127.0.0.1", "", "")
|
||||
order := Order{
|
||||
Name: "测试",
|
||||
OrderNo: "123456789",
|
||||
@@ -19,7 +19,7 @@ func TestEpay(t *testing.T) {
|
||||
|
||||
func TestQueryOrderStatus(t *testing.T) {
|
||||
t.Skipf("Skip TestQueryOrderStatus test")
|
||||
client := NewClient("Pid", "Url", "Key")
|
||||
client := NewClient("Pid", "Url", "Key", "Type")
|
||||
orderNo := "123456789"
|
||||
status := client.QueryOrderStatus(orderNo)
|
||||
t.Logf("OrderNo: %s, Status: %v\n", orderNo, status)
|
||||
@@ -40,7 +40,7 @@ func TestVerifySign(t *testing.T) {
|
||||
}
|
||||
|
||||
key := "LbTabbB580zWyhXhyyww7wwvy5u8k0wl"
|
||||
c := NewClient("Pid", "Url", key)
|
||||
c := NewClient("Pid", "Url", key, "Type")
|
||||
if c.VerifySign(params) {
|
||||
t.Logf("Sign verification success!")
|
||||
} else {
|
||||
|
||||
@@ -65,9 +65,10 @@ func GetSupportedPlatforms() []types.PlatformInfo {
|
||||
Platform: EPay.String(),
|
||||
PlatformUrl: "",
|
||||
PlatformFieldDescription: map[string]string{
|
||||
"pid": "PID",
|
||||
"url": "URL",
|
||||
"key": "Key",
|
||||
"pid": "PID",
|
||||
"url": "URL",
|
||||
"key": "Key",
|
||||
"type": "Type",
|
||||
},
|
||||
},
|
||||
{
|
||||
|
||||
@@ -2,12 +2,14 @@ package tool
|
||||
|
||||
import (
|
||||
"crypto/md5"
|
||||
"crypto/sha256"
|
||||
"crypto/sha512"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/anaskhan96/go-password-encoder"
|
||||
"golang.org/x/crypto/bcrypt"
|
||||
)
|
||||
|
||||
var options = &password.Options{SaltLen: 16, Iterations: 100, KeyLen: 32, HashFunction: sha512.New}
|
||||
@@ -32,3 +34,24 @@ func Md5Encode(str string, isUpper bool) string {
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
func MultiPasswordVerify(algo, salt, password, hash string) bool {
|
||||
switch algo {
|
||||
case "md5":
|
||||
sum := md5.Sum([]byte(password))
|
||||
return hex.EncodeToString(sum[:]) == hash
|
||||
case "sha256":
|
||||
sum := sha256.Sum256([]byte(password))
|
||||
return hex.EncodeToString(sum[:]) == hash
|
||||
case "md5salt":
|
||||
sum := md5.Sum([]byte(password + salt))
|
||||
return hex.EncodeToString(sum[:]) == hash
|
||||
case "default": // PPanel's default algorithm
|
||||
return VerifyPassWord(password, hash)
|
||||
case "bcrypt":
|
||||
// Bcrypt (corresponding to PHP's password_hash/password_verify)
|
||||
err := bcrypt.CompareHashAndPassword([]byte(hash), []byte(password))
|
||||
return err == nil
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -1,7 +1,15 @@
|
||||
package tool
|
||||
|
||||
import "testing"
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestEncodePassWord(t *testing.T) {
|
||||
t.Logf("EncodePassWord: %v", EncodePassWord("password"))
|
||||
}
|
||||
|
||||
func TestMultiPasswordVerify(t *testing.T) {
|
||||
pwd := "$2y$10$WFO17pdtohfeBILjEChoGeVxpDG.u9kVCKhjDAeEeNmCjIlj3tDRy"
|
||||
status := MultiPasswordVerify("bcrypt", "", "admin1", pwd)
|
||||
t.Logf("MultiPasswordVerify: %v", status)
|
||||
}
|
||||
|
||||
@@ -57,6 +57,7 @@ const (
|
||||
CouponAlreadyUsed uint32 = 50002 // Coupon has already been used
|
||||
CouponNotApplicable uint32 = 50003 // Coupon does not match the order or conditions
|
||||
CouponInsufficientUsage uint32 = 50004 // Coupon has insufficient remaining uses
|
||||
CouponExpired uint32 = 50005 // Coupon is expired
|
||||
)
|
||||
|
||||
// Subscribe
|
||||
|
||||
@@ -46,6 +46,7 @@ func init() {
|
||||
CouponAlreadyUsed: "Coupon has already been used",
|
||||
CouponNotApplicable: "Coupon does not match the order or conditions",
|
||||
CouponInsufficientUsage: "Coupon has insufficient remaining uses",
|
||||
CouponExpired: "Coupon is expired",
|
||||
|
||||
// Subscribe
|
||||
SubscribeExpired: "Subscribe is expired",
|
||||
|
||||
Reference in New Issue
Block a user