使用用户名和密码进行身份验证。 用户名不能更改,必须使用service-admin,缺省密码为123456,可以通过修改CtpConfig系统参数配置的webservice.password值修改密码。
为了设置方便,缺省情况下密码使用明文保存,如果为了安全,可以将webservice.password.encode设置为1,在webservice.password保存密码的MD5值。
方法:authenticate
参数
参数 | 数据类型 | 说明 |
username | string | 服务用户名 |
password | string | 服务用户密码 |
返回值
UserToken
返回身份验证令牌。返回的令牌可以多次使用,有效期为15分钟,每一次有效请求令牌的有效期延长10分钟,最长15分钟;没有必要每次请求前都登录。
示例:
远程调用:完整例程请参考AuthorityServiceTest.authenticate
AuthorityServiceStub.Authenticate req = new AuthorityServiceStub.Authenticate(); req.setUserName("service-admin"); req.setPassword("123456"); AuthorityServiceStub stub = new AuthorityServiceStub(); AuthorityServiceStub.AuthenticateResponse resp = stub.authenticate(req); AuthorityServiceStub.UserToken token = resp.get_return(); if(token.getId()!=-1){ ..... }
本地调用:
import ***.***.***; ... AuthorityService service = new AuthorityServiceImpl(); UserToken token = service.authenticate(userName, password);