import{_ as r,c,b as n,a as p,d as a,e,w as o,r as D,o as t}from"./app-CDdN0tOz.js";const i={};function y(d,s){const l=D("RouteLink");return t(),c("div",null,[s[16]||(s[16]=n("h1",{id:"app-api-签名与鉴权",tabindex:"-1"},[n("a",{class:"header-anchor",href:"#app-api-签名与鉴权"},[n("span",null,"APP API 签名与鉴权")])],-1)),s[17]||(s[17]=n("h2",{id:"app-api-签名特性",tabindex:"-1"},[n("a",{class:"header-anchor",href:"#app-api-签名特性"},[n("span",null,"APP API 签名特性")])],-1)),n("p",null,[s[1]||(s[1]=a("部分客户端专用的 REST API 存在基于参数签名的鉴权，需要使用规定的")),s[2]||(s[2]=n("code",null,"appkey",-1)),s[3]||(s[3]=a("及其对应的")),s[4]||(s[4]=n("code",null,"appsec",-1)),s[5]||(s[5]=a("与原始请求参数进行签名计算，部分")),s[6]||(s[6]=n("code",null,"AppKey",-1)),s[7]||(s[7]=a("及与之对应的")),s[8]||(s[8]=n("code",null,"AppSec",-1)),s[9]||(s[9]=a("已经被公开：见该文档 ")),e(l,{to:"/docs/misc/sign/APPKey.html"},{default:o(()=>s[0]||(s[0]=[a("APPKey")])),_:1,__:[0]})]),s[18]||(s[18]=p('<ul><li><p>不同 <code>appkey</code> 对应不同的 app (如客户端、概念版、必剪、漫画、bililink等)</p></li><li><p>不同平台同 app 也会存在不同的 <code>appkey</code> (如安卓端、ios端、TV端等)</p></li><li><p>同平台同 app 下不同功能也会存在不同的 <code>appkey</code>（如登录专用、取流专用等）</p></li><li><p>不同版本的客户端的 <code>appkey</code> 也可能不同</p></li><li><p><strong>appkey与appsec一一对应</strong></p></li></ul><h2 id="app-api-签名算法" tabindex="-1"><a class="header-anchor" href="#app-api-签名算法"><span>APP API 签名算法</span></a></h2><ol><li>首先为参数中添加<code>appkey</code>字段</li><li>然后按照参数的 Key 重新排序</li><li>再对这个 Key-Value 进行 url query 序列化，并拼接与之对应的<code>appsec</code> (盐) 进行 <strong>md5 Hash 运算</strong>（32-bit 字符小写），该 hash 便是 API 签名</li><li>最后在参数尾部增添<code>sign</code>字段，它的 Value 为上一步计算所得的 hash，一并作为表单或 Query 提交</li></ol><h2 id="demo" tabindex="-1"><a class="header-anchor" href="#demo"><span>Demo</span></a></h2><p>该 Demo 提供 <a href="#python">Python</a>、<a href="#java">Java</a>、<a href="#typescript-javascript">TS/JS</a>、<a href="#swift">Swift</a>、<a href="#cplusplus">C++</a> 语言例程</p><p>使用 appkey = <code>1d8b6e7d45233436</code>, appsec = <code>560c52ccd288fed045859ed18bffd973</code> 对如下 <code>params</code> 参数进行签名</p>',6)),n("p",null,[s[11]||(s[11]=a("上述示例")),s[12]||(s[12]=n("code",null,"appkey",-1)),s[13]||(s[13]=a("、")),s[14]||(s[14]=n("code",null,"AppSec",-1)),s[15]||(s[15]=a("均来自文档 ")),e(l,{to:"/docs/misc/sign/APPKey.html"},{default:o(()=>s[10]||(s[10]=[a("APPKey")])),_:1,__:[10]})]),s[19]||(s[19]=p(`<h3 id="python" tabindex="-1"><a class="header-anchor" href="#python"><span>Python</span></a></h3><div class="language-python line-numbers-mode" data-highlighter="shiki" data-ext="python" style="background-color:#1E1E1E;color:#D4D4D4;"><pre class="shiki dark-plus vp-code"><code class="language-python"><span class="line"><span style="color:#C586C0;">import</span><span style="color:#D4D4D4;"> hashlib</span></span>
<span class="line"><span style="color:#C586C0;">import</span><span style="color:#D4D4D4;"> urllib.parse</span></span>
<span class="line"></span>
<span class="line"><span style="color:#569CD6;">def</span><span style="color:#DCDCAA;"> appsign</span><span style="color:#D4D4D4;">(</span><span style="color:#9CDCFE;">params</span><span style="color:#D4D4D4;">, </span><span style="color:#9CDCFE;">appkey</span><span style="color:#D4D4D4;">, </span><span style="color:#9CDCFE;">appsec</span><span style="color:#D4D4D4;">):</span></span>
<span class="line"><span style="color:#CE9178;">    &#39;为请求参数进行 APP 签名&#39;</span></span>
<span class="line"><span style="color:#D4D4D4;">    params.update({</span><span style="color:#CE9178;">&#39;appkey&#39;</span><span style="color:#D4D4D4;">: appkey})</span></span>
<span class="line"><span style="color:#D4D4D4;">    params = </span><span style="color:#4EC9B0;">dict</span><span style="color:#D4D4D4;">(</span><span style="color:#DCDCAA;">sorted</span><span style="color:#D4D4D4;">(params.items())) </span><span style="color:#6A9955;"># 按照 key 重排参数</span></span>
<span class="line"><span style="color:#D4D4D4;">    query = urllib.parse.urlencode(params) </span><span style="color:#6A9955;"># 序列化参数</span></span>
<span class="line"><span style="color:#D4D4D4;">    sign = hashlib.md5((query+appsec).encode()).hexdigest() </span><span style="color:#6A9955;"># 计算 api 签名</span></span>
<span class="line"><span style="color:#D4D4D4;">    params.update({</span><span style="color:#CE9178;">&#39;sign&#39;</span><span style="color:#D4D4D4;">:sign})</span></span>
<span class="line"><span style="color:#C586C0;">    return</span><span style="color:#D4D4D4;"> params</span></span>
<span class="line"></span>
<span class="line"><span style="color:#D4D4D4;">appkey = </span><span style="color:#CE9178;">&#39;1d8b6e7d45233436&#39;</span></span>
<span class="line"><span style="color:#D4D4D4;">appsec = </span><span style="color:#CE9178;">&#39;560c52ccd288fed045859ed18bffd973&#39;</span></span>
<span class="line"><span style="color:#D4D4D4;">params = {</span></span>
<span class="line"><span style="color:#CE9178;">    &#39;id&#39;</span><span style="color:#D4D4D4;">:</span><span style="color:#B5CEA8;">114514</span><span style="color:#D4D4D4;">,</span></span>
<span class="line"><span style="color:#CE9178;">    &#39;str&#39;</span><span style="color:#D4D4D4;">:</span><span style="color:#CE9178;">&#39;1919810&#39;</span><span style="color:#D4D4D4;">,</span></span>
<span class="line"><span style="color:#CE9178;">    &#39;test&#39;</span><span style="color:#D4D4D4;">:</span><span style="color:#CE9178;">&#39;いいよ，こいよ&#39;</span><span style="color:#D4D4D4;">,</span></span>
<span class="line"><span style="color:#D4D4D4;">}</span></span>
<span class="line"><span style="color:#D4D4D4;">signed_params = appsign(params, appkey, appsec)</span></span>
<span class="line"><span style="color:#D4D4D4;">query = urllib.parse.urlencode(signed_params)</span></span>
<span class="line"><span style="color:#DCDCAA;">print</span><span style="color:#D4D4D4;">(signed_params)</span></span>
<span class="line"><span style="color:#DCDCAA;">print</span><span style="color:#D4D4D4;">(query)</span></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>输出内容分别是进行 APP 签名的后参数的 key-Value 以及 url query 形式</p><div class="language- line-numbers-mode" data-highlighter="shiki" data-ext="" style="background-color:#1E1E1E;color:#D4D4D4;"><pre class="shiki dark-plus vp-code"><code class="language-"><span class="line"><span>{&#39;appkey&#39;: &#39;1d8b6e7d45233436&#39;, &#39;id&#39;: 114514, &#39;str&#39;: &#39;1919810&#39;, &#39;test&#39;: &#39;いいよ，こいよ&#39;, &#39;sign&#39;: &#39;01479cf20504d865519ac50f33ba3a7d&#39;}</span></span>
<span class="line"><span>appkey=1d8b6e7d45233436&amp;id=114514&amp;str=1919810&amp;test=%E3%81%84%E3%81%84%E3%82%88%EF%BC%8C%E3%81%93%E3%81%84%E3%82%88&amp;sign=01479cf20504d865519ac50f33ba3a7d</span></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="java" tabindex="-1"><a class="header-anchor" href="#java"><span>Java</span></a></h3><div class="language-java line-numbers-mode" data-highlighter="shiki" data-ext="java" style="background-color:#1E1E1E;color:#D4D4D4;"><pre class="shiki dark-plus vp-code"><code class="language-java"><span class="line"><span style="color:#569CD6;">package</span><span style="color:#D4D4D4;"> io.github.cctyl;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#569CD6;">import</span><span style="color:#D4D4D4;"> java.nio.charset.StandardCharsets;</span></span>
<span class="line"><span style="color:#569CD6;">import</span><span style="color:#D4D4D4;"> java.util.HashMap;</span></span>
<span class="line"><span style="color:#569CD6;">import</span><span style="color:#D4D4D4;"> java.util.Map;</span></span>
<span class="line"><span style="color:#569CD6;">import</span><span style="color:#D4D4D4;"> java.security.MessageDigest;</span></span>
<span class="line"><span style="color:#569CD6;">import</span><span style="color:#D4D4D4;"> java.security.NoSuchAlgorithmException;</span></span>
<span class="line"><span style="color:#569CD6;">import</span><span style="color:#D4D4D4;"> java.net.URLEncoder;</span></span>
<span class="line"><span style="color:#569CD6;">import</span><span style="color:#D4D4D4;"> java.util.TreeMap;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#6A9955;">/**</span></span>
<span class="line"><span style="color:#6A9955;"> * </span><span style="color:#569CD6;">@author</span><span style="color:#6A9955;"> cctyl</span></span>
<span class="line"><span style="color:#6A9955;"> */</span></span>
<span class="line"><span style="color:#569CD6;">public</span><span style="color:#569CD6;"> class</span><span style="color:#4EC9B0;"> AppSigner</span><span style="color:#D4D4D4;"> {</span></span>
<span class="line"></span>
<span class="line"><span style="color:#569CD6;">    private</span><span style="color:#569CD6;"> static</span><span style="color:#569CD6;"> final</span><span style="color:#4EC9B0;"> String</span><span style="color:#9CDCFE;"> APP_KEY</span><span style="color:#D4D4D4;"> = </span><span style="color:#CE9178;">&quot;1d8b6e7d45233436&quot;</span><span style="color:#D4D4D4;">;</span></span>
<span class="line"><span style="color:#569CD6;">    private</span><span style="color:#569CD6;"> static</span><span style="color:#569CD6;"> final</span><span style="color:#4EC9B0;"> String</span><span style="color:#9CDCFE;"> APP_SEC</span><span style="color:#D4D4D4;"> = </span><span style="color:#CE9178;">&quot;560c52ccd288fed045859ed18bffd973&quot;</span><span style="color:#D4D4D4;">;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#569CD6;">    public</span><span style="color:#569CD6;"> static</span><span style="color:#4EC9B0;"> String</span><span style="color:#DCDCAA;"> appSign</span><span style="color:#D4D4D4;">(</span><span style="color:#4EC9B0;">Map</span><span style="color:#D4D4D4;">&lt;</span><span style="color:#4EC9B0;">String</span><span style="color:#D4D4D4;">, </span><span style="color:#4EC9B0;">String</span><span style="color:#D4D4D4;">&gt; </span><span style="color:#9CDCFE;">params</span><span style="color:#D4D4D4;">) {</span></span>
<span class="line"><span style="color:#6A9955;">        // 为请求参数进行 APP 签名</span></span>
<span class="line"><span style="color:#9CDCFE;">        params</span><span style="color:#D4D4D4;">.</span><span style="color:#DCDCAA;">put</span><span style="color:#D4D4D4;">(</span><span style="color:#CE9178;">&quot;appkey&quot;</span><span style="color:#D4D4D4;">, APP_KEY);</span></span>
<span class="line"><span style="color:#6A9955;">        // 按照 key 重排参数</span></span>
<span class="line"><span style="color:#4EC9B0;">        Map</span><span style="color:#D4D4D4;">&lt;</span><span style="color:#4EC9B0;">String</span><span style="color:#D4D4D4;">, </span><span style="color:#4EC9B0;">String</span><span style="color:#D4D4D4;">&gt; </span><span style="color:#9CDCFE;">sortedParams</span><span style="color:#D4D4D4;"> = </span><span style="color:#C586C0;">new</span><span style="color:#4EC9B0;"> TreeMap</span><span style="color:#D4D4D4;">&lt;&gt;(params);</span></span>
<span class="line"><span style="color:#6A9955;">        // 序列化参数</span></span>
<span class="line"><span style="color:#4EC9B0;">        StringBuilder</span><span style="color:#9CDCFE;"> queryBuilder</span><span style="color:#D4D4D4;"> = </span><span style="color:#C586C0;">new</span><span style="color:#DCDCAA;"> StringBuilder</span><span style="color:#D4D4D4;">();</span></span>
<span class="line"><span style="color:#C586C0;">        for</span><span style="color:#D4D4D4;"> (</span><span style="color:#4EC9B0;">Map</span><span style="color:#D4D4D4;">.</span><span style="color:#4EC9B0;">Entry</span><span style="color:#D4D4D4;">&lt;</span><span style="color:#4EC9B0;">String</span><span style="color:#D4D4D4;">, </span><span style="color:#4EC9B0;">String</span><span style="color:#D4D4D4;">&gt; </span><span style="color:#9CDCFE;">entry</span><span style="color:#C586C0;"> :</span><span style="color:#9CDCFE;"> sortedParams</span><span style="color:#D4D4D4;">.</span><span style="color:#DCDCAA;">entrySet</span><span style="color:#D4D4D4;">()) {</span></span>
<span class="line"><span style="color:#C586C0;">            if</span><span style="color:#D4D4D4;"> (</span><span style="color:#9CDCFE;">queryBuilder</span><span style="color:#D4D4D4;">.</span><span style="color:#DCDCAA;">length</span><span style="color:#D4D4D4;">() &gt; </span><span style="color:#B5CEA8;">0</span><span style="color:#D4D4D4;">) {</span></span>
<span class="line"><span style="color:#9CDCFE;">                queryBuilder</span><span style="color:#D4D4D4;">.</span><span style="color:#DCDCAA;">append</span><span style="color:#D4D4D4;">(</span><span style="color:#CE9178;">&#39;&amp;&#39;</span><span style="color:#D4D4D4;">);</span></span>
<span class="line"><span style="color:#D4D4D4;">            }</span></span>
<span class="line"><span style="color:#D4D4D4;">            queryBuilder</span></span>
<span class="line"><span style="color:#D4D4D4;">                    .</span><span style="color:#DCDCAA;">append</span><span style="color:#D4D4D4;">(</span><span style="color:#9CDCFE;">URLEncoder</span><span style="color:#D4D4D4;">.</span><span style="color:#DCDCAA;">encode</span><span style="color:#D4D4D4;">(</span><span style="color:#9CDCFE;">entry</span><span style="color:#D4D4D4;">.</span><span style="color:#DCDCAA;">getKey</span><span style="color:#D4D4D4;">(), </span><span style="color:#9CDCFE;">StandardCharsets</span><span style="color:#D4D4D4;">.</span><span style="color:#9CDCFE;">UTF_8</span><span style="color:#D4D4D4;">))</span></span>
<span class="line"><span style="color:#D4D4D4;">                    .</span><span style="color:#DCDCAA;">append</span><span style="color:#D4D4D4;">(</span><span style="color:#CE9178;">&#39;=&#39;</span><span style="color:#D4D4D4;">)</span></span>
<span class="line"><span style="color:#D4D4D4;">                    .</span><span style="color:#DCDCAA;">append</span><span style="color:#D4D4D4;">(</span><span style="color:#9CDCFE;">URLEncoder</span><span style="color:#D4D4D4;">.</span><span style="color:#DCDCAA;">encode</span><span style="color:#D4D4D4;">(</span><span style="color:#9CDCFE;">entry</span><span style="color:#D4D4D4;">.</span><span style="color:#DCDCAA;">getValue</span><span style="color:#D4D4D4;">(), </span><span style="color:#9CDCFE;">StandardCharsets</span><span style="color:#D4D4D4;">.</span><span style="color:#9CDCFE;">UTF_8</span><span style="color:#D4D4D4;">));</span></span>
<span class="line"><span style="color:#D4D4D4;">        }</span></span>
<span class="line"><span style="color:#C586C0;">        return</span><span style="color:#DCDCAA;"> generateMD5</span><span style="color:#D4D4D4;">(</span><span style="color:#9CDCFE;">queryBuilder</span><span style="color:#D4D4D4;"> .</span><span style="color:#DCDCAA;">append</span><span style="color:#D4D4D4;">(APP_SEC).</span><span style="color:#DCDCAA;">toString</span><span style="color:#D4D4D4;">());</span></span>
<span class="line"><span style="color:#D4D4D4;">    }</span></span>
<span class="line"></span>
<span class="line"><span style="color:#569CD6;">    private</span><span style="color:#569CD6;"> static</span><span style="color:#4EC9B0;"> String</span><span style="color:#DCDCAA;"> generateMD5</span><span style="color:#D4D4D4;">(</span><span style="color:#4EC9B0;">String</span><span style="color:#9CDCFE;"> input</span><span style="color:#D4D4D4;">) {</span></span>
<span class="line"><span style="color:#C586C0;">        try</span><span style="color:#D4D4D4;"> {</span></span>
<span class="line"><span style="color:#4EC9B0;">            MessageDigest</span><span style="color:#9CDCFE;"> md</span><span style="color:#D4D4D4;"> = </span><span style="color:#9CDCFE;">MessageDigest</span><span style="color:#D4D4D4;">.</span><span style="color:#DCDCAA;">getInstance</span><span style="color:#D4D4D4;">(</span><span style="color:#CE9178;">&quot;MD5&quot;</span><span style="color:#D4D4D4;">);</span></span>
<span class="line"><span style="color:#4EC9B0;">            byte</span><span style="color:#D4D4D4;">[] </span><span style="color:#9CDCFE;">digest</span><span style="color:#D4D4D4;"> = </span><span style="color:#9CDCFE;">md</span><span style="color:#D4D4D4;">.</span><span style="color:#DCDCAA;">digest</span><span style="color:#D4D4D4;">(</span><span style="color:#9CDCFE;">input</span><span style="color:#D4D4D4;">.</span><span style="color:#DCDCAA;">getBytes</span><span style="color:#D4D4D4;">());</span></span>
<span class="line"><span style="color:#4EC9B0;">            StringBuilder</span><span style="color:#9CDCFE;"> sb</span><span style="color:#D4D4D4;"> = </span><span style="color:#C586C0;">new</span><span style="color:#DCDCAA;"> StringBuilder</span><span style="color:#D4D4D4;">();</span></span>
<span class="line"><span style="color:#C586C0;">            for</span><span style="color:#D4D4D4;"> (</span><span style="color:#4EC9B0;">byte</span><span style="color:#9CDCFE;"> b</span><span style="color:#C586C0;"> :</span><span style="color:#D4D4D4;"> digest) {</span></span>
<span class="line"><span style="color:#9CDCFE;">                sb</span><span style="color:#D4D4D4;">.</span><span style="color:#DCDCAA;">append</span><span style="color:#D4D4D4;">(</span><span style="color:#9CDCFE;">String</span><span style="color:#D4D4D4;">.</span><span style="color:#DCDCAA;">format</span><span style="color:#D4D4D4;">(</span><span style="color:#CE9178;">&quot;%02x&quot;</span><span style="color:#D4D4D4;">, b));</span></span>
<span class="line"><span style="color:#D4D4D4;">            }</span></span>
<span class="line"><span style="color:#C586C0;">            return</span><span style="color:#9CDCFE;"> sb</span><span style="color:#D4D4D4;">.</span><span style="color:#DCDCAA;">toString</span><span style="color:#D4D4D4;">();</span></span>
<span class="line"><span style="color:#D4D4D4;">        } </span><span style="color:#C586C0;">catch</span><span style="color:#D4D4D4;"> (</span><span style="color:#4EC9B0;">NoSuchAlgorithmException</span><span style="color:#9CDCFE;"> e</span><span style="color:#D4D4D4;">) {</span></span>
<span class="line"><span style="color:#9CDCFE;">            e</span><span style="color:#D4D4D4;">.</span><span style="color:#DCDCAA;">printStackTrace</span><span style="color:#D4D4D4;">();</span></span>
<span class="line"><span style="color:#D4D4D4;">        }</span></span>
<span class="line"><span style="color:#C586C0;">        return</span><span style="color:#569CD6;"> null</span><span style="color:#D4D4D4;">;</span></span>
<span class="line"><span style="color:#D4D4D4;">    }</span></span>
<span class="line"></span>
<span class="line"><span style="color:#569CD6;">    public</span><span style="color:#569CD6;"> static</span><span style="color:#4EC9B0;"> void</span><span style="color:#DCDCAA;"> main</span><span style="color:#D4D4D4;">(</span><span style="color:#4EC9B0;">String</span><span style="color:#D4D4D4;">[] </span><span style="color:#9CDCFE;">args</span><span style="color:#D4D4D4;">) {</span></span>
<span class="line"><span style="color:#4EC9B0;">        Map</span><span style="color:#D4D4D4;">&lt;</span><span style="color:#4EC9B0;">String</span><span style="color:#D4D4D4;">, </span><span style="color:#4EC9B0;">String</span><span style="color:#D4D4D4;">&gt; </span><span style="color:#9CDCFE;">params</span><span style="color:#D4D4D4;"> = </span><span style="color:#C586C0;">new</span><span style="color:#4EC9B0;"> HashMap</span><span style="color:#D4D4D4;">&lt;&gt;();</span></span>
<span class="line"><span style="color:#9CDCFE;">        params</span><span style="color:#D4D4D4;">.</span><span style="color:#DCDCAA;">put</span><span style="color:#D4D4D4;">(</span><span style="color:#CE9178;">&quot;id&quot;</span><span style="color:#D4D4D4;">, </span><span style="color:#CE9178;">&quot;114514&quot;</span><span style="color:#D4D4D4;">);</span></span>
<span class="line"><span style="color:#9CDCFE;">        params</span><span style="color:#D4D4D4;">.</span><span style="color:#DCDCAA;">put</span><span style="color:#D4D4D4;">(</span><span style="color:#CE9178;">&quot;str&quot;</span><span style="color:#D4D4D4;">, </span><span style="color:#CE9178;">&quot;1919810&quot;</span><span style="color:#D4D4D4;">);</span></span>
<span class="line"><span style="color:#9CDCFE;">        params</span><span style="color:#D4D4D4;">.</span><span style="color:#DCDCAA;">put</span><span style="color:#D4D4D4;">(</span><span style="color:#CE9178;">&quot;test&quot;</span><span style="color:#D4D4D4;">, </span><span style="color:#CE9178;">&quot;いいよ，こいよ&quot;</span><span style="color:#D4D4D4;">);</span></span>
<span class="line"><span style="color:#9CDCFE;">        System</span><span style="color:#D4D4D4;">.</span><span style="color:#9CDCFE;">out</span><span style="color:#D4D4D4;">.</span><span style="color:#DCDCAA;">println</span><span style="color:#D4D4D4;">(</span><span style="color:#DCDCAA;">appSign</span><span style="color:#D4D4D4;">(params));</span></span>
<span class="line"><span style="color:#D4D4D4;">    }</span></span>
<span class="line"><span style="color:#D4D4D4;">}</span></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>输出结果为：01479cf20504d865519ac50f33ba3a7d</p><h3 id="typescript-javascript" tabindex="-1"><a class="header-anchor" href="#typescript-javascript"><span>TypeScript/JavaScript</span></a></h3><div class="language-typescript line-numbers-mode" data-highlighter="shiki" data-ext="typescript" style="background-color:#1E1E1E;color:#D4D4D4;"><pre class="shiki dark-plus vp-code"><code class="language-typescript"><span class="line"><span style="color:#C586C0;">import</span><span style="color:#D4D4D4;"> { </span><span style="color:#9CDCFE;">createHash</span><span style="color:#D4D4D4;"> } </span><span style="color:#C586C0;">from</span><span style="color:#CE9178;"> &#39;node:crypto&#39;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#569CD6;">type</span><span style="color:#4EC9B0;"> Params</span><span style="color:#D4D4D4;"> = </span><span style="color:#4EC9B0;">Record</span><span style="color:#D4D4D4;">&lt;</span><span style="color:#4EC9B0;">string</span><span style="color:#D4D4D4;">, </span><span style="color:#4EC9B0;">any</span><span style="color:#D4D4D4;">&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#569CD6;">const</span><span style="color:#DCDCAA;"> md5</span><span style="color:#D4D4D4;"> = (</span><span style="color:#9CDCFE;">str</span><span style="color:#D4D4D4;">: </span><span style="color:#4EC9B0;">string</span><span style="color:#D4D4D4;">) </span><span style="color:#569CD6;">=&gt;</span><span style="color:#DCDCAA;"> createHash</span><span style="color:#D4D4D4;">(</span><span style="color:#CE9178;">&#39;md5&#39;</span><span style="color:#D4D4D4;">).</span><span style="color:#DCDCAA;">update</span><span style="color:#D4D4D4;">(</span><span style="color:#9CDCFE;">str</span><span style="color:#D4D4D4;">).</span><span style="color:#DCDCAA;">digest</span><span style="color:#D4D4D4;">(</span><span style="color:#CE9178;">&#39;hex&#39;</span><span style="color:#D4D4D4;">)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#6A9955;">/**</span></span>
<span class="line"><span style="color:#6A9955;"> * 为请求参数进行 APP 签名</span></span>
<span class="line"><span style="color:#6A9955;"> */</span></span>
<span class="line"><span style="color:#C586C0;">export</span><span style="color:#569CD6;"> function</span><span style="color:#DCDCAA;"> appSign</span><span style="color:#D4D4D4;">(</span><span style="color:#9CDCFE;">params</span><span style="color:#D4D4D4;">: </span><span style="color:#4EC9B0;">Params</span><span style="color:#D4D4D4;">, </span><span style="color:#9CDCFE;">appkey</span><span style="color:#D4D4D4;">: </span><span style="color:#4EC9B0;">string</span><span style="color:#D4D4D4;">, </span><span style="color:#9CDCFE;">appsec</span><span style="color:#D4D4D4;">: </span><span style="color:#4EC9B0;">string</span><span style="color:#D4D4D4;">) {</span></span>
<span class="line"><span style="color:#9CDCFE;">  params</span><span style="color:#D4D4D4;">.</span><span style="color:#9CDCFE;">appkey</span><span style="color:#D4D4D4;"> = </span><span style="color:#9CDCFE;">appkey</span></span>
<span class="line"><span style="color:#569CD6;">  const</span><span style="color:#4FC1FF;"> searchParams</span><span style="color:#D4D4D4;"> = </span><span style="color:#569CD6;">new</span><span style="color:#DCDCAA;"> URLSearchParams</span><span style="color:#D4D4D4;">(</span><span style="color:#9CDCFE;">params</span><span style="color:#D4D4D4;">)</span></span>
<span class="line"><span style="color:#9CDCFE;">  searchParams</span><span style="color:#D4D4D4;">.</span><span style="color:#DCDCAA;">sort</span><span style="color:#D4D4D4;">()</span></span>
<span class="line"><span style="color:#C586C0;">  return</span><span style="color:#DCDCAA;"> md5</span><span style="color:#D4D4D4;">(</span><span style="color:#9CDCFE;">searchParams</span><span style="color:#D4D4D4;">.</span><span style="color:#DCDCAA;">toString</span><span style="color:#D4D4D4;">() + </span><span style="color:#9CDCFE;">appsec</span><span style="color:#D4D4D4;">)</span></span>
<span class="line"><span style="color:#D4D4D4;">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#9CDCFE;">console</span><span style="color:#D4D4D4;">.</span><span style="color:#DCDCAA;">log</span><span style="color:#D4D4D4;">(</span></span>
<span class="line"><span style="color:#DCDCAA;">  appSign</span><span style="color:#D4D4D4;">(</span></span>
<span class="line"><span style="color:#D4D4D4;">    {</span></span>
<span class="line"><span style="color:#9CDCFE;">      id:</span><span style="color:#B5CEA8;"> 114514</span><span style="color:#D4D4D4;">,</span></span>
<span class="line"><span style="color:#9CDCFE;">      str:</span><span style="color:#CE9178;"> &#39;1919810&#39;</span><span style="color:#D4D4D4;">,</span></span>
<span class="line"><span style="color:#9CDCFE;">      test:</span><span style="color:#CE9178;"> &#39;いいよ，こいよ&#39;</span><span style="color:#D4D4D4;">,</span></span>
<span class="line"><span style="color:#D4D4D4;">    },</span></span>
<span class="line"><span style="color:#CE9178;">    &#39;1d8b6e7d45233436&#39;</span><span style="color:#D4D4D4;">,</span></span>
<span class="line"><span style="color:#CE9178;">    &#39;560c52ccd288fed045859ed18bffd973&#39;</span><span style="color:#D4D4D4;">,</span></span>
<span class="line"><span style="color:#D4D4D4;">  ),</span></span>
<span class="line"><span style="color:#CE9178;">  &#39;01479cf20504d865519ac50f33ba3a7d&#39;</span><span style="color:#D4D4D4;">,</span></span>
<span class="line"><span style="color:#D4D4D4;">)</span></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>输出结果为：01479cf20504d865519ac50f33ba3a7d</p><h3 id="swift" tabindex="-1"><a class="header-anchor" href="#swift"><span>Swift</span></a></h3><div class="language-swift line-numbers-mode" data-highlighter="shiki" data-ext="swift" style="background-color:#1E1E1E;color:#D4D4D4;"><pre class="shiki dark-plus vp-code"><code class="language-swift"><span class="line"><span style="color:#C586C0;">import</span><span style="color:#4EC9B0;"> Foundation</span></span>
<span class="line"><span style="color:#C586C0;">import</span><span style="color:#4EC9B0;"> CommonCrypto</span></span>
<span class="line"></span>
<span class="line"><span style="color:#6A9955;">//Swift标准库没有MD5函数，所以我们要自己实现一个</span></span>
<span class="line"><span style="color:#569CD6;">func</span><span style="color:#DCDCAA;"> MD5</span><span style="color:#D4D4D4;">(</span><span style="color:#DCDCAA;">string</span><span style="color:#D4D4D4;">: </span><span style="color:#4EC9B0;">String</span><span style="color:#D4D4D4;">) -&gt; </span><span style="color:#4EC9B0;">String</span><span style="color:#D4D4D4;"> {</span></span>
<span class="line"><span style="color:#569CD6;">    let</span><span style="color:#D4D4D4;"> length = </span><span style="color:#4EC9B0;">Int</span><span style="color:#D4D4D4;">(CC_MD5_DIGEST_LENGTH)</span></span>
<span class="line"><span style="color:#569CD6;">    var</span><span style="color:#D4D4D4;"> digest = [</span><span style="color:#4EC9B0;">UInt8</span><span style="color:#D4D4D4;">](</span><span style="color:#DCDCAA;">repeating</span><span style="color:#D4D4D4;">: </span><span style="color:#B5CEA8;">0</span><span style="color:#D4D4D4;">, </span><span style="color:#DCDCAA;">count</span><span style="color:#D4D4D4;">: length)</span></span>
<span class="line"></span>
<span class="line"><span style="color:#C586C0;">    if</span><span style="color:#569CD6;"> let</span><span style="color:#D4D4D4;"> d = string.</span><span style="color:#DCDCAA;">data</span><span style="color:#D4D4D4;">(</span><span style="color:#DCDCAA;">using</span><span style="color:#D4D4D4;">: .</span><span style="color:#9CDCFE;">utf8</span><span style="color:#D4D4D4;">) {</span></span>
<span class="line"><span style="color:#9CDCFE;">        _</span><span style="color:#D4D4D4;"> = d.</span><span style="color:#DCDCAA;">withUnsafeBytes</span><span style="color:#D4D4D4;"> { body -&gt; </span><span style="color:#4EC9B0;">String</span><span style="color:#C586C0;"> in</span></span>
<span class="line"><span style="color:#DCDCAA;">            CC_MD5</span><span style="color:#D4D4D4;">(body.</span><span style="color:#9CDCFE;">baseAddress</span><span style="color:#D4D4D4;">, </span><span style="color:#DCDCAA;">CC_LONG</span><span style="color:#D4D4D4;">(d.</span><span style="color:#9CDCFE;">count</span><span style="color:#D4D4D4;">), &amp;digest)</span></span>
<span class="line"><span style="color:#C586C0;">            return</span><span style="color:#CE9178;"> &quot;&quot;</span></span>
<span class="line"><span style="color:#D4D4D4;">        }</span></span>
<span class="line"><span style="color:#D4D4D4;">    }</span></span>
<span class="line"></span>
<span class="line"><span style="color:#C586C0;">    return</span><span style="color:#D4D4D4;"> (</span><span style="color:#B5CEA8;">0</span><span style="color:#D4D4D4;">..&lt;length).</span><span style="color:#DCDCAA;">reduce</span><span style="color:#D4D4D4;">(</span><span style="color:#CE9178;">&quot;&quot;</span><span style="color:#D4D4D4;">) {</span></span>
<span class="line"><span style="color:#569CD6;">        $0</span><span style="color:#D4D4D4;"> + </span><span style="color:#4EC9B0;">String</span><span style="color:#D4D4D4;">(</span><span style="color:#DCDCAA;">format</span><span style="color:#D4D4D4;">: </span><span style="color:#CE9178;">&quot;%02x&quot;</span><span style="color:#D4D4D4;">, digest[</span><span style="color:#569CD6;">$1</span><span style="color:#D4D4D4;">])</span></span>
<span class="line"><span style="color:#D4D4D4;">    }</span></span>
<span class="line"><span style="color:#D4D4D4;">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#569CD6;">func</span><span style="color:#DCDCAA;"> appSign</span><span style="color:#D4D4D4;">(</span><span style="color:#DCDCAA;">params</span><span style="color:#D4D4D4;">: [</span><span style="color:#4EC9B0;">String</span><span style="color:#D4D4D4;">:</span><span style="color:#4EC9B0;">String</span><span style="color:#D4D4D4;">],</span><span style="color:#DCDCAA;">appKey</span><span style="color:#D4D4D4;">:</span><span style="color:#4EC9B0;">String</span><span style="color:#D4D4D4;">,</span><span style="color:#DCDCAA;">appSec</span><span style="color:#D4D4D4;">:</span><span style="color:#4EC9B0;">String</span><span style="color:#D4D4D4;">) -&gt; </span><span style="color:#4EC9B0;">String</span><span style="color:#D4D4D4;"> {</span></span>
<span class="line"><span style="color:#569CD6;">    var</span><span style="color:#D4D4D4;"> signedParams = params</span></span>
<span class="line"><span style="color:#D4D4D4;">    signedParams[</span><span style="color:#CE9178;">&quot;appkey&quot;</span><span style="color:#D4D4D4;">] = appKey</span></span>
<span class="line"><span style="color:#569CD6;">    let</span><span style="color:#D4D4D4;"> sortedParams = signedParams.</span><span style="color:#DCDCAA;">sorted</span><span style="color:#D4D4D4;"> { </span><span style="color:#569CD6;">$0</span><span style="color:#D4D4D4;">.</span><span style="color:#9CDCFE;">key</span><span style="color:#D4D4D4;"> &lt; </span><span style="color:#569CD6;">$1</span><span style="color:#D4D4D4;">.</span><span style="color:#9CDCFE;">key</span><span style="color:#D4D4D4;"> }</span></span>
<span class="line"><span style="color:#6A9955;">    //在制作成query时，需要显式addingPercentEncoding转换</span></span>
<span class="line"><span style="color:#569CD6;">    let</span><span style="color:#D4D4D4;"> query = sortedParams.</span><span style="color:#DCDCAA;">map</span><span style="color:#D4D4D4;"> { </span><span style="color:#CE9178;">&quot;</span><span style="color:#569CD6;">\\($0</span><span style="color:#D4D4D4;">.</span><span style="color:#9CDCFE;">key</span><span style="color:#569CD6;">)</span><span style="color:#CE9178;">=</span><span style="color:#569CD6;">\\($0</span><span style="color:#D4D4D4;">.</span><span style="color:#9CDCFE;">value</span><span style="color:#D4D4D4;">.</span><span style="color:#DCDCAA;">addingPercentEncoding</span><span style="color:#D4D4D4;">(</span><span style="color:#DCDCAA;">withAllowedCharacters</span><span style="color:#D4D4D4;">: .</span><span style="color:#9CDCFE;">urlQueryAllowed</span><span style="color:#D4D4D4;">)!</span><span style="color:#569CD6;">)</span><span style="color:#CE9178;">&quot;</span><span style="color:#D4D4D4;"> }.</span><span style="color:#DCDCAA;">joined</span><span style="color:#D4D4D4;">(</span><span style="color:#DCDCAA;">separator</span><span style="color:#D4D4D4;">: </span><span style="color:#CE9178;">&quot;&amp;&quot;</span><span style="color:#D4D4D4;">)</span></span>
<span class="line"><span style="color:#569CD6;">    let</span><span style="color:#D4D4D4;"> sign = </span><span style="color:#DCDCAA;">MD5</span><span style="color:#D4D4D4;">(</span><span style="color:#DCDCAA;">string</span><span style="color:#D4D4D4;">: query+appSec)</span></span>
<span class="line"><span style="color:#C586C0;">    return</span><span style="color:#D4D4D4;"> sign</span></span>
<span class="line"><span style="color:#D4D4D4;">}</span></span>
<span class="line"></span>
<span class="line"></span>
<span class="line"><span style="color:#6A9955;">//testSign</span></span>
<span class="line"><span style="color:#569CD6;">let</span><span style="color:#D4D4D4;"> appKey = </span><span style="color:#CE9178;">&quot;1d8b6e7d45233436&quot;</span></span>
<span class="line"><span style="color:#569CD6;">let</span><span style="color:#D4D4D4;"> appSec = </span><span style="color:#CE9178;">&quot;560c52ccd288fed045859ed18bffd973&quot;</span></span>
<span class="line"><span style="color:#569CD6;">let</span><span style="color:#D4D4D4;"> signResult = </span><span style="color:#DCDCAA;">appSign</span><span style="color:#D4D4D4;">(</span><span style="color:#DCDCAA;">params</span><span style="color:#D4D4D4;">: [</span></span>
<span class="line"><span style="color:#CE9178;">    &quot;id&quot;</span><span style="color:#D4D4D4;">: </span><span style="color:#CE9178;">&quot;114514&quot;</span><span style="color:#D4D4D4;">,</span></span>
<span class="line"><span style="color:#CE9178;">    &quot;str&quot;</span><span style="color:#D4D4D4;">: </span><span style="color:#CE9178;">&quot;1919810&quot;</span><span style="color:#D4D4D4;">,</span></span>
<span class="line"><span style="color:#CE9178;">    &quot;test&quot;</span><span style="color:#D4D4D4;">: </span><span style="color:#CE9178;">&quot;いいよ，こいよ&quot;</span><span style="color:#D4D4D4;">,</span></span>
<span class="line"><span style="color:#D4D4D4;">],</span><span style="color:#DCDCAA;">appKey</span><span style="color:#D4D4D4;">:appKey,</span><span style="color:#DCDCAA;">appSec</span><span style="color:#D4D4D4;">:appSec)</span></span>
<span class="line"><span style="color:#DCDCAA;">print</span><span style="color:#D4D4D4;">(signResult)</span></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>输出结果为：01479cf20504d865519ac50f33ba3a7d</p><h3 id="cplusplus" tabindex="-1"><a class="header-anchor" href="#cplusplus"><span>CplusPlus</span></a></h3><p>需要 c++ 23 标准库，<a href="https://github.com/libcpr/cpr" target="_blank" rel="noopener noreferrer">cpr</a>、<a href="https://github.com/weidai11/cryptopp" target="_blank" rel="noopener noreferrer">cryptopp</a>、<a href="https://github.com/nlohmann/json" target="_blank" rel="noopener noreferrer">nlohmann/json</a> 等依赖</p><div class="language-c++ line-numbers-mode" data-highlighter="shiki" data-ext="c++" style="background-color:#1E1E1E;color:#D4D4D4;"><pre class="shiki dark-plus vp-code"><code class="language-c++"><span class="line"><span style="color:#C586C0;">#include</span><span style="color:#CE9178;"> &lt;print&gt;</span><span style="color:#6A9955;">    // std::println</span></span>
<span class="line"></span>
<span class="line"><span style="color:#6A9955;">/// thrid party libraries</span></span>
<span class="line"><span style="color:#C586C0;">#include</span><span style="color:#CE9178;"> &lt;cpr/cpr.h&gt;</span><span style="color:#6A9955;">            // cpr::util::urlEncode()</span></span>
<span class="line"><span style="color:#C586C0;">#include</span><span style="color:#CE9178;"> &lt;cryptopp/md5.h&gt;</span></span>
<span class="line"><span style="color:#C586C0;">#include</span><span style="color:#CE9178;"> &lt;cryptopp/hex.h&gt;</span></span>
<span class="line"><span style="color:#C586C0;">#include</span><span style="color:#CE9178;"> &lt;nlohmann/json.hpp&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#6A9955;">/*</span></span>
<span class="line"><span style="color:#6A9955;"> * 注意，假定不会发生错误！</span></span>
<span class="line"><span style="color:#6A9955;"> */</span></span>
<span class="line"></span>
<span class="line"><span style="color:#6A9955;">/* 获取 md5 hex(lower) */</span></span>
<span class="line"><span style="color:#4EC9B0;">std</span><span style="color:#D4D4D4;">::</span><span style="color:#4EC9B0;">string</span><span style="color:#DCDCAA;"> Get_md5_hex</span><span style="color:#D4D4D4;">(</span><span style="color:#569CD6;">const</span><span style="color:#4EC9B0;"> std</span><span style="color:#D4D4D4;">::</span><span style="color:#4EC9B0;">string</span><span style="color:#569CD6;"> &amp;</span><span style="color:#9CDCFE;">Input_str</span><span style="color:#D4D4D4;">) {</span></span>
<span class="line"><span style="color:#4EC9B0;">    CryptoPP</span><span style="color:#D4D4D4;">::</span><span style="color:#4EC9B0;">Weak1</span><span style="color:#D4D4D4;">::MD5 hash;</span></span>
<span class="line"><span style="color:#4EC9B0;">    std</span><span style="color:#D4D4D4;">::string          md5_hex;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#4EC9B0;">    CryptoPP</span><span style="color:#D4D4D4;">::StringSource </span><span style="color:#DCDCAA;">ss</span><span style="color:#D4D4D4;">(Input_str, </span><span style="color:#569CD6;">true</span><span style="color:#D4D4D4;">,</span></span>
<span class="line"><span style="color:#C586C0;">        new</span><span style="color:#4EC9B0;"> CryptoPP</span><span style="color:#D4D4D4;">::</span><span style="color:#DCDCAA;">HashFilter</span><span style="color:#D4D4D4;">(hash,</span></span>
<span class="line"><span style="color:#C586C0;">            new</span><span style="color:#4EC9B0;"> CryptoPP</span><span style="color:#D4D4D4;">::</span><span style="color:#DCDCAA;">HexEncoder</span><span style="color:#D4D4D4;">(</span></span>
<span class="line"><span style="color:#C586C0;">                new</span><span style="color:#4EC9B0;"> CryptoPP</span><span style="color:#D4D4D4;">::</span><span style="color:#DCDCAA;">StringSink</span><span style="color:#D4D4D4;">(md5_hex)</span></span>
<span class="line"><span style="color:#D4D4D4;">            )</span></span>
<span class="line"><span style="color:#D4D4D4;">        )</span></span>
<span class="line"><span style="color:#D4D4D4;">    );</span></span>
<span class="line"></span>
<span class="line"><span style="color:#4EC9B0;">    std</span><span style="color:#D4D4D4;">::</span><span style="color:#4EC9B0;">ranges</span><span style="color:#D4D4D4;">::</span><span style="color:#DCDCAA;">for_each</span><span style="color:#D4D4D4;">(md5_hex, [](</span><span style="color:#569CD6;">char</span><span style="color:#569CD6;"> &amp;</span><span style="color:#9CDCFE;">x</span><span style="color:#D4D4D4;">) { x = </span><span style="color:#4EC9B0;">std</span><span style="color:#D4D4D4;">::</span><span style="color:#DCDCAA;">tolower</span><span style="color:#D4D4D4;">(x); });</span></span>
<span class="line"><span style="color:#C586C0;">    return</span><span style="color:#D4D4D4;"> md5_hex;</span></span>
<span class="line"><span style="color:#D4D4D4;">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#6A9955;">/* 将 json 转换为 url 编码字符串 */</span></span>
<span class="line"><span style="color:#4EC9B0;">std</span><span style="color:#D4D4D4;">::</span><span style="color:#4EC9B0;">string</span><span style="color:#DCDCAA;"> Json_to_url_encode_str</span><span style="color:#D4D4D4;">(</span><span style="color:#569CD6;">const</span><span style="color:#4EC9B0;"> nlohmann</span><span style="color:#D4D4D4;">::</span><span style="color:#4EC9B0;">json</span><span style="color:#569CD6;"> &amp;</span><span style="color:#9CDCFE;">Json</span><span style="color:#D4D4D4;">) {</span></span>
<span class="line"><span style="color:#4EC9B0;">    std</span><span style="color:#D4D4D4;">::string encode_str;</span></span>
<span class="line"><span style="color:#C586C0;">    for</span><span style="color:#D4D4D4;"> (</span><span style="color:#569CD6;">const</span><span style="color:#569CD6;"> auto</span><span style="color:#D4D4D4;"> &amp;[key, value]: </span><span style="color:#9CDCFE;">Json</span><span style="color:#D4D4D4;">.</span><span style="color:#DCDCAA;">items</span><span style="color:#D4D4D4;">()) {</span></span>
<span class="line"><span style="color:#9CDCFE;">        encode_str</span><span style="color:#D4D4D4;">.</span><span style="color:#DCDCAA;">append</span><span style="color:#D4D4D4;">(key).</span><span style="color:#DCDCAA;">append</span><span style="color:#D4D4D4;">(</span><span style="color:#CE9178;">&quot;=&quot;</span><span style="color:#D4D4D4;">).</span><span style="color:#DCDCAA;">append</span><span style="color:#D4D4D4;">(</span><span style="color:#4EC9B0;">cpr</span><span style="color:#D4D4D4;">::</span><span style="color:#4EC9B0;">util</span><span style="color:#D4D4D4;">::</span><span style="color:#DCDCAA;">urlEncode</span><span style="color:#D4D4D4;">(</span><span style="color:#9CDCFE;">value</span><span style="color:#D4D4D4;">.</span><span style="color:#DCDCAA;">is_string</span><span style="color:#D4D4D4;">() ? </span><span style="color:#9CDCFE;">value</span><span style="color:#D4D4D4;">.</span><span style="color:#9CDCFE;">get</span><span style="color:#D4D4D4;">&lt;</span><span style="color:#4EC9B0;">std</span><span style="color:#D4D4D4;">::string&gt;() : </span><span style="color:#DCDCAA;">to_string</span><span style="color:#D4D4D4;">(value))).</span><span style="color:#DCDCAA;">append</span><span style="color:#D4D4D4;">(</span><span style="color:#CE9178;">&quot;&amp;&quot;</span><span style="color:#D4D4D4;">);</span></span>
<span class="line"><span style="color:#D4D4D4;">    }</span></span>
<span class="line"></span>
<span class="line"><span style="color:#6A9955;">    // remove the last &#39;&amp;&#39;</span></span>
<span class="line"><span style="color:#9CDCFE;">    encode_str</span><span style="color:#D4D4D4;">.</span><span style="color:#DCDCAA;">resize</span><span style="color:#D4D4D4;">(</span><span style="color:#9CDCFE;">encode_str</span><span style="color:#D4D4D4;">.</span><span style="color:#DCDCAA;">size</span><span style="color:#D4D4D4;">() - </span><span style="color:#B5CEA8;">1</span><span style="color:#D4D4D4;">, </span><span style="color:#CE9178;">&#39;</span><span style="color:#D7BA7D;">\\0</span><span style="color:#CE9178;">&#39;</span><span style="color:#D4D4D4;">);</span></span>
<span class="line"><span style="color:#C586C0;">    return</span><span style="color:#D4D4D4;"> encode_str;</span></span>
<span class="line"><span style="color:#D4D4D4;">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#4EC9B0;">std</span><span style="color:#D4D4D4;">::</span><span style="color:#4EC9B0;">string</span><span style="color:#DCDCAA;"> App_sign</span><span style="color:#D4D4D4;">(</span><span style="color:#4EC9B0;">nlohmann</span><span style="color:#D4D4D4;">::</span><span style="color:#4EC9B0;">json</span><span style="color:#569CD6;"> &amp;</span><span style="color:#9CDCFE;">Params</span><span style="color:#D4D4D4;">, </span><span style="color:#569CD6;">const</span><span style="color:#4EC9B0;"> std</span><span style="color:#D4D4D4;">::</span><span style="color:#4EC9B0;">string</span><span style="color:#569CD6;"> &amp;</span><span style="color:#9CDCFE;">App_key</span><span style="color:#D4D4D4;">, </span><span style="color:#569CD6;">const</span><span style="color:#4EC9B0;"> std</span><span style="color:#D4D4D4;">::</span><span style="color:#4EC9B0;">string</span><span style="color:#569CD6;"> &amp;</span><span style="color:#9CDCFE;">App_sec</span><span style="color:#D4D4D4;">) {</span></span>
<span class="line"><span style="color:#9CDCFE;">    Params</span><span style="color:#D4D4D4;">[</span><span style="color:#CE9178;">&quot;appkey&quot;</span><span style="color:#D4D4D4;">] = App_key;</span></span>
<span class="line"><span style="color:#9CDCFE;">    Params</span><span style="color:#D4D4D4;">[</span><span style="color:#CE9178;">&quot;sign&quot;</span><span style="color:#D4D4D4;">]   = </span><span style="color:#DCDCAA;">Get_md5_hex</span><span style="color:#D4D4D4;">(</span><span style="color:#DCDCAA;">Json_to_url_encode_str</span><span style="color:#D4D4D4;">(Params) + App_sec);</span></span>
<span class="line"><span style="color:#C586C0;">    return</span><span style="color:#DCDCAA;"> Json_to_url_encode_str</span><span style="color:#D4D4D4;">(Params);</span></span>
<span class="line"><span style="color:#D4D4D4;">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#569CD6;">int</span><span style="color:#DCDCAA;"> main</span><span style="color:#D4D4D4;">() {</span></span>
<span class="line"><span style="color:#4EC9B0;">    nlohmann</span><span style="color:#D4D4D4;">::json Params;</span></span>
<span class="line"><span style="color:#9CDCFE;">    Params</span><span style="color:#D4D4D4;">[</span><span style="color:#CE9178;">&quot;id&quot;</span><span style="color:#D4D4D4;">]   = </span><span style="color:#B5CEA8;">114514</span><span style="color:#D4D4D4;">;</span></span>
<span class="line"><span style="color:#9CDCFE;">    Params</span><span style="color:#D4D4D4;">[</span><span style="color:#CE9178;">&quot;str&quot;</span><span style="color:#D4D4D4;">]  = </span><span style="color:#CE9178;">&quot;1919810&quot;</span><span style="color:#D4D4D4;">;</span></span>
<span class="line"><span style="color:#9CDCFE;">    Params</span><span style="color:#D4D4D4;">[</span><span style="color:#CE9178;">&quot;test&quot;</span><span style="color:#D4D4D4;">] = </span><span style="color:#CE9178;">&quot;いいよ，こいよ&quot;</span><span style="color:#D4D4D4;">;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#569CD6;">    constexpr</span><span style="color:#569CD6;"> auto</span><span style="color:#D4D4D4;"> App_key = </span><span style="color:#CE9178;">&quot;1d8b6e7d45233436&quot;</span><span style="color:#D4D4D4;">;</span></span>
<span class="line"><span style="color:#569CD6;">    constexpr</span><span style="color:#569CD6;"> auto</span><span style="color:#D4D4D4;"> App_sec = </span><span style="color:#CE9178;">&quot;560c52ccd288fed045859ed18bffd973&quot;</span><span style="color:#D4D4D4;">;</span></span>
<span class="line"><span style="color:#4EC9B0;">    std</span><span style="color:#D4D4D4;">::string    sign    = </span><span style="color:#DCDCAA;">App_sign</span><span style="color:#D4D4D4;">(Params, App_key, App_sec);</span></span>
<span class="line"><span style="color:#4EC9B0;">    std</span><span style="color:#D4D4D4;">::</span><span style="color:#DCDCAA;">println</span><span style="color:#D4D4D4;">(</span><span style="color:#CE9178;">&quot;{}&quot;</span><span style="color:#D4D4D4;">, </span><span style="color:#DCDCAA;">to_string</span><span style="color:#D4D4D4;">(Params));</span></span>
<span class="line"><span style="color:#4EC9B0;">    std</span><span style="color:#D4D4D4;">::</span><span style="color:#DCDCAA;">println</span><span style="color:#D4D4D4;">(</span><span style="color:#CE9178;">&quot;{}&quot;</span><span style="color:#D4D4D4;">, sign);</span></span>
<span class="line"><span style="color:#D4D4D4;">}</span></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><div class="language-text line-numbers-mode" data-highlighter="shiki" data-ext="text" style="background-color:#1E1E1E;color:#D4D4D4;"><pre class="shiki dark-plus vp-code"><code class="language-text"><span class="line"><span>{&quot;appkey&quot;:&quot;1d8b6e7d45233436&quot;,&quot;id&quot;:114514,&quot;sign&quot;:&quot;01479cf20504d865519ac50f33ba3a7d&quot;,&quot;str&quot;:&quot;1919810&quot;,&quot;test&quot;:&quot;いいよ，こいよ&quot;}</span></span>
<span class="line"><span>appkey=1d8b6e7d45233436&amp;id=114514&amp;sign=01479cf20504d865519ac50f33ba3a7d&amp;str=1919810&amp;test=%E3%81%84%E3%81%84%E3%82%88%EF%BC%8C%E3%81%93%E3%81%84%E3%82%88</span></span></code></pre><div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0;"><div class="line-number"></div><div class="line-number"></div></div></div>`,17))])}const u=r(i,[["render",y]]),v=JSON.parse('{"path":"/docs/misc/sign/APP.html","title":"APP API 签名与鉴权","lang":"zh-CN","frontmatter":{},"git":{"updatedTime":1745052268000,"contributors":[{"name":"SocialSisterYi","username":"SocialSisterYi","email":"1440239038@qq.com","commits":1,"url":"https://github.com/SocialSisterYi"},{"name":"cctyl","username":"cctyl","email":"34262992+cctyl@users.noreply.github.com","commits":1,"url":"https://github.com/cctyl"},{"name":"LaMerChiang","username":"LaMerChiang","email":"catlair@qq.com","commits":1,"url":"https://github.com/LaMerChiang"},{"name":"Lightning-Lion","username":"Lightning-Lion","email":"85005672+Lightning-Lion@users.noreply.github.com","commits":1,"url":"https://github.com/Lightning-Lion"},{"name":"YuHuanTin","username":"YuHuanTin","email":"51024916+YuHuanTin@users.noreply.github.com","commits":1,"url":"https://github.com/YuHuanTin"},{"name":"SessionHu","username":"SessionHu","email":"102411014+SessionHu@users.noreply.github.com","commits":1,"url":"https://github.com/SessionHu"}],"changelog":[{"hash":"0c42c00036ec457a4786431ba9944daf72c96fc0","time":1745052268000,"email":"102411014+SessionHu@users.noreply.github.com","author":"SessionHu","message":"fix(misc/sign/APP.md): broken demo links"},{"hash":"e7ab2d770b423a891ed7e663d94bfe1f0f59501d","time":1718245563000,"email":"51024916+YuHuanTin@users.noreply.github.com","author":"YuHuanTin","message":"wbi、av2bv、bv2av 的 c++ 实现 (#1035)"},{"hash":"faa3d97c263907ca8c492093d91406e27fc106ed","time":1703135741000,"email":"85005672+Lightning-Lion@users.noreply.github.com","author":"Lightning-Lion","message":"Update APP.md (#911)"},{"hash":"5603b1acbd02f33e54616c8a5e0ae7061a426c8e","time":1695047571000,"email":"catlair@qq.com","author":"LaMerChiang","message":"Update APP.md (#819)"},{"hash":"901e787fc655962b88dac9896b25f41d796cd2c9","time":1688262289000,"email":"34262992+cctyl@users.noreply.github.com","author":"cctyl","message":"feature: App Sign 添加java版本实现 (#729)"},{"hash":"05ac3d5e2a9e28be3bf129ae8c78ffdbebaa161c","time":1684805901000,"email":"1440239038@qq.com","author":"SocialSisterYi","message":"添加文档【Wbi 接口签名】，修改目录结构"}]},"filePathRelative":"docs/misc/sign/APP.md"}');export{u as comp,v as data};
