0
我正在嘗試將我的網站與Ecwid集成,以便我的用戶可以擁有無縫的購物體驗。 Ecwid舉例說明了如何使用PHP對有效載荷進行編碼,然後通過JavaScript發送數據。我需要一個Python/Django實現。該Ecwid例子可以在這裏找到:http://api.ecwid.com/#sso-payloadEcwid SSO與django集成
Ecwid例如:
import time, hmac
from hashlib import sha1
def ecwid_sso(request):
sso_password = "XXXXXXXXXX"
message = base64.b64encode("{appId:'bc',userId:'123',profile:{email:'[email protected]'}}")
time_stamp = time.time()
payload = hmac.new(sso_password, "%s %s" %(message,time_stamp), sha1).hexdigest()
template_data = {'message':message,'payload':payload, 'timestamp':time_stamp}
return render_to_response("site/ecwid.html", template_data, context_instance=RequestContext(request))
HTML/JavaScript的輸出:
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title>Ecwid test</title>
</head>
<body>
<script src="http://app.ecwid.com/script.js?1003"></script>
<script>
var ecwid_sso_profile = '{{ message }} {{ payload }} {{ timestamp }}' ;
window.Ecwid.setSsoProfile(ecwid_sso_profile);
</script>
</body>
</html>
的Ecwid腳本示例的
<?php
$sso_secret = "TEST";
$message = base64_encode("{appId:'123',userId:'234',profile:{email:'[email protected]'}}");
$timestamp = time();
$hmac = hash_hmac('sha1', "$message $timestamp", $sso_secret);
echo "<script> var ecwid_sso_profile = '$message $hmac $timestamp' </script>";
?>
我的Python/Django的翻譯
我從Ecwid得到的錯誤是「無法到達商店。請檢查您的互聯網連接。「這顯然不是真的,因爲我可以發送這篇文章。我認爲我很接近,但是,我目前的假設是,我沒有正確地打包我的負載?思考?