环境
我本地用的是thinkphp框架和guzzle
I'm using the thinkphp frame and guzzle locally.
安装guzzle
Install Guzzle
配置请求头、签名
我们需要准备api_key,secret_key,passphrase
We need to prepare api_key, secret_key, passphrace
api_key,secret_key,passphrase需要我们自己注册账号去申请
这是官方的要求 This is an official request OK-ACCESS-KEY字符串类型的APIKey。 OK-ACCESS-KEY string type APIKey. OK-ACCESS-SIGN使用HMAC SHA256哈希函数获得哈希值,再使用Base-64编码(请参阅签名)。 OK-ACCESS-SIGN uses the HMAC SHA256 Hashi function to obtain Hashi xff0c; again uses the Base-64 code xff08; see signature xff09; OK-ACCESS-TIMESTAMP发起请求的时间(UTC),如:2020-12-08T09:08:57.715Z OK-ACCESS-TIMESTAMP launch request time xff08; UTC) xff0c; e.g. xff1a; 2020-12-08T09:08:57.715Z OK-ACCESS-PASSPHRASE您在创建API密钥时指定的Passphrase。 OK-ACCESS-PASSPHRASE, which you specified when creating the API key. 所有请求都应该含有application/json类型内容,并且是有效的JSON。 All requests should contain application/json type & #xff0c; and are valid JSON. 签名 Sign OK-ACCESS-SIGN的请求头是对timestamp + method + requestPath + body字符串(+表示字符串连接),以及SecretKey,使用HMAC SHA256方法加密,通过Base-64编码输出而得到的。 OK-ACCESS-SIGN's request header is Timestamp & #43; method & #43; requestPath & #43; body & #xff08; & #43; for string connections & #xff09; & #xff0c; and SecretKey & #xff0c; encrypted by HMAC SHA256 method xff0c; obtained through Base-64 coded output. 如:sign=CryptoJS.enc.Base64.stringify(CryptoJS.HmacSHA256(timestamp + ‘GET’ + ‘/api/v5/account/balance?ccy=BTC’, SecretKey)) e.g. xff1a; sign= CryptoJS.enc. Base64.stringify (CryptoJS. HmacSHA256 (timestamp & #43; `GET' & #43; `api/v5/acaccount/balance?ccy= BTC', SecretKey)) 其中,timestamp的值与OK-ACCESS-TIMESTAMP请求头相同,为ISO格式,如2020-12-08T09:08:57.715Z。 Of which xff0c; Timestamp has the same value as OK-ACCESS-TIMESTAMP request head xff0c; is ISO format xff0c; e.g. 2020-12-08T09:08:57.715Z. method是请求方法,字母全部大写:GET/POST。 Method is the request method xff0c; all letters capitalise xff1a; GET/POST. requestPath是请求接口路径。如:/api/v5/account/balance requestPath is the path to the request interface. e.g. & #xff1a;/api/v5/account/balance body是指请求主体的字符串,如果请求没有主体(通常为GET请求)则body可省略。如:{“instId”:“BTC-USDT”,“lever”:“5”,“mgnMode”:“isolated”} body means the string & #xff0c of the subject of the request; if there is no subject & #xff08; usually request & #xff09 for GET; and body can be omitted. e.g. & #xff1a; {InstID: {BTC-USDT" ), "lever": 5, "mgnMode":isolated} 请求国外接口需要配置一个代理,我这边本地配置了VPN,所以用的是本地的代理 Request an external interface to configure an agent & #xff0c; I localize VPN, so use local agents Res是一个返回类 Res is a returned class okx.php控制器类 kx.php controller class 配置路由 Configure route 返回结果 returns result
发起请求
所有REST私有请求头都必须包含以下内容:
to initiate a request
that all REST private requesters must include the following xff1a;
生成签名
Generate signature设置签名
配置代理
全部代码
res.php
res.php
route/app.php
route/app.php
发表评论