如何使用第三方api的结果并在其中添加参数



我想将今天的日期转换为hijri日期。为此,我得到代码点火器今天的天,月和年分别。例如,url(在线api(在hijri中显示今天的日期。我们在其中传递今天的日期、年份和月份。

https://hilalcommittee.org/api/hijridates/gethijridate?year=2020&month=2&day=20

并将结果显示为

{"hijridate":"28 Jumada al-Ukhra 1441"}

现在我想使用这个网址

https://hilalcommittee.org/api/hijridates/gethijridate?

并添加参数"年"、"月"one_answers"日",动态获取hijri日期。请看一下我的代码。

控制器类别:

//show Hijri today's date
public function todayHijriDate()
{
$data = json_decode(file_get_contents('php://input'));
$result = $this->hpm->todayHijriDate();
echo json_encode($result);    
}

型号类别:

public function todayHijriDate(){
$getTodatDate = new DateTime("now");
$print_getTodatDat = $getTodatDate->format('d M Y '); // will print local date like 20 Feb 2020.
$month = date('M');
$year = date('Y');
$monthDay = date('d');
$path = "https://hilalcommittee.org/api/hijridates/gethijridate?year=$year&month=$month&day=$monthDay";
return $path;
}

现在的问题是它目前正在返回这个结果。

"https://hilalcommittee.org/api/hijridates/gethijridate?year=2020&month=Feb&day=20"

请帮帮我。

我认为您可以尝试使用http_buil_query来构建$path

https://www.php.net/manual/en/function.http-build-query.php

public function todayHijriDate(){
$getTodatDate = new DateTime("now");
$print_getTodatDat = $getTodatDate->format('d M Y '); // will print local date like 20 Feb 2020.
$month = date('M');
$year = date('Y');
$monthDay = date('d');
$query = http_build_query([
'month'=>$month,
'year'=>$year,
'day'=>$monthDay
]) . "n"
$path = "https://hilalcommittee.org/api/hijridates/gethijridate?".$query;
return $path;
}

或者您可以尝试return urlencode(path)

相关内容

  • 没有找到相关文章

最新更新