按键精灵手机助手代码示例
<p>将以下代码复制到脚本代码的顶部,替换<code>RParamUrl</code>为你的获取参数API网址。<code>MiaoCode</code>保存喵码,喵码通常由用户提供。</p>
<pre><code class="language-vb">//获取参数API网址
Dim RParamUrl = &quot;http://miaotixing.com/rparam?rp=rp-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx&amp;code=&quot;
//喵码,通常由用户输入提供
Dim MiaoCode = &quot;txxxxxx&quot;
//API返回的数据
Dim RParamData = Array()
//拉取参数数据到变量RParamData。需要注意:参数有缓存,缓存失效后才能拿到用户填写的最新参数。
Function LoadRParam()
Dim apiUrl = RParamUrl &amp; MiaoCode &amp; &quot;&amp;type=json&quot;
Dim responseText = URL.Get(apiUrl)
//TracePrint &quot;RParam API 网址 : &quot; &amp; apiUrl
//TracePrint &quot;RParam API 返回:&quot; &amp; responseText
RParamData = Encode.JsonToTable(responseText)
End Function
//读取参数key的值,如果key不存在则返回defValue
Function RParam(key, defValue)
If IsNull(RParamData[key]) Then
RParam = defValue
Else
RParam = RParamData[key]
End If
End Function</code></pre>
<p>拉取参数时,通过<code>LoadRParam()</code>方式,参数数据会保存到变量RParamData,供后面读取参数时候使用。
读取参数时,通过<code>RParam(key, defValue)</code>方式读取指定key的参数;特殊情况下我们会担心指定key的参数获取失败而影响脚本运行,比如发布新版时候不慎删除某个有用的key,而defValue参数的作用是发现key参数不存在时,以defValue值作为参数值返回。</p>
<pre><code class="language-vb">//拉取参数
LoadRParam()
//返回key为submited_at的参数值,如果不存在该参数,则返回0
TracePrint &quot;submited_at : &quot; &amp; RParam(&quot;submited_at&quot;, 0)
//返回key为key1的参数值,如果不存在该参数,则返回123
TracePrint &quot;key1 : &quot; &amp; RParam(&quot;key1&quot;, 123)</code></pre>