摘录自底部第13页:
https://www.textbroker.com/wp-content/uploads/2018/10/API_Documentation_EN_V1.3.7.pdf
API的结构
此API中的基本功能位于四个不同的位置 位置。
•LoginService•budgetOrderService•budgetOrderChangeService •budgetProofreadingService
要调用每个函数,我们首先需要创建API的对象 其中包含API的URL和功能的位置 要打电话。
$apiUrl = 'https://api.textbroker.com/Budget/';
$location = 'https://api.textbroker.de/Budget/loginService.php';
$options = array(
'location' => $location,
'uri' => $apiUrl
);
$client = new SoapClient(null, $options);
我已经建立了SOAP客户端来尝试直接调用budgetOrderService
,并且它可以与以下代码一起使用,但是响应显示我的登录名不正确(不是),因此我假设它需要我执行{每次{1}}。当我尝试调用LoginService WSDL时,好像它不存在。
doLogin
从我测试过的所有东西开始,soap.createClient期望的是 // exports for routes
exports.getPendingOrders = (req, res) => {
let args = {};
bcrypt.genSalt(6, (error, salt) => {
if (error) console.error(error);
args["salt"] = "1234AA"; // left this un-random for testing
bcrypt.hash(config.password, salt, null, (error, encrypted) => {
if (error) console.error(error);
args["token"] = encrypted;
args["budgetKey"] = config.budgetKey;
args["status-ID"] = 4;
soap.createClient(TEXTBROKER_BUDGET_LOGIN_WSDL, function(err, client) {
if (err) {
console.error(err);
}
res.send(client.describe()); // This fails, can't describe undefined.
// Below does not fail with the WSDL Digest, but responds not logged in.
// client.budgetOrderServiceService.budgetOrderServicePort.getOrdersByStatus(
// args,
// function(error, response) {
// res.send(response);
// }
// );
});
});
});
};
而不是String
,Array
或Object
,所以我有些困惑。我有什么办法可以解决这个问题?
答案 0 :(得分:0)
正确!服务分布在第13页的多个位置。要调用每个服务,您每次都需要传递您的凭据,通过调用服务完成 doLogin ,您不必分别调用它。因此,假设您要创建一个订单。 首先,您如下创建Soap客户端:
$apiUrl = 'https://api.textbroker.com/Budget/';
$location = 'https://api.textbroker.de/Budget/loginService.php';
$options = array(
'location' => $location,
'uri' => $apiUrl
);
$client = new SoapClient(null, $options);
设置您的凭据:
$salt = rand(0, 10000);
$password = '0123456';
$token = md5($salt . $password);
$budgetKey = 'abc12f6548930fe6ae53b';
然后调用服务并传递凭据
$category = 1053;//can be researched with getCategories
$title = "Siemens Cell Phone";
$desc = "Which would you choose and why?";
$min = 100;
$max = 200;
$stars = 3;
$deadline = 2; //has to be completed in 2 days after the author started writing
$response = $client->create($salt, $token, $budgetKey, $category, $title, $desc, $min, $max, $stars, $deadline);
if ($response['error'] == null) {
echo "Order created with the following ID: " . $response['budget_order_id'];
$response2 = $client->getStatus( $salt, $token, $budgetKey, $response['budget_order_id']);
echo "\nType: ".$response2['budget_order_type']. ", Status: " . $response2['budget_order_status'];
} else {
echo $response['error'];
}
现在致电其他服务:
$response = $client->getOrdersByStatus($salt, $token, $budgetKey, 4);
echo "Order List: " . implode(',', $response);
如果要从其他位置拨打服务,请确保调整客户的位置。