AI绘画
<p>[TOC]</p>
<h3>简介</h3>
<ul>
<li>根据用户输入的文本,自动创作图片,每次可自定义生成1张至6张图片</li>
<li>涉及2个接口,分别为:提交请求、查询结果</li>
<li>根据生成图片张数计费,若一次请求生成多张图片,则每张图片计费1次</li>
</ul>
<h3>接入流程</h3>
<ol>
<li>提交请求:传入文本、分辨率、风格参数,创建AI作画任务,获得任务ID</li>
<li>查询结果:用于在任务创建后,查看图片生成状态。待图片生成完毕,通过查询接口即可查看生成图片的地址链接</li>
</ol>
<h3>接口调用说明</h3>
<h4>请求方式</h4>
<p>如接口没有单独说明,所有接口均为:<strong>POST</strong></p>
<h4>请求格式</h4>
<p>如接口没有单独说明,所有接口均为:<strong>application/form-data</strong></p>
<h4>请求参数</h4>
<p>请求参数均包括公共参数和业务参数(业务参数见具体接口说明)
如接口没有单独说明,所有接口调用时,均需要把<strong>公共参数</strong>和<strong>业务参数</strong>一并放在<strong>请求参数</strong>中提交</p>
<p><a name="公共请求参数"></a></p>
<h5>公共请求参数</h5>
<table>
<thead>
<tr>
<th>名称</th>
<th>类型</th>
<th>必须</th>
<th><div style="width:420px;">说明</div></th>
</tr>
</thead>
<tbody>
<tr>
<td>appId</td>
<td>String</td>
<td>是</td>
<td>服务商分配的唯一标识</td>
</tr>
<tr>
<td>timestamp</td>
<td>Long</td>
<td>是</td>
<td>当前时间戳(毫秒)</td>
</tr>
<tr>
<td>sign</td>
<td>String</td>
<td>是</td>
<td>签名,详见签名算法说明</td>
</tr>
</tbody>
</table>
<h5>签名算法说明</h5>
<pre><code>sign = sha256(appId + appSecret + timestamp)</code></pre>
<p>用服务商分配的 <strong>appId</strong>、服务商分配的 <strong>appSecret</strong>,当前时间戳(毫秒) <strong>timestamp</strong>,按上述顺序拼接成字符串,再进行 <strong>sha256</strong> 哈希得到。如下:</p>
<pre><code class="language-java">String appId = &quot;xyzxy2121zxyz&quot;;
String timestamp = &quot;1555378976238&quot;;
String appSecret = &quot;efcefcef1121cefcefc1212121&quot;;
String str = appId + appSecret + timestamp;
String sign = sha256(str);</code></pre>
<h4>返回说明</h4>
<h5>公共返回字段说明</h5>
<p>所有接口均返回以下公共字段:</p>
<table>
<thead>
<tr>
<th>字段名</th>
<th><div style="width:420px">说明</div></th>
</tr>
</thead>
<tbody>
<tr>
<td>code</td>
<td>返回码,详见:code返回码说明</td>
</tr>
<tr>
<td>msg</td>
<td>code对应的描述</td>
</tr>
<tr>
<td>charge</td>
<td>计费标志 true为计费,false为不计费</td>
</tr>
<tr>
<td>taskNo</td>
<td>本次请求号</td>
</tr>
<tr>
<td>data</td>
<td>返回具体结果,object类型,详见data返回字段描述</td>
</tr>
</tbody>
</table>
<p><a name="code返回码说明"></a></p>
<table>
<thead>
<tr>
<th>code</th>
<th><div style="width:420px;">说明</div></th>
</tr>
</thead>
<tbody>
<tr>
<td>200</td>
<td>成功</td>
</tr>
<tr>
<td>201</td>
<td>taskId不存在</td>
</tr>
<tr>
<td>202</td>
<td>文本黄反拦截</td>
</tr>
<tr>
<td>400</td>
<td>参数错误</td>
</tr>
<tr>
<td>404</td>
<td>接口地址不正确</td>
</tr>
<tr>
<td>500</td>
<td>系统维护,请稍候再试</td>
</tr>
<tr>
<td>601</td>
<td>接口未开通</td>
</tr>
<tr>
<td>602</td>
<td>账号停用</td>
</tr>
<tr>
<td>604</td>
<td>接口停用</td>
</tr>
<tr>
<td>606</td>
<td>调用超限,请稍候再试</td>
</tr>
<tr>
<td>607</td>
<td>ip不在白名单</td>
</tr>
<tr>
<td>609</td>
<td>请求过于频繁,请稍候再试</td>
</tr>
<tr>
<td>610</td>
<td>请求超时</td>
</tr>
<tr>
<td>999</td>
<td>其他,以实际返回为准</td>
</tr>
</tbody>
</table>
<hr />
<h3>提交请求</h3>
<h4>请求地址</h4>
<p><code>https://api-hw.jumdata.com/ai/draw/submit</code></p>
<h4>业务参数</h4>
<table>
<thead>
<tr>
<th>名称</th>
<th>类型</th>
<th>必须</th>
<th><div style="width:420px;">说明</div></th>
</tr>
</thead>
<tbody>
<tr>
<td>text</td>
<td>String</td>
<td>是</td>
<td>输入内容,长度不超过100个字</td>
</tr>
<tr>
<td>resolution</td>
<td>String</td>
<td>是</td>
<td>图片分辨率,支持: 1024*1024、 1024*1536、1536*1024</td>
</tr>
<tr>
<td>style</td>
<td>String</td>
<td>是</td>
<td>风格 目前支持风格有:探索无限、古风、二次元、写实风格、浮世绘、low poly 、未来主义、像素风格、概念艺术、赛博朋克、洛丽塔风格、巴洛克风格、超现实主义、水彩画、蒸汽波艺术、油画、卡通画</td>
</tr>
<tr>
<td>num</td>
<td>int</td>
<td>否</td>
<td>图片生成数量,支持1-6张,默认1张,计费按图片生成数量来计费</td>
</tr>
</tbody>
</table>
<p>公共请求参数请参阅:<a href="#公共请求参数">公共请求参数</a></p>
<h4>成功返回样例</h4>
<pre><code class="language-json">{
&quot;code&quot;: 200,// 返回码,详见返回码说明
&quot;msg&quot;: &quot;成功&quot;,// 返回码对应描述
&quot;taskNo&quot;: &quot;043439882226367117195632&quot;,// 本次请求号
&quot;charge&quot;: true, // 计费标志
&quot;data&quot;: {
&quot;taskId&quot;: &quot;xxxx&quot; //taskId (有效期一个月)
}
}</code></pre>
<h4>失败返回样例</h4>
<pre><code class="language-json">{
&quot;code&quot;: 400,// 返回码,详见返回码说明
&quot;taskNo&quot;: &quot;255033697205413852131601&quot;,// 本次请求号
&quot;charge&quot;: false,// 计费标志
&quot;msg&quot;: &quot;风格值不正确&quot;// 返回码对应描述
}</code></pre>
<hr />
<h3>查询结果</h3>
<h4>请求地址</h4>
<p><code>https://api-hw.jumdata.com/ai/draw/query</code></p>
<h4>业务参数</h4>
<p>参数说明</p>
<table>
<thead>
<tr>
<th>名称</th>
<th>类型</th>
<th>必须</th>
<th><div style="width:420px;">说明</div></th>
</tr>
</thead>
<tbody>
<tr>
<td>taskId</td>
<td>String</td>
<td>是</td>
<td>提交请求接口返回的taskId</td>
</tr>
</tbody>
</table>
<h4>成功返回样例</h4>
<pre><code class="language-json">{
&quot;code&quot;: 200,// 返回码,详见返回码说明
&quot;msg&quot;: &quot;成功&quot;, // 返回码对应描述
&quot;taskNo&quot;: &quot;448290834186092138576138&quot;,// 本次请求号
&quot;charge&quot;: false, //计费标志,查询结果接口不计费
&quot;data&quot;: {
&quot;img&quot;: &quot;xxxxx&quot;,//生成结果地址,生产多张时,取第一张图(有效期三个月)
&quot;imgUrls&quot;: [ //生成结果数组
{
&quot;image&quot;: &quot;xxxxx&quot; //生成结果地址 (有效期三个月)
}
],
&quot;createTime&quot;: &quot;2023-09-21 22:15:41&quot;,//任务创建时间
&quot;status&quot;: 1 //0或1。&quot;1&quot;表示已生成完成,&quot;0&quot;表示任务排队中或正在处理。
}
}
</code></pre>
<h4>失败返回样例</h4>
<pre><code class="language-json">{
&quot;code&quot;: 400,// 返回码,详见返回码说明
&quot;msg&quot;: &quot;taskId不能为空&quot;, // 返回码对应描述
&quot;taskNo&quot;: &quot;255033697205413852131601&quot;,// 本次请求号
&quot;charge&quot;: false, //计费标志,查询结果接口不计费
}</code></pre>