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
@@ -2,17 +2,31 @@
|
||||
set -eu
|
||||
|
||||
root_dir=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)
|
||||
require_all=false
|
||||
|
||||
if [ "${1:-}" = "--all" ]; then
|
||||
require_all=true
|
||||
shift
|
||||
fi
|
||||
|
||||
expected_goos=${1:-}
|
||||
expected_goarch=${2:-}
|
||||
|
||||
if [ "$expected_goos" != "linux" ]; then
|
||||
echo "payment package verification currently requires expected GOOS linux" >&2
|
||||
if [ -z "$expected_goos" ] || [ -z "$expected_goarch" ]; then
|
||||
echo "usage: $0 [--all] <goos> <goarch>" >&2
|
||||
exit 2
|
||||
fi
|
||||
|
||||
case "$expected_goos" in
|
||||
linux|darwin|windows) ;;
|
||||
*)
|
||||
echo "unsupported payment package OS: $expected_goos" >&2
|
||||
exit 2
|
||||
;;
|
||||
esac
|
||||
|
||||
case "$expected_goarch" in
|
||||
amd64) expected_machine=3e00 ;;
|
||||
arm64) expected_machine=b700 ;;
|
||||
amd64|arm64) ;;
|
||||
*)
|
||||
echo "unsupported payment package architecture: $expected_goarch" >&2
|
||||
exit 2
|
||||
@@ -22,44 +36,132 @@ esac
|
||||
temporary_dir=$(mktemp -d)
|
||||
trap 'rm -rf "$temporary_dir"' EXIT HUP INT TERM
|
||||
|
||||
for package_id in official-payment-wechat-native official-payment-alipay-page; do
|
||||
provider="$root_dir/$package_id/backend/provider"
|
||||
file_magic() {
|
||||
od -An -tx1 -N4 "$1" | tr -d '[:space:]'
|
||||
}
|
||||
|
||||
payment_artifact_name() {
|
||||
goos=$1
|
||||
goarch=$2
|
||||
if [ "$goos" = "windows" ]; then
|
||||
printf 'provider-%s-%s.exe\n' "$goos" "$goarch"
|
||||
else
|
||||
printf 'provider-%s-%s\n' "$goos" "$goarch"
|
||||
fi
|
||||
}
|
||||
|
||||
verify_platform_magic() {
|
||||
path=$1
|
||||
goos=$2
|
||||
goarch=$3
|
||||
magic=$(file_magic "$path")
|
||||
case "$goos" in
|
||||
linux)
|
||||
if [ "$magic" != "7f454c46" ]; then
|
||||
echo "$path is not an ELF executable (magic=$magic)" >&2
|
||||
return 1
|
||||
fi
|
||||
class=$(od -An -tx1 -j4 -N1 "$path" | tr -d '[:space:]')
|
||||
byte_order=$(od -An -tx1 -j5 -N1 "$path" | tr -d '[:space:]')
|
||||
if [ "$class" != "02" ] || [ "$byte_order" != "01" ]; then
|
||||
echo "$path is not a 64-bit little-endian ELF executable" >&2
|
||||
return 1
|
||||
fi
|
||||
expected_machine=3e00
|
||||
if [ "$goarch" = "arm64" ]; then
|
||||
expected_machine=b700
|
||||
fi
|
||||
machine=$(od -An -tx1 -j18 -N2 "$path" | tr -d '[:space:]')
|
||||
if [ "$machine" != "$expected_machine" ]; then
|
||||
echo "$path architecture does not match linux/$goarch (ELF machine=$machine)" >&2
|
||||
return 1
|
||||
fi
|
||||
;;
|
||||
darwin)
|
||||
case "$magic" in
|
||||
cffaedfe|cefaedfe|feedfacf|feedface|cafebabe|bebafeca) ;;
|
||||
*)
|
||||
echo "$path is not a Mach-O executable (magic=$magic)" >&2
|
||||
return 1
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
windows)
|
||||
mz=$(od -An -tx1 -N2 "$path" | tr -d '[:space:]')
|
||||
if [ "$mz" != "4d5a" ]; then
|
||||
echo "$path is not a Windows PE executable (magic=$mz)" >&2
|
||||
return 1
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
verify_packaged_file() {
|
||||
package_file=$1
|
||||
relative_path=$2
|
||||
source_file=$3
|
||||
archived_file=$4
|
||||
unzip -p "$package_file" "$relative_path" >"$archived_file"
|
||||
if ! cmp -s "$source_file" "$archived_file"; then
|
||||
echo "$relative_path in $package_file differs from the directory file" >&2
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
all_targets="linux/amd64 linux/arm64 darwin/amd64 darwin/arm64 windows/amd64 windows/arm64"
|
||||
verify_targets="$expected_goos/$expected_goarch"
|
||||
if [ "$require_all" = true ]; then
|
||||
verify_targets="$all_targets"
|
||||
if [ "$expected_goos/$expected_goarch" != "linux/amd64" ]; then
|
||||
echo "--all currently expects canonical linux/amd64 as the host verification target" >&2
|
||||
exit 2
|
||||
fi
|
||||
fi
|
||||
|
||||
for package_id in official-payment-wechat-native official-payment-alipay-page official-payment-xunhupay; do
|
||||
backend_dir="$root_dir/$package_id/backend"
|
||||
provider="$backend_dir/provider"
|
||||
package_file="$root_dir/$package_id.yingce-plugin"
|
||||
archived_provider="$temporary_dir/$package_id-provider"
|
||||
expected_artifact=$(payment_artifact_name "$expected_goos" "$expected_goarch")
|
||||
|
||||
test -f "$provider"
|
||||
if [ "$(uname -s)" = "Linux" ]; then
|
||||
test -f "$package_file"
|
||||
if [ "$(uname -s)" = "Linux" ] || [ "$(uname -s)" = "Darwin" ]; then
|
||||
test -x "$provider"
|
||||
fi
|
||||
test -f "$package_file"
|
||||
|
||||
magic=$(od -An -tx1 -N4 "$provider" | tr -d '[:space:]')
|
||||
if [ "$magic" != "7f454c46" ]; then
|
||||
echo "$package_id provider is not an ELF executable (magic=$magic)" >&2
|
||||
verify_platform_magic "$provider" "$expected_goos" "$expected_goarch"
|
||||
verify_packaged_file "$package_file" backend/provider "$provider" "$temporary_dir/$package_id-provider"
|
||||
|
||||
test -f "$backend_dir/$expected_artifact"
|
||||
if ! cmp -s "$provider" "$backend_dir/$expected_artifact"; then
|
||||
echo "$package_id backend/provider does not match $expected_artifact" >&2
|
||||
exit 1
|
||||
fi
|
||||
verify_packaged_file "$package_file" "backend/$expected_artifact" "$backend_dir/$expected_artifact" "$temporary_dir/$package_id-$expected_artifact"
|
||||
|
||||
class=$(od -An -tx1 -j4 -N1 "$provider" | tr -d '[:space:]')
|
||||
byte_order=$(od -An -tx1 -j5 -N1 "$provider" | tr -d '[:space:]')
|
||||
if [ "$class" != "02" ] || [ "$byte_order" != "01" ]; then
|
||||
echo "$package_id provider is not a 64-bit little-endian ELF executable" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
machine=$(od -An -tx1 -j18 -N2 "$provider" | tr -d '[:space:]')
|
||||
if [ "$machine" != "$expected_machine" ]; then
|
||||
echo "$package_id provider architecture does not match linux/$expected_goarch (ELF machine=$machine)" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
unzip -p "$package_file" backend/provider >"$archived_provider"
|
||||
if ! cmp -s "$provider" "$archived_provider"; then
|
||||
echo "$package_id directory provider and packaged provider differ" >&2
|
||||
exit 1
|
||||
fi
|
||||
for target in $verify_targets; do
|
||||
target_goos=${target%/*}
|
||||
target_goarch=${target#*/}
|
||||
artifact_name=$(payment_artifact_name "$target_goos" "$target_goarch")
|
||||
artifact_path="$backend_dir/$artifact_name"
|
||||
test -f "$artifact_path"
|
||||
verify_platform_magic "$artifact_path" "$target_goos" "$target_goarch"
|
||||
verify_packaged_file "$package_file" "backend/$artifact_name" "$artifact_path" "$temporary_dir/$package_id-$artifact_name"
|
||||
done
|
||||
|
||||
if [ "${PAYMENT_PLUGIN_SMOKE_TEST:-0}" = "1" ]; then
|
||||
response=$(printf 'invalid-json\n' | "$provider")
|
||||
printf '%s\n' "$response" | grep -F '"code":"invalid_request"' >/dev/null
|
||||
current_sys=$(uname -s)
|
||||
can_smoke=0
|
||||
if [ "$expected_goos" = "linux" ] && [ "$current_sys" = "Linux" ]; then
|
||||
can_smoke=1
|
||||
fi
|
||||
if [ "$expected_goos" = "darwin" ] && [ "$current_sys" = "Darwin" ]; then
|
||||
can_smoke=1
|
||||
fi
|
||||
if [ "$can_smoke" = "1" ]; then
|
||||
response=$(printf 'invalid-json\n' | "$provider")
|
||||
printf '%s\n' "$response" | grep -F '"code":"invalid_request"' >/dev/null
|
||||
fi
|
||||
fi
|
||||
done
|
||||
Reference in new issue
Block a user