feat(payment): 虎皮椒聚合支付 - 官方插件与跨平台可执行文件
新增 xunhupay 官方包,支付 RPC 与宿主只保留订单和验签边界;官方支付包同时带上各系统 provider,避免把 Linux ELF 当成本机入口。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
e5a5f0ccc8
commit
a23df0cb32
63 files changed
+2070
-128
No files matched your search
@@ -0,0 +1,72 @@
|
||||
package protocol
|
||||
|
||||
import (
|
||||
"path"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func PaymentRPCBackendCandidates(entry, goos, goarch string) []string {
|
||||
entry = strings.TrimSuffix(strings.TrimSpace(entry), ".exe")
|
||||
goos = strings.TrimSpace(goos)
|
||||
goarch = strings.TrimSpace(goarch)
|
||||
if entry == "" || goos == "" || goarch == "" || path.Clean(entry) != entry || !strings.HasPrefix(entry, "backend/") {
|
||||
return nil
|
||||
}
|
||||
base := path.Base(entry)
|
||||
dir := path.Dir(entry)
|
||||
tagged := entry + "-" + goos + "-" + goarch
|
||||
nested := dir + "/" + goos + "-" + goarch + "/" + base
|
||||
candidates := make([]string, 0, 6)
|
||||
if goos == "windows" {
|
||||
candidates = append(candidates, tagged+".exe", nested+".exe", entry+".exe")
|
||||
}
|
||||
candidates = append(candidates, tagged, nested, entry)
|
||||
return uniqueStrings(candidates)
|
||||
}
|
||||
|
||||
func HasAnyPaymentRPCBackend(entry string, files map[string][]byte) bool {
|
||||
entry = strings.TrimSuffix(strings.TrimSpace(entry), ".exe")
|
||||
if entry == "" {
|
||||
return false
|
||||
}
|
||||
if _, ok := files[entry]; ok {
|
||||
return true
|
||||
}
|
||||
if _, ok := files[entry+".exe"]; ok {
|
||||
return true
|
||||
}
|
||||
prefix := entry + "-"
|
||||
nestedRoot := path.Dir(entry) + "/"
|
||||
base := path.Base(entry)
|
||||
for name := range files {
|
||||
if strings.HasPrefix(name, prefix) {
|
||||
return true
|
||||
}
|
||||
rest, ok := strings.CutPrefix(name, nestedRoot)
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
slash := strings.IndexByte(rest, '/')
|
||||
if slash <= 0 {
|
||||
continue
|
||||
}
|
||||
leaf := rest[slash+1:]
|
||||
if leaf == base || leaf == base+".exe" {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func uniqueStrings(values []string) []string {
|
||||
seen := make(map[string]struct{}, len(values))
|
||||
result := make([]string, 0, len(values))
|
||||
for _, value := range values {
|
||||
if _, exists := seen[value]; exists {
|
||||
continue
|
||||
}
|
||||
seen[value] = struct{}{}
|
||||
result = append(result, value)
|
||||
}
|
||||
return result
|
||||
}
|
||||
Reference in new issue
Block a user