企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
## 1、获取 Accesstoken 后端可以调用这个接口再封装个接口,让自己业务系统的前端来获取 Accesstoken,appid 和 secret 为了安全和方便尽量放在后端使用,获取的 Accesstoken 用来做权限验证,比如下面接口的 Authorization 。 # ~~~[api:notDebug] get:/v1/token *appid=a44r4aMbO7BZ1NoW#申请的appid *secret=a4474wRq9BwujRV7hM4SGH0QMyrEJF5J#申请的appsecret *grant_type=client_credential#类型 <<< success { "accessToken": "a447bdDAUeKORvmt", "expires": 7200 } <<< 403 { "status": 403, "error": "SecretIsInvalid", "message": "无效的 secret" } ~~~ # ##### C#访问示例代码: ~~~CSharp var client = new RestClient("http://gateway.api.yun2win.com/v1/token?grant_type=client_credential&appid=a44r4aMbO7BZ1NoW&secret=a4474wRq9BwujRV7hM4SGH0QMyrEJF5J"); client.Timeout = -1; var request = new RestRequest(Method.GET); request.AlwaysMultipartFormData = true; IRestResponse response = client.Execute(request); Console.WriteLine(response.Content); ~~~ # ##### Java访问示例代码: ~~~ java OkHttpClient client = new OkHttpClient().newBuilder().build(); Request request = new Request.Builder() .url("http://gateway.api.yun2win.com/v1/token?grant_type=client_credential&appid=a44r4aMbO7BZ1NoW&secret=a4474wRq9BwujRV7hM4SGH0QMyrEJF5J") .method("GET", null) .build(); Response response = client.newCall(request).execute(); ~~~ # #### Nodejs访问示例代码: ~~~javascript var unirest = require('unirest'); var req = unirest('GET', 'http://gateway.api.yun2win.com/v1/token?grant_type=client_credential&appid=a44r4aMbO7BZ1NoW&secret=a4474wRq9BwujRV7hM4SGH0QMyrEJF5J') .end(function (res) { if (res.error) throw new Error(res.error); console.log(res.raw_body); }); ~~~ # ## 2、人脸检测请求 # ~~~[api:notDebug] post:/api/face-detect/detect *file:image=c:/a.png#上传的图片 <<< success [{ "score": 0.5605007451502193, "imageSize": { "width": 640, "height": 480     }, "area": { "x": 134.38352846986365, "y": 129.8811520064815, "width": 357.25394640532244, "height": 312.61737152315015         }     }] <<< 400 { "status": 400, "error": "FRS.0001", "message": "输入格式不正确" } <<< 401 错误一: { "status": 401, "error": "AccessTokenNoExist", "message": "必须有 accessToken" } 错误二: { "status": 401, "error": "AccessTokenIsInvalid", "message": "无效的 accessToken" } 错误三: { "status": 401, "error": "AccessTokenHasExpired", "message": "accessToken 已过期" } <<< 403 错误一: { "status": 403, "error": "SecretIsInvalid", "message": "无效的 secret" } 错误二: { "status": 403, "error": "SecretHasDisabled", "message": "secret 已被禁用" } 错误三: { "status": 403, "error": "SecretError", "message": "secret 状态异常" } 错误四: { "status": 403, "error": "LimitExceeded", "message": "已超出用量限制" } ~~~ # ##### C#访问示例代码: ~~~CSharp var client = new RestClient("http://gateway.api.yun2win.com/api/face-detect/detect"); client.Timeout = -1; var request = new RestRequest(Method.POST); request.AddHeader("Authorization", "Bearer a447bdDAUeKORvmt"); // 这里的a447bdDAUeKORvmt就是接口1取得的access_token request.AddFile("image", "/Users/test/Desktop/a.png"); IRestResponse response = client.Execute(request); Console.WriteLine(response.Content); ~~~ # ##### Java访问示例代码: ~~~ java OkHttpClient client = new OkHttpClient().newBuilder() .build(); MediaType mediaType = MediaType.parse("text/plain"); RequestBody body = new MultipartBody.Builder().setType(MultipartBody.FORM) .addFormDataPart("image","a.png", RequestBody.create(MediaType.parse("application/octet-stream"), new File("/Users/test/Desktop/a.png"))) .build(); Request request = new Request.Builder() .url("http://gateway.api.yun2win.com/api/face-detect/detect") .method("POST", body) .addHeader("Authorization", "Bearer a447bdDAUeKORvmt") // 这里的a447bdDAUeKORvmt就是接口1取得的access_token .build(); Response response = client.newCall(request).execute(); ~~~ # #### Nodejs访问示例代码 ~~~javascript var unirest = require('unirest'); var req = unirest('POST', 'http://gateway.api.yun2win.com/api/face-detect/detect') .headers({ 'Authorization': 'Bearer a447bdDAUeKORvmt' // 这里的a447bdDAUeKORvmt就是接口1取得的access_token }) .attach('file', '/Users/test/Desktop/a.png') .end(function (res) { if (res.error) throw new Error(res.error); console.log(res.raw_body); }); ~~~