我想测试一个Api函数,但Post方法发送null作为争论。这是我的代码
public function testPOST() {
require 'vendor/autoload.php';
// create our http client (Guzzle)
$client = new \GuzzleHttp\Client();
$data = array("MobileNumber" => "923024175176", "Type" => "mobile no validation");
$url = 'http://192.168.8.101/ren-money/index.php/OTP/generateOTPbyType';
$response = $client -> post($url, $data);
echo $response -> getBody();
$this -> assertEquals(1, (int)$result["StatusCode"]);
}
我想通过该函数访问状态代码发送给客户端,但我得到{“错误”:“太少或错误的参数”}而是,它告诉我Api函数是发送给我的,因为null parameters ..这是Api函数
public function generateOTPbyType_post() {
//getting number from post
$Number = $this -> post("MobileNumber");
//getting type from post
$Type = strtolower($this -> post("Type"));
//Generating 6 digit Random number
$Pin = random_string('numeric', 6);
//checking weather all/requied parametters are provided correctly
if ($Number === NULL || $Type === NULL) {
$this -> response(array("StatusCode" => "2", "Description" => "Too few or wrong Arguments"));
//return 2;
}
//infoBip SDK code for sending pin to user
$Client = new infobip\api\client\SendSingleTextualSms(new infobip\api\configuration\BasicAuthConfiguration("husnainMalik", "BlueRose"));
$RequestBody = new infobip\api\model\sms\mt\send\textual\SMSTextualRequest();
$RequestBody -> setFrom("InfoSMS");
$RequestBody -> setTo($Number);
//checking type
if ($Type === 'mobile no validation' || $Type === 'goods delivery' || $Type === 'goods receipt') {
$DbObj = array("number" => $Number, "key" => $Pin, "time" => (int)time(), "status" => "0", "type" => strtolower($Type));
//checking DB error and saving into DB
if ($this -> OTP_Model -> saveOTP($DbObj) === FALSE) {
$this -> response(array("StatusCode" => "2", "Description" => "Internal Db Error"));
//return 2;
}
//infoBip SDK setting parametters
$RequestBody -> setText("Your " . strtolower($Type) . " code: " . $Pin);
$Response = json_decode(json_encode($Client -> execute($RequestBody)));
$GrpName = $Response -> messages[0] -> status -> groupName;
$Discription = $Response -> messages[0] -> status -> description;
//InfoBip error handling
if ("REJECTED" === $GrpName) {
$this -> response(array("StatusCode" => "2", "Description" => $Discription));
//return 2;
} else {
$this -> response(array("StatusCode" => "1", "Description" => $Discription));
//return 1;
}
} else {
$this -> response(array("StatusCode" => "2", "Description" => "Invalid Type"));
//return 2;
}
}
请大家看一下