# -*- coding: utf-8 -*-
# 与 AppEn 请求体中各字段值的百分号编码规则一致（字母数字与 -._~ 不编码）。


def encode_parameter(s: str) -> str:
    out: list[str] = []
    for ch in s:
        o = ord(ch)
        if (
            (65 <= o <= 90)
            or (97 <= o <= 122)
            or (48 <= o <= 57)
            or ch in "-._~"
        ):
            out.append(ch)
        else:
            for b in ch.encode("utf-8"):
                out.append(f"%{b:02X}")
    return "".join(out)
