目前,我能够在部署代码后写入数据存储区,但是我无法使用本地代码写入数据存储区模拟器,因为它会引发ca-bundle错误。本地数据存储在localhost:8000
中可见use google\appengine\api\users\User;
use google\appengine\api\users\UserService;
use google\appengine\api\app_identity\AppIdentityService;
echo AppIdentityService::getApplicationId()."<br>";
echo AppIdentityService::getDefaultVersionHostname()."<br>";
# Includes the autoloader for libraries installed with composer
require __DIR__ . '/vendor/autoload.php';
use Google\Cloud\ServiceBuilder;
$cloud = new ServiceBuilder([
'projectId' => AppIdentityService::getApplicationId(),
'keyFilePath'=>'review-9504000716d8.json'
]);
$datastore = $cloud->datastore();
# The kind for the new entity
$kind = 'Task';
# The name/ID for the new entity
$name = 'sampletask1';
# The Cloud Datastore key for the new entity
$taskKey = $datastore->key($kind, $name);
# Prepares the new entity
$task = $datastore->entity($taskKey, ['description' => 'Buy milk']);
# Saves the entity
$datastore->upsert($task);
此代码在部署时运行时没有任何问题。但在当地引发:
Fatal error: Uncaught exception 'Google\Cloud\Exception\ServiceException' with message 'No system CA bundle could be found in any of the the common system locations. PHP versions earlier than 5.6 are not properly configured to use the system's CA bundle by default. In order to verify peer certificates, you will need to supply the path on disk to a certificate bundle to the 'verify' request option: http://docs.guzzlephp.org/en/latest/clients.html#verify. If you do not need a specific certificate bundle, then Mozilla provides a commonly used CA bundle which can be downloaded here (provided by the maintainer of cURL): https://raw.githubusercontent.com/bagder/ca-bundle/master/ca-bundle.crt. Once you have a CA bundle available on disk, you can set the 'openssl.cafile' PHP ini setting to point to the path to the file, allowing you to omit the 'verify' request option. See http://curl.haxx.se/docs/sslcerts.html for more information.' in D:\Google\php\appengine-php-guestbook-phase0-helloworld\appengine-php-guestbook-phase0-hellowo in D:\Google\php\appengine-php-guestbook-phase0-helloworld\appengine-php-guestbook-phase0-helloworld\vendor\google\cloud\src\RequestWrapper.php on line 219
我没有设法使本地服务器甚至考虑php.ini文件,也没有设法将捆绑的php55升级到至少php56。
因此我实际上有两个问题:
答案 0 :(得分:1)
API使用CA证书文件进行身份验证,更具体地说,他们正在使用@Transient
public Set<ManagedApplication> getManagedApplications() {
if (this.managedApplications.isEmpty()) {
this.managedApplications = this.managedApplicationToContacts.stream()
.map(ManagedApplicationToContact::getManagedApplication)
.collect(Collectors.toSet());
}
return this.managedApplications;
}
。
现在您的服务器可能已经在 php.ini 中配置了此文件。您可以签入服务器文件。请记住,对于不同的环境,例如apache,cli,可能会有不同的ini文件。
现在您可以复制该文件或Create your own authority file
选项1:
在php.ini中设置绝对路径
选项2:
使用curl.cainfo
设置此配置。
选项3:
尝试使用其他一些身份验证模式,我相信谷歌会有这种模式。
选项4:
正如你的问题本身所示。
如果您不需要特定的证书捆绑包,则Mozilla会提供常用的CA捆绑包,可以在此处下载 https://raw.githubusercontent.com/bagder/ca-bundle/master/ca-bundle.crt。在磁盘上提供CA捆绑后,您可以设置&#39; openssl.ca文件&#39; PHP ini设置指向文件的路径,允许您省略&#39;验证&#39;请求选项