RESTful API에 연결해야합니다. 회사가 API에 연결하는 유일한 예는 Python의 예입니다. 나는 언어를 이해하지 못하지만 PHP는 편합니다. cuRL 및/또는 PHP로이 작업을 수행 할 수있는 방법이 있습니까?python API 예제를 PHP로 변환
import requests
import hmac
import hashlib
import datetime as dt
import simplejson as json
import sys
tech_prefix = '' #the Account Tech Prefix
secret_key = '' #the API Key
#creating URI info
t = dt.datetime.utcnow().replace(microsecond=0)
timestamp = t.isoformat()
url_scheme = 'https'
net_location = 'api.thesite.com'
path = '/v1/available-tns/npas/'
method = 'GET'
ordered_query_params = ''
body = ''
body_md5 = ''
canonical_uri = url_scheme + "://" + net_location + path + "\n" + ordered_query_params
tokens = (
timestamp,
method,
body_md5,
canonical_uri
)
message_string = u'\n'.join(tokens).encode('utf-8')
signature = hmac.new(secret_key, message_string, digestmod=hashlib.sha1).hexdigest()
headers = {'X-Timestamp':timestamp}
request_url = url_scheme + '://' + net_location + path + '?' + ordered_query_params # append ordered query params here
request = requests.get(request_url,auth=(tech_prefix,signature),headers=headers)
print request
+1 가능했으나하지 않았 음을 확인했습니다. –
고마워, 나는 종종 곱슬 곱슬 함을 사용하지만이 API는 시간 스탬프를 필요로하고 응답 코드를 다시 보내는 API 키를 해시해야하므로 필자는 분실했다. 나는이 코드를 PHP 나 curl 예제로 변환해야이 코드를 기반으로해야한다고 생각한다. –