php - API函数OctoberCMS / Laravel
问题描述
各位下午。我正在尝试使用 VATLayer 来验证增值税号。
我有一个Organisation
有字段 的模型company_vat
我可以检查增值税号是否有效,如果有效,则返回成功消息。这看起来对吗?
我正在使用十月CMS。
public function onVatValidation()
{
$organisation = Organisation::find($this->param('id'));
// set API Endpoint and Access Key
$endpoint = 'validate';
$access_key = 'xxxxxxxxxxxxxxx';
// set VAT number
$vat_number = $organisation->company_vat;
// Initialize CURL:
$ch = curl_init('http://apilayer.net/api/'.$endpoint.'?access_key='.$access_key.'&vat_number='.$vat_number.''); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// Store the data:
$json = curl_exec($ch);
curl_close($ch);
// Decode JSON response:
$validationResult = json_decode($json, true);
// Access and use your preferred validation result objects
$validationResult['valid'];
$validationResult['query'];
$validationResult['company_name'];
$validationResult['company_address'];
Flash::success($organisation->name." has a valid VAT number.");
return Redirect::refresh();
}
解决方案
推荐阅读
- django - Django注销方法不起作用
- reactjs - 有条件地在特定路线和视口高度上渲染组件
- node.js - Discord.JS ReferenceError:未定义 stopTyping
- python - Discord.py ctx 命令没有响应
- r - 在 R 中使用 dplyr 重命名具有系列索引的多列
- java - java.util.Stack 和 java.util.ArrayDeque 中的 grow() 方法之间的区别
- python-3.x - 如何安全地停止无限循环以完成在 Python 中收集 Json 数据?
- bash - 运行 shell 脚本时出现条件二元运算符预期错误
- python - 熊猫打印条件在数据框列中成立的日期期间?
- apache - Fail2Ban 忽略本地重定向的 404