接口描述
请求方式
POST
请求地址
https://127.0.0.1:8080/TransInitUrl (以实际提供接口地址为准)
请求头
属性名 | 类型 | 参数描述 |
Content-Type | String | application/json |
请求参数
let recorder = new TencentSOE({TransInitUrl: 'https://127.0.0.1:8080/TransInitUrl', //服务端获取评测结果地址WorkMode: 0,EvalMode: 1,success() {recorder.start({RefText: "I would like to eat an orange",});},error(err) {console.log(err);}});
请求示例
请求流程
Python 示例
使用 flask 框架,需要使用 pip 安装以下依赖。
tencentcloud-sdk-pythonflaskflask_corsgevent
示例代码:
import jsonfrom flask import Flask, request, render_templatefrom flask_cors import CORSfrom gevent import pywsgifrom tencentcloud.common import credentialfrom tencentcloud.common.profile.client_profile import ClientProfilefrom tencentcloud.common.profile.http_profile import HttpProfilefrom tencentcloud.common.exception.tencent_cloud_sdk_exception import TencentCloudSDKExceptionapp = Flask(__name__)CORS(app) # 允许跨域@app.route("/TransInitUrl", methods=["POST"]) # 通过该地址请求接口,推荐使用post方法def TransInitUrl():try:# 实例化一个认证对象,入参需要传入腾讯云账户secretId,secretKeycred = credential.Credential("", "")# 实例化一个http选项,可选的,没有特殊需求可以跳过。httpProfile = HttpProfile()httpProfile.reqMethod = "POST" # post请求(默认为post请求)httpProfile.reqTimeout = 30 # 请求超时时间,单位为秒(默认60秒)httpProfile.endpoint = "soe.tencentcloudapi.com" # 指定接入地域域名(默认就近接入)# 实例化一个client选项,可选的,没有特殊r需求可以跳过。clientProfile = ClientProfile()clientProfile.signMethod = "TC3-HMAC-SHA256" # 指定签名算法(默认为HmacSHA256)clientProfile.unsignedPayload = TrueclientProfile.httpProfile = httpProfilefrom tencentcloud.soe.v20180724 import soe_client, modelsclient = soe_client.SoeClient(cred, "", clientProfile)req = models.TransmitOralProcessWithInitRequest()req.from_json_string(json.dumps(request.json))# 请求服务,获取结果resp = client.TransmitOralProcessWithInit(req)json_resp = resp.to_json_string()# SDK 封装了返回结果。此处需要加上Responsereturn json.dumps({"Response": json.loads(json_resp)}) # 回调except TencentCloudSDKException as err:return errif __name__ == '__main__':server = pywsgi.WSGIServer(('0.0.0.0', 8080), app)server.serve_forever()
Node.js 示例
使用 express 框架,需要 npm 安装如下依赖。
npm install express cors tencentcloud-sdk-nodejs body-parser
示例代码
let express = require('express')let server = express();const cors = require('cors');server.use(cors());const bodyParser = require('body-parser');server.use(bodyParser());server.post('/TransInitUrl', (req, resp) => {const SoeClient = tencentcloud.soe.v20180724.Client;const clientConfig = {credential: {secretId: "",secretKey: "",},region: "ap-beijing",};const client = new SoeClient(clientConfig);client.TransmitOralProcessWithInit(req.body).then((data) => {resp.json({"Response":data})},(err) => {resp.json(err)});})server.listen(8080, () => {console.log('服务器已就绪')})module.exports = server;