2127 lines
118 KiB
HTML
2127 lines
118 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" />
|
||
<link rel="prev" title="YJS语法" href="YJSInDepth.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 class="current">
|
||
<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 current"><a class="current reference internal" href="#">YJS SDK</a><ul>
|
||
<li class="toctree-l2"><a class="reference internal" href="#yjs-build-in-api">YJS Build-in API</a><ul>
|
||
<li class="toctree-l3"><a class="reference internal" href="#global">内置对象 Global</a></li>
|
||
<li class="toctree-l3"><a class="reference internal" href="#requester">内置对象 requester</a></li>
|
||
<li class="toctree-l3"><a class="reference internal" href="#executecontract">执行合约 executeContract</a></li>
|
||
<li class="toctree-l3"><a class="reference internal" href="#subscribe">订阅事件主题 subscribe</a></li>
|
||
<li class="toctree-l3"><a class="reference internal" href="#pubevent">发布事件 pubEvent</a></li>
|
||
<li class="toctree-l3"><a class="reference internal" href="#pubeventconstraint">发布带语义事件 pubEventConstraint</a></li>
|
||
<li class="toctree-l3"><a class="reference internal" href="#id1">访问资源文件</a><ul>
|
||
<li class="toctree-l4"><a class="reference internal" href="#loadasinputstream">loadAsInputStream</a></li>
|
||
<li class="toctree-l4"><a class="reference internal" href="#loadasscanner">loadAsScanner</a></li>
|
||
</ul>
|
||
</li>
|
||
</ul>
|
||
</li>
|
||
<li class="toctree-l2"><a class="reference internal" href="#yjs-build-in-annotation">YJS Build-in Annotation</a><ul>
|
||
<li class="toctree-l3"><a class="reference internal" href="#access">@Access</a></li>
|
||
<li class="toctree-l3"><a class="reference internal" href="#logtype">@LogType</a></li>
|
||
<li class="toctree-l3"><a class="reference internal" href="#loglocation">@LogLocation</a></li>
|
||
<li class="toctree-l3"><a class="reference internal" href="#permission">@Permission</a></li>
|
||
<li class="toctree-l3"><a class="reference internal" href="#description">@Description</a></li>
|
||
<li class="toctree-l3"><a class="reference internal" href="#param">@Param</a></li>
|
||
<li class="toctree-l3"><a class="reference internal" href="#mocktemplate">@MockTemplate</a></li>
|
||
<li class="toctree-l3"><a class="reference internal" href="#result">@Result</a></li>
|
||
</ul>
|
||
</li>
|
||
<li class="toctree-l2"><a class="reference internal" href="#io">IO工具类</a><ul>
|
||
<li class="toctree-l3"><a class="reference internal" href="#id2">概览</a></li>
|
||
<li class="toctree-l3"><a class="reference internal" href="#fileutil">FileUtil</a><ul>
|
||
<li class="toctree-l4"><a class="reference internal" href="#copyto">copyTo</a></li>
|
||
<li class="toctree-l4"><a class="reference internal" href="#getcontent">getContent</a></li>
|
||
<li class="toctree-l4"><a class="reference internal" href="#getdir">getDir</a></li>
|
||
<li class="toctree-l4"><a class="reference internal" href="#getfilename">getFileName</a></li>
|
||
<li class="toctree-l4"><a class="reference internal" href="#openfileasprinter">openFileAsPrinter</a></li>
|
||
</ul>
|
||
</li>
|
||
<li class="toctree-l3"><a class="reference internal" href="#ledgerutil">LedgerUtil</a><ul>
|
||
<li class="toctree-l4"><a class="reference internal" href="#getclient">getClient</a></li>
|
||
<li class="toctree-l4"><a class="reference internal" href="#querybyhash">queryByHash</a></li>
|
||
<li class="toctree-l4"><a class="reference internal" href="#sendtransaction">sendTransaction</a></li>
|
||
</ul>
|
||
</li>
|
||
<li class="toctree-l3"><a class="reference internal" href="#httputil">HttpUtil</a><ul>
|
||
<li class="toctree-l4"><a class="reference internal" href="#createapigate">createAPIGate</a></li>
|
||
<li class="toctree-l4"><a class="reference internal" href="#createapigate-1">createAPIGate</a></li>
|
||
<li class="toctree-l4"><a class="reference internal" href="#get">get</a></li>
|
||
<li class="toctree-l4"><a class="reference internal" href="#post">post</a></li>
|
||
</ul>
|
||
</li>
|
||
<li class="toctree-l3"><a class="reference internal" href="#doiputil">DOIPUtil</a><ul>
|
||
<li class="toctree-l4"><a class="reference internal" href="#call">call</a></li>
|
||
<li class="toctree-l4"><a class="reference internal" href="#create">create</a></li>
|
||
<li class="toctree-l4"><a class="reference internal" href="#delete">delete</a></li>
|
||
<li class="toctree-l4"><a class="reference internal" href="#hello">hello</a></li>
|
||
<li class="toctree-l4"><a class="reference internal" href="#listoperation">listOperation</a></li>
|
||
<li class="toctree-l4"><a class="reference internal" href="#register">register</a></li>
|
||
<li class="toctree-l4"><a class="reference internal" href="#reregister">reregister</a></li>
|
||
<li class="toctree-l4"><a class="reference internal" href="#retrieve">retrieve</a></li>
|
||
</ul>
|
||
</li>
|
||
<li class="toctree-l3"><a class="reference internal" href="#test">test</a><ul>
|
||
<li class="toctree-l4"><a class="reference internal" href="#update">update</a></li>
|
||
</ul>
|
||
</li>
|
||
<li class="toctree-l3"><a class="reference internal" href="#sqlutil">SQLUtil</a><ul>
|
||
<li class="toctree-l4"><a class="reference internal" href="#initdriver">initDriver</a></li>
|
||
<li class="toctree-l4"><a class="reference internal" href="#getconnection">getConnection</a></li>
|
||
</ul>
|
||
</li>
|
||
<li class="toctree-l3"><a class="reference internal" href="#mongodbutil">MongoDBUtil</a><ul>
|
||
<li class="toctree-l4"><a class="reference internal" href="#getconnection-1">getConnection</a></li>
|
||
</ul>
|
||
</li>
|
||
<li class="toctree-l3"><a class="reference internal" href="#rocksdbutil">RocksDBUtil</a><ul>
|
||
<li class="toctree-l4"><a class="reference internal" href="#loaddb">loadDB</a></li>
|
||
</ul>
|
||
</li>
|
||
<li class="toctree-l3"><a class="reference internal" href="#bdwaretimeseriesdbutil">BDWareTimeSeriesDBUtil</a></li>
|
||
</ul>
|
||
</li>
|
||
<li class="toctree-l2"><a class="reference internal" href="#id106">加解密工具类</a><ul>
|
||
<li class="toctree-l3"><a class="reference internal" href="#sm2">SM2</a><ul>
|
||
<li class="toctree-l4"><a class="reference internal" href="#generatekeypair">generateKeyPair</a></li>
|
||
<li class="toctree-l4"><a class="reference internal" href="#sign">sign</a></li>
|
||
<li class="toctree-l4"><a class="reference internal" href="#verify">verify</a></li>
|
||
</ul>
|
||
</li>
|
||
</ul>
|
||
</li>
|
||
<li class="toctree-l2"><a class="reference internal" href="#id119">多线程工具类</a><ul>
|
||
<li class="toctree-l3"><a class="reference internal" href="#asyncutil">AsyncUtil</a><ul>
|
||
<li class="toctree-l4"><a class="reference internal" href="#postfunction">postFunction</a></li>
|
||
<li class="toctree-l4"><a class="reference internal" href="#setinterval">setInterval</a></li>
|
||
<li class="toctree-l4"><a class="reference internal" href="#settimeout">setTimeOut</a></li>
|
||
<li class="toctree-l4"><a class="reference internal" href="#sleep">sleep</a></li>
|
||
</ul>
|
||
</li>
|
||
</ul>
|
||
</li>
|
||
<li class="toctree-l2"><a class="reference internal" href="#ecma5-build-in-objects">ECMA5 Build-in Objects</a></li>
|
||
<li class="toctree-l2"><a class="reference internal" href="#yjs">YJS应用框架</a><ul>
|
||
<li class="toctree-l3"><a class="reference internal" href="#id136">加载流程</a></li>
|
||
<li class="toctree-l3"><a class="reference internal" href="#id137">前端函数说明</a></li>
|
||
<li class="toctree-l3"><a class="reference internal" href="#id138">后端函数约定</a></li>
|
||
</ul>
|
||
</li>
|
||
</ul>
|
||
</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/YJSAPI.rst.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 class="section" id="pubevent">
|
||
<h3>发布事件 pubEvent<a class="headerlink" href="#pubevent" title="永久链接至标题">¶</a></h3>
|
||
<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>
|
||
<div class="section" id="pubeventconstraint">
|
||
<h3>发布带语义事件 pubEventConstraint<a class="headerlink" href="#pubeventconstraint" title="永久链接至标题">¶</a></h3>
|
||
<p>参数</p>
|
||
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>topic:字符串类型,发布的事件主题
|
||
content:字符串类型,发布的事件内容
|
||
semantics:枚举类型,作为字符串输入,事件语义
|
||
</pre></div>
|
||
</div>
|
||
<p>事件语义参数 + AT_LEAST_ONCE:至少一次,默认语义 +
|
||
AT_MOST_ONCE:至多一次 + ONLY_ONCE:只有一次</p>
|
||
<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">pubEventConstraint</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="s2">"AT_MOST_ONCE"</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">AT_MOST_ONCE</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>
|
||
<p>事先声明的事件无论是否声明语义,都可以用后缀s作为方法名的方式调用,发布任意语义的事件:</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">pub3</span><span class="p">(</span><span class="nx">arg</span><span class="p">)</span> <span class="p">{</span>
|
||
<span class="nx">topics</span><span class="p">(</span><span class="nx">arg</span><span class="p">,</span> <span class="s2">"AT_MOST_ONCE"</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> <span class="pre">pub2</span></code>等价。</p>
|
||
<p><em>不带事件语义声明事件时,语义默认为至少一次(AT_LEAST_ONCE)。</em></p>
|
||
</div>
|
||
<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
|
||
@word 单词 @cword 中文单词
|
||
@first @last 英文姓,名
|
||
@cfirst @clast @cname 中文姓,名,全名
|
||
@url @domin @ip @email
|
||
@region @province @city @county 地区,省,市,县
|
||
……
|
||
详细格式可以参考http://mockjs.com/examples.html
|
||
</pre></div>
|
||
</div>
|
||
<p>####注意:模板的格式为{‘result’:模板}</p>
|
||
<div class="highlight-json notranslate"><div class="highlight"><pre><span></span>//返回一个对象包含如下字段
|
||
@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 class="docutils align-default">
|
||
<colgroup>
|
||
<col style="width: 66%" />
|
||
<col style="width: 34%" />
|
||
</colgroup>
|
||
<thead>
|
||
<tr class="row-odd"><th class="head"><p>IO工具类名称</p></th>
|
||
<th class="head"><p>说明</p></th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
<tr class="row-even"><td><p><a class="reference external" href="./YJSAPI.html#fileutil">FileUtil</a></p></td>
|
||
<td><p>文件操作相关的类</p></td>
|
||
</tr>
|
||
<tr class="row-odd"><td><p><a class="reference external" href="./YJSAPI.html#ledgerutil">LedgerUtil</a></p></td>
|
||
<td><p>账本操作相关的类</p></td>
|
||
</tr>
|
||
<tr class="row-even"><td><p><a class="reference external" href="./YJSAPI.html#httputil">HttpUtil</a></p></td>
|
||
<td><p>Http接口相关的类</p></td>
|
||
</tr>
|
||
<tr class="row-odd"><td><p><a class="reference external" href="./YJSAPI.html#doiputil">DOIPUtil</a></p></td>
|
||
<td><p>DoIP相关的类</p></td>
|
||
</tr>
|
||
<tr class="row-even"><td><p><a class="reference external" href="./YJSAPI.html#mysqlutil">MySQLUtil</a></p></td>
|
||
<td><p>连接mysql数据库</p></td>
|
||
</tr>
|
||
<tr class="row-odd"><td><p><a class="reference external" href="./YJSAPI.html#mongodbutil">MongoDBUtil</a></p></td>
|
||
<td><p>MongoDB连接相关的类</p></td>
|
||
</tr>
|
||
<tr class="row-even"><td><p><a class="reference external" href="./YJSAPI.html#rocksdbutil">RocksDBUtil</a></p></td>
|
||
<td><p>RocksDB(基于本地文件的k-v数据库)</p></td>
|
||
</tr>
|
||
<tr class="row-odd"><td><p><a class="reference external" href="./YJSAPI.html#BDWareTimeSeriesDBUtil">BDWareTimeSeriesDBUtil</a></p></td>
|
||
<td><p>基于本地文件的时间序列数据库</p></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 class="docutils align-default">
|
||
<colgroup>
|
||
<col style="width: 20%" />
|
||
<col style="width: 20%" />
|
||
<col style="width: 60%" />
|
||
</colgroup>
|
||
<thead>
|
||
<tr class="row-odd"><th class="head"><p>序号</p></th>
|
||
<th class="head"><p>参数</p></th>
|
||
<th class="head"><p>说明</p></th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
<tr class="row-even"><td><p>1</p></td>
|
||
<td><p>src</p></td>
|
||
<td><p>类型为String</p></td>
|
||
</tr>
|
||
<tr class="row-odd"><td><p>2</p></td>
|
||
<td><p>dest</p></td>
|
||
<td><p>类型为String</p></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">
|
||
<span id="id6"></span><h5>参数<a class="headerlink" href="#id5" title="永久链接至标题">¶</a></h5>
|
||
<table class="docutils align-default">
|
||
<colgroup>
|
||
<col style="width: 20%" />
|
||
<col style="width: 20%" />
|
||
<col style="width: 60%" />
|
||
</colgroup>
|
||
<thead>
|
||
<tr class="row-odd"><th class="head"><p>序号</p></th>
|
||
<th class="head"><p>参数</p></th>
|
||
<th class="head"><p>说明</p></th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
<tr class="row-even"><td><p>1</p></td>
|
||
<td><p>path</p></td>
|
||
<td><p>类型为String</p></td>
|
||
</tr>
|
||
</tbody>
|
||
</table>
|
||
</div>
|
||
<div class="section" id="id7">
|
||
<span id="id8"></span><h5>使用示例<a class="headerlink" href="#id7" 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="id9">
|
||
<span id="id10"></span><h5>参数<a class="headerlink" href="#id9" title="永久链接至标题">¶</a></h5>
|
||
<table class="docutils align-default">
|
||
<colgroup>
|
||
<col style="width: 20%" />
|
||
<col style="width: 20%" />
|
||
<col style="width: 60%" />
|
||
</colgroup>
|
||
<thead>
|
||
<tr class="row-odd"><th class="head"><p>序号</p></th>
|
||
<th class="head"><p>参数</p></th>
|
||
<th class="head"><p>说明</p></th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
<tr class="row-even"><td><p>1</p></td>
|
||
<td><p>path</p></td>
|
||
<td><p>类型为String</p></td>
|
||
</tr>
|
||
</tbody>
|
||
</table>
|
||
</div>
|
||
<div class="section" id="id11">
|
||
<span id="id12"></span><h5>使用示例<a class="headerlink" href="#id11" 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="id13">
|
||
<span id="id14"></span><h5>参数<a class="headerlink" href="#id13" title="永久链接至标题">¶</a></h5>
|
||
<table class="docutils align-default">
|
||
<colgroup>
|
||
<col style="width: 20%" />
|
||
<col style="width: 20%" />
|
||
<col style="width: 60%" />
|
||
</colgroup>
|
||
<thead>
|
||
<tr class="row-odd"><th class="head"><p>序号</p></th>
|
||
<th class="head"><p>参数</p></th>
|
||
<th class="head"><p>说明</p></th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
<tr class="row-even"><td><p>1</p></td>
|
||
<td><p>path</p></td>
|
||
<td><p>类型为String</p></td>
|
||
</tr>
|
||
</tbody>
|
||
</table>
|
||
</div>
|
||
<div class="section" id="id15">
|
||
<span id="id16"></span><h5>使用示例<a class="headerlink" href="#id15" 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="id17">
|
||
<span id="id18"></span><h5>参数<a class="headerlink" href="#id17" title="永久链接至标题">¶</a></h5>
|
||
<table class="docutils align-default">
|
||
<colgroup>
|
||
<col style="width: 8%" />
|
||
<col style="width: 16%" />
|
||
<col style="width: 76%" />
|
||
</colgroup>
|
||
<thead>
|
||
<tr class="row-odd"><th class="head"><p>序号</p></th>
|
||
<th class="head"><p>参数</p></th>
|
||
<th class="head"><p>说明</p></th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
<tr class="row-even"><td><p>1</p></td>
|
||
<td><p>path</p></td>
|
||
<td><p>文件名,类型为String</p></td>
|
||
</tr>
|
||
<tr class="row-odd"><td><p>2</p></td>
|
||
<td><p>isAppend</p></td>
|
||
<td><p>类型为boolean,表示是否往文件末尾添加</p></td>
|
||
</tr>
|
||
</tbody>
|
||
</table>
|
||
</div>
|
||
<div class="section" id="id19">
|
||
<span id="id20"></span><h5>使用示例<a class="headerlink" href="#id19" 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="id21">
|
||
<span id="id22"></span><h5>参数<a class="headerlink" href="#id21" title="永久链接至标题">¶</a></h5>
|
||
<table class="docutils align-default">
|
||
<colgroup>
|
||
<col style="width: 13%" />
|
||
<col style="width: 23%" />
|
||
<col style="width: 65%" />
|
||
</colgroup>
|
||
<thead>
|
||
<tr class="row-odd"><th class="head"><p>序号</p></th>
|
||
<th class="head"><p>参数</p></th>
|
||
<th class="head"><p>说明</p></th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
<tr class="row-even"><td><p>1</p></td>
|
||
<td><p>address</p></td>
|
||
<td><p>包含ip和端口两个字段</p></td>
|
||
</tr>
|
||
</tbody>
|
||
</table>
|
||
</div>
|
||
<div class="section" id="id23">
|
||
<span id="id24"></span><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">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="id25">
|
||
<span id="id26"></span><h5>参数<a class="headerlink" href="#id25" title="永久链接至标题">¶</a></h5>
|
||
<table class="docutils align-default">
|
||
<colgroup>
|
||
<col style="width: 7%" />
|
||
<col style="width: 10%" />
|
||
<col style="width: 83%" />
|
||
</colgroup>
|
||
<thead>
|
||
<tr class="row-odd"><th class="head"><p>序号</p></th>
|
||
<th class="head"><p>参数</p></th>
|
||
<th class="head"><p>说明</p></th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
<tr class="row-even"><td><p>1</p></td>
|
||
<td><p>client</p></td>
|
||
<td><p>通过getClient方法获得的对象</p></td>
|
||
</tr>
|
||
<tr class="row-odd"><td><p>2</p></td>
|
||
<td><p>info</p></td>
|
||
<td><p>对象类型,有两个字段ledger和hash,均为字符串类型</p></td>
|
||
</tr>
|
||
</tbody>
|
||
</table>
|
||
</div>
|
||
<div class="section" id="id27">
|
||
<span id="id28"></span><h5>使用示例<a class="headerlink" href="#id27" 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="id29">
|
||
<span id="id30"></span><h5>参数<a class="headerlink" href="#id29" title="永久链接至标题">¶</a></h5>
|
||
<table class="docutils align-default">
|
||
<colgroup>
|
||
<col style="width: 5%" />
|
||
<col style="width: 7%" />
|
||
<col style="width: 88%" />
|
||
</colgroup>
|
||
<thead>
|
||
<tr class="row-odd"><th class="head"><p>序号</p></th>
|
||
<th class="head"><p>参数</p></th>
|
||
<th class="head"><p>说明</p></th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
<tr class="row-even"><td><p>1</p></td>
|
||
<td><p>client</p></td>
|
||
<td><p>通过getClient方法获得的对象</p></td>
|
||
</tr>
|
||
<tr class="row-odd"><td><p>2</p></td>
|
||
<td><p>info</p></td>
|
||
<td><p>对象类型,有from:raw-latex:<cite>to</cite><a href="#id31"><span class="problematic" id="id32">:raw-latex:`\data三个字段`</span></a>,均为String类型</p></td>
|
||
</tr>
|
||
</tbody>
|
||
</table>
|
||
</div>
|
||
<div class="section" id="id33">
|
||
<span id="id34"></span><h5>使用示例<a class="headerlink" href="#id33" 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="id35">
|
||
<span id="id36"></span><h5>参数<a class="headerlink" href="#id35" title="永久链接至标题">¶</a></h5>
|
||
<table class="docutils align-default">
|
||
<colgroup>
|
||
<col style="width: 11%" />
|
||
<col style="width: 11%" />
|
||
<col style="width: 79%" />
|
||
</colgroup>
|
||
<thead>
|
||
<tr class="row-odd"><th class="head"><p>序号</p></th>
|
||
<th class="head"><p>参数</p></th>
|
||
<th class="head"><p>说明</p></th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
<tr class="row-even"><td><p>1</p></td>
|
||
<td><p>ip</p></td>
|
||
<td><p>字符串类型,ip,端口默认为6161</p></td>
|
||
</tr>
|
||
</tbody>
|
||
</table>
|
||
</div>
|
||
<div class="section" id="id37">
|
||
<span id="id38"></span><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">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="createapigate-1">
|
||
<span id="id39"></span><h4>createAPIGate<a class="headerlink" href="#createapigate-1" title="永久链接至标题">¶</a></h4>
|
||
<p>配合手机的元邦使用,当手机安装元邦且安装了API 接口后,可成为数据来源。</p>
|
||
<div class="section" id="id40">
|
||
<span id="id41"></span><h5>参数<a class="headerlink" href="#id40" title="永久链接至标题">¶</a></h5>
|
||
<table class="docutils align-default">
|
||
<colgroup>
|
||
<col style="width: 17%" />
|
||
<col style="width: 17%" />
|
||
<col style="width: 67%" />
|
||
</colgroup>
|
||
<thead>
|
||
<tr class="row-odd"><th class="head"><p>序号</p></th>
|
||
<th class="head"><p>参数</p></th>
|
||
<th class="head"><p>说明</p></th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
<tr class="row-even"><td><p>1</p></td>
|
||
<td><p>ip</p></td>
|
||
<td><p>字符串类型,ip</p></td>
|
||
</tr>
|
||
<tr class="row-odd"><td><p>2</p></td>
|
||
<td><p>port</p></td>
|
||
<td><p>字符串类型,端口</p></td>
|
||
</tr>
|
||
</tbody>
|
||
</table>
|
||
</div>
|
||
<div class="section" id="id42">
|
||
<span id="id43"></span><h5>使用示例<a class="headerlink" href="#id42" 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="id44">
|
||
<span id="id45"></span><h5>参数<a class="headerlink" href="#id44" title="永久链接至标题">¶</a></h5>
|
||
<table class="docutils align-default">
|
||
<colgroup>
|
||
<col style="width: 15%" />
|
||
<col style="width: 15%" />
|
||
<col style="width: 70%" />
|
||
</colgroup>
|
||
<thead>
|
||
<tr class="row-odd"><th class="head"><p>序号</p></th>
|
||
<th class="head"><p>参数</p></th>
|
||
<th class="head"><p>说明</p></th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
<tr class="row-even"><td><p>1</p></td>
|
||
<td><p>url</p></td>
|
||
<td><p>字符串,表示url类型</p></td>
|
||
</tr>
|
||
</tbody>
|
||
</table>
|
||
</div>
|
||
<div class="section" id="id46">
|
||
<span id="id47"></span><h5>使用示例<a class="headerlink" href="#id46" 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="id48">
|
||
<span id="id49"></span><h5>参数<a class="headerlink" href="#id48" title="永久链接至标题">¶</a></h5>
|
||
<table class="docutils align-default">
|
||
<colgroup>
|
||
<col style="width: 5%" />
|
||
<col style="width: 5%" />
|
||
<col style="width: 90%" />
|
||
</colgroup>
|
||
<thead>
|
||
<tr class="row-odd"><th class="head"><p>序号</p></th>
|
||
<th class="head"><p>参数</p></th>
|
||
<th class="head"><p>说明</p></th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
<tr class="row-even"><td><p>1</p></td>
|
||
<td><p>args</p></td>
|
||
<td><p>对象类型,有url,headers和data三个字段。其中,args.headers为对象类型。</p></td>
|
||
</tr>
|
||
</tbody>
|
||
</table>
|
||
</div>
|
||
<div class="section" id="id50">
|
||
<span id="id51"></span><h5>使用示例<a class="headerlink" href="#id50" 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="id52">
|
||
<span id="id53"></span><h5>参数<a class="headerlink" href="#id52" title="永久链接至标题">¶</a></h5>
|
||
<table class="docutils align-default">
|
||
<colgroup>
|
||
<col style="width: 12%" />
|
||
<col style="width: 12%" />
|
||
<col style="width: 76%" />
|
||
</colgroup>
|
||
<thead>
|
||
<tr class="row-odd"><th class="head"><p>序号</p></th>
|
||
<th class="head"><p>参数</p></th>
|
||
<th class="head"><p>说明</p></th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
<tr class="row-even"><td><p>1</p></td>
|
||
<td><p>arg0</p></td>
|
||
<td><p>字符串类型, 目标DO标识</p></td>
|
||
</tr>
|
||
<tr class="row-odd"><td><p>2</p></td>
|
||
<td><p>arg1</p></td>
|
||
<td><p>字符串类型, 输入参数字符串</p></td>
|
||
</tr>
|
||
</tbody>
|
||
</table>
|
||
</div>
|
||
<div class="section" id="id54">
|
||
<span id="id55"></span><h5>使用示例<a class="headerlink" href="#id54" 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="id56">
|
||
<span id="id57"></span><h5>参数<a class="headerlink" href="#id56" title="永久链接至标题">¶</a></h5>
|
||
<table class="docutils align-default">
|
||
<colgroup>
|
||
<col style="width: 11%" />
|
||
<col style="width: 11%" />
|
||
<col style="width: 78%" />
|
||
</colgroup>
|
||
<thead>
|
||
<tr class="row-odd"><th class="head"><p>序号</p></th>
|
||
<th class="head"><p>参数</p></th>
|
||
<th class="head"><p>说明</p></th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
<tr class="row-even"><td><p>1</p></td>
|
||
<td><p>arg0</p></td>
|
||
<td><p>字符串类型, 目标Repo标识</p></td>
|
||
</tr>
|
||
<tr class="row-odd"><td><p>2</p></td>
|
||
<td><p>arg1</p></td>
|
||
<td><p>对象类型,包括doID,doBody字段</p></td>
|
||
</tr>
|
||
</tbody>
|
||
</table>
|
||
</div>
|
||
<div class="section" id="id58">
|
||
<span id="id59"></span><h5>使用示例<a class="headerlink" href="#id58" 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="id60">
|
||
<span id="id61"></span><h5>参数<a class="headerlink" href="#id60" title="永久链接至标题">¶</a></h5>
|
||
<table class="docutils align-default">
|
||
<colgroup>
|
||
<col style="width: 13%" />
|
||
<col style="width: 13%" />
|
||
<col style="width: 74%" />
|
||
</colgroup>
|
||
<thead>
|
||
<tr class="row-odd"><th class="head"><p>序号</p></th>
|
||
<th class="head"><p>参数</p></th>
|
||
<th class="head"><p>说明</p></th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
<tr class="row-even"><td><p>1</p></td>
|
||
<td><p>arg0</p></td>
|
||
<td><p>字符串类型 目标DO标识</p></td>
|
||
</tr>
|
||
<tr class="row-odd"><td><p>2</p></td>
|
||
<td><p>arg1</p></td>
|
||
<td><p>字符串类型 目标Repo标识</p></td>
|
||
</tr>
|
||
</tbody>
|
||
</table>
|
||
</div>
|
||
<div class="section" id="id62">
|
||
<span id="id63"></span><h5>使用示例<a class="headerlink" href="#id62" 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="id64">
|
||
<span id="id65"></span><h5>参数<a class="headerlink" href="#id64" title="永久链接至标题">¶</a></h5>
|
||
<table class="docutils align-default">
|
||
<colgroup>
|
||
<col style="width: 13%" />
|
||
<col style="width: 13%" />
|
||
<col style="width: 74%" />
|
||
</colgroup>
|
||
<thead>
|
||
<tr class="row-odd"><th class="head"><p>序号</p></th>
|
||
<th class="head"><p>参数</p></th>
|
||
<th class="head"><p>说明</p></th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
<tr class="row-even"><td><p>1</p></td>
|
||
<td><p>arg0</p></td>
|
||
<td><p>字符串类型 目标Repo标识</p></td>
|
||
</tr>
|
||
</tbody>
|
||
</table>
|
||
</div>
|
||
<div class="section" id="id66">
|
||
<span id="id67"></span><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">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="id68">
|
||
<span id="id69"></span><h5>参数<a class="headerlink" href="#id68" title="永久链接至标题">¶</a></h5>
|
||
<table class="docutils align-default">
|
||
<colgroup>
|
||
<col style="width: 14%" />
|
||
<col style="width: 14%" />
|
||
<col style="width: 72%" />
|
||
</colgroup>
|
||
<thead>
|
||
<tr class="row-odd"><th class="head"><p>序号</p></th>
|
||
<th class="head"><p>参数</p></th>
|
||
<th class="head"><p>说明</p></th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
<tr class="row-even"><td><p>1</p></td>
|
||
<td><p>arg0</p></td>
|
||
<td><p>字符串类型 目标DO标识</p></td>
|
||
</tr>
|
||
</tbody>
|
||
</table>
|
||
</div>
|
||
<div class="section" id="id70">
|
||
<span id="id71"></span><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">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="id72">
|
||
<span id="id73"></span><h5>参数<a class="headerlink" href="#id72" title="永久链接至标题">¶</a></h5>
|
||
<table class="docutils align-default">
|
||
<colgroup>
|
||
<col style="width: 11%" />
|
||
<col style="width: 11%" />
|
||
<col style="width: 77%" />
|
||
</colgroup>
|
||
<thead>
|
||
<tr class="row-odd"><th class="head"><p>序号</p></th>
|
||
<th class="head"><p>参数</p></th>
|
||
<th class="head"><p>说明</p></th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
<tr class="row-even"><td><p>1</p></td>
|
||
<td><p>arg0</p></td>
|
||
<td><p>字符串类型 DO所在Repo标识</p></td>
|
||
</tr>
|
||
<tr class="row-odd"><td><p>2</p></td>
|
||
<td><p>arg1</p></td>
|
||
<td><p>字符串类型 DO格式描述字符串</p></td>
|
||
</tr>
|
||
</tbody>
|
||
</table>
|
||
</div>
|
||
<div class="section" id="id74">
|
||
<span id="id75"></span><h5>使用示例<a class="headerlink" href="#id74" 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="id76">
|
||
<span id="id77"></span><h5>参数<a class="headerlink" href="#id76" title="永久链接至标题">¶</a></h5>
|
||
<table class="docutils align-default">
|
||
<colgroup>
|
||
<col style="width: 11%" />
|
||
<col style="width: 11%" />
|
||
<col style="width: 77%" />
|
||
</colgroup>
|
||
<thead>
|
||
<tr class="row-odd"><th class="head"><p>序号</p></th>
|
||
<th class="head"><p>参数</p></th>
|
||
<th class="head"><p>说明</p></th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
<tr class="row-even"><td><p>1</p></td>
|
||
<td><p>arg0</p></td>
|
||
<td><p>字符串类型 目标DO标识</p></td>
|
||
</tr>
|
||
<tr class="row-odd"><td><p>2</p></td>
|
||
<td><p>arg1</p></td>
|
||
<td><p>字符串类型 DO所在Repo标识</p></td>
|
||
</tr>
|
||
<tr class="row-even"><td><p>3</p></td>
|
||
<td><p>arg2</p></td>
|
||
<td><p>字符串类型 DO格式描述字符串</p></td>
|
||
</tr>
|
||
</tbody>
|
||
</table>
|
||
</div>
|
||
<div class="section" id="id78">
|
||
<span id="id79"></span><h5>使用示例<a class="headerlink" href="#id78" 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="id80">
|
||
<span id="id81"></span><h5>参数<a class="headerlink" href="#id80" title="永久链接至标题">¶</a></h5>
|
||
<table class="docutils align-default">
|
||
<colgroup>
|
||
<col style="width: 14%" />
|
||
<col style="width: 14%" />
|
||
<col style="width: 72%" />
|
||
</colgroup>
|
||
<thead>
|
||
<tr class="row-odd"><th class="head"><p>序号</p></th>
|
||
<th class="head"><p>参数</p></th>
|
||
<th class="head"><p>说明</p></th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
<tr class="row-even"><td><p>1</p></td>
|
||
<td><p>arg0</p></td>
|
||
<td><p>字符串类型 目标DO标识</p></td>
|
||
</tr>
|
||
</tbody>
|
||
</table>
|
||
</div>
|
||
<div class="section" id="id82">
|
||
<span id="id83"></span><h5>使用示例<a class="headerlink" href="#id82" 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>
|
||
<table class="docutils align-default">
|
||
<colgroup>
|
||
<col style="width: 14%" />
|
||
<col style="width: 14%" />
|
||
<col style="width: 72%" />
|
||
</colgroup>
|
||
<thead>
|
||
<tr class="row-odd"><th class="head"><p>序号</p></th>
|
||
<th class="head"><p>参数</p></th>
|
||
<th class="head"><p>说明</p></th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
<tr class="row-even"><td><p>1</p></td>
|
||
<td><p>arg0</p></td>
|
||
<td><p>字符串类型 任意字符串</p></td>
|
||
</tr>
|
||
</tbody>
|
||
</table>
|
||
<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 class="section" id="update">
|
||
<h4>update<a class="headerlink" href="#update" title="永久链接至标题">¶</a></h4>
|
||
<p>更新目标DO</p>
|
||
<div class="section" id="id85">
|
||
<span id="id86"></span><h5>参数<a class="headerlink" href="#id85" title="永久链接至标题">¶</a></h5>
|
||
<table class="docutils align-default">
|
||
<colgroup>
|
||
<col style="width: 12%" />
|
||
<col style="width: 12%" />
|
||
<col style="width: 76%" />
|
||
</colgroup>
|
||
<thead>
|
||
<tr class="row-odd"><th class="head"><p>序号</p></th>
|
||
<th class="head"><p>参数</p></th>
|
||
<th class="head"><p>说明</p></th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
<tr class="row-even"><td><p>1</p></td>
|
||
<td><p>arg0</p></td>
|
||
<td><p>JS对象,包括doID,doBody字段</p></td>
|
||
</tr>
|
||
</tbody>
|
||
</table>
|
||
</div>
|
||
<div class="section" id="id87">
|
||
<span id="id88"></span><h5>使用示例<a class="headerlink" href="#id87" 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="sqlutil">
|
||
<h3>SQLUtil<a class="headerlink" href="#sqlutil" title="永久链接至标题">¶</a></h3>
|
||
<p>可以使用@Permission(“SQL”)来引入SQLUtil对象。
|
||
可支持MySQL/PostgreSQL/Oracle/GuassDB200等SQL数据库。
|
||
需要将对应的jdbc的jar上传到项目中。
|
||
例如,要使用mysql,可上传mysql-connector-java-8.0.24.jar</p>
|
||
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="nd">@Permission</span><span class="p">(</span><span class="s2">"SQL"</span><span class="p">)</span>
|
||
<span class="n">oracle</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="initdriver">
|
||
<h4>initDriver<a class="headerlink" href="#initdriver" title="永久链接至标题">¶</a></h4>
|
||
<div class="section" id="id89">
|
||
<span id="id90"></span><h5>参数<a class="headerlink" href="#id89" title="永久链接至标题">¶</a></h5>
|
||
<table class="docutils align-default">
|
||
<colgroup>
|
||
<col style="width: 16%" />
|
||
<col style="width: 44%" />
|
||
<col style="width: 40%" />
|
||
</colgroup>
|
||
<thead>
|
||
<tr class="row-odd"><th class="head"><p>序号</p></th>
|
||
<th class="head"><p>参数</p></th>
|
||
<th class="head"><p>说明</p></th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
<tr class="row-even"><td><p>1</p></td>
|
||
<td><p>driverClass</p></td>
|
||
<td><p>字符串类型</p></td>
|
||
</tr>
|
||
</tbody>
|
||
</table>
|
||
</div>
|
||
<div class="section" id="id91">
|
||
<span id="id92"></span><h5>使用示例<a class="headerlink" href="#id91" title="永久链接至标题">¶</a></h5>
|
||
<div class="highlight-javascript notranslate"><div class="highlight"><pre><span></span><span class="c1">//使用mysql</span>
|
||
<span class="nx">SQLUtil</span><span class="p">.</span><span class="nx">initDriver</span><span class="p">(</span><span class="s2">"com.mysql.cj.jdbc.Driver"</span><span class="p">);</span>
|
||
<span class="c1">//使用postgresql</span>
|
||
<span class="nx">SQLUtil</span><span class="p">.</span><span class="nx">initDriver</span><span class="p">(</span><span class="s2">"org.postgresql.Driver"</span><span class="p">);</span>
|
||
<span class="c1">//使用oracle</span>
|
||
<span class="nx">SQLUtil</span><span class="p">.</span><span class="nx">initDriver</span><span class="p">(</span><span class="s2">"oracle.jdbc.OracleDriver"</span><span class="p">);</span>
|
||
</pre></div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<div class="section" id="getconnection">
|
||
<h4>getConnection<a class="headerlink" href="#getconnection" title="永久链接至标题">¶</a></h4>
|
||
<div class="section" id="id93">
|
||
<span id="id94"></span><h5>参数<a class="headerlink" href="#id93" title="永久链接至标题">¶</a></h5>
|
||
<table class="docutils align-default">
|
||
<colgroup>
|
||
<col style="width: 13%" />
|
||
<col style="width: 23%" />
|
||
<col style="width: 65%" />
|
||
</colgroup>
|
||
<thead>
|
||
<tr class="row-odd"><th class="head"><p>序号</p></th>
|
||
<th class="head"><p>参数</p></th>
|
||
<th class="head"><p>说明</p></th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
<tr class="row-even"><td><p>1</p></td>
|
||
<td><p>URL</p></td>
|
||
<td><p>字符串类型,jdbc连接</p></td>
|
||
</tr>
|
||
<tr class="row-odd"><td><p>2</p></td>
|
||
<td><p>usrName</p></td>
|
||
<td><p>字符串类型,用户名</p></td>
|
||
</tr>
|
||
<tr class="row-even"><td><p>3</p></td>
|
||
<td><p>pwd</p></td>
|
||
<td><p>字符串类型,密码</p></td>
|
||
</tr>
|
||
</tbody>
|
||
</table>
|
||
</div>
|
||
<div class="section" id="id95">
|
||
<span id="id96"></span><h5>使用示例<a class="headerlink" href="#id95" 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">SQLUtil</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="getconnection-1">
|
||
<span id="id97"></span><h4>getConnection<a class="headerlink" href="#getconnection-1" title="永久链接至标题">¶</a></h4>
|
||
<div class="section" id="id98">
|
||
<span id="id99"></span><h5>参数<a class="headerlink" href="#id98" title="永久链接至标题">¶</a></h5>
|
||
<table class="docutils align-default">
|
||
<colgroup>
|
||
<col style="width: 11%" />
|
||
<col style="width: 19%" />
|
||
<col style="width: 69%" />
|
||
</colgroup>
|
||
<thead>
|
||
<tr class="row-odd"><th class="head"><p>序号</p></th>
|
||
<th class="head"><p>参数</p></th>
|
||
<th class="head"><p>说明</p></th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
<tr class="row-even"><td><p>1</p></td>
|
||
<td><p>URL</p></td>
|
||
<td><p>字符串类型 数据库的URL</p></td>
|
||
</tr>
|
||
<tr class="row-odd"><td><p>2</p></td>
|
||
<td><p>port</p></td>
|
||
<td><p>整数类型 端口号</p></td>
|
||
</tr>
|
||
<tr class="row-even"><td><p>3</p></td>
|
||
<td><p>dbName</p></td>
|
||
<td><p>字符串类型 数据库的名称</p></td>
|
||
</tr>
|
||
<tr class="row-odd"><td><p>4</p></td>
|
||
<td><p>usrName</p></td>
|
||
<td><p>字符串类型 数据库的用户名</p></td>
|
||
</tr>
|
||
<tr class="row-even"><td><p>5</p></td>
|
||
<td><p>pwd</p></td>
|
||
<td><p>字符串类型 数据库的密码</p></td>
|
||
</tr>
|
||
</tbody>
|
||
</table>
|
||
</div>
|
||
<div class="section" id="id100">
|
||
<span id="id101"></span><h5>使用示例<a class="headerlink" href="#id100" 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="id102">
|
||
<span id="id103"></span><h5>参数<a class="headerlink" href="#id102" title="永久链接至标题">¶</a></h5>
|
||
<table class="docutils align-default">
|
||
<colgroup>
|
||
<col style="width: 10%" />
|
||
<col style="width: 21%" />
|
||
<col style="width: 69%" />
|
||
</colgroup>
|
||
<thead>
|
||
<tr class="row-odd"><th class="head"><p>序号</p></th>
|
||
<th class="head"><p>参数</p></th>
|
||
<th class="head"><p>说明</p></th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
<tr class="row-even"><td><p>1</p></td>
|
||
<td><p>path</p></td>
|
||
<td><p>字符串类型 数据库部署的路径</p></td>
|
||
</tr>
|
||
<tr class="row-odd"><td><p>2</p></td>
|
||
<td><p>readOnly</p></td>
|
||
<td><p>布尔类型 数据库只读</p></td>
|
||
</tr>
|
||
</tbody>
|
||
</table>
|
||
</div>
|
||
<div class="section" id="id104">
|
||
<span id="id105"></span><h5>使用示例<a class="headerlink" href="#id104" 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="id106">
|
||
<h2>加解密工具类<a class="headerlink" href="#id106" 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="id107">
|
||
<span id="id108"></span><h5>参数<a class="headerlink" href="#id107" title="永久链接至标题">¶</a></h5>
|
||
<p>无参数。</p>
|
||
</div>
|
||
<div class="section" id="id109">
|
||
<span id="id110"></span><h5>使用示例<a class="headerlink" href="#id109" 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="id111">
|
||
<span id="id112"></span><h5>参数<a class="headerlink" href="#id111" title="永久链接至标题">¶</a></h5>
|
||
<table class="docutils align-default">
|
||
<colgroup>
|
||
<col style="width: 11%" />
|
||
<col style="width: 18%" />
|
||
<col style="width: 71%" />
|
||
</colgroup>
|
||
<thead>
|
||
<tr class="row-odd"><th class="head"><p>序号</p></th>
|
||
<th class="head"><p>参数</p></th>
|
||
<th class="head"><p>说明</p></th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
<tr class="row-even"><td><p>1</p></td>
|
||
<td><p>content</p></td>
|
||
<td><p>字符串类型 要进行签名的内容</p></td>
|
||
</tr>
|
||
<tr class="row-odd"><td><p>2</p></td>
|
||
<td><p>keyPair</p></td>
|
||
<td><p>sm2</p></td>
|
||
</tr>
|
||
</tbody>
|
||
</table>
|
||
</div>
|
||
<div class="section" id="id113">
|
||
<span id="id114"></span><h5>使用示例<a class="headerlink" href="#id113" 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="id115">
|
||
<span id="id116"></span><h5>参数<a class="headerlink" href="#id115" title="永久链接至标题">¶</a></h5>
|
||
<table class="docutils align-default">
|
||
<colgroup>
|
||
<col style="width: 11%" />
|
||
<col style="width: 25%" />
|
||
<col style="width: 64%" />
|
||
</colgroup>
|
||
<thead>
|
||
<tr class="row-odd"><th class="head"><p>序号</p></th>
|
||
<th class="head"><p>参数</p></th>
|
||
<th class="head"><p>说明</p></th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
<tr class="row-even"><td><p>1</p></td>
|
||
<td><p>content</p></td>
|
||
<td><p>字符串类型 待验签的内容</p></td>
|
||
</tr>
|
||
<tr class="row-odd"><td><p>2</p></td>
|
||
<td><p>signature</p></td>
|
||
<td><p>字符串类型 签名</p></td>
|
||
</tr>
|
||
<tr class="row-even"><td><p>3</p></td>
|
||
<td><p>publicKey</p></td>
|
||
<td><p>字符串类型 公钥</p></td>
|
||
</tr>
|
||
</tbody>
|
||
</table>
|
||
</div>
|
||
<div class="section" id="id117">
|
||
<span id="id118"></span><h5>使用示例<a class="headerlink" href="#id117" 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="id119">
|
||
<h2>多线程工具类<a class="headerlink" href="#id119" 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="id120">
|
||
<span id="id121"></span><h5>参数<a class="headerlink" href="#id120" title="永久链接至标题">¶</a></h5>
|
||
<table class="docutils align-default">
|
||
<colgroup>
|
||
<col style="width: 18%" />
|
||
<col style="width: 18%" />
|
||
<col style="width: 64%" />
|
||
</colgroup>
|
||
<thead>
|
||
<tr class="row-odd"><th class="head"><p>序号</p></th>
|
||
<th class="head"><p>参数</p></th>
|
||
<th class="head"><p>说明</p></th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
<tr class="row-even"><td><p>1</p></td>
|
||
<td><p>arg0</p></td>
|
||
<td><p>ScriptFunction</p></td>
|
||
</tr>
|
||
<tr class="row-odd"><td><p>2</p></td>
|
||
<td><p>arg1</p></td>
|
||
<td><p>对象</p></td>
|
||
</tr>
|
||
</tbody>
|
||
</table>
|
||
</div>
|
||
<div class="section" id="id122">
|
||
<span id="id123"></span><h5>使用示例<a class="headerlink" href="#id122" 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="id124">
|
||
<span id="id125"></span><h5>参数<a class="headerlink" href="#id124" title="永久链接至标题">¶</a></h5>
|
||
<table class="docutils align-default">
|
||
<colgroup>
|
||
<col style="width: 18%" />
|
||
<col style="width: 18%" />
|
||
<col style="width: 64%" />
|
||
</colgroup>
|
||
<thead>
|
||
<tr class="row-odd"><th class="head"><p>序号</p></th>
|
||
<th class="head"><p>参数</p></th>
|
||
<th class="head"><p>说明</p></th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
<tr class="row-even"><td><p>1</p></td>
|
||
<td><p>arg0</p></td>
|
||
<td><p>ScriptFunction</p></td>
|
||
</tr>
|
||
<tr class="row-odd"><td><p>2</p></td>
|
||
<td><p>arg1</p></td>
|
||
<td><p>long</p></td>
|
||
</tr>
|
||
<tr class="row-even"><td><p>3</p></td>
|
||
<td><p>arg2</p></td>
|
||
<td><p>long</p></td>
|
||
</tr>
|
||
<tr class="row-odd"><td><p>4</p></td>
|
||
<td><p>arg3</p></td>
|
||
<td><p>对象</p></td>
|
||
</tr>
|
||
</tbody>
|
||
</table>
|
||
</div>
|
||
<div class="section" id="id126">
|
||
<span id="id127"></span><h5>使用示例<a class="headerlink" href="#id126" 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="id128">
|
||
<span id="id129"></span><h5>参数<a class="headerlink" href="#id128" title="永久链接至标题">¶</a></h5>
|
||
<table class="docutils align-default">
|
||
<colgroup>
|
||
<col style="width: 18%" />
|
||
<col style="width: 18%" />
|
||
<col style="width: 64%" />
|
||
</colgroup>
|
||
<thead>
|
||
<tr class="row-odd"><th class="head"><p>序号</p></th>
|
||
<th class="head"><p>参数</p></th>
|
||
<th class="head"><p>说明</p></th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
<tr class="row-even"><td><p>1</p></td>
|
||
<td><p>arg0</p></td>
|
||
<td><p>ScriptFunction</p></td>
|
||
</tr>
|
||
<tr class="row-odd"><td><p>2</p></td>
|
||
<td><p>arg1</p></td>
|
||
<td><p>long</p></td>
|
||
</tr>
|
||
<tr class="row-even"><td><p>3</p></td>
|
||
<td><p>arg2</p></td>
|
||
<td><p>Object</p></td>
|
||
</tr>
|
||
</tbody>
|
||
</table>
|
||
</div>
|
||
<div class="section" id="id130">
|
||
<span id="id131"></span><h5>使用示例<a class="headerlink" href="#id130" 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="id132">
|
||
<span id="id133"></span><h5>参数<a class="headerlink" href="#id132" title="永久链接至标题">¶</a></h5>
|
||
<table class="docutils align-default">
|
||
<colgroup>
|
||
<col style="width: 33%" />
|
||
<col style="width: 33%" />
|
||
<col style="width: 33%" />
|
||
</colgroup>
|
||
<thead>
|
||
<tr class="row-odd"><th class="head"><p>序号</p></th>
|
||
<th class="head"><p>参数</p></th>
|
||
<th class="head"><p>说明</p></th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
<tr class="row-even"><td><p>1</p></td>
|
||
<td><p>arg0</p></td>
|
||
<td><p>long</p></td>
|
||
</tr>
|
||
</tbody>
|
||
</table>
|
||
</div>
|
||
<div class="section" id="id134">
|
||
<span id="id135"></span><h5>使用示例<a class="headerlink" href="#id134" 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 class="section" id="yjs">
|
||
<h2>YJS应用框架<a class="headerlink" href="#yjs" title="永久链接至标题">¶</a></h2>
|
||
<div class="section" id="id136">
|
||
<h3>加载流程<a class="headerlink" href="#id136" title="永久链接至标题">¶</a></h3>
|
||
<p>函数约定(getMainFrame)</p>
|
||
</div>
|
||
<div class="section" id="id137">
|
||
<h3>前端函数说明<a class="headerlink" href="#id137" title="永久链接至标题">¶</a></h3>
|
||
<p>executeCurrentContract/….. 如何loadScript/loadCss..</p>
|
||
</div>
|
||
<div class="section" id="id138">
|
||
<h3>后端函数约定<a class="headerlink" href="#id138" title="永久链接至标题">¶</a></h3>
|
||
<p>getMainFrame</p>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
|
||
</div>
|
||
|
||
</div>
|
||
<footer>
|
||
<div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
|
||
<a href="YJSInDepth.html" class="btn btn-neutral float-left" title="YJS语法" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left" aria-hidden="true"></span> 上一页</a>
|
||
</div>
|
||
|
||
<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> |