# 科学计算器:5 分钟接入,从注册到第一条计算结果
> 接口 免费科学计算器(apiCode 1699)· 接入点 科学计算器(1699-1)· 免费 · POST/GET · 返回 JSON · 适合 新注册用户 / 学生 / 初级开发者 · 阅读约 5 分钟
## 核心要点
- 免费、注册即送调用额度,取一个 AppKey 就能开始,无需采购资源包。
- 一次调用只要 3 个参数:`num`(要计算的值)、`operation`(操作名)、`rad_or_ang`(角度制,三角函数才需要)。
- 计算结果在 `showapi_res_body.result` 里,成功时 `ret_code` 为 `0`。
## Why:这跟我有什么关系
你可能在写一个小工具、做一道数学题、或者给学生出练习卷时需要可靠的计算能力,但又不想自己实现阶乘、对数、三角函数那一大堆公式。科学计算器接口把这些算法封装好,你只要把「算什么、怎么算」通过 HTTP 传过去,它返回结果字符串。
- 学生 / 老师:把公式交给接口,专注在「为什么这么算」,而不是「怎么实现算」。
- 开发者:在后台、脚本、低代码平台里直接调用,省掉自己维护数学库。
- AI 玩家:通过 MCP 配置,让 AI 客户端直接「开口算数」。
## What:前置条件与接口速览
| 项目 | 说明 |
|------|------|
| 接口名称 | 免费科学计算器(apiCode 1699) |
| 接入点 | 科学计算器 `1699-1`(计算)、支持的规则列表 `1699-2`(查操作名) |
| 请求地址 | `https://route.showapi.com/1699-1?appKey={your_appKey}` |
| 请求方式 | POST 或 GET |
| 鉴权 | URL 上的 `appKey`(在 [AppKey 管理](https://www.showapi.com/console#/myApp) 获取) |
| 返回格式 | JSON |
| 计费 | 免费,注册后默认可调用;为防止滥用设有[使用档次限制](https://www.showapi.com/free-api) |
| 集成能力 | 提供 [MCP 配置](https://www.showapi.com/guides/calculator-mcp-integration-1699)、[OpenAPI 文档](https://www.showapi.com/openapi/market/1699.yaml) |
请求参数(1699-1):
| 参数 | 类型 | 必填 | 说明 |
|------|------|------|------|
| `num` | String | 是 | 要计算的值;多参数用逗号 `,` 分隔 |
| `operation` | String | 是 | 操作名,共 32 个(见[操作名速查](https://www.showapi.com/guides/calculator-operations-reference-1699)) |
| `rad_or_ang` | String | 否 | `rad`=弧度、`ang`=角度,仅对三角函数生效,其余留空 |
| `content-type` | Header | 否 | `application/x-www-form-urlencoded` |
## How:三步跑通第一条计算
下面以「计算 `2 + 3 + 4`」为例,三种语言任选其一,**把 `YOUR_APPKEY` 换成你自己的 AppKey** 即可直接运行。
### Python(requests)
```python
import requests
APP_KEY = "YOUR_APPKEY"
url = "https://route.showapi.com/1699-1"
data = {
"num": "2,3,4", # 多个数用逗号分隔
"operation": "add", # 加法
"rad_or_ang": "" # 非三角函数留空
}
try:
r = requests.post(url, params={"appKey": APP_KEY}, data=data, timeout=10)
r.raise_for_status()
body = r.json()["showapi_res_body"]
if str(body.get("ret_code")) == "0":
print("计算结果:", body["result"]) # 输出 9.0
else:
print("调用失败:", body.get("remark"))
except Exception as e:
print("请求异常:", e)
```
### cURL
```bash
curl -X POST "https://route.showapi.com/1699-1?appKey=YOUR_APPKEY" \
-H "content-type: application/x-www-form-urlencoded" \
-d "num=2,3,4&operation=add&rad_or_ang="
```
### Node.js(fetch)
```javascript
const APP_KEY = "YOUR_APPKEY";
const body = new URLSearchParams({ num: "2,3,4", operation: "add", rad_or_ang: "" });
fetch(`https://route.showapi.com/1699-1?appKey=${APP_KEY}`, {
method: "POST",
headers: { "content-type": "application/x-www-form-urlencoded" },
body
})
.then(r => r.json())
.then(res => {
const b = res.showapi_res_body;
if (String(b.ret_code) === "0") console.log("计算结果:", b.result);
else console.log("调用失败:", b.remark);
})
.catch(e => console.error("请求异常:", e));
```
## 返回示例与解析
请求 `num=2,3,4&operation=add` 的真实返回(实测):
```json
{
"showapi_res_error": "",
"showapi_res_id": "6a991175fb638c8138ea6db3",
"showapi_res_code": 0,
"showapi_fee_num": 1,
"showapi_res_body": {
"ret_code": 0,
"remark": "成功",
"result": 9.0
}
}
```
- `showapi_res_body.result`:计算结果,这里是 `9.0`。
- `showapi_res_body.ret_code`:`0` 表示成功(会计费 1 次,免费额度内不扣钱)。
- `showapi_res_body.remark`:文字说明,`成功` 或错误原因。
- 系统级字段:`showapi_res_code`(整次请求状态)、`showapi_res_id`(请求追踪 ID)、`showapi_fee_num`(计费次数)。
> 想一次性看懂 `ret_code` / `result` / `remark` 的每种取值,看[科学计算器返回字段全解](https://www.showapi.com/guides/calculator-response-fields-1699)。
## 进阶 / 边界
- **结果都是字符串形式的数值**:`result` 是 `"9.0"` 这类,前端展示时按需 `parseFloat` 即可。
- **角度制要显式传**:算 `sin(30°)` 必须传 `rad_or_ang=ang`,否则按弧度算会得到 `sin(30 弧度)≈-0.988`。详见[三角函数角度制实战](https://www.showapi.com/guides/calculator-trig-angles-1699)。
- **开方 / 幂要传两个参数**:`sqrt(9)` 单参数会退化成返回 `9`(原值),正确写法是 `sqrt(2,9)` 表示「9 次根号下 2」。详见[幂与根用法](https://www.showapi.com/guides/calculator-power-root-1699)。
## FAQ
**Q1:完全免费吗?要不要买资源包?**
免费。注册后默认就有调用额度,只是有[使用档次限制](https://www.showapi.com/free-api)防止滥用,普通学习 / 小工具场景足够。
**Q2:AppKey 在哪拿?**
登录后在 [AppKey 管理](https://www.showapi.com/console#/myApp) 创建应用即可拿到。
**Q3:GET 能调吗?**
能。参数拼到 URL 上即可,但涉及多个 `num` 时 POST 表单更清晰,推荐 POST。
**Q4:返回里的 `result` 是数字还是字符串?**
是数值(如 `9.0`)。直接当数字用即可。
**Q5:算错了 / 结果不对怎么办?**
先看 `ret_code`:为 `0` 说明接口算对了,多半是参数语义理解偏差(比如忘了传角度制、开方少传了参数);非 0 再看 `remark`。排查清单见[错误码排查](https://www.showapi.com/guides/calculator-error-codes-1699)。
**Q6:有哪些运算可以做?**
共 32 个操作名,从加减乘除到对数、三角函数、双曲函数、阶乘、幂、根。完整清单见[操作名速查](https://www.showapi.com/guides/calculator-operations-reference-1699)。
## 相关能力 / 下一步阅读
- [科学计算器返回字段全解](https://www.showapi.com/guides/calculator-response-fields-1699) —— 读懂 `ret_code` / `result` / `remark`
- [科学计算器操作名速查](https://www.showapi.com/guides/calculator-operations-reference-1699) —— 32 个 operation 完整清单
- [科学计算器已知问题与使用避坑](https://www.showapi.com/guides/calculator-known-issues-1699) —— 提前避开几个官方文档没写的坑
- **本系列共 11 篇**:查看[科学计算器开发指南总目录](https://www.showapi.com/guides/calculator-guides-1699)