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得到的错误是“无法到达商店。请检查您的互联网连接。“这显然不是真的,因为我可以发送这篇文章。我认为我很接近,但是,我目前的假设是,我没有正确地打包我的负载?思考?