safan-lab / google
Google服务的Safan模块
1.0.0
2015-08-29 11:09 UTC
Requires
- php: >=5.4.0
This package is not auto-updated.
Last update: 2024-09-18 09:41:19 UTC
README
需求
PHP > 5.4.0
设置
如果您正在使用Composer来管理项目的依赖项,请在您的"composer.json"中添加以下内容
"require": {
"safan-lab/google": "1.*"
}
更新模块配置列表 - safan-framework-standard/application/Settings/modules.config.php
<?php
return [
...
'Google' => 'vendor/safan-lab/google/Google'
...
];
验证码
添加新的配置文件,文件名为 - safan-framework-standard/application/Settings/google.config.php 官方文档 - Google reCaptcha
<?php
return [
'captcha' => [
'siteKey' => 'your_site_key',
'secretKey' => 'your_secret_key'
]
];
对于渲染验证码,您可以使用Safan对象管理器
<?= \Safan\Safan::handler()->getObjectManager()->getInstance('Google\Google')->getService('captcha')->render() ?>
对于检查数据
<?php
// get post data
$captchaField = \Safan\GlobalData\Post::str('g-recaptcha-response');
// check data
$googleCaptchaService = \Safan\Safan::handler()->getObjectManager()->getInstance('Google\Google')->getService('captcha');
$response = $googleCaptchaService->check($captchaField);
if($response['status'] === false)
return $response['message'];
?>