码学堂商户接入指南
1. 概述与接入流程
2. 题目加载接口指南
3. 提交判题接口指南
4. 测评结果查询接口指南
5. 知识点加载接口指南
6. 知识点管理接口指南
7. 题目管理接口指南
选项格式说明
编程语言对应说明
8. 编程题、函数题、程序填空题批量上传测试数据集
9. 商户授权说明
-
+
home page
3. 提交判题接口指南
## 3.1 概述 码学堂支持除主观题型外的7种题型自动判题服务,各类题目提交答案的规则不同。 ## 3.2 请求地址及方式 请求地址:`https://mp.api.maxuetang.cn/solve` 请求方式:`POST` ## 3.3 提交请求参数说明 | 序号 | 参数 | 名称 | 是否必须提供 |描述 | | :----: | :----: | :----: | :----: |:---- | | 01 | merchant_id | 商户号 | 是 | | | 02 | ptype | 题目类型 | 是| {1,2,3,...,8},1:判断题、2:单项选择题、3:多项选择题、4:填空题、5:程序函数题、6:程序填空题、7:编程题、8:主观题| | 03 | sign | 签名 | 是 | SHA256签名 | | 04 | pid | 题目ID | 是 | 整型,指定时仅返回当前题目 | | 05 | ans | 学生答案 | 是 | JSON字符串,不同题型格式不同,长度不能超过8000个字符| | 06 |timestamp|时间戳|否|长整型数| |07|order_id|商户提交编号|是|商户端系统唯一编号| ## 3.4 返回结果参数说明 | 序号 | 参数 | 名称 | 描述 | | :---- | :----: | :----: |:---- | |01|success|成功标识|true 或 false| |02|msg|消息|返回执行消息| |03|data|数据|返回数据对象| |04|merchant_order_id|商户提交编号|原样返回商户提交编号| |05|attach_ids|程序填空题提交ID|每个空对应一个提交ID,以“,“分隔| |06|ptype|题目类型|| |07|result|判题结果|0:未判,1:待重判,2:正在编译(程序题),3:正在判题中,4:答案正确,5:输出格式错误,6:答案错误,7:运行超时,8:内存超限,9:输出超限,10:运行错误,11:编译错误(编程题),12:编译成功,20:部分正确| |08|score|得分|判题得分| |09|solve_id|判题ID|码学堂判题ID| |10|time|判题时间戳|| |11|sign|签名|码学堂返回签名| |12|ans|答案|| |13|error|编译错误信息|程序题编译错误时返回| ## 3.4 JAVA接入示例 ```java package com.mxt.problem.load; import java.util.Map; import java.util.TreeMap; import com.mxt.config.MxtApiConfig; import com.mxt.sign.SignHelper; import cn.hutool.http.HttpUtil; import cn.hutool.json.JSONObject; public class ProblemSolve { public static JSONObject solveProblem(int pid, int ptype, String ans) { Map params = new TreeMap(); params.put("merchant_id", MxtApiConfig.MERCHANT_ID); params.put("ptype" , ptype); params.put("pid" , pid); params.put("order_id" , System.currentTimeMillis()); params.put("timestamp" , System.currentTimeMillis()); params.put("ans" , ans); params.put("sign" , SignHelper.sign(params, MxtApiConfig.MERCHANT_KEY)); return new JSONObject(HttpUtil.post(MxtApiConfig.PROBLEM_SOLVE_API, params)); } } ``` ## 3.5 判断题判题接入指南 ### 3.5.1 请求参数ans格式 `{"1":0,"0":1}` 说明:key为1表示“对”,key为0表示“错”,value为1表示“已选择”,value为0表示“未选择”。 ### 3.5.2 JAVA示例 (1) 请求代码 ```java int pid=9203; int ptype=1; String ans = "{\"1\":0,\"0\":1}"; String result = ProblemSolve.solveProblem(pid, ptype, ans).toString(); ``` (2) 返回json ```json { "success": true, "msg": "", "data": { "result": "6", "score": "0", "merchant_order_id": "1649214667335", "success": "OK", "ans": {"0":1,"1":0}, "sign": "f95cdd7a1defa3dfa299...216d3dbdd1e4", "pid": "9203", "ptype": "1", "merchant_id": "82040611338", "time": "20220406111107", "attach_ids": "", "solve_id": "53445073012073002" } } ``` ## 3.6 选择题判题接入指南 选择题分为单项选择题与多项选择题,提交判题答案格式相同。 ### 3.6.1 请求参数ans格式 `{"A":0,"B":0,"C":0,"D":1}` 说明:key为选项,value为1表示“已选择”,value为0表示“未选择”。 ### 3.6.2 JAVA示例 (1) 请求代码 ```java int pid=8528; int ptype=2; String ans = "{\"A\":0,\"B\":0,\"C\":0,\"D\":1}"; String result = ProblemSolve.solveProblem(pid, ptype, ans).toString(); ``` (2) 返回json ```json { "success": true, "msg": "", "data": { "result": "6", "score": "0", "merchant_order_id": "1649234492083", "success": "OK", "ans": {"A":0,"B":0,"C":0,"D":1}, "sign": "d7800c1af5dbf...da81b907f", "pid": "8528", "ptype": "2", "merchant_id": "804061648", "time": "20220406164132", "attach_ids": "", "solve_id": "80900261341122902" } } ``` ## 3.7 填空题判题接入指南 ### 3.7.1 请求参数ans格式 `{"1":"模型","2":"视图","3":"控制器"}` 说明:key为第几个空,value为答案。 ### 3.7.2 JAVA示例 (1) 请求代码 ```java int pid = 8369; int ptype = 4; String ans = "{\"1\":\"模型\",\"2\":\"视图\",\"3\":\"控制器\"}"; String result = ProblemSolve.solveProblem(pid, ptype, ans).toString(); ``` (2) 返回json ```json { "success": true, "msg": "", "data": { "result": "4", "score": "3", "merchant_order_id": "1649239248823", "success": "OK", "ans": {"1":{"result":1,"score":1,"ans":"模型"},"2":{"result":1,"score":1,"ans":"视图"},"3":{"result":1,"score":1,"ans":"控制器"}}, "sign": "a1d1d0ad768677ce8...f5ae3497bad23584", "pid": "8369", "ptype": "4", "merchant_id": "88", "time": "20220406180049", "attach_ids": "", "solve_id": "16019591061505260" } } ``` ## 3.8 程序填空题判题接入指南 ### 3.8.1 请求参数ans格式 `{"language":"c","length":3,"1":"a,+low,+mid-1,+k","2":"a,+mid+1,+high,+k+","3":"-1"}` 说明:key为第几个空,value为答案,language为提交语言,length为“空”的个数。 ### 3.8.2 JAVA示例 (1) 请求代码 ```java int pid = 7789; int ptype = 5; String ans = "{\"language\":\"c\",\"length\":3,\"1\":\"a,+low,+mid-1,+k\",\"2\":\"a,+mid+1,+high,+k+\",\"3\":\"-1\"}"; String result = ProblemSolve.solveProblem(pid, ptype, ans).toString(); ``` (2) 返回json ```json { "success": true, "msg": "", "data": { "result": "0", "score": "0", "merchant_order_id": "1649253219385", "success": "OK", "ans": {"1":{"score":0,"ans":"a, low, mid-1, k"},"2":{"score":0,"ans":"a, mid+1, high, k "},"3":{"score":0,"ans":"-1"},"length":3,"language":"c"}, "sign": "25d6ced5a696b115...ed9981cc0c157b35cec5f", "pid": "7789", "ptype": "5", "merchant_id": "89998", "time": "20220406215339", "attach_ids": "655273,655274,655275", "solve_id": "10549111912095337" } } ``` (3) 程序填空题提交后,需要等待程序测评服务器测评后返回结果,属于异步执行,因此,需要执行查询接口方可查看测评结果,程序测评结果查询请参考《[测评结果查询接口指南](http://help.maxuetang.cn/modify_doc/62/ "测评结果查询接口指南")》。 ## 3.9 函数题判题接入指南 ### 3.9.1 请求参数ans格式 `{"language":"c","source":"int fun(int a,int b){\n return a+b;\n}"}` 说明:language为提交语言,source为程序代码。 提交语言的映射如下: ```json { "c": "C", "cc": "C++", "pas": "Pascal", "java": "java", "rb": "Ruby", "sh": "Bash", "py": "Python3", "php": "Php", "pl": "Perl", "cs": "C#", "m": "Obj-C", "bas": "FreeBasic", "scm": "Scheme", "lua": "Lua", "js": "JavaScript", "go": "Go", "sql": "SQL(sqlite3)", "f95": "Fortran", "mt": "Matlab(Octave)" } ``` ### 3.9.2 JAVA示例 (1) 请求代码 ```java int pid = 1412; int ptype = 6; String ans = "{\"language\":\"c\",\"source\":\"int fun(int a,int b){\\n return a+b;\\n}\"}"; String result = ProblemSolve.solveProblem(pid, ptype, ans).toString(); ``` (2) 返回json ```json { "success": true, "msg": "", "data": { "result": "0", "score": "0", "merchant_order_id": "1649323310615", "success": "OK", "ans": { "language": "c", "source": "int fun(int a,int b){\n return a+b;\n}" }, "sign": "5358c2decba86b0...b30aa896e2f89a27cbd896", "pid": "1412", "ptype": "6", "merchant_id": "88", "time": "20220407172150", "solve_id": "655431" } } ``` (3) 函数题提交后,需要等待程序测评服务器测评后返回结果,属于异步执行,因此,需要执行查询接口方可查看测评结果,程序测评结果查询请参考《[测评结果查询接口指南](http://help.maxuetang.cn/modify_doc/62/ "测评结果查询接口指南")》。 ## 3.10 编程题判题接入指南 ### 3.10.1 请求参数ans格式 `{"language":"c","source":"int fun(int a,int b){\n return a+b;\n}"}` 说明:language为提交语言,source为程序代码。 提交语言的映射详见3.9.1 ### 3.10.2 JAVA示例 (1) 请求代码 ```java int pid = 1008; int ptype = 7; String ans = "{\"language\":\"c\",\"source\":\"int fun(int a,int b){\\n return a+b;\\n}\"}"; String result = ProblemSolve.solveProblem(pid, ptype, ans).toString(); ``` (2) 返回json ```json { "success": true, "msg": "", "data": { "result": "0", "score": "0", "merchant_order_id": "1649326731854", "success": "OK", "ans": { "language": "cc", "source": "#include<iostream>\nusing namespace std;\nconst int N=1e5;\nint n,r,num=-1;\nint a[N];\nchar alp[10]={'A','B','C','D','E','F','G','H','I'};\nvoid print(int x){\n if(x<10) cout<<x;\n else cout<<alp[x-10];\n}\nint main(){\n cin>>n>>r;\n cout<<n<<\"=\";\n while(n!=0){\n a[++num]=n%r;\n n/=r;\n if(a[num]<0) a[num]-=r,n++;\n //cout<<a[num]<<\"\\n\";\n }\n for(int j=num;j>=0;j--) if(a[j]!=0||j!=num) print(a[j]);\n \n cout<<\"(base\"<<r<<\")\";\n}" }, "pid": "1008", "ptype": "7", "merchant_id": "88", "time": "20220407181851", "solve_id": "655435" } } ``` (3) 编程题提交后,需要等待程序测评服务器测评后返回结果,属于异步执行,因此,需要执行查询接口方可查看测评结果,程序测评结果查询请参考《[测评结果查询接口指南](http://help.maxuetang.cn/modify_doc/62/ "测评结果查询接口指南")》。 ## 3.11 主观题判题接入指南 ### 3.10.1 请求参数ans格式 `{"ans":"答案"}` ### 3.10.2 JAVA示例 (1) 请求代码 ```java int pid = 8543; int ptype = 8; String ans = "{\"ans\":\"答案\"}"; String result = ProblemSolve.solveProblem(pid, ptype, ans).toString(); ``` (2) 返回json ```json { "success": true, "msg": "", "data": { "result": "0", "score": "0", "merchant_order_id": "1649326583062", "success": "OK", "ans": { "ans": "答案" }, "sign": "104a1e58f673...188b8ad5a424b2b5a97a59bba2", "pid": "8543", "ptype": "8", "merchant_id": "88", "time": "20220407181623", "solve_id": "32433312104014822" } } ``` (3) 主观题提交后,仅作存储,不支持主观题自动判题。
码学堂管理员
April 9, 2022, 6:03 p.m.
Share documents
Collection documents
Last
Next
Scan wechat
Copy link
Scan your mobile phone to share
Copy link
关于 MrDoc
觅思文档MrDoc
是
州的先生
开发并开源的在线文档系统,其适合作为个人和小型团队的云笔记、文档和知识库管理工具。
如果觅思文档给你或你的团队带来了帮助,欢迎对作者进行一些打赏捐助,这将有力支持作者持续投入精力更新和维护觅思文档,感谢你的捐助!
>>>捐助鸣谢列表
微信
支付宝
QQ
PayPal
Markdown文件
share
link
type
password
Update password