我正在尝试实现DudaMobile API白标自助服务解决方案:https://support.dudamobile.com/API/API-Use-Cases/White-Label-Self-Service
我有一个表单,用户填写的名字和姓氏,电子邮件和网站地址,他们想要导入到移动构建器。
形式代码:
<form action="mobile.php" method="post">
E-mail: <input type="text" name="email"><br>
First Name: <input type="text" name="firstname"><br>
Last Name: <input type="text" name="lastname"><br>
Existing Website URL to Import <input type="text" name="site"><br>
<input type="submit">
</form>
PHP代码获取POST值到变量:
// Here you should define the sub account name, the first name and the last name
$accountName = $_POST["email"];
$firstName = $_POST["firstname"];
$lastName = $_POST["lastname"];
$site = $_POST["site"];
API一直工作到第2步,它尝试从$site变量或post数据$_POST["site"]调用站点URL。
// define the site url you would like to provide. We are using moeplumbing.com as an example here
$data = '
{
"site_data":
{
"original_site_url":"{original_site_url}"
}
}
';
我试过用$site, "site"或$_POST["site"]和不同的引号,点和括号的每个组合替换{original_site_url},我要么得到语法错误,无法识别的令牌错误或没有这样的URL错误。我甚至试过用数组来代替,但没有成功。
给original_site_url $site变量的值的正确语法是什么?
明白了。JSON调用变量的正确格式是:
"original_site_url":"'.$site.'"
您还可以转义JSON中的双引号,以便您可以引用内联变量:
// define the site url you would like to provide. We are using moeplumbing.com as an example here
$data = "
{
'"site_data'":
{
'"original_site_url'":'"$site'"
}
}
";