【发布时间】:2017-12-04 08:32:35
【问题描述】:
我必须使用 Google Apps 脚本发出 url 请求,为此,我需要使用 sha 1 算法和 base64 编码对我的登录名和密码进行编码。在请求的文档中,我有以下 php 代码:
$string = "loginpassword2017-15-04T09:25:00";
$hash = sha1($string, true);
$hash = base64_encode($hash);
所以在 Google Apps 脚本中,我使用以下代码:
function GetSHA1(input) {
var rawHash = Utilities.computeDigest(Utilities.DigestAlgorithm.SHA_1, input);
var txtHash = '';
for (j = 0; j <rawHash.length; j++) {
var hashVal = rawHash[j];
if (hashVal < 0)
hashVal += 256;
if (hashVal.toString(16).length == 1)
txtHash += "0";
txtHash += hashVal.toString(16);
}
return txtHash;
}
然后是函数
Utilities.base64Encode
最后我发出了 url 请求,但身份验证不成功。有人知道如何在 Google Apps Script 中执行 php sha1 和 base64encode 吗?谢谢
【问题讨论】:
-
“身份验证不成功”是什么意思?
-
这是一个连接到 web 服务的 url 请求我实际上发现了问题,我在谷歌应用程序脚本上测试的不同 sha1 与 php 不同(我在 php 中测试了加密并在谷歌应用程序脚本,它工作)
-
现在我的问题是找到一个与 php 相同的 google apps 脚本