How to generate an oauth signature in PHP ( convert python to php ) -
i need convert python function php (oauth signature)
def generate_signature(method, url, data): data['client_id'] = client_id sorted_keys = sorted(data.keys()) message = '&'.join(["%s=%s" % (k, urllib.quote_plus(data[k])) k in sorted_keys]) message = "%s&%s&%s" % (method.upper(), urllib.quote_plus(url), message) signature = hmac.new(client_secret, message.encode('utf-8'), hashlib.sha256).hexdigest() return signature
so far have
private function buildbasestring($baseuri, $method, $params) { $return = array(); ksort($params); foreach($params $key=>$value) { $return[] = "$key=" . $value; } return $method . "&" . rawurlencode($baseuri) . '&' . rawurlencode(implode('&', $return)); } if (!is_null($getfield)) { $getfields = str_replace('?', '', explode('&', $getfield)); foreach ($getfields $g) { $split = explode('=', $g); $oauth[$split[0]] = $split[1]; } } $base_info = $this->buildbasestring($url, $requestmethod, $oauth); $composite_key = rawurlencode($consumer_secret) . '&'; $oauth_signature = base64_encode(hash_hmac('sha1', $base_info, $composite_key, true)); return $oauth_signature;
however reasons doesn't work . ?
Comments
Post a Comment