1848 lines
96 KiB
HTML
1848 lines
96 KiB
HTML
|
||
|
||
<!DOCTYPE html>
|
||
<html class="writer-html5" lang="zh-CN" >
|
||
<head>
|
||
<meta charset="utf-8" />
|
||
|
||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||
|
||
<title>YJS SDK — 北大数瑞大数据区块链 V1.0 文档</title>
|
||
|
||
|
||
|
||
<link rel="stylesheet" href="../_static/css/theme.css" type="text/css" />
|
||
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
|
||
|
||
|
||
|
||
<link rel="shortcut icon" href="../_static/favicon.ico"/>
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
<!--[if lt IE 9]>
|
||
<script src="../_static/js/html5shiv.min.js"></script>
|
||
<![endif]-->
|
||
|
||
|
||
<script type="text/javascript" id="documentation_options" data-url_root="../" src="../_static/documentation_options.js"></script>
|
||
<script src="../_static/jquery.js"></script>
|
||
<script src="../_static/underscore.js"></script>
|
||
<script src="../_static/doctools.js"></script>
|
||
<script src="../_static/translations.js"></script>
|
||
|
||
<script type="text/javascript" src="../_static/js/theme.js"></script>
|
||
|
||
|
||
<link rel="index" title="索引" href="../genindex.html" />
|
||
<link rel="search" title="搜索" href="../search.html" />
|
||
</head>
|
||
|
||
<body class="wy-body-for-nav">
|
||
|
||
|
||
<div class="wy-grid-for-nav">
|
||
|
||
<nav data-toggle="wy-nav-shift" class="wy-nav-side">
|
||
<div class="wy-side-scroll">
|
||
<div class="wy-side-nav-search" >
|
||
|
||
|
||
|
||
<a href="../index.html">
|
||
|
||
|
||
|
||
|
||
<img src="../_static/logo.png" class="logo" alt="Logo"/>
|
||
|
||
</a>
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
<div role="search">
|
||
<form id="rtd-search-form" class="wy-form" action="../search.html" method="get">
|
||
<input type="text" name="q" placeholder="在文档中搜索" />
|
||
<input type="hidden" name="check_keywords" value="yes" />
|
||
<input type="hidden" name="area" value="default" />
|
||
</form>
|
||
</div>
|
||
|
||
|
||
</div>
|
||
|
||
|
||
<div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
|
||
|
||
|
||
|
||
|
||
|
||
|
||
<p class="caption"><span class="caption-text">目录</span></p>
|
||
<ul>
|
||
<li class="toctree-l1"><a class="reference internal" href="../Introduction.html">BDContract介绍</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="../InstallTips.html">BDContract安装说明</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="../IDEUsage.html">BDContract管理界面</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="../ContractAPI.html">BDContract SDK</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="../YJSInDepth.html">YJS语法</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="../YJSAPI.html">YJS SDK</a></li>
|
||
</ul>
|
||
|
||
|
||
|
||
</div>
|
||
|
||
</div>
|
||
</nav>
|
||
|
||
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
|
||
|
||
|
||
<nav class="wy-nav-top" aria-label="top navigation">
|
||
|
||
<i data-toggle="wy-nav-top" class="fa fa-bars"></i>
|
||
<a href="../index.html">北大数瑞大数据区块链</a>
|
||
|
||
</nav>
|
||
|
||
|
||
<div class="wy-nav-content">
|
||
|
||
<div class="rst-content">
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
<div role="navigation" aria-label="breadcrumbs navigation">
|
||
|
||
<ul class="wy-breadcrumbs">
|
||
|
||
<li><a href="../index.html" class="icon icon-home"></a> »</li>
|
||
|
||
<li>YJS SDK</li>
|
||
|
||
|
||
<li class="wy-breadcrumbs-aside">
|
||
|
||
|
||
<a href="../_sources/markdown_BDWare/YJSAPI.md.txt" rel="nofollow"> 查看页面源码</a>
|
||
|
||
|
||
</li>
|
||
|
||
</ul>
|
||
|
||
|
||
<hr/>
|
||
</div>
|
||
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
|
||
<div itemprop="articleBody">
|
||
|
||
<div class="section" id="yjs-sdk">
|
||
<h1>YJS SDK<a class="headerlink" href="#yjs-sdk" title="永久链接至标题">¶</a></h1>
|
||
<div class="section" id="yjs-build-in-api">
|
||
<h2>YJS Build-in API<a class="headerlink" href="#yjs-build-in-api" title="永久链接至标题">¶</a></h2>
|
||
<div class="section" id="global">
|
||
<h3>内置对象 Global<a class="headerlink" href="#global" title="永久链接至标题">¶</a></h3>
|
||
</div>
|
||
<div class="section" id="requester">
|
||
<h3>内置对象 requester<a class="headerlink" href="#requester" title="永久链接至标题">¶</a></h3>
|
||
<p>该内置对象在export function里面会有值,仅当合约调用签名验证通过。</p>
|
||
</div>
|
||
<div class="section" id="executecontract">
|
||
<h3>执行合约 executeContract<a class="headerlink" href="#executecontract" title="永久链接至标题">¶</a></h3>
|
||
<p>参数:</p>
|
||
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>action:executeContract<span class="p">;</span>
|
||
contractID:合约的id或名称均可;
|
||
operation:调用合约的方法名;
|
||
arg: 参数;格式为JSON字符串,有action与arg两个字段。
|
||
</pre></div>
|
||
</div>
|
||
<p>可选参数:</p>
|
||
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>requestID:字符串类型,自行生成,用于查询hash
|
||
</pre></div>
|
||
</div>
|
||
<p>使用示例:</p>
|
||
<div class="highlight-javascript notranslate"><div class="highlight"><pre><span></span> <span class="kd">function</span> <span class="nx">testExecutorContract</span><span class="p">(</span><span class="nx">arg</span><span class="p">){</span>
|
||
<span class="kd">var</span> <span class="nx">ret</span> <span class="o">=</span> <span class="nx">JSON</span><span class="p">.</span><span class="nx">parse</span><span class="p">(</span><span class="nx">executeContract</span><span class="p">(</span><span class="s2">"ElemeProvider"</span><span class="p">,</span><span class="s2">"queryDB"</span><span class="p">,</span><span class="nx">arg</span><span class="p">));</span>
|
||
<span class="k">if</span> <span class="p">(</span><span class="nx">ret</span><span class="p">.</span><span class="nx">status</span> <span class="o">==</span> <span class="s2">"Success"</span><span class="p">){</span>
|
||
<span class="k">return</span> <span class="nx">JSON</span><span class="p">.</span><span class="nx">parse</span><span class="p">(</span><span class="nx">ret</span><span class="p">.</span><span class="nx">result</span><span class="p">);</span>
|
||
<span class="p">}</span><span class="k">else</span> <span class="k">return</span> <span class="kc">null</span><span class="p">;</span>
|
||
<span class="p">}</span>
|
||
</pre></div>
|
||
</div>
|
||
</div>
|
||
<div class="section" id="subscribe">
|
||
<h3>订阅事件主题 subscribe<a class="headerlink" href="#subscribe" title="永久链接至标题">¶</a></h3>
|
||
<p>参数</p>
|
||
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>contractID:字符串类型 合约id或名称均可。
|
||
event:字符串类型
|
||
handler:方法名,该方法必须接受Event(内含字段topic和content)类型的唯一变量为参数;可以不是export方法
|
||
</pre></div>
|
||
</div>
|
||
<p>使用示例:</p>
|
||
<div class="highlight-javascript notranslate"><div class="highlight"><pre><span></span><span class="kr">export</span> <span class="kd">function</span> <span class="nx">init</span><span class="p">(</span><span class="nx">arg</span><span class="p">)</span> <span class="p">{</span>
|
||
<span class="nx">YancloudUtil</span><span class="p">.</span><span class="nx">subscribe</span><span class="p">(</span><span class="s2">"topic"</span><span class="p">,</span> <span class="nx">handler</span><span class="p">);</span>
|
||
<span class="nx">print</span><span class="p">(</span><span class="s2">"Handler: "</span> <span class="o">+</span> <span class="nx">handler</span><span class="p">);</span>
|
||
<span class="p">}</span>
|
||
|
||
<span class="kd">function</span> <span class="nx">handler</span><span class="p">(</span><span class="nx">e</span><span class="p">)</span> <span class="p">{</span>
|
||
<span class="nx">print</span><span class="p">(</span><span class="s2">"topic: "</span> <span class="o">+</span> <span class="nx">e</span><span class="p">.</span><span class="nx">topic</span><span class="p">);</span>
|
||
<span class="nx">print</span><span class="p">(</span><span class="s2">"content: "</span> <span class="o">+</span> <span class="nx">e</span><span class="p">.</span><span class="nx">content</span><span class="p">);</span>
|
||
<span class="p">}</span>
|
||
</pre></div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<div class="section" id="pubevent">
|
||
<h2>发布事件 pubEvent<a class="headerlink" href="#pubevent" title="永久链接至标题">¶</a></h2>
|
||
<p>参数</p>
|
||
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>topic:字符串类型,发布的事件主题
|
||
content:字符串类型,发布的事件内容
|
||
</pre></div>
|
||
</div>
|
||
<p>使用示例:</p>
|
||
<div class="highlight-javascript notranslate"><div class="highlight"><pre><span></span><span class="kr">export</span> <span class="kd">function</span> <span class="nx">pub1</span><span class="p">(</span><span class="nx">arg</span><span class="p">)</span> <span class="p">{</span>
|
||
<span class="nx">YancloudUtil</span><span class="p">.</span><span class="nx">pubEvent</span><span class="p">(</span><span class="s2">"topic"</span><span class="p">,</span> <span class="nx">arg</span><span class="p">);</span>
|
||
<span class="k">return</span> <span class="s2">"done"</span><span class="p">;</span>
|
||
<span class="p">}</span>
|
||
</pre></div>
|
||
</div>
|
||
<p>也可以在合约开头定义事件,则事件名即为事件主题,此时可直接使用事件作为方法名发布事件</p>
|
||
<div class="highlight-javascript notranslate"><div class="highlight"><pre><span></span><span class="nx">event</span> <span class="nx">topic</span><span class="p">;</span>
|
||
<span class="kr">export</span> <span class="kd">function</span> <span class="nx">pub2</span><span class="p">(</span><span class="nx">arg</span><span class="p">)</span> <span class="p">{</span>
|
||
<span class="nx">topic</span><span class="p">(</span><span class="nx">arg</span><span class="p">);</span>
|
||
<span class="k">return</span> <span class="s2">"done"</span><span class="p">;</span>
|
||
<span class="p">}</span>
|
||
</pre></div>
|
||
</div>
|
||
<p>该写法与上面的<code class="docutils literal notranslate"><span class="pre">pub1</span></code>等价。</p>
|
||
<div class="section" id="id1">
|
||
<h3>访问资源文件<a class="headerlink" href="#id1" title="永久链接至标题">¶</a></h3>
|
||
<p>通过Global.Resources去加载ypk内部的资源文件。</p>
|
||
<div class="section" id="loadasinputstream">
|
||
<h4>loadAsInputStream<a class="headerlink" href="#loadasinputstream" title="永久链接至标题">¶</a></h4>
|
||
<p>参数:</p>
|
||
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>path:字符串类型 需要加载文件的地址
|
||
</pre></div>
|
||
</div>
|
||
<p>使用示例:</p>
|
||
<div class="highlight-javascript notranslate"><div class="highlight"><pre><span></span><span class="kd">var</span> <span class="nx">file</span> <span class="o">=</span> <span class="nx">Global</span><span class="p">.</span><span class="nx">Resources</span><span class="p">.</span><span class="nx">loadAsInputStream</span><span class="p">(</span><span class="s2">"/deleteit.txt"</span><span class="p">);</span>
|
||
</pre></div>
|
||
</div>
|
||
</div>
|
||
<div class="section" id="loadasscanner">
|
||
<h4>loadAsScanner<a class="headerlink" href="#loadasscanner" title="永久链接至标题">¶</a></h4>
|
||
<p>参数:</p>
|
||
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>path:字符串类型 需要加载文件的地址
|
||
</pre></div>
|
||
</div>
|
||
<p>使用示例:</p>
|
||
<div class="highlight-javascript notranslate"><div class="highlight"><pre><span></span><span class="kd">var</span> <span class="nx">scanner</span> <span class="o">=</span> <span class="nx">Global</span><span class="p">.</span><span class="nx">Resources</span><span class="p">.</span><span class="nx">loadAsScanner</span><span class="p">(</span><span class="s2">"/local.txt"</span><span class="p">);</span>
|
||
</pre></div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<div class="section" id="yjs-build-in-annotation">
|
||
<h2>YJS Build-in Annotation<a class="headerlink" href="#yjs-build-in-annotation" title="永久链接至标题">¶</a></h2>
|
||
<div class="section" id="access">
|
||
<h3>@Access<a class="headerlink" href="#access" title="永久链接至标题">¶</a></h3>
|
||
<p>设置合约的调用是否需要签名,这里分为两种,需签名和无签名。
|
||
其中,”verified”表示需要签名。其他则表示无需签名。</p>
|
||
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="nd">@Access</span><span class="p">(</span><span class="s2">"verified"</span><span class="p">)</span>
|
||
<span class="n">export</span> <span class="n">function</span> <span class="n">easy</span><span class="p">(</span><span class="n">arg</span><span class="p">){</span>
|
||
<span class="k">return</span> <span class="s2">"true"</span><span class="p">;</span>
|
||
<span class="p">}</span>
|
||
</pre></div>
|
||
</div>
|
||
</div>
|
||
<div class="section" id="logtype">
|
||
<h3>@LogType<a class="headerlink" href="#logtype" title="永久链接至标题">¶</a></h3>
|
||
<p>LogType注解通过参数的方式声明合约或函数的需要记录的日志类型。</p>
|
||
<p>其中,Arg表示日志中记录合约执行的参数;Result表示记录合约执行的返回结果;Branch表示记录合约执行分支。</p>
|
||
<p>例如 ,通过如下LogType注解来声明函数</p>
|
||
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="nd">@LogType</span><span class="p">(</span><span class="s2">"Arg"</span><span class="p">,</span><span class="s2">"Result"</span><span class="p">,</span><span class="s2">"Branch"</span><span class="p">)</span>
|
||
<span class="n">export</span> <span class="n">function</span> <span class="n">easy</span><span class="p">(</span><span class="n">arg</span><span class="p">){</span>
|
||
<span class="n">Global</span><span class="o">.</span><span class="n">a</span> <span class="o">=</span> <span class="s2">"a"</span><span class="p">;</span>
|
||
<span class="n">Global</span><span class="o">.</span><span class="n">b</span> <span class="o">=</span> <span class="s2">"b"</span><span class="p">;</span>
|
||
<span class="k">if</span><span class="p">(</span><span class="n">arg</span> <span class="o">></span> <span class="mi">0</span><span class="p">)</span>
|
||
<span class="k">return</span> <span class="n">Global</span><span class="o">.</span><span class="n">a</span><span class="p">;</span>
|
||
<span class="k">else</span>
|
||
<span class="k">return</span> <span class="n">Global</span><span class="o">.</span><span class="n">b</span><span class="p">;</span>
|
||
<span class="p">}</span>
|
||
</pre></div>
|
||
</div>
|
||
</div>
|
||
<div class="section" id="loglocation">
|
||
<h3>@LogLocation<a class="headerlink" href="#loglocation" title="永久链接至标题">¶</a></h3>
|
||
<p>该注解可以修饰<code class="docutils literal notranslate"><span class="pre">contract</span></code>或<code class="docutils literal notranslate"><span class="pre">function</span></code>。
|
||
设置日志存储的位置。参数中指定为“dataware”则存储在账本和本地,如果没有指定为“dataware”则仅存储在本地。
|
||
例如,通过如下LogLocation设置存储位置。</p>
|
||
<p>在BaaS平台中,可以指定账本名称,BaaS平台默认账本为default,使用
|
||
<code class="docutils literal notranslate"><span class="pre">@LogLocation("bdledger:default")</span></code>。如想保存到自定义的账本,比如,”abc”账本,就使用
|
||
<code class="docutils literal notranslate"><span class="pre">@LogLocation("bdledger:abc")</span></code></p>
|
||
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="nd">@LogLocation</span><span class="p">(</span><span class="s2">"dataware"</span><span class="p">)</span>
|
||
<span class="n">export</span> <span class="n">function</span> <span class="n">easy</span><span class="p">(</span><span class="n">arg</span><span class="p">){</span>
|
||
<span class="n">Global</span><span class="o">.</span><span class="n">a</span> <span class="o">=</span> <span class="s2">"a"</span><span class="p">;</span>
|
||
<span class="p">}</span>
|
||
</pre></div>
|
||
</div>
|
||
</div>
|
||
<div class="section" id="permission">
|
||
<h3>@Permission<a class="headerlink" href="#permission" title="永久链接至标题">¶</a></h3>
|
||
<p>该注解只能修饰<code class="docutils literal notranslate"><span class="pre">contract</span></code>
|
||
设置合约中调用的工具类的权限,包括File、Http、MySQL、MongoDB、RocksDB等工具类。如果合约中用到了以上工具类,需要在注解中添加对应的授权字段,默认只有YJS自带的YancloudUtil;如果没有添加则会抛出”未授权工具类”的异常。
|
||
这6种工具类的详细说明在本小节后续中有说明。</p>
|
||
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="nd">@Permission</span><span class="p">(</span><span class="s2">"Http"</span><span class="p">,</span><span class="s2">"File"</span><span class="p">)</span>
|
||
<span class="n">contract</span> <span class="n">HttpPermission</span> <span class="p">{</span>
|
||
<span class="n">export</span> <span class="n">function</span> <span class="n">main</span><span class="p">(</span><span class="n">args</span><span class="p">){</span>
|
||
<span class="n">var</span> <span class="n">http</span><span class="o">=</span><span class="n">HttpUtil</span><span class="o">.</span><span class="n">httpGet</span><span class="p">(</span><span class="n">args</span><span class="p">);</span>
|
||
<span class="n">var</span> <span class="nb">dir</span><span class="o">=</span><span class="s2">"adf/adfas/"</span><span class="p">;</span>
|
||
<span class="n">var</span> <span class="n">file</span><span class="o">=</span><span class="n">FileUtil</span><span class="o">.</span><span class="n">getDir</span><span class="p">(</span><span class="nb">dir</span><span class="p">);</span>
|
||
<span class="k">return</span> <span class="n">YancloudUtil</span><span class="o">.</span><span class="n">currentTimeMillis</span><span class="p">();</span>
|
||
<span class="p">}</span>
|
||
<span class="p">}</span>
|
||
</pre></div>
|
||
</div>
|
||
</div>
|
||
<div class="section" id="description">
|
||
<h3>@Description<a class="headerlink" href="#description" title="永久链接至标题">¶</a></h3>
|
||
<p>该注解可以修饰<code class="docutils literal notranslate"><span class="pre">contract</span></code>或<code class="docutils literal notranslate"><span class="pre">function</span></code>。
|
||
传入合约及函数的简介,可用于生成说明文档中关于exported函数的介绍。</p>
|
||
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="nd">@Description</span><span class="p">(</span><span class="s2">"返回数据条目,无需参数"</span><span class="p">)</span>
|
||
<span class="n">export</span> <span class="n">function</span> <span class="n">count</span><span class="p">(</span><span class="n">args</span><span class="p">){</span>
|
||
<span class="n">var</span> <span class="n">sql</span> <span class="o">=</span> <span class="s2">"select count(*) from data;"</span><span class="p">;</span>
|
||
<span class="n">var</span> <span class="n">conn</span> <span class="o">=</span> <span class="n">getConn</span><span class="p">();</span>
|
||
<span class="n">var</span> <span class="n">statement</span> <span class="o">=</span> <span class="n">conn</span><span class="o">.</span><span class="n">createStatement</span><span class="p">();</span>
|
||
<span class="n">var</span> <span class="n">resultSet</span> <span class="o">=</span> <span class="n">statement</span><span class="o">.</span><span class="n">executeQuery</span><span class="p">(</span><span class="n">sql</span><span class="p">);</span>
|
||
<span class="n">var</span> <span class="n">c</span> <span class="o">=</span> <span class="p">{};</span>
|
||
<span class="n">resultSet</span><span class="o">.</span><span class="n">next</span><span class="p">();</span>
|
||
<span class="n">c</span><span class="o">.</span><span class="n">count</span> <span class="o">=</span> <span class="n">resultSet</span><span class="o">.</span><span class="n">getLong</span><span class="p">(</span><span class="mi">1</span><span class="p">);</span>
|
||
<span class="k">return</span> <span class="n">JSON</span><span class="o">.</span><span class="n">stringify</span><span class="p">(</span><span class="n">c</span><span class="p">);</span>
|
||
<span class="p">}</span>
|
||
</pre></div>
|
||
</div>
|
||
</div>
|
||
<div class="section" id="param">
|
||
<h3>@Param<a class="headerlink" href="#param" title="永久链接至标题">¶</a></h3>
|
||
<p>该注解可以修饰<code class="docutils literal notranslate"><span class="pre">function</span></code>。
|
||
提供调用函数的参数示例,也为生成说明文档中的返回结果提供默认参数。</p>
|
||
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="nd">@Param</span><span class="p">({</span><span class="s2">"offset"</span><span class="p">:</span><span class="mi">0</span><span class="p">,</span><span class="s2">"count"</span><span class="p">:</span><span class="mi">100</span><span class="p">})</span>
|
||
<span class="n">export</span> <span class="n">function</span> <span class="n">get</span><span class="p">(</span><span class="n">args</span><span class="p">){</span>
|
||
<span class="n">var</span> <span class="n">offset</span> <span class="o">=</span> <span class="n">args</span><span class="o">.</span><span class="n">offset</span><span class="p">;</span>
|
||
<span class="n">var</span> <span class="n">count</span> <span class="o">=</span> <span class="n">args</span><span class="o">.</span><span class="n">count</span><span class="p">;</span>
|
||
<span class="o">...</span>
|
||
<span class="p">}</span>
|
||
</pre></div>
|
||
</div>
|
||
</div>
|
||
<div class="section" id="mocktemplate">
|
||
<h3>@MockTemplate<a class="headerlink" href="#mocktemplate" title="永久链接至标题">¶</a></h3>
|
||
<p>该注解可以修饰<code class="docutils literal notranslate"><span class="pre">function</span></code>。
|
||
提供函数的返回模拟数据模板,用于描述返回值的格式.若加此注解在debug方式调用时,返回按照此格式生成的模拟数据。</p>
|
||
<p>####支持的字段类型</p>
|
||
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>@integer
|
||
@string
|
||
@boolean
|
||
@date
|
||
@time
|
||
@datatime
|
||
/[a-z][A-Z][0-9]/ (正则表达式)
|
||
……
|
||
详细格式可以参考http://mockjs.com/examples.html
|
||
</pre></div>
|
||
</div>
|
||
<p>####注意:模板的格式为{‘result’:模板}</p>
|
||
<div class="highlight-json notranslate"><div class="highlight"><pre><span></span>//返回一个1-100之间的整数
|
||
@MockTemplate({'result|1-100':1})
|
||
//返回
|
||
{'result':76}
|
||
|
||
//返回一个1-5个数的数组
|
||
@MockTemplate({'result|1-5':[{'value|1-100':1}]})
|
||
//返回
|
||
{"result":[{"value":34},{"value":8},{"value":48},{"value":50},{"value":43}]}
|
||
|
||
//返回一个对象包含如下字段
|
||
@MockTemplate({'result':{'id':'@integer','email':'@email','password':'@string','name':'@name'}})
|
||
//返回
|
||
{"password":"3ZLc","name":"William Young","id":36097783842688,"email":"d.fuunwe@gqnr.to"}
|
||
|
||
//返回元素个数为1-5个之间的一个数组,数组的每个元素都是上述格式的一个对象
|
||
{'result|1-5':[{'id':'@integer','email':'@email','password':'@string','name':'@name'}]}
|
||
//返回
|
||
[
|
||
{"password":"dO]wW","name":"Jeffrey Lopez","id":1783453207480410,"email":"a.ckokgxrga@hgiesugi.bb"},
|
||
{"password":"BQYRL","name":"Brian Moore","id":4310212972071102,"email":"k.lbpxocydrh@msgnjtox.na"},
|
||
{"password":"Gw1","name":"Susan Jackson","id":7766580783668916,"email":"h.zjgusl@htce.cr"}
|
||
]
|
||
</pre></div>
|
||
</div>
|
||
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="nd">@MockTemplate</span><span class="p">({</span><span class="s1">'result'</span><span class="p">:{</span><span class="s1">'id'</span><span class="p">:</span><span class="s1">'@integer'</span><span class="p">,</span><span class="s1">'email'</span><span class="p">:</span><span class="s1">'@email'</span><span class="p">,</span><span class="s1">'password'</span><span class="p">:</span><span class="s1">'@string'</span><span class="p">,</span><span class="s1">'name'</span><span class="p">:</span><span class="s1">'@name'</span><span class="p">}})</span>
|
||
<span class="n">export</span> <span class="n">function</span> <span class="n">count</span><span class="p">(</span><span class="n">args</span><span class="p">){</span>
|
||
<span class="n">var</span> <span class="n">sql</span> <span class="o">=</span> <span class="s2">"select count(*) from data;"</span><span class="p">;</span>
|
||
<span class="n">var</span> <span class="n">conn</span> <span class="o">=</span> <span class="n">getConn</span><span class="p">();</span>
|
||
<span class="n">var</span> <span class="n">statement</span> <span class="o">=</span> <span class="n">conn</span><span class="o">.</span><span class="n">createStatement</span><span class="p">();</span>
|
||
<span class="n">var</span> <span class="n">resultSet</span> <span class="o">=</span> <span class="n">statement</span><span class="o">.</span><span class="n">executeQuery</span><span class="p">(</span><span class="n">sql</span><span class="p">);</span>
|
||
<span class="n">var</span> <span class="n">c</span> <span class="o">=</span> <span class="p">{};</span>
|
||
<span class="n">resultSet</span><span class="o">.</span><span class="n">next</span><span class="p">();</span>
|
||
<span class="n">c</span><span class="o">.</span><span class="n">count</span> <span class="o">=</span> <span class="n">resultSet</span><span class="o">.</span><span class="n">getLong</span><span class="p">(</span><span class="mi">1</span><span class="p">);</span>
|
||
<span class="k">return</span> <span class="n">JSON</span><span class="o">.</span><span class="n">stringify</span><span class="p">(</span><span class="n">c</span><span class="p">);</span>
|
||
<span class="p">}</span>
|
||
</pre></div>
|
||
</div>
|
||
</div>
|
||
<div class="section" id="result">
|
||
<h3>@Result<a class="headerlink" href="#result" title="永久链接至标题">¶</a></h3>
|
||
<p>该注解可以修饰<code class="docutils literal notranslate"><span class="pre">function</span></code>。
|
||
若没有模拟数据模板,则返回模拟数据时使用该注解的内容
|
||
提供函数的返回结果示例,若加此注解则生成说明文档时将直接返回此结果而不使用默认参数调用函数。</p>
|
||
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="nd">@Result</span><span class="p">(</span><span class="mi">666</span><span class="p">)</span>
|
||
<span class="n">export</span> <span class="n">function</span> <span class="n">count</span><span class="p">(</span><span class="n">args</span><span class="p">){</span>
|
||
<span class="n">var</span> <span class="n">sql</span> <span class="o">=</span> <span class="s2">"select count(*) from data;"</span><span class="p">;</span>
|
||
<span class="n">var</span> <span class="n">conn</span> <span class="o">=</span> <span class="n">getConn</span><span class="p">();</span>
|
||
<span class="n">var</span> <span class="n">statement</span> <span class="o">=</span> <span class="n">conn</span><span class="o">.</span><span class="n">createStatement</span><span class="p">();</span>
|
||
<span class="n">var</span> <span class="n">resultSet</span> <span class="o">=</span> <span class="n">statement</span><span class="o">.</span><span class="n">executeQuery</span><span class="p">(</span><span class="n">sql</span><span class="p">);</span>
|
||
<span class="n">var</span> <span class="n">c</span> <span class="o">=</span> <span class="p">{};</span>
|
||
<span class="n">resultSet</span><span class="o">.</span><span class="n">next</span><span class="p">();</span>
|
||
<span class="n">c</span><span class="o">.</span><span class="n">count</span> <span class="o">=</span> <span class="n">resultSet</span><span class="o">.</span><span class="n">getLong</span><span class="p">(</span><span class="mi">1</span><span class="p">);</span>
|
||
<span class="k">return</span> <span class="n">JSON</span><span class="o">.</span><span class="n">stringify</span><span class="p">(</span><span class="n">c</span><span class="p">);</span>
|
||
<span class="p">}</span>
|
||
</pre></div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<div class="section" id="io">
|
||
<h2>IO工具类<a class="headerlink" href="#io" title="永久链接至标题">¶</a></h2>
|
||
<div class="section" id="id2">
|
||
<h3>概览<a class="headerlink" href="#id2" title="永久链接至标题">¶</a></h3>
|
||
<table border="1" class="docutils">
|
||
<thead>
|
||
<tr>
|
||
<th>IO工具类名称</th>
|
||
<th>说明</th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
<tr>
|
||
<td><a href="./YJSAPI.html#fileutil">FileUtil</a></td>
|
||
<td>文件操作相关的类</td>
|
||
</tr>
|
||
<tr>
|
||
<td><a href="./YJSAPI.html#ledgerutil">LedgerUtil</a></td>
|
||
<td>账本操作相关的类</td>
|
||
</tr>
|
||
<tr>
|
||
<td><a href="./YJSAPI.html#httputil">HttpUtil</a></td>
|
||
<td>Http接口相关的类</td>
|
||
</tr>
|
||
<tr>
|
||
<td><a href="./YJSAPI.html#doiputil">DOIPUtil</a></td>
|
||
<td>DoIP相关的类</td>
|
||
</tr>
|
||
<tr>
|
||
<td><a href="./YJSAPI.html#mysqlutil">MySQLUtil</a></td>
|
||
<td>连接mysql数据库</td>
|
||
</tr>
|
||
<tr>
|
||
<td><a href="./YJSAPI.html#mongodbutil">MongoDBUtil</a></td>
|
||
<td>MongoDB连接相关的类</td>
|
||
</tr>
|
||
<tr>
|
||
<td><a href="./YJSAPI.html#rocksdbutil">RocksDBUtil</a></td>
|
||
<td>RocksDB(基于本地文件的k-v数据库)</td>
|
||
</tr>
|
||
<tr>
|
||
<td><a href="./YJSAPI.html#BDWareTimeSeriesDBUtil">BDWareTimeSeriesDBUtil</a></td>
|
||
<td>基于本地文件的时间序列数据库</td>
|
||
</tr>
|
||
</tbody>
|
||
</table></div>
|
||
<div class="section" id="fileutil">
|
||
<h3>FileUtil<a class="headerlink" href="#fileutil" title="永久链接至标题">¶</a></h3>
|
||
<p>可以使用@Permission(“File”)来引入FileUtil对象。</p>
|
||
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="nd">@Permission</span><span class="p">(</span><span class="s2">"File"</span><span class="p">)</span>
|
||
<span class="n">contract</span> <span class="n">FileSample</span> <span class="p">{</span>
|
||
<span class="o">...</span>
|
||
<span class="p">}</span>
|
||
</pre></div>
|
||
</div>
|
||
<p>该对象支持以下方法:</p>
|
||
<div class="section" id="copyto">
|
||
<h4>copyTo<a class="headerlink" href="#copyto" title="永久链接至标题">¶</a></h4>
|
||
<p>可以复制文件和目录。第一个参数是source,第二个参数是destination。</p>
|
||
<div class="section" id="id3">
|
||
<h5>参数<a class="headerlink" href="#id3" title="永久链接至标题">¶</a></h5>
|
||
<table border="1" class="docutils">
|
||
<thead>
|
||
<tr>
|
||
<th>序号</th>
|
||
<th>参数</th>
|
||
<th>说明</th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
<tr>
|
||
<td>1</td>
|
||
<td>src</td>
|
||
<td>类型为String</td>
|
||
</tr>
|
||
<tr>
|
||
<td>2</td>
|
||
<td>dest</td>
|
||
<td>类型为String</td>
|
||
</tr>
|
||
</tbody>
|
||
</table></div>
|
||
<div class="section" id="id4">
|
||
<h5>使用示例<a class="headerlink" href="#id4" title="永久链接至标题">¶</a></h5>
|
||
<div class="highlight-javascript notranslate"><div class="highlight"><pre><span></span><span class="kd">var</span> <span class="nx">ret</span> <span class="o">=</span> <span class="nx">FileUtil</span><span class="p">.</span><span class="nx">copyTo</span><span class="p">(</span><span class="s2">"./source.txt"</span><span class="p">,</span><span class="s2">"./dest.txt"</span><span class="p">);</span>
|
||
</pre></div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<div class="section" id="getcontent">
|
||
<h4>getContent<a class="headerlink" href="#getcontent" title="永久链接至标题">¶</a></h4>
|
||
<p>获取文件的文本内容,当文件不存在时,返回<code class="docutils literal notranslate"><span class="pre">undefined</span></code>。</p>
|
||
<div class="section" id="id5">
|
||
<h5>参数<a class="headerlink" href="#id5" title="永久链接至标题">¶</a></h5>
|
||
<table border="1" class="docutils">
|
||
<thead>
|
||
<tr>
|
||
<th>序号</th>
|
||
<th>参数</th>
|
||
<th>说明</th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
<tr>
|
||
<td>1</td>
|
||
<td>path</td>
|
||
<td>类型为String</td>
|
||
</tr>
|
||
</tbody>
|
||
</table></div>
|
||
<div class="section" id="id6">
|
||
<h5>使用示例<a class="headerlink" href="#id6" title="永久链接至标题">¶</a></h5>
|
||
<div class="highlight-javascript notranslate"><div class="highlight"><pre><span></span><span class="kd">var</span> <span class="nx">ret</span> <span class="o">=</span> <span class="nx">FileUtil</span><span class="p">.</span><span class="nx">getContent</span><span class="p">(</span><span class="s2">"./source.txt"</span><span class="p">);</span>
|
||
</pre></div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<div class="section" id="getdir">
|
||
<h4>getDir<a class="headerlink" href="#getdir" title="永久链接至标题">¶</a></h4>
|
||
<p>获取文件所在的文件夹名,输入参数为字符串。</p>
|
||
<div class="section" id="id7">
|
||
<h5>参数<a class="headerlink" href="#id7" title="永久链接至标题">¶</a></h5>
|
||
<table border="1" class="docutils">
|
||
<thead>
|
||
<tr>
|
||
<th>序号</th>
|
||
<th>参数</th>
|
||
<th>说明</th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
<tr>
|
||
<td>1</td>
|
||
<td>path</td>
|
||
<td>类型为String</td>
|
||
</tr>
|
||
</tbody>
|
||
</table></div>
|
||
<div class="section" id="id8">
|
||
<h5>使用示例<a class="headerlink" href="#id8" title="永久链接至标题">¶</a></h5>
|
||
<div class="highlight-javascript notranslate"><div class="highlight"><pre><span></span><span class="kd">var</span> <span class="nx">ret</span> <span class="o">=</span> <span class="nx">FileUtil</span><span class="p">.</span><span class="nx">getDir</span><span class="p">(</span><span class="s2">"./parent/src.txt"</span><span class="p">);</span>
|
||
<span class="c1">// ret 为 "./parent/";</span>
|
||
</pre></div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<div class="section" id="getfilename">
|
||
<h4>getFileName<a class="headerlink" href="#getfilename" title="永久链接至标题">¶</a></h4>
|
||
<p>获取文件名。输入参数为字符串。</p>
|
||
<div class="section" id="id9">
|
||
<h5>参数<a class="headerlink" href="#id9" title="永久链接至标题">¶</a></h5>
|
||
<table border="1" class="docutils">
|
||
<thead>
|
||
<tr>
|
||
<th>序号</th>
|
||
<th>参数</th>
|
||
<th>说明</th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
<tr>
|
||
<td>1</td>
|
||
<td>path</td>
|
||
<td>类型为String</td>
|
||
</tr>
|
||
</tbody>
|
||
</table></div>
|
||
<div class="section" id="id10">
|
||
<h5>使用示例<a class="headerlink" href="#id10" title="永久链接至标题">¶</a></h5>
|
||
<div class="highlight-javascript notranslate"><div class="highlight"><pre><span></span><span class="kd">var</span> <span class="nx">ret</span> <span class="o">=</span> <span class="nx">FileUtil</span><span class="p">.</span><span class="nx">getFileName</span><span class="p">(</span><span class="s2">"./parent/src.txt"</span><span class="p">);</span>
|
||
<span class="c1">// ret 为 "src.txt"</span>
|
||
</pre></div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<div class="section" id="openfileasprinter">
|
||
<h4>openFileAsPrinter<a class="headerlink" href="#openfileasprinter" title="永久链接至标题">¶</a></h4>
|
||
<p>以PrintStream的形式打开文件。
|
||
返回结果是<code class="docutils literal notranslate"><span class="pre">java.io.PrintStream</span></code>类型。</p>
|
||
<div class="section" id="id11">
|
||
<h5>参数<a class="headerlink" href="#id11" title="永久链接至标题">¶</a></h5>
|
||
<table border="1" class="docutils">
|
||
<thead>
|
||
<tr>
|
||
<th>序号</th>
|
||
<th>参数</th>
|
||
<th>说明</th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
<tr>
|
||
<td>1</td>
|
||
<td>path</td>
|
||
<td>文件名,类型为String</td>
|
||
</tr>
|
||
<tr>
|
||
<td>2</td>
|
||
<td>isAppend</td>
|
||
<td>类型为boolean,表示是否往文件末尾添加</td>
|
||
</tr>
|
||
</tbody>
|
||
</table></div>
|
||
<div class="section" id="id12">
|
||
<h5>使用示例<a class="headerlink" href="#id12" title="永久链接至标题">¶</a></h5>
|
||
<div class="highlight-javascript notranslate"><div class="highlight"><pre><span></span><span class="kd">var</span> <span class="nx">ret</span> <span class="o">=</span> <span class="nx">FileUtil</span><span class="p">.</span><span class="nx">openFileAsPrinter</span><span class="p">(</span><span class="s2">"./parent/src.txt"</span><span class="p">,</span><span class="kc">true</span><span class="p">);</span>
|
||
<span class="nx">ret</span><span class="p">.</span><span class="nx">println</span><span class="p">(</span><span class="s2">"hello"</span><span class="p">);</span>
|
||
<span class="nx">ret</span><span class="p">.</span><span class="nx">close</span><span class="p">();</span>
|
||
</pre></div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<div class="section" id="ledgerutil">
|
||
<h3>LedgerUtil<a class="headerlink" href="#ledgerutil" title="永久链接至标题">¶</a></h3>
|
||
<p>可以使用@Permission(“Ledger”)来引入LedgerUtil对象。</p>
|
||
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="nd">@Permission</span><span class="p">(</span><span class="s2">"Ledger"</span><span class="p">)</span>
|
||
<span class="n">contract</span> <span class="n">LedgerExample</span><span class="p">{</span>
|
||
<span class="o">...</span>
|
||
<span class="p">}</span>
|
||
</pre></div>
|
||
</div>
|
||
<div class="section" id="getclient">
|
||
<h4>getClient<a class="headerlink" href="#getclient" title="永久链接至标题">¶</a></h4>
|
||
<p>获取一个连接客户端,一个参数,为对象类型。
|
||
返回结果为LedgerClient类型,用于后续的查询账本等操作。</p>
|
||
<div class="section" id="id13">
|
||
<h5>参数<a class="headerlink" href="#id13" title="永久链接至标题">¶</a></h5>
|
||
<table border="1" class="docutils">
|
||
<thead>
|
||
<tr>
|
||
<th>序号</th>
|
||
<th>参数</th>
|
||
<th>说明</th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
<tr>
|
||
<td>1</td>
|
||
<td>address</td>
|
||
<td>包含ip和端口两个字段</td>
|
||
</tr>
|
||
</tbody>
|
||
</table></div>
|
||
<div class="section" id="id14">
|
||
<h5>使用示例<a class="headerlink" href="#id14" title="永久链接至标题">¶</a></h5>
|
||
<div class="highlight-javascript notranslate"><div class="highlight"><pre><span></span><span class="kd">var</span> <span class="nx">address</span> <span class="o">=</span> <span class="p">{};</span>
|
||
<span class="nx">address</span><span class="p">.</span><span class="nx">ip</span> <span class="o">=</span> <span class="s2">"127.0.0.1"</span><span class="p">;</span>
|
||
<span class="nx">address</span><span class="p">.</span><span class="nx">port</span> <span class="o">=</span> <span class="mi">18091</span><span class="p">;</span>
|
||
<span class="kd">var</span> <span class="nx">ledgerClient</span> <span class="o">=</span> <span class="nx">LedgerUtil</span><span class="p">.</span><span class="nx">getClient</span><span class="p">(</span><span class="nx">address</span><span class="p">);</span>
|
||
</pre></div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<div class="section" id="querybyhash">
|
||
<h4>queryByHash<a class="headerlink" href="#querybyhash" title="永久链接至标题">¶</a></h4>
|
||
<p>根据Hash查询Transaction。
|
||
返回结果为对象,包含from、to、type和data四个字段,均为String类型。
|
||
其中data为按utf-8编码解析字节数组,如果存证时用的不是utf8编码,可能返回乱码。</p>
|
||
<div class="section" id="id15">
|
||
<h5>参数<a class="headerlink" href="#id15" title="永久链接至标题">¶</a></h5>
|
||
<table border="1" class="docutils">
|
||
<thead>
|
||
<tr>
|
||
<th>序号</th>
|
||
<th>参数</th>
|
||
<th>说明</th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
<tr>
|
||
<td>1</td>
|
||
<td>client</td>
|
||
<td>通过getClient方法获得的对象</td>
|
||
</tr>
|
||
<tr>
|
||
<td>2</td>
|
||
<td>info</td>
|
||
<td>对象类型,有两个字段ledger和hash,均为字符串类型</td>
|
||
</tr>
|
||
</tbody>
|
||
</table></div>
|
||
<div class="section" id="id16">
|
||
<h5>使用示例<a class="headerlink" href="#id16" title="永久链接至标题">¶</a></h5>
|
||
<div class="highlight-javascript notranslate"><div class="highlight"><pre><span></span><span class="c1">// ... ledgerClient = LedgerUtil.getClient(...);</span>
|
||
<span class="kd">var</span> <span class="nx">info</span> <span class="o">=</span> <span class="p">{};</span>
|
||
<span class="nx">info</span><span class="p">.</span><span class="nx">ledger</span> <span class="o">=</span> <span class="s2">"bdcontract"</span><span class="p">;</span>
|
||
<span class="nx">info</span><span class="p">.</span><span class="nx">hash</span> <span class="o">=</span> <span class="s2">"4d3b75750835092a50085127702669615b602e53"</span><span class="p">;</span>
|
||
<span class="kd">var</span> <span class="nx">ret</span> <span class="o">=</span> <span class="nx">LedgerUtil</span><span class="p">.</span><span class="nx">queryByHash</span><span class="p">(</span><span class="nx">ledgerClient</span><span class="p">,</span><span class="nx">info</span><span class="p">);</span>
|
||
<span class="nx">print</span><span class="p">(</span><span class="nx">ret</span><span class="p">.</span><span class="nx">from</span><span class="p">);</span>
|
||
<span class="nx">print</span><span class="p">(</span><span class="nx">ret</span><span class="p">.</span><span class="nx">to</span><span class="p">);</span>
|
||
<span class="nx">print</span><span class="p">(</span><span class="nx">ret</span><span class="p">.</span><span class="nx">type</span><span class="p">);</span>
|
||
<span class="nx">print</span><span class="p">(</span><span class="nx">ret</span><span class="p">.</span><span class="nx">data</span><span class="p">);</span>
|
||
</pre></div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<div class="section" id="sendtransaction">
|
||
<h4>sendTransaction<a class="headerlink" href="#sendtransaction" title="永久链接至标题">¶</a></h4>
|
||
<p>存证数据。</p>
|
||
<div class="section" id="id17">
|
||
<h5>参数<a class="headerlink" href="#id17" title="永久链接至标题">¶</a></h5>
|
||
<table border="1" class="docutils">
|
||
<thead>
|
||
<tr>
|
||
<th>序号</th>
|
||
<th>参数</th>
|
||
<th>说明</th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
<tr>
|
||
<td>1</td>
|
||
<td>client</td>
|
||
<td>通过getClient方法获得的对象</td>
|
||
</tr>
|
||
<tr>
|
||
<td>2</td>
|
||
<td>info</td>
|
||
<td>对象类型,有from\to\data三个字段,均为String类型</td>
|
||
</tr>
|
||
</tbody>
|
||
</table></div>
|
||
<div class="section" id="id18">
|
||
<h5>使用示例<a class="headerlink" href="#id18" title="永久链接至标题">¶</a></h5>
|
||
<div class="highlight-javascript notranslate"><div class="highlight"><pre><span></span><span class="c1">// ... ledgerClient = LedgerUtil.getClient(...);</span>
|
||
<span class="kd">var</span> <span class="nx">info</span> <span class="o">=</span> <span class="p">{};</span>
|
||
<span class="nx">info</span><span class="p">.</span><span class="nx">ledger</span> <span class="o">=</span> <span class="s2">"bdcontract"</span><span class="p">;</span>
|
||
<span class="nx">info</span><span class="p">.</span><span class="nx">from</span> <span class="o">=</span> <span class="s2">"b60e8dd61c5d32be8058bb8eb970870f07233155"</span><span class="p">;</span>
|
||
<span class="nx">info</span><span class="p">.</span><span class="nx">to</span> <span class="o">=</span> <span class="s2">"b60e8dd61c5d32be8058bb8eb970870f07233155"</span><span class="p">;</span>
|
||
<span class="nx">info</span><span class="p">.</span><span class="nx">data</span> <span class="o">=</span> <span class="s2">"hello world"</span><span class="p">;</span>
|
||
<span class="kd">var</span> <span class="nx">ret</span> <span class="o">=</span> <span class="nx">LedgerUtil</span><span class="p">.</span><span class="nx">sendTransaction</span><span class="p">(</span><span class="nx">ledgerClient</span><span class="p">,</span><span class="nx">info</span><span class="p">);</span>
|
||
<span class="c1">//ret为存证的哈希值</span>
|
||
<span class="nx">print</span><span class="p">(</span><span class="nx">ret</span><span class="p">);</span>
|
||
</pre></div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<div class="section" id="httputil">
|
||
<h3>HttpUtil<a class="headerlink" href="#httputil" title="永久链接至标题">¶</a></h3>
|
||
<p>可以使用@Permission(“Http”)来引入HttpUtil对象。</p>
|
||
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="nd">@Permission</span><span class="p">(</span><span class="s2">"Http"</span><span class="p">)</span>
|
||
<span class="n">contract</span> <span class="n">HttpExample</span><span class="p">{</span>
|
||
<span class="o">...</span>
|
||
<span class="p">}</span>
|
||
</pre></div>
|
||
</div>
|
||
<div class="section" id="createapigate">
|
||
<h4>createAPIGate<a class="headerlink" href="#createapigate" title="永久链接至标题">¶</a></h4>
|
||
<p>配合手机的元邦使用,当手机安装元邦且安装了API 接口后,可成为数据来源。</p>
|
||
<div class="section" id="id19">
|
||
<h5>参数<a class="headerlink" href="#id19" title="永久链接至标题">¶</a></h5>
|
||
<table border="1" class="docutils">
|
||
<thead>
|
||
<tr>
|
||
<th>序号</th>
|
||
<th>参数</th>
|
||
<th>说明</th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
<tr>
|
||
<td>1</td>
|
||
<td>ip</td>
|
||
<td>字符串类型,ip,端口默认为6161</td>
|
||
</tr>
|
||
</tbody>
|
||
</table></div>
|
||
<div class="section" id="id20">
|
||
<h5>使用示例<a class="headerlink" href="#id20" title="永久链接至标题">¶</a></h5>
|
||
<div class="highlight-javascript notranslate"><div class="highlight"><pre><span></span><span class="kd">var</span> <span class="nx">ret</span> <span class="o">=</span> <span class="nx">HttpUtil</span><span class="p">.</span><span class="nx">createAPIGate</span><span class="p">(</span><span class="s2">"192.168.4.4"</span><span class="p">);</span>
|
||
<span class="nx">ret</span><span class="p">.</span><span class="nx">get</span><span class="p">(</span><span class="s2">"com.tencent.mm"</span><span class="p">,</span><span class="s2">"sendMsg"</span><span class="p">,</span><span class="s2">"msg"</span><span class="p">);</span>
|
||
<span class="nx">print</span><span class="p">(</span><span class="nx">ret</span><span class="p">);</span>
|
||
</pre></div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<div class="section" id="id21">
|
||
<h4>createAPIGate<a class="headerlink" href="#id21" title="永久链接至标题">¶</a></h4>
|
||
<p>配合手机的元邦使用,当手机安装元邦且安装了API 接口后,可成为数据来源。</p>
|
||
<div class="section" id="id22">
|
||
<h5>参数<a class="headerlink" href="#id22" title="永久链接至标题">¶</a></h5>
|
||
<table border="1" class="docutils">
|
||
<thead>
|
||
<tr>
|
||
<th>序号</th>
|
||
<th>参数</th>
|
||
<th>说明</th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
<tr>
|
||
<td>1</td>
|
||
<td>ip</td>
|
||
<td>字符串类型,ip</td>
|
||
</tr>
|
||
<tr>
|
||
<td>2</td>
|
||
<td>port</td>
|
||
<td>字符串类型,端口</td>
|
||
</tr>
|
||
</tbody>
|
||
</table></div>
|
||
<div class="section" id="id23">
|
||
<h5>使用示例<a class="headerlink" href="#id23" title="永久链接至标题">¶</a></h5>
|
||
<div class="highlight-javascript notranslate"><div class="highlight"><pre><span></span><span class="kd">var</span> <span class="nx">ret</span> <span class="o">=</span> <span class="nx">HttpUtil</span><span class="p">.</span><span class="nx">createAPIGate</span><span class="p">(</span><span class="s2">"192.168.4.4"</span><span class="p">,</span> <span class="s2">"6161"</span><span class="p">);</span>
|
||
<span class="nx">ret</span><span class="p">.</span><span class="nx">get</span><span class="p">(</span><span class="s2">"com.tencent.mm"</span><span class="p">,</span><span class="s2">"sendMsg"</span><span class="p">,</span><span class="s2">"msg"</span><span class="p">);</span>
|
||
<span class="nx">print</span><span class="p">(</span><span class="nx">ret</span><span class="p">);</span>
|
||
</pre></div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<div class="section" id="get">
|
||
<h4>get<a class="headerlink" href="#get" title="永久链接至标题">¶</a></h4>
|
||
<p>发起Http的get请求。
|
||
返回结果为对象类型,包含response和responseCode两个字段。</p>
|
||
<div class="section" id="id24">
|
||
<h5>参数<a class="headerlink" href="#id24" title="永久链接至标题">¶</a></h5>
|
||
<table border="1" class="docutils">
|
||
<thead>
|
||
<tr>
|
||
<th>序号</th>
|
||
<th>参数</th>
|
||
<th>说明</th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
<tr>
|
||
<td>1</td>
|
||
<td>url</td>
|
||
<td>字符串,表示url类型</td>
|
||
</tr>
|
||
</tbody>
|
||
</table></div>
|
||
<div class="section" id="id25">
|
||
<h5>使用示例<a class="headerlink" href="#id25" title="永久链接至标题">¶</a></h5>
|
||
<div class="highlight-javascript notranslate"><div class="highlight"><pre><span></span><span class="kd">var</span> <span class="nx">ret</span> <span class="o">=</span> <span class="nx">HttpUtil</span><span class="p">.</span><span class="nx">get</span><span class="p">(</span><span class="s2">"https://www.baidu.com"</span><span class="p">);</span>
|
||
<span class="nx">print</span><span class="p">(</span><span class="nx">ret</span><span class="p">.</span><span class="nx">responseCode</span><span class="p">);</span>
|
||
<span class="nx">print</span><span class="p">(</span><span class="nx">ret</span><span class="p">.</span><span class="nx">response</span><span class="p">);</span>
|
||
</pre></div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<div class="section" id="post">
|
||
<h4>post<a class="headerlink" href="#post" title="永久链接至标题">¶</a></h4>
|
||
<p>发起Http的post请求。
|
||
返回结果为对象类型,包含response和responseCode两个字段。</p>
|
||
<div class="section" id="id26">
|
||
<h5>参数<a class="headerlink" href="#id26" title="永久链接至标题">¶</a></h5>
|
||
<table border="1" class="docutils">
|
||
<thead>
|
||
<tr>
|
||
<th>序号</th>
|
||
<th>参数</th>
|
||
<th>说明</th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
<tr>
|
||
<td>1</td>
|
||
<td>args</td>
|
||
<td>对象类型,有url,headers和data三个字段。其中,args.headers为对象类型。</td>
|
||
</tr>
|
||
</tbody>
|
||
</table></div>
|
||
<div class="section" id="id27">
|
||
<h5>使用示例<a class="headerlink" href="#id27" title="永久链接至标题">¶</a></h5>
|
||
<div class="highlight-javascript notranslate"><div class="highlight"><pre><span></span><span class="kd">var</span> <span class="nx">req</span> <span class="o">=</span> <span class="p">{};</span>
|
||
<span class="nx">req</span><span class="p">.</span><span class="nx">url</span> <span class="o">=</span> <span class="s2">"https://www.baidu.com"</span><span class="p">;</span>
|
||
<span class="nx">req</span><span class="p">.</span><span class="nx">data</span> <span class="o">=</span> <span class="s2">"hello"</span><span class="p">;</span>
|
||
<span class="nx">req</span><span class="p">.</span><span class="nx">header</span> <span class="o">=</span> <span class="p">{};</span>
|
||
<span class="nx">req</span><span class="p">.</span><span class="nx">header</span><span class="p">.</span><span class="nx">Accept</span> <span class="o">=</span> <span class="s2">"application/json"</span><span class="p">;</span>
|
||
<span class="nx">req</span><span class="p">.</span><span class="nx">header</span><span class="p">[</span><span class="s2">"Content-Type"</span><span class="p">]</span> <span class="o">=</span> <span class="s2">"application/json"</span><span class="p">;</span>
|
||
<span class="kd">var</span> <span class="nx">ret</span> <span class="o">=</span> <span class="nx">HttpUtil</span><span class="p">.</span><span class="nx">post</span><span class="p">(</span><span class="nx">req</span><span class="p">);</span>
|
||
<span class="nx">print</span><span class="p">(</span><span class="nx">ret</span><span class="p">.</span><span class="nx">resposeCode</span><span class="p">);</span>
|
||
<span class="nx">print</span><span class="p">(</span><span class="nx">ret</span><span class="p">.</span><span class="nx">response</span><span class="p">);</span>
|
||
</pre></div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<div class="section" id="doiputil">
|
||
<h3>DOIPUtil<a class="headerlink" href="#doiputil" title="永久链接至标题">¶</a></h3>
|
||
<p>可以使用@Permission(“DOIP”)来引入DOIPUtil对象。</p>
|
||
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="nd">@Permission</span><span class="p">(</span><span class="s2">"DOIP"</span><span class="p">)</span>
|
||
<span class="n">contract</span> <span class="n">DOIPExample</span><span class="p">{</span>
|
||
<span class="o">...</span>
|
||
<span class="p">}</span>
|
||
</pre></div>
|
||
</div>
|
||
<div class="section" id="call">
|
||
<h4>call<a class="headerlink" href="#call" title="永久链接至标题">¶</a></h4>
|
||
<p>调用一个DO</p>
|
||
<div class="section" id="id28">
|
||
<h5>参数<a class="headerlink" href="#id28" title="永久链接至标题">¶</a></h5>
|
||
<table border="1" class="docutils">
|
||
<thead>
|
||
<tr>
|
||
<th>序号</th>
|
||
<th>参数</th>
|
||
<th>说明</th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
<tr>
|
||
<td>1</td>
|
||
<td>arg0</td>
|
||
<td>字符串类型, 目标DO标识</td>
|
||
</tr>
|
||
<tr>
|
||
<td>2</td>
|
||
<td>arg1</td>
|
||
<td>字符串类型, 输入参数字符串</td>
|
||
</tr>
|
||
</tbody>
|
||
</table></div>
|
||
<div class="section" id="id29">
|
||
<h5>使用示例<a class="headerlink" href="#id29" title="永久链接至标题">¶</a></h5>
|
||
<div class="highlight-javascript notranslate"><div class="highlight"><pre><span></span><span class="kd">var</span> <span class="nx">ret</span> <span class="o">=</span> <span class="nx">DOIPUtil</span><span class="p">.</span><span class="nx">call</span><span class="p">(</span><span class="s2">"86.5000.470/do.hello"</span><span class="p">,</span><span class="s2">"inputString"</span><span class="p">);</span>
|
||
</pre></div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<div class="section" id="create">
|
||
<h4>create<a class="headerlink" href="#create" title="永久链接至标题">¶</a></h4>
|
||
<p>向一个Repository创建一个字符串类型DO</p>
|
||
<div class="section" id="id30">
|
||
<h5>参数<a class="headerlink" href="#id30" title="永久链接至标题">¶</a></h5>
|
||
<table border="1" class="docutils">
|
||
<thead>
|
||
<tr>
|
||
<th>序号</th>
|
||
<th>参数</th>
|
||
<th>说明</th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
<tr>
|
||
<td>1</td>
|
||
<td>arg0</td>
|
||
<td>字符串类型, 目标Repo标识</td>
|
||
</tr>
|
||
<tr>
|
||
<td>2</td>
|
||
<td>arg1</td>
|
||
<td>对象类型,包括doID,doBody字段</td>
|
||
</tr>
|
||
</tbody>
|
||
</table></div>
|
||
<div class="section" id="id31">
|
||
<h5>使用示例<a class="headerlink" href="#id31" title="永久链接至标题">¶</a></h5>
|
||
<div class="highlight-javascript notranslate"><div class="highlight"><pre><span></span><span class="kd">var</span> <span class="nx">digitalObject</span> <span class="o">=</span> <span class="nx">JSON</span><span class="p">.</span><span class="nx">parse</span><span class="p">(</span><span class="s2">"{\"doID\":\"86.5000.470/do.hello\",\"doBody\":\"hello world\"}"</span><span class="p">);</span>
|
||
<span class="kd">var</span> <span class="nx">ret</span> <span class="o">=</span> <span class="nx">DOIPUtil</span><span class="p">.</span><span class="nx">create</span><span class="p">(</span><span class="s2">"86.5000.470/repo.localTcpRepo"</span><span class="p">,</span><span class="nx">digitalObject</span><span class="p">);</span>
|
||
</pre></div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<div class="section" id="delete">
|
||
<h4>delete<a class="headerlink" href="#delete" title="永久链接至标题">¶</a></h4>
|
||
<p>从一个Repository中删除DO</p>
|
||
<div class="section" id="id32">
|
||
<h5>参数<a class="headerlink" href="#id32" title="永久链接至标题">¶</a></h5>
|
||
<table border="1" class="docutils">
|
||
<thead>
|
||
<tr>
|
||
<th>序号</th>
|
||
<th>参数</th>
|
||
<th>说明</th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
<tr>
|
||
<td>1</td>
|
||
<td>arg0</td>
|
||
<td>字符串类型 目标DO标识</td>
|
||
</tr>
|
||
<tr>
|
||
<td>2</td>
|
||
<td>arg1</td>
|
||
<td>字符串类型 目标Repo标识</td>
|
||
</tr>
|
||
</tbody>
|
||
</table></div>
|
||
<div class="section" id="id33">
|
||
<h5>使用示例<a class="headerlink" href="#id33" title="永久链接至标题">¶</a></h5>
|
||
<div class="highlight-javascript notranslate"><div class="highlight"><pre><span></span><span class="kd">var</span> <span class="nx">ret</span> <span class="o">=</span> <span class="nx">DOIPUtil</span><span class="p">.</span><span class="k">delete</span><span class="p">(</span><span class="s2">"86.5000.470/do.hello"</span><span class="p">,</span><span class="s2">"86.5000.470/repo.localTcpRepo"</span><span class="p">);</span>
|
||
</pre></div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<div class="section" id="hello">
|
||
<h4>hello<a class="headerlink" href="#hello" title="永久链接至标题">¶</a></h4>
|
||
<p>获取目标Repository的DOIP服务信息</p>
|
||
<div class="section" id="id34">
|
||
<h5>参数<a class="headerlink" href="#id34" title="永久链接至标题">¶</a></h5>
|
||
<table border="1" class="docutils">
|
||
<thead>
|
||
<tr>
|
||
<th>序号</th>
|
||
<th>参数</th>
|
||
<th>说明</th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
<tr>
|
||
<td>1</td>
|
||
<td>arg0</td>
|
||
<td>字符串类型 目标Repo标识</td>
|
||
</tr>
|
||
</tbody>
|
||
</table></div>
|
||
<div class="section" id="id35">
|
||
<h5>使用示例<a class="headerlink" href="#id35" title="永久链接至标题">¶</a></h5>
|
||
<div class="highlight-javascript notranslate"><div class="highlight"><pre><span></span><span class="kd">var</span> <span class="nx">ret</span> <span class="o">=</span> <span class="nx">DOIPUtil</span><span class="p">.</span><span class="nx">hello</span><span class="p">(</span><span class="s2">"86.5000.470/repo.localTcpRepo"</span><span class="p">);</span>
|
||
</pre></div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<div class="section" id="listoperation">
|
||
<h4>listOperation<a class="headerlink" href="#listoperation" title="永久链接至标题">¶</a></h4>
|
||
<p>获取目标DO支持的DOIP操作</p>
|
||
<div class="section" id="id36">
|
||
<h5>参数<a class="headerlink" href="#id36" title="永久链接至标题">¶</a></h5>
|
||
<table border="1" class="docutils">
|
||
<thead>
|
||
<tr>
|
||
<th>序号</th>
|
||
<th>参数</th>
|
||
<th>说明</th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
<tr>
|
||
<td>1</td>
|
||
<td>arg0</td>
|
||
<td>字符串类型 目标DO标识</td>
|
||
</tr>
|
||
</tbody>
|
||
</table></div>
|
||
<div class="section" id="id37">
|
||
<h5>使用示例<a class="headerlink" href="#id37" title="永久链接至标题">¶</a></h5>
|
||
<div class="highlight-javascript notranslate"><div class="highlight"><pre><span></span><span class="kd">var</span> <span class="nx">ret</span> <span class="o">=</span> <span class="nx">DOIPUtil</span><span class="p">.</span><span class="nx">listOperation</span><span class="p">(</span><span class="s2">"86.5000.470/do.hello"</span><span class="p">);</span>
|
||
</pre></div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<div class="section" id="register">
|
||
<h4>register<a class="headerlink" href="#register" title="永久链接至标题">¶</a></h4>
|
||
<p>向LHS注册一个DO,返回分配的标识</p>
|
||
<div class="section" id="id38">
|
||
<h5>参数<a class="headerlink" href="#id38" title="永久链接至标题">¶</a></h5>
|
||
<table border="1" class="docutils">
|
||
<thead>
|
||
<tr>
|
||
<th>序号</th>
|
||
<th>参数</th>
|
||
<th>说明</th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
<tr>
|
||
<td>1</td>
|
||
<td>arg0</td>
|
||
<td>字符串类型 DO所在Repo标识</td>
|
||
</tr>
|
||
<tr>
|
||
<td>2</td>
|
||
<td>arg1</td>
|
||
<td>字符串类型 DO格式描述字符串</td>
|
||
</tr>
|
||
</tbody>
|
||
</table></div>
|
||
<div class="section" id="id39">
|
||
<h5>使用示例<a class="headerlink" href="#id39" title="永久链接至标题">¶</a></h5>
|
||
<div class="highlight-javascript notranslate"><div class="highlight"><pre><span></span><span class="kd">var</span> <span class="nx">ret</span> <span class="o">=</span> <span class="nx">DOIPUtil</span><span class="p">.</span><span class="nx">register</span><span class="p">(</span><span class="s2">"86.5000.470/repo.localTcpRepo"</span><span class="p">,</span><span class="s2">"String"</span><span class="p">);</span>
|
||
</pre></div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<div class="section" id="reregister">
|
||
<h4>reregister<a class="headerlink" href="#reregister" title="永久链接至标题">¶</a></h4>
|
||
<p>修改LHS中DO的注册信息</p>
|
||
<div class="section" id="id40">
|
||
<h5>参数<a class="headerlink" href="#id40" title="永久链接至标题">¶</a></h5>
|
||
<table border="1" class="docutils">
|
||
<thead>
|
||
<tr>
|
||
<th>序号</th>
|
||
<th>参数</th>
|
||
<th>说明</th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
<tr>
|
||
<td>1</td>
|
||
<td>arg0</td>
|
||
<td>字符串类型 目标DO标识</td>
|
||
</tr>
|
||
<tr>
|
||
<td>2</td>
|
||
<td>arg1</td>
|
||
<td>字符串类型 DO所在Repo标识</td>
|
||
</tr>
|
||
<tr>
|
||
<td>3</td>
|
||
<td>arg2</td>
|
||
<td>字符串类型 DO格式描述字符串</td>
|
||
</tr>
|
||
</tbody>
|
||
</table></div>
|
||
<div class="section" id="id41">
|
||
<h5>使用示例<a class="headerlink" href="#id41" title="永久链接至标题">¶</a></h5>
|
||
<div class="highlight-javascript notranslate"><div class="highlight"><pre><span></span><span class="kd">var</span> <span class="nx">ret</span> <span class="o">=</span> <span class="nx">DOIPUtil</span><span class="p">.</span><span class="nx">reregister</span><span class="p">(</span><span class="s2">"86.5000.470/do.hello"</span><span class="p">,</span><span class="s2">"86.5000.470/repo.localTcpRepo"</span><span class="p">,</span><span class="s2">"String"</span><span class="p">);</span>
|
||
</pre></div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<div class="section" id="retrieve">
|
||
<h4>retrieve<a class="headerlink" href="#retrieve" title="永久链接至标题">¶</a></h4>
|
||
<p>获取一个DO</p>
|
||
<div class="section" id="id42">
|
||
<h5>参数<a class="headerlink" href="#id42" title="永久链接至标题">¶</a></h5>
|
||
<table border="1" class="docutils">
|
||
<thead>
|
||
<tr>
|
||
<th>序号</th>
|
||
<th>参数</th>
|
||
<th>说明</th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
<tr>
|
||
<td>1</td>
|
||
<td>arg0</td>
|
||
<td>字符串类型 目标DO标识</td>
|
||
</tr>
|
||
</tbody>
|
||
</table></div>
|
||
<div class="section" id="id43">
|
||
<h5>使用示例<a class="headerlink" href="#id43" title="永久链接至标题">¶</a></h5>
|
||
<div class="highlight-javascript notranslate"><div class="highlight"><pre><span></span><span class="kd">var</span> <span class="nx">ret</span> <span class="o">=</span> <span class="nx">DOIPUtil</span><span class="p">.</span><span class="nx">retrieve</span><span class="p">(</span><span class="s2">"86.5000.470/do.hello"</span><span class="p">);</span>
|
||
</pre></div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<div class="section" id="test">
|
||
<h3>test<a class="headerlink" href="#test" title="永久链接至标题">¶</a></h3>
|
||
<p>测试DOIPUtils是否可用</p>
|
||
<div class="section" id="id44">
|
||
<h4>参数<a class="headerlink" href="#id44" title="永久链接至标题">¶</a></h4>
|
||
<table border="1" class="docutils">
|
||
<thead>
|
||
<tr>
|
||
<th>序号</th>
|
||
<th>参数</th>
|
||
<th>说明</th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
<tr>
|
||
<td>1</td>
|
||
<td>arg0</td>
|
||
<td>字符串类型 任意字符串</td>
|
||
</tr>
|
||
</tbody>
|
||
</table></div>
|
||
<div class="section" id="id45">
|
||
<h4>使用示例<a class="headerlink" href="#id45" title="永久链接至标题">¶</a></h4>
|
||
<div class="highlight-javascript notranslate"><div class="highlight"><pre><span></span><span class="kd">var</span> <span class="nx">ret</span> <span class="o">=</span> <span class="nx">DOIPUtil</span><span class="p">.</span><span class="nx">test</span><span class="p">(</span><span class="s2">"hello"</span><span class="p">);</span>
|
||
</pre></div>
|
||
</div>
|
||
</div>
|
||
<div class="section" id="update">
|
||
<h4>update<a class="headerlink" href="#update" title="永久链接至标题">¶</a></h4>
|
||
<p>更新目标DO</p>
|
||
<div class="section" id="id46">
|
||
<h5>参数<a class="headerlink" href="#id46" title="永久链接至标题">¶</a></h5>
|
||
<table border="1" class="docutils">
|
||
<thead>
|
||
<tr>
|
||
<th>序号</th>
|
||
<th>参数</th>
|
||
<th>说明</th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
<tr>
|
||
<td>1</td>
|
||
<td>arg0</td>
|
||
<td>JS对象,包括doID,doBody字段</td>
|
||
</tr>
|
||
</tbody>
|
||
</table></div>
|
||
<div class="section" id="id47">
|
||
<h5>使用示例<a class="headerlink" href="#id47" title="永久链接至标题">¶</a></h5>
|
||
<div class="highlight-javascript notranslate"><div class="highlight"><pre><span></span><span class="kd">var</span> <span class="nx">digitalObject</span> <span class="o">=</span> <span class="nx">JSON</span><span class="p">.</span><span class="nx">parse</span><span class="p">(</span><span class="s2">"{\"doID\":\"86.5000.470/do.hello\",\"doBody\":\"hello world\"}"</span><span class="p">);</span>
|
||
<span class="kd">var</span> <span class="nx">ret</span> <span class="o">=</span> <span class="nx">DOIPUtil</span><span class="p">.</span><span class="nx">update</span><span class="p">(</span><span class="nx">digitalObject</span><span class="p">);</span>
|
||
</pre></div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<div class="section" id="mysqlutil">
|
||
<h3>MySQLUtil<a class="headerlink" href="#mysqlutil" title="永久链接至标题">¶</a></h3>
|
||
<p>可以使用@Permission(“MySQL”)来引入MySQLUtil对象。</p>
|
||
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="nd">@Permission</span><span class="p">(</span><span class="s2">"MySQL"</span><span class="p">)</span>
|
||
<span class="n">contract</span> <span class="n">MySQLExample</span><span class="p">{</span>
|
||
<span class="o">...</span>
|
||
<span class="p">}</span>
|
||
</pre></div>
|
||
</div>
|
||
<div class="section" id="getconnection">
|
||
<h4>getConnection<a class="headerlink" href="#getconnection" title="永久链接至标题">¶</a></h4>
|
||
<div class="section" id="id48">
|
||
<h5>参数<a class="headerlink" href="#id48" title="永久链接至标题">¶</a></h5>
|
||
<table border="1" class="docutils">
|
||
<thead>
|
||
<tr>
|
||
<th>序号</th>
|
||
<th>参数</th>
|
||
<th>说明</th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
<tr>
|
||
<td>1</td>
|
||
<td>URL</td>
|
||
<td>字符串类型,jdbc连接</td>
|
||
</tr>
|
||
<tr>
|
||
<td>2</td>
|
||
<td>usrName</td>
|
||
<td>字符串类型,用户名</td>
|
||
</tr>
|
||
<tr>
|
||
<td>3</td>
|
||
<td>pwd</td>
|
||
<td>字符串类型,密码</td>
|
||
</tr>
|
||
</tbody>
|
||
</table></div>
|
||
<div class="section" id="id49">
|
||
<h5>使用示例<a class="headerlink" href="#id49" title="永久链接至标题">¶</a></h5>
|
||
<div class="highlight-javascript notranslate"><div class="highlight"><pre><span></span><span class="kd">var</span> <span class="nx">url</span> <span class="o">=</span> <span class="s2">"jdbc:mysql://xx.xx.xx:port/tableName"</span><span class="p">;</span>
|
||
<span class="kd">var</span> <span class="nx">usrName</span> <span class="o">=</span> <span class="s2">"xxx"</span><span class="p">;</span>
|
||
<span class="kd">var</span> <span class="nx">pwd</span> <span class="o">=</span> <span class="s2">"xxx"</span><span class="p">;</span>
|
||
<span class="c1">//配置好用户名和密码,url格式为ip或域名+端口,中间以”:”隔开。</span>
|
||
<span class="kd">var</span> <span class="nx">conn</span> <span class="o">=</span> <span class="nx">MySQLUtil</span><span class="p">.</span><span class="nx">getConnection</span><span class="p">(</span><span class="nx">url</span><span class="p">,</span><span class="nx">usrName</span><span class="p">,</span><span class="nx">pwd</span><span class="p">);</span>
|
||
<span class="c1">//获取数据库连接</span>
|
||
<span class="kd">var</span> <span class="nx">sql</span> <span class="o">=</span> <span class="s2">"select * from newele.data"</span><span class="p">;</span>
|
||
<span class="c1">//创建查询语句</span>
|
||
<span class="kd">var</span> <span class="nx">statement</span> <span class="o">=</span> <span class="nx">conn</span><span class="p">.</span><span class="nx">createStatement</span><span class="p">();</span>
|
||
<span class="kd">var</span> <span class="nx">resultSet</span> <span class="o">=</span> <span class="nx">statement</span><span class="p">.</span><span class="nx">executeQuery</span><span class="p">(</span><span class="nx">sql</span><span class="p">);</span>
|
||
<span class="kd">var</span> <span class="nx">waimailist</span> <span class="o">=</span> <span class="p">[];</span>
|
||
<span class="c1">//解析查询结果</span>
|
||
<span class="kd">var</span> <span class="nx">meta</span> <span class="o">=</span> <span class="nx">resultSet</span><span class="p">.</span><span class="nx">getMetaData</span><span class="p">();</span>
|
||
<span class="k">for</span> <span class="p">(;</span><span class="nx">resultSet</span><span class="p">.</span><span class="nx">next</span><span class="p">();){</span>
|
||
<span class="kd">var</span> <span class="nx">line</span> <span class="o">=</span> <span class="p">{};</span>
|
||
<span class="k">for</span> <span class="p">(</span><span class="kd">var</span> <span class="nx">j</span><span class="o">=</span><span class="mi">1</span><span class="p">;</span><span class="nx">j</span><span class="o"><=</span><span class="nx">meta</span><span class="p">.</span><span class="nx">getColumnCount</span><span class="p">();</span><span class="nx">j</span><span class="o">++</span><span class="p">){</span>
|
||
<span class="nx">line</span><span class="p">[</span><span class="nx">meta</span><span class="p">.</span><span class="nx">getColumnName</span><span class="p">(</span><span class="nx">j</span><span class="p">)]</span> <span class="o">=</span> <span class="nx">resultSet</span><span class="p">.</span><span class="nx">getString</span><span class="p">(</span><span class="nx">j</span><span class="p">);</span>
|
||
<span class="p">}</span>
|
||
<span class="nx">waimailist</span><span class="p">.</span><span class="nx">push</span><span class="p">(</span><span class="nx">line</span><span class="p">);</span>
|
||
<span class="p">}</span>
|
||
</pre></div>
|
||
</div>
|
||
<p>其中,getConnection方法返回的对象通过反射机制绑定到了Java的一个java.util.Connection对象。因此,可以查看:
|
||
<a class="reference external" href="https://docs.oracle.com/javase/7/docs/api/java/sql/Connection.html">https://docs.oracle.com/javase/7/docs/api/java/sql/Connection.html</a>
|
||
以了解如何进行Mysql数据库操作。</p>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<div class="section" id="mongodbutil">
|
||
<h3>MongoDBUtil<a class="headerlink" href="#mongodbutil" title="永久链接至标题">¶</a></h3>
|
||
<p>可以使用@Permission(“MongoDB”)来引入MongoDBUtil对象。</p>
|
||
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="nd">@Permission</span><span class="p">(</span><span class="s2">"MongoDB"</span><span class="p">)</span>
|
||
<span class="n">contract</span> <span class="n">MongoDBExample</span><span class="p">{</span>
|
||
<span class="o">...</span>
|
||
<span class="p">}</span>
|
||
</pre></div>
|
||
</div>
|
||
<div class="section" id="id50">
|
||
<h4>getConnection<a class="headerlink" href="#id50" title="永久链接至标题">¶</a></h4>
|
||
<div class="section" id="id51">
|
||
<h5>参数<a class="headerlink" href="#id51" title="永久链接至标题">¶</a></h5>
|
||
<table border="1" class="docutils">
|
||
<thead>
|
||
<tr>
|
||
<th>序号</th>
|
||
<th>参数</th>
|
||
<th>说明</th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
<tr>
|
||
<td>1</td>
|
||
<td>URL</td>
|
||
<td>字符串类型 数据库的URL</td>
|
||
</tr>
|
||
<tr>
|
||
<td>2</td>
|
||
<td>port</td>
|
||
<td>整数类型 端口号</td>
|
||
</tr>
|
||
<tr>
|
||
<td>3</td>
|
||
<td>dbName</td>
|
||
<td>字符串类型 数据库的名称</td>
|
||
</tr>
|
||
<tr>
|
||
<td>4</td>
|
||
<td>usrName</td>
|
||
<td>字符串类型 数据库的用户名</td>
|
||
</tr>
|
||
<tr>
|
||
<td>5</td>
|
||
<td>pwd</td>
|
||
<td>字符串类型 数据库的密码</td>
|
||
</tr>
|
||
</tbody>
|
||
</table></div>
|
||
<div class="section" id="id52">
|
||
<h5>使用示例<a class="headerlink" href="#id52" title="永久链接至标题">¶</a></h5>
|
||
<p><strong>注意:port为整型,其他参数为String类型</strong></p>
|
||
<div class="highlight-javascript notranslate"><div class="highlight"><pre><span></span><span class="kd">var</span> <span class="nx">client</span> <span class="o">=</span> <span class="nx">MongoDBUtil</span><span class="p">.</span><span class="nx">getConnection</span><span class="p">(</span><span class="nx">url</span><span class="p">,</span><span class="nx">port</span><span class="p">,</span><span class="nx">dbName</span><span class="p">,</span><span class="nx">usrName</span><span class="p">,</span><span class="nx">pwd</span><span class="p">);</span>
|
||
<span class="c1">//获取数据库对象</span>
|
||
<span class="kd">var</span> <span class="nx">db</span> <span class="o">=</span> <span class="nx">client</span><span class="p">.</span><span class="nx">getDatabase</span><span class="p">(</span><span class="s2">"yancloud"</span><span class="p">);</span>
|
||
<span class="kd">var</span> <span class="nx">collection</span> <span class="o">=</span> <span class="nx">db</span><span class="p">.</span><span class="nx">getCollection</span><span class="p">(</span><span class="s2">"containers"</span><span class="p">);</span>
|
||
<span class="kd">var</span> <span class="nx">iter</span> <span class="o">=</span> <span class="nx">collection</span><span class="p">.</span><span class="nx">find</span><span class="p">().</span><span class="nx">iterator</span><span class="p">();</span>
|
||
<span class="kd">var</span> <span class="nx">ret</span> <span class="o">=</span><span class="s2">""</span><span class="p">;</span>
|
||
<span class="k">for</span> <span class="p">(;</span><span class="nx">iter</span><span class="p">.</span><span class="nx">hasNext</span><span class="p">();){</span>
|
||
<span class="nx">ret</span><span class="o">+=</span><span class="nx">iter</span><span class="p">.</span><span class="nx">next</span><span class="p">().</span><span class="nx">toJson</span><span class="p">();</span>
|
||
<span class="nx">ret</span><span class="o">+=</span><span class="s2">"\n"</span><span class="p">;</span>
|
||
<span class="p">}</span>
|
||
</pre></div>
|
||
</div>
|
||
<p>其中,getMongoDBClient对象通过反射机制绑定到了Java的一个com.mongodb.MongoClient对象。因此,可以查看:
|
||
<a class="reference external" href="https://mongodb.github.io/mongo-java-driver/3.4/javadoc/com/mongodb/MongoClient.html">https://mongodb.github.io/mongo-java-driver/3.4/javadoc/com/mongodb/MongoClient.html</a></p>
|
||
<p>以了解该对象的更多方法和使用方式。</p>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<div class="section" id="rocksdbutil">
|
||
<h3>RocksDBUtil<a class="headerlink" href="#rocksdbutil" title="永久链接至标题">¶</a></h3>
|
||
<p>使用@Permission(“RocksDB”)来引入RocksDBUtil对象。</p>
|
||
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="nd">@Permission</span><span class="p">(</span><span class="s2">"RocksDB"</span><span class="p">)</span>
|
||
<span class="n">contract</span> <span class="n">RocksDBSample</span> <span class="p">{</span>
|
||
<span class="o">...</span>
|
||
<span class="p">}</span>
|
||
</pre></div>
|
||
</div>
|
||
<div class="section" id="loaddb">
|
||
<h4>loadDB<a class="headerlink" href="#loaddb" title="永久链接至标题">¶</a></h4>
|
||
<p>通过loadDB来加载一个RocksDB数据库。
|
||
加载后,可进行get/delete/put等操作。</p>
|
||
<div class="section" id="id53">
|
||
<h5>参数<a class="headerlink" href="#id53" title="永久链接至标题">¶</a></h5>
|
||
<table border="1" class="docutils">
|
||
<thead>
|
||
<tr>
|
||
<th>序号</th>
|
||
<th>参数</th>
|
||
<th>说明</th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
<tr>
|
||
<td>1</td>
|
||
<td>path</td>
|
||
<td>字符串类型 数据库部署的路径</td>
|
||
</tr>
|
||
<tr>
|
||
<td>2</td>
|
||
<td>readOnly</td>
|
||
<td>布尔类型 数据库只读</td>
|
||
</tr>
|
||
</tbody>
|
||
</table></div>
|
||
<div class="section" id="id54">
|
||
<h5>使用示例<a class="headerlink" href="#id54" title="永久链接至标题">¶</a></h5>
|
||
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="nd">@Permission</span><span class="p">(</span><span class="s2">"RocksDB"</span><span class="p">)</span>
|
||
<span class="nd">@Description</span><span class="p">(</span><span class="s2">"这是个使用RocksDB的参考代码"</span><span class="p">)</span>
|
||
<span class="n">contract</span> <span class="n">RocksDBSample</span><span class="p">{</span>
|
||
<span class="n">function</span> <span class="n">onCreate</span><span class="p">(){</span>
|
||
<span class="n">Global</span><span class="o">.</span><span class="n">rocksdb</span> <span class="o">=</span> <span class="n">RocksDBUtil</span><span class="o">.</span><span class="n">loadDB</span><span class="p">(</span><span class="s2">"./dbdir/"</span><span class="p">,</span><span class="s2">"false"</span><span class="p">);</span>
|
||
<span class="p">}</span>
|
||
<span class="nd">@Description</span><span class="p">(</span><span class="s2">"示例参数: {</span><span class="se">\"</span><span class="s2">key</span><span class="se">\"</span><span class="s2">:</span><span class="se">\"</span><span class="s2">abc</span><span class="se">\"</span><span class="s2">,</span><span class="se">\"</span><span class="s2">value</span><span class="se">\"</span><span class="s2">:</span><span class="se">\"</span><span class="s2">def</span><span class="se">\"</span><span class="s2">}"</span><span class="p">)</span>
|
||
<span class="n">export</span> <span class="n">function</span> <span class="n">put</span><span class="p">(</span><span class="n">arg</span><span class="p">){</span>
|
||
<span class="n">arg</span> <span class="o">=</span> <span class="n">JSON</span><span class="o">.</span><span class="n">parse</span><span class="p">(</span><span class="n">arg</span><span class="p">);</span>
|
||
<span class="n">Global</span><span class="o">.</span><span class="n">rocksdb</span><span class="o">.</span><span class="n">put</span><span class="p">(</span><span class="n">arg</span><span class="o">.</span><span class="n">key</span><span class="p">,</span><span class="n">arg</span><span class="o">.</span><span class="n">value</span><span class="p">);</span>
|
||
<span class="k">return</span> <span class="s2">"success"</span><span class="p">;</span>
|
||
<span class="p">}</span>
|
||
<span class="nd">@Description</span><span class="p">(</span><span class="s2">"示例参数: </span><span class="se">\"</span><span class="s2">abc</span><span class="se">\"</span><span class="s2">}"</span><span class="p">)</span>
|
||
<span class="n">export</span> <span class="n">function</span> <span class="n">get</span><span class="p">(</span><span class="n">arg</span><span class="p">){</span>
|
||
<span class="k">return</span> <span class="n">Global</span><span class="o">.</span><span class="n">rocksdb</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">arg</span><span class="p">);</span>
|
||
<span class="k">return</span> <span class="s2">"failed"</span><span class="p">;</span>
|
||
<span class="p">}</span>
|
||
<span class="nd">@Description</span><span class="p">(</span><span class="s2">"示例参数: </span><span class="se">\"</span><span class="s2">abc</span><span class="se">\"</span><span class="s2">"</span><span class="p">)</span>
|
||
<span class="n">export</span> <span class="n">function</span> <span class="n">deleteKey</span><span class="p">(</span><span class="n">arg</span><span class="p">){</span>
|
||
<span class="k">return</span> <span class="n">Global</span><span class="o">.</span><span class="n">rocksdb</span><span class="o">.</span><span class="n">delete</span><span class="p">(</span><span class="n">arg</span><span class="p">);</span>
|
||
<span class="p">}</span>
|
||
<span class="nd">@Description</span><span class="p">(</span><span class="s2">"遍历KV库,无需参数"</span><span class="p">)</span>
|
||
<span class="n">export</span> <span class="n">function</span> <span class="nb">iter</span><span class="p">(</span><span class="n">arg</span><span class="p">){</span>
|
||
<span class="n">var</span> <span class="nb">iter</span> <span class="o">=</span> <span class="n">Global</span><span class="o">.</span><span class="n">rocksdb</span><span class="o">.</span><span class="n">newIterator</span><span class="p">();</span>
|
||
<span class="n">var</span> <span class="n">obj</span> <span class="o">=</span> <span class="n">undefined</span><span class="p">;</span>
|
||
<span class="n">var</span> <span class="n">ret</span> <span class="o">=</span> <span class="p">{</span>
|
||
<span class="p">};</span>
|
||
<span class="k">for</span> <span class="p">(</span><span class="nb">iter</span><span class="o">.</span><span class="n">seekToFirst</span><span class="p">();(</span><span class="n">obj</span><span class="o">=</span><span class="n">Global</span><span class="o">.</span><span class="n">rocksdb</span><span class="o">.</span><span class="n">getNext</span><span class="p">(</span><span class="nb">iter</span><span class="p">))</span><span class="o">!=</span><span class="n">undefined</span><span class="p">;){</span>
|
||
<span class="n">ret</span><span class="p">[</span><span class="n">obj</span><span class="o">.</span><span class="n">key</span><span class="p">]</span><span class="o">=</span><span class="n">obj</span><span class="o">.</span><span class="n">value</span><span class="p">;</span>
|
||
<span class="p">}</span>
|
||
<span class="k">return</span> <span class="n">JSON</span><span class="o">.</span><span class="n">stringify</span><span class="p">(</span><span class="n">ret</span><span class="p">)</span>
|
||
<span class="p">}</span>
|
||
<span class="p">}</span>
|
||
</pre></div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<div class="section" id="bdwaretimeseriesdbutil">
|
||
<h3>BDWareTimeSeriesDBUtil<a class="headerlink" href="#bdwaretimeseriesdbutil" title="永久链接至标题">¶</a></h3>
|
||
<p>使用示例</p>
|
||
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>@Permission("BDWareTimeSeriesDB")
|
||
contract BDWareTimeDBExample{
|
||
function onCreate(arg){
|
||
Global.dbutil = BDWareTimeSeriesDBUtil.getConnection();
|
||
}
|
||
|
||
export function put(arg){
|
||
//第一个参数为表名,第二个参数为要放的value,时间戳自动打。
|
||
Global.dbutil.put("defaultTable",arg);
|
||
return "success";
|
||
}
|
||
@Param
|
||
export function getCount(arg){
|
||
return Global.dbutil.getCount("defaultTable");
|
||
}
|
||
@Param(1617254937373)
|
||
export function queryByStartTime(arg){
|
||
var startDate = java.lang.Long.valueOf(arg);
|
||
//查询从开始时刻startDate到最新的数据
|
||
var list = Global.dbutil.query("defaultTable",startDate);
|
||
var ret=[];
|
||
print("DBUtil"+Global.dbutil+" list:"+list+" list.size"+list.size());
|
||
var i=0;
|
||
for (i=0;i<list.size();i++){
|
||
print(i+"-->"+list.get(i));
|
||
ret.push(list.get(i));
|
||
}
|
||
return ret;
|
||
}
|
||
|
||
@Description("示例参数: {\"offset\":1,\"len\":1}")
|
||
@Param({"offset":1,"len":1})
|
||
export function queryByOffset(arg){
|
||
var offsetLen = JSON.parse(arg);
|
||
//可配合getCount使用,查询第offset至offset+len条数据
|
||
var list = Global.dbutil.queryByOffset("defaultTable",offsetLen.offset,offsetLen.len);
|
||
var ret=[];
|
||
print("DBUtil"+Global.dbutil+" list:"+list+" list.size"+list.size());
|
||
var i=0;
|
||
for (i=0;i<list.size();i++){
|
||
print(i+"-->"+list.get(i));
|
||
ret.push(list.get(i));
|
||
}
|
||
return ret;
|
||
}
|
||
}
|
||
</pre></div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<div class="section" id="id55">
|
||
<h2>加解密工具类<a class="headerlink" href="#id55" title="永久链接至标题">¶</a></h2>
|
||
<div class="section" id="sm2">
|
||
<h3>SM2<a class="headerlink" href="#sm2" title="永久链接至标题">¶</a></h3>
|
||
<p>可以使用@Permission(“SM2”)来引入SM2Util对象。</p>
|
||
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="nd">@Permission</span><span class="p">(</span><span class="s2">"SM2"</span><span class="p">)</span>
|
||
<span class="n">contract</span> <span class="n">SM2Sample</span> <span class="p">{</span>
|
||
<span class="o">...</span>
|
||
<span class="p">}</span>
|
||
</pre></div>
|
||
</div>
|
||
<div class="section" id="generatekeypair">
|
||
<h4>generateKeyPair<a class="headerlink" href="#generatekeypair" title="永久链接至标题">¶</a></h4>
|
||
<p>生成公私钥。</p>
|
||
<div class="section" id="id56">
|
||
<h5>参数<a class="headerlink" href="#id56" title="永久链接至标题">¶</a></h5>
|
||
<p>无参数。</p>
|
||
</div>
|
||
<div class="section" id="id57">
|
||
<h5>使用示例<a class="headerlink" href="#id57" title="永久链接至标题">¶</a></h5>
|
||
<div class="highlight-javascript notranslate"><div class="highlight"><pre><span></span><span class="kd">var</span> <span class="nx">ret</span> <span class="o">=</span> <span class="nx">SM2Util</span><span class="p">.</span><span class="nx">generateKeyPair</span><span class="p">();</span>
|
||
<span class="nx">print</span><span class="p">(</span><span class="nx">ret</span><span class="p">.</span><span class="nx">publicKey</span><span class="p">);</span>
|
||
<span class="nx">print</span><span class="p">(</span><span class="nx">ret</span><span class="p">.</span><span class="nx">privateKey</span><span class="p">);</span>
|
||
<span class="k">return</span> <span class="nx">JSON</span><span class="p">.</span><span class="nx">stringify</span><span class="p">(</span><span class="nx">ret</span><span class="p">);</span>
|
||
</pre></div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<div class="section" id="sign">
|
||
<h4>sign<a class="headerlink" href="#sign" title="永久链接至标题">¶</a></h4>
|
||
<p>签名。</p>
|
||
<div class="section" id="id58">
|
||
<h5>参数<a class="headerlink" href="#id58" title="永久链接至标题">¶</a></h5>
|
||
<table border="1" class="docutils">
|
||
<thead>
|
||
<tr>
|
||
<th>序号</th>
|
||
<th>参数</th>
|
||
<th>说明</th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
<tr>
|
||
<td>1</td>
|
||
<td>content</td>
|
||
<td>字符串类型 要进行签名的内容</td>
|
||
</tr>
|
||
<tr>
|
||
<td>2</td>
|
||
<td>keyPair</td>
|
||
<td>sm2</td>
|
||
</tr>
|
||
</tbody>
|
||
</table></div>
|
||
<div class="section" id="id59">
|
||
<h5>使用示例<a class="headerlink" href="#id59" title="永久链接至标题">¶</a></h5>
|
||
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">var</span> <span class="n">keypair</span> <span class="o">=</span> <span class="n">SM2Util</span><span class="o">.</span><span class="n">generateKeyPair</span><span class="p">();</span>
|
||
<span class="n">var</span> <span class="n">ret</span> <span class="o">=</span> <span class="n">SM2Util</span><span class="o">.</span><span class="n">sign</span><span class="p">(</span><span class="s2">"Hello"</span><span class="p">,</span><span class="n">keypair</span><span class="p">);</span>
|
||
<span class="nb">print</span><span class="p">(</span><span class="n">ret</span><span class="o">.</span><span class="n">status</span><span class="p">);</span>
|
||
<span class="o">//</span><span class="n">如果status是success</span>
|
||
<span class="nb">print</span><span class="p">(</span><span class="n">ret</span><span class="o">.</span><span class="n">signature</span><span class="p">);</span>
|
||
<span class="o">//</span><span class="n">如果status是failed</span>
|
||
<span class="nb">print</span><span class="p">(</span><span class="n">ret</span><span class="o">.</span><span class="n">message</span><span class="p">);</span>
|
||
</pre></div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<div class="section" id="verify">
|
||
<h4>verify<a class="headerlink" href="#verify" title="永久链接至标题">¶</a></h4>
|
||
<p>验签。</p>
|
||
<div class="section" id="id60">
|
||
<h5>参数<a class="headerlink" href="#id60" title="永久链接至标题">¶</a></h5>
|
||
<table border="1" class="docutils">
|
||
<thead>
|
||
<tr>
|
||
<th>序号</th>
|
||
<th>参数</th>
|
||
<th>说明</th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
<tr>
|
||
<td>1</td>
|
||
<td>content</td>
|
||
<td>字符串类型 待验签的内容</td>
|
||
</tr>
|
||
<tr>
|
||
<td>2</td>
|
||
<td>signature</td>
|
||
<td>字符串类型 签名</td>
|
||
</tr>
|
||
<tr>
|
||
<td>3</td>
|
||
<td>publicKey</td>
|
||
<td>字符串类型 公钥</td>
|
||
</tr>
|
||
</tbody>
|
||
</table></div>
|
||
<div class="section" id="id61">
|
||
<h5>使用示例<a class="headerlink" href="#id61" title="永久链接至标题">¶</a></h5>
|
||
<div class="highlight-javascript notranslate"><div class="highlight"><pre><span></span><span class="kd">var</span> <span class="nx">ret</span> <span class="o">=</span> <span class="nx">SM2Util</span><span class="p">.</span><span class="nx">verify</span><span class="p">(</span><span class="s2">"Hello"</span><span class="p">,</span><span class="s2">"....签名"</span><span class="p">,</span><span class="s2">"...公钥"</span><span class="p">);</span>
|
||
<span class="c1">// 验证通过时,result为true,status为success</span>
|
||
<span class="c1">// 失败时,result为failed,status为failed</span>
|
||
<span class="nx">print</span><span class="p">(</span><span class="nx">ret</span><span class="p">.</span><span class="nx">status</span><span class="p">);</span>
|
||
<span class="nx">print</span><span class="p">(</span><span class="nx">ret</span><span class="p">.</span><span class="nx">result</span><span class="p">);</span>
|
||
</pre></div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<div class="section" id="id62">
|
||
<h2>多线程工具类<a class="headerlink" href="#id62" title="永久链接至标题">¶</a></h2>
|
||
<div class="section" id="asyncutil">
|
||
<h3>AsyncUtil<a class="headerlink" href="#asyncutil" title="永久链接至标题">¶</a></h3>
|
||
<p>可以使用@Permission(“Async”)来引入AsyncUtil对象。</p>
|
||
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="nd">@Permission</span><span class="p">(</span><span class="s2">"Async"</span><span class="p">)</span>
|
||
<span class="n">contract</span> <span class="n">AsyncExample</span><span class="p">{</span>
|
||
<span class="n">export</span> <span class="n">function</span> <span class="n">longTimeTask</span><span class="p">(</span><span class="n">arg</span><span class="p">){</span>
|
||
<span class="n">var</span> <span class="n">a</span> <span class="o">=</span> <span class="p">{</span>
|
||
<span class="p">};</span>
|
||
<span class="n">a</span><span class="o">.</span><span class="n">count</span> <span class="o">=</span> <span class="mi">100</span><span class="p">;</span>
|
||
<span class="n">AsyncUtil</span><span class="o">.</span><span class="n">postFunction</span><span class="p">(</span><span class="n">taskFun</span><span class="p">,</span><span class="n">a</span><span class="p">);</span>
|
||
<span class="p">}</span>
|
||
<span class="n">function</span> <span class="n">taskFun</span><span class="p">(</span><span class="n">arg</span><span class="p">){</span>
|
||
<span class="n">Global</span><span class="o">.</span><span class="n">progress</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
|
||
<span class="k">for</span> <span class="p">(</span><span class="n">var</span> <span class="n">i</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span><span class="n">i</span><span class="o"><</span><span class="n">arg</span><span class="o">.</span><span class="n">count</span><span class="p">;</span><span class="n">i</span><span class="o">++</span><span class="p">){</span>
|
||
<span class="n">AsyncUtil</span><span class="o">.</span><span class="n">sleep</span><span class="p">(</span><span class="mi">100</span><span class="p">);</span>
|
||
<span class="n">Global</span><span class="o">.</span><span class="n">progress</span><span class="o">++</span><span class="p">;</span>
|
||
<span class="p">}</span>
|
||
<span class="p">}</span>
|
||
<span class="n">export</span> <span class="n">function</span> <span class="n">getProgress</span><span class="p">(</span><span class="n">arg</span><span class="p">){</span>
|
||
<span class="k">return</span> <span class="n">Global</span><span class="o">.</span><span class="n">progress</span><span class="p">;</span>
|
||
<span class="p">}</span>
|
||
<span class="p">}</span>
|
||
</pre></div>
|
||
</div>
|
||
<div class="section" id="postfunction">
|
||
<h4>postFunction<a class="headerlink" href="#postfunction" title="永久链接至标题">¶</a></h4>
|
||
<div class="section" id="id63">
|
||
<h5>参数<a class="headerlink" href="#id63" title="永久链接至标题">¶</a></h5>
|
||
<table border="1" class="docutils">
|
||
<thead>
|
||
<tr>
|
||
<th>序号</th>
|
||
<th>参数</th>
|
||
<th>说明</th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
<tr>
|
||
<td>1</td>
|
||
<td>arg0</td>
|
||
<td>ScriptFunction</td>
|
||
</tr>
|
||
<tr>
|
||
<td>2</td>
|
||
<td>arg1</td>
|
||
<td>对象</td>
|
||
</tr>
|
||
</tbody>
|
||
</table></div>
|
||
<div class="section" id="id64">
|
||
<h5>使用示例<a class="headerlink" href="#id64" title="永久链接至标题">¶</a></h5>
|
||
<div class="highlight-javascript notranslate"><div class="highlight"><pre><span></span><span class="kd">var</span> <span class="nx">ret</span> <span class="o">=</span> <span class="nx">AsyncUtil</span><span class="p">.</span><span class="nx">postFunction</span><span class="p">(</span><span class="nx">a</span><span class="p">,{</span><span class="s2">"a"</span><span class="o">:</span><span class="s2">"b"</span><span class="p">});</span>
|
||
</pre></div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<div class="section" id="setinterval">
|
||
<h4>setInterval<a class="headerlink" href="#setinterval" title="永久链接至标题">¶</a></h4>
|
||
<div class="section" id="id65">
|
||
<h5>参数<a class="headerlink" href="#id65" title="永久链接至标题">¶</a></h5>
|
||
<table border="1" class="docutils">
|
||
<thead>
|
||
<tr>
|
||
<th>序号</th>
|
||
<th>参数</th>
|
||
<th>说明</th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
<tr>
|
||
<td>1</td>
|
||
<td>arg0</td>
|
||
<td>ScriptFunction</td>
|
||
</tr>
|
||
<tr>
|
||
<td>2</td>
|
||
<td>arg1</td>
|
||
<td>long</td>
|
||
</tr>
|
||
<tr>
|
||
<td>3</td>
|
||
<td>arg2</td>
|
||
<td>long</td>
|
||
</tr>
|
||
<tr>
|
||
<td>4</td>
|
||
<td>arg3</td>
|
||
<td>对象</td>
|
||
</tr>
|
||
</tbody>
|
||
</table></div>
|
||
<div class="section" id="id66">
|
||
<h5>使用示例<a class="headerlink" href="#id66" title="永久链接至标题">¶</a></h5>
|
||
<div class="highlight-javascript notranslate"><div class="highlight"><pre><span></span><span class="kd">var</span> <span class="nx">ret</span> <span class="o">=</span> <span class="nx">AsyncUtil</span><span class="p">.</span><span class="nx">setInterval</span><span class="p">(</span><span class="nx">a</span><span class="p">,</span><span class="mi">100</span><span class="p">,</span><span class="mi">1000</span><span class="p">,</span><span class="s2">"abc"</span><span class="p">);</span>
|
||
</pre></div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<div class="section" id="settimeout">
|
||
<h4>setTimeOut<a class="headerlink" href="#settimeout" title="永久链接至标题">¶</a></h4>
|
||
<div class="section" id="id67">
|
||
<h5>参数<a class="headerlink" href="#id67" title="永久链接至标题">¶</a></h5>
|
||
<table border="1" class="docutils">
|
||
<thead>
|
||
<tr>
|
||
<th>序号</th>
|
||
<th>参数</th>
|
||
<th>说明</th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
<tr>
|
||
<td>1</td>
|
||
<td>arg0</td>
|
||
<td>ScriptFunction</td>
|
||
</tr>
|
||
<tr>
|
||
<td>2</td>
|
||
<td>arg1</td>
|
||
<td>long</td>
|
||
</tr>
|
||
<tr>
|
||
<td>3</td>
|
||
<td>arg2</td>
|
||
<td>Object</td>
|
||
</tr>
|
||
</tbody>
|
||
</table></div>
|
||
<div class="section" id="id68">
|
||
<h5>使用示例<a class="headerlink" href="#id68" title="永久链接至标题">¶</a></h5>
|
||
<div class="highlight-javascript notranslate"><div class="highlight"><pre><span></span><span class="kd">var</span> <span class="nx">ret</span> <span class="o">=</span> <span class="nx">AsyncUtil</span><span class="p">.</span><span class="nx">setTimeOut</span><span class="p">(</span><span class="nx">a</span><span class="p">,</span><span class="mi">100</span><span class="p">,</span><span class="s2">"abc"</span><span class="p">);</span>
|
||
</pre></div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<div class="section" id="sleep">
|
||
<h4>sleep<a class="headerlink" href="#sleep" title="永久链接至标题">¶</a></h4>
|
||
<div class="section" id="id69">
|
||
<h5>参数<a class="headerlink" href="#id69" title="永久链接至标题">¶</a></h5>
|
||
<table border="1" class="docutils">
|
||
<thead>
|
||
<tr>
|
||
<th>序号</th>
|
||
<th>参数</th>
|
||
<th>说明</th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
<tr>
|
||
<td>1</td>
|
||
<td>arg0</td>
|
||
<td>long</td>
|
||
</tr>
|
||
</tbody>
|
||
</table></div>
|
||
<div class="section" id="id70">
|
||
<h5>使用示例<a class="headerlink" href="#id70" title="永久链接至标题">¶</a></h5>
|
||
<div class="highlight-javascript notranslate"><div class="highlight"><pre><span></span><span class="kd">var</span> <span class="nx">ret</span> <span class="o">=</span> <span class="nx">AsyncUtil</span><span class="p">.</span><span class="nx">sleep</span><span class="p">();</span>
|
||
</pre></div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<div class="section" id="ecma5-build-in-objects">
|
||
<h2>ECMA5 Build-in Objects<a class="headerlink" href="#ecma5-build-in-objects" title="永久链接至标题">¶</a></h2>
|
||
<p>YJS支持ECMAScript6的部分内置对象 :</p>
|
||
<ul class="simple">
|
||
<li><p>String <a class="reference external" href="https://www.w3schools.com/js/js_strings.asp">https://www.w3schools.com/js/js_strings.asp</a></p></li>
|
||
<li><p>Number <a class="reference external" href="https://www.w3schools.com/js/js_numbers.asp">https://www.w3schools.com/js/js_numbers.asp</a></p></li>
|
||
<li><p>Math <a class="reference external" href="https://www.w3schools.com/js/js_math.asp">https://www.w3schools.com/js/js_math.asp</a></p></li>
|
||
<li><p>Date <a class="reference external" href="https://www.w3schools.com/js/js_dates.asp">https://www.w3schools.com/js/js_dates.asp</a></p></li>
|
||
<li><p>RegExp <a class="reference external" href="https://www.w3schools.com/js/js_regexp.asp">https://www.w3schools.com/js/js_regexp.asp</a></p></li>
|
||
<li><p>Error <a class="reference external" href="https://www.w3schools.com/js/js_errors.asp">https://www.w3schools.com/js/js_errors.asp</a></p></li>
|
||
<li><p>JSON <a class="reference external" href="https://www.w3schools.com/js/js_json.asp">https://www.w3schools.com/js/js_json.asp</a></p></li>
|
||
</ul>
|
||
</div>
|
||
</div>
|
||
|
||
|
||
</div>
|
||
|
||
</div>
|
||
<footer>
|
||
|
||
<hr/>
|
||
|
||
<div role="contentinfo">
|
||
<p>
|
||
© 版权所有 2021, Peking University.
|
||
|
||
</p>
|
||
</div>
|
||
|
||
|
||
|
||
利用 <a href="https://www.sphinx-doc.org/">Sphinx</a> 构建,使用了
|
||
|
||
<a href="https://github.com/readthedocs/sphinx_rtd_theme">主题</a>
|
||
|
||
由 <a href="https://readthedocs.org">Read the Docs</a>开发.
|
||
|
||
</footer>
|
||
</div>
|
||
</div>
|
||
|
||
</section>
|
||
|
||
</div>
|
||
|
||
|
||
<script type="text/javascript">
|
||
jQuery(function () {
|
||
SphinxRtdTheme.Navigation.enable(true);
|
||
});
|
||
</script>
|
||
|
||
|
||
|
||
|
||
|
||
|
||
</body>
|
||
</html> |