我在php系统上工作,客户端必须插入他的sms api信息才能让系统自动发送sms,因此,如果您希望SMS API的参数不同,例如clickatell api需要APIKEY,Message,Phone参数才能将其插入像这样的
http://api.clickatell.com/http/sendmsg?apiKey=xxxxxxxxxxxxxx&message=hello &phone=2331212312
但是其他人的SMS API使用具有这样不同参数的xml代码或jsondata发送短信
<Information>
<UserNAme>xxxxx</UserNAme>
<Password>xxxxx</Password>
<Subject>Hello</Subject>
</Information>
<Process>
<Send>
<Message>TEST Message</Message>
<NO>5394153105</NO>
</Send>
</Process>';
您看到第一个使用http请求发送短信的API,另一个使用json数据发送短信的API,那么如何让用户设置他的SMS Api信息并让他自动发送SMS。
答案 0 :(得分:0)
您应该从<form>
获取用户数据,然后将HTTP请求发送到API。
// $_GET as example, you can use $_POST
$myUserApiKey = $_GET['userInputapiKey'];
$myUserMessage = $_GET['userInputMessage'];
$myUserPhone = $_GET['userInputPhone'];
$serverResponse = http_get("http://api.clickatell.com/http/sendmsg", array("apiKey"=>$myUserApiKey, "message"=>$myUserMessage, "phone"=>$myUserPhone ));
switch ($serverResponse) {
// Handle API response here
}
如果您需要使用名称不同的参数处理多个API,则可以选择:
如果要选择第一个解决方案,它应该类似于:
// $_GET as example, you can use $_POST
$apiToUse = $_GET['userApiChoice']; // Can be a HTML <input type="radio"> with a value
$myUserApiKey = $_GET['userInputapiKey'];
$myUserMessage = $_GET['userInputMessage'];
$myUserPhone = $_GET['userInputPhone'];
if ($apiToUse == 1) { // We use the first API
$serverResponse = http_get("http://api.clickatell.com/http/sendmsg", array("apiKey"=>$myUserApiKey, "message"=>$myUserMessage, "phone"=>$myUserPhone ));
switch ($serverResponse) {
// Handle API response here
}
} else if ($apiToUse == 2) {
// Implement Other API Here
} else {
// Here's an unknown API.. Handle that error here
}