企业🤖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、获取用户信息 人脸识别成功后,返回给客户端 `identityToken` ,客户端可以根据这个 `identityToken` 去自己的业务系统后端获取用户的信息,比如可以从后端获取到此人信息那么客户端就执行登录成功业务逻辑,若没有,那提示用户注册或者绑定,可根据自己的业务系统来具体实现。ps:此接口的在线调试暂不可用,`identityToken`是拼接在`url`后面的,而不是拼接在`url`后面的参数,所以此处需要开发者自己注意,不要搞错了。 # ~~~[api:notDebug] get:/api/face-login/account/:identityToken identityToken=9bqzkNIrbeEpA5Ar#身份token,由人脸识别成功返回的 <<< success { "id": "9bqzkNIrbeEpA5Ar", "uid": "f3292423", //富士康工号 "name": "张德强", //姓名 "expire": "2019-12-26T06:25:02.000Z", "createdAt": "2019-12-26T06:20:02.000Z", "updatedAt": "2019-12-26T06:20:02.000Z" } <<< 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": "已超出用量限制" } <<< 500 错误一: { error: "Identity_Token_Invalid", message: "identityToken无效", status:500 } 错误二: { error: "Identity_Token_In_Expire", message: "identityToken无效已过期", status:500 } ~~~ # ##### C#访问示例代码: ~~~CSharp var client = new RestClient("http://gateway.api.yun2win.com/api/face-login/account/9bqzkNIrbeEpA5Ar"); client.Timeout = -1; var request = new RestRequest(Method.GET); request.AddHeader("Authorization", "Bearer a447bdDAUeKORvmt"); // 这里的a447bdDAUeKORvmt就是接口1取得的access_token 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/api/face-login/account/9bqzkNIrbeEpA5Ar") .method("GET", null) .addHeader("Authorization", "Bearer a447bdDAUeKORvmt") // 这里的a447bdDAUeKORvmt就是接口1取得的access_token .build(); Response response = client.newCall(request).execute(); ~~~ # #### Nodejs访问示例代码: ~~~javascript var unirest = require('unirest'); var req = unirest('GET', 'http://gateway.api.yun2win.com/api/face-login/account/9bqzkNIrbeEpA5Ar') .headers({ 'Authorization': 'Bearer a447bdDAUeKORvmt' // 这里的a447bdDAUeKORvmt就是接口1取得的access_token }) .end(function (res) { if (res.error) throw new Error(res.error); console.log(res.raw_body); }); ~~~