{"id":433,"date":"2025-03-19T02:22:29","date_gmt":"2025-03-18T17:22:29","guid":{"rendered":"https:\/\/shugomatsuzawa.com\/techblog\/?p=433"},"modified":"2025-03-19T02:40:26","modified_gmt":"2025-03-18T17:40:26","slug":"%e6%96%b0%e3%81%97%e3%81%84recaptcha-google-cloud-%e3%82%92php%e3%81%a7%e5%ae%9f%e8%a3%85%e3%81%97%e3%81%a6%e3%81%bf%e3%81%9f","status":"publish","type":"post","link":"https:\/\/shugomatsuzawa.com\/techblog\/2025\/03\/19\/433\/","title":{"rendered":"\u65b0\u3057\u3044reCAPTCHA (Google Cloud) \u3092PHP\u3067\u5b9f\u88c5\u3057\u3066\u307f\u305f"},"content":{"rendered":"\n<p>\u65b0\u3057\u304f\u306a\u3063\u305freCAPTCHA (Google Cloud) \u3092\u3001\u81ea\u524d\u3067\u5b9f\u88c5\u3057\u3066\u307f\u305f\u3002<br>reCAPTCHA\u3092\u81ea\u524d\u3067\u5b9f\u88c5\u3059\u308b\u3053\u3068\u81ea\u4f53\u304c\u521d\u3081\u3066\u306a\u306e\u3067\u3001\u5b66\u3093\u3060\u3053\u3068\u3092\u307e\u3068\u3081\u305f\u3002<\/p>\n\n\n\n<div class=\"wp-block-buttons is-layout-flex wp-block-buttons-is-layout-flex\">\n<div class=\"wp-block-button\"><a class=\"wp-block-button__link has-white-color has-black-background-color has-text-color has-background has-link-color wp-element-button\" href=\"https:\/\/github.com\/shugomatsuzawa\/PHP-DEMO-reCAPTCHA-GCP\" target=\"_blank\" rel=\"noreferrer noopener\">\u30bd\u30fc\u30b9\u3092\u898b\u308b(GitHub)<\/a><\/div>\n\n\n\n<div class=\"wp-block-button\"><a class=\"wp-block-button__link has-white-color has-black-background-color has-text-color has-background has-link-color wp-element-button\" href=\"https:\/\/demo.shugomatsuzawa.com\/php-demo-recaptcha-gcp\/\" target=\"_blank\" rel=\"noreferrer noopener\">\u30c7\u30e2\u3092\u898b\u308b<\/a><\/div>\n<\/div>\n\n\n\n<h2 class=\"wp-block-heading\">reCAPTCHA\u30ad\u30fc\u306e\u4f5c\u6210<\/h2>\n\n\n\n<p>\u307e\u305a\u306fGoogle Cloud\u30b3\u30f3\u30bd\u30fc\u30eb\u3067<a href=\"https:\/\/console.cloud.google.com\/security\/recaptcha\/create?hl=ja\" data-type=\"link\" data-id=\"https:\/\/console.cloud.google.com\/security\/recaptcha\/create?hl=ja\" target=\"_blank\" rel=\"noreferrer noopener\">reCAPTCHA\u306e\u30ad\u30fc\u3092\u4f5c\u6210<\/a>\u3059\u308b\u3002<br>\u30c9\u30e1\u30a4\u30f3\u3092\u6307\u5b9a\u3057\u3001\u30d7\u30e9\u30c3\u30c8\u30d5\u30a9\u30fc\u30e0\u306f\u300c\u30a6\u30a7\u30d6\u30b5\u30a4\u30c8\u300d\u3092\u9078\u629e\u3059\u308b\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"998\" src=\"https:\/\/shugomatsuzawa.com\/techblog\/wp-content\/uploads\/sites\/3\/2025\/03\/25509df8194b513c0467ff0d368fbae3-1024x998.png\" alt=\"\" class=\"wp-image-436\" srcset=\"https:\/\/shugomatsuzawa.com\/techblog\/wp-content\/uploads\/sites\/3\/2025\/03\/25509df8194b513c0467ff0d368fbae3-1024x998.png 1024w, https:\/\/shugomatsuzawa.com\/techblog\/wp-content\/uploads\/sites\/3\/2025\/03\/25509df8194b513c0467ff0d368fbae3-300x293.png 300w, https:\/\/shugomatsuzawa.com\/techblog\/wp-content\/uploads\/sites\/3\/2025\/03\/25509df8194b513c0467ff0d368fbae3-768x749.png 768w, https:\/\/shugomatsuzawa.com\/techblog\/wp-content\/uploads\/sites\/3\/2025\/03\/25509df8194b513c0467ff0d368fbae3-1536x1498.png 1536w, https:\/\/shugomatsuzawa.com\/techblog\/wp-content\/uploads\/sites\/3\/2025\/03\/25509df8194b513c0467ff0d368fbae3.png 1600w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>\u300c\u30ad\u30fc\u306e\u8a73\u7d30\u300d\uff1e\u300c\u30b7\u30b9\u30c6\u30e0\u958b\u767a\u300d\u306e\u30da\u30fc\u30b8\u304c\u958b\u304f\u306e\u3067\u3001\u6307\u793a\u306b\u5f93\u3063\u3066\u30d5\u30ed\u30f3\u30c8\u30a8\u30f3\u30c9\u3068\u30d0\u30c3\u30af\u30a8\u30f3\u30c9\u306e\u5b9f\u88c5\u3092\u3059\u308b\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u5b9f\u88c5\u4e0a\u306e\u30cf\u30de\u308a\u30dd\u30a4\u30f3\u30c8<\/h2>\n\n\n\n<p>\u30d5\u30ed\u30f3\u30c8\u30a8\u30f3\u30c9\u306e\u5b9f\u88c5\u306f\u6307\u793a\u901a\u308a\u306e\u5b9f\u88c5\u3067\u52d5\u304f\u304c\u3001<br>PHP\u306e\u30d0\u30c3\u30af\u30a8\u30f3\u30c9\u306b\u95a2\u3057\u3066\u306f\u30c9\u30ad\u30e5\u30e1\u30f3\u30c8\u306e\u66f4\u65b0\u304c\u6ede\u3063\u3066\u3044\u308b\u306e\u304b\u3001\u5b9f\u60c5\u3068\u7570\u306a\u308b\u90e8\u5206\u3082\u3042\u308b\u3002<br>\u56f0\u3063\u305f\u6642\u306f<a href=\"https:\/\/github.com\/googleapis\/google-cloud-php-recaptcha-enterprise\/blob\/main\/samples\/V1\/RecaptchaEnterpriseServiceClient\/create_assessment.php\" data-type=\"link\" data-id=\"https:\/\/github.com\/googleapis\/google-cloud-php-recaptcha-enterprise\/blob\/main\/samples\/V1\/RecaptchaEnterpriseServiceClient\/create_assessment.php\" target=\"_blank\" rel=\"noreferrer noopener\">\u30e9\u30a4\u30d6\u30e9\u30ea\u516c\u5f0fGitHub\u306e\u30b5\u30f3\u30d7\u30eb\u30b3\u30fc\u30c9<\/a>\u3092\u898b\u308b\u3068\u826f\u3044\u3002<\/p>\n\n\n\n<p>\u307e\u305a<code>composer<\/code>\u3067\u30e9\u30a4\u30d6\u30e9\u30ea\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3059\u308b\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ composer require google\/cloud-recaptcha-enterprise<\/code><\/pre>\n\n\n\n<p>\u307e\u305a<code>RecaptchaEnterpriseServiceClient<\/code>\u3060\u304c\u3001\u30d1\u30b9\u304c\u5909\u308f\u3063\u3066\u3044\u3066<code>Client\/<\/code>\u4ed8\u304d\u304c\u6b63\u89e3\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ use Google\\Cloud\\RecaptchaEnterprise\\V1\\RecaptchaEnterpriseServiceClient;\nuse Google\\Cloud\\RecaptchaEnterprise\\V1\\Client\\RecaptchaEnterpriseServiceClient;<\/code><\/pre>\n\n\n\n<p><code>createAssessment()<\/code>\u306e\u5f15\u6570\u306f<code>CreateAssessmentRequest<\/code>\u306b\u5909\u308f\u3063\u3066\u3044\u308b\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>use Google\\Cloud\\RecaptchaEnterprise\\V1\\CreateAssessmentRequest;\n\n\/\/ ...\u7701\u7565...\n\n  $request = (new CreateAssessmentRequest())\n    ->setParent($projectName)\n    ->setAssessment($assessment);\n\n  $response = $client->createAssessment($request);<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">ADC\u8a8d\u8a3c\uff08\u30ed\u30fc\u30ab\u30ebDocker\u958b\u767a\u74b0\u5883\uff09<\/h2>\n\n\n\n<p><a href=\"https:\/\/cloud.google.com\/docs\/authentication\/set-up-adc-local-dev-environment?hl=ja\" data-type=\"link\" data-id=\"https:\/\/cloud.google.com\/docs\/authentication\/set-up-adc-local-dev-environment?hl=ja\" target=\"_blank\" rel=\"noreferrer noopener\">Google Cloud CLI\u3092\u4f7f\u7528\u3057\u308d<\/a>\u3068\u306e\u3053\u3068\u306a\u306e\u3067\u3001<code>Dockerfile<\/code>\u3092\u7de8\u96c6\u3057\u3066\u4f7f\u3048\u308b\u3088\u3046\u306b\u3059\u308b\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>FROM php:8.2-apache\n\n# Google Cloud CLI\nRUN apt-get install -y apt-transport-https ca-certificates gnupg curl\nRUN echo \"deb &#91;signed-by=\/usr\/share\/keyrings\/cloud.google.gpg] https:\/\/packages.cloud.google.com\/apt cloud-sdk main\" | tee -a \/etc\/apt\/sources.list.d\/google-cloud-sdk.list &amp;&amp; curl https:\/\/packages.cloud.google.com\/apt\/doc\/apt-key.gpg | gpg --dearmor -o \/usr\/share\/keyrings\/cloud.google.gpg &amp;&amp; apt-get update -y &amp;&amp; apt-get install google-cloud-cli -\n\n# NOTE: \u30c7\u30d5\u30a9\u30eb\u30c8\u306e\u69cb\u6210\u30c7\u30a3\u30ec\u30af\u30c8\u30ea \/root\/.config\/gcloud \u306bPHP\u304b\u3089\u53c2\u7167\u3067\u304d\u306a\u3044\u305f\u3081\u3001\u30d1\u30b9\u3092\u5909\u66f4\n# https:\/\/cloud.google.com\/sdk\/docs\/configurations?hl=ja\nENV CLOUDSDK_CONFIG=\/var\/www\/.config\/gcloud\nENV GOOGLE_APPLICATION_CREDENTIALS=\/var\/www\/.config\/gcloud\/application_default_credentials.json<\/code><\/pre>\n\n\n\n<p><code>gcloud init<\/code>\u3068<code>gcloud auth application-default login<\/code>\u3092\u5b9f\u884c\u3057\u3001\u30d6\u30e9\u30a6\u30b6\u3067\u30ed\u30b0\u30a4\u30f3\u3059\u308c\u3070OK\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">ADC\u8a8d\u8a3c\uff08\u30b5\u30fc\u30d0\u30fc\u30c7\u30d7\u30ed\u30a4\uff09<\/h2>\n\n\n\n<p>\u4eca\u56de\u306f<a href=\"https:\/\/console.cloud.google.com\/iam-admin\/serviceaccounts\/create\" data-type=\"link\" data-id=\"https:\/\/console.cloud.google.com\/iam-admin\/serviceaccounts\/create\" target=\"_blank\" rel=\"noreferrer noopener\">\u30b5\u30fc\u30d3\u30b9\u30a2\u30ab\u30a6\u30f3\u30c8\u3092\u4f5c\u6210<\/a>\u3057\u3066\u5bfe\u5fdc\u3002<br>\u30ed\u30fc\u30eb\u306f\u300creCAPTCHA Enterprise \u30a8\u30fc\u30b8\u30a7\u30f3\u30c8\u300d\u3092\u8a2d\u5b9a\u3059\u308b\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"998\" src=\"https:\/\/shugomatsuzawa.com\/techblog\/wp-content\/uploads\/sites\/3\/2025\/03\/5f623d829ee4010cdf6a4115fdc11587-1024x998.png\" alt=\"\" class=\"wp-image-438\" srcset=\"https:\/\/shugomatsuzawa.com\/techblog\/wp-content\/uploads\/sites\/3\/2025\/03\/5f623d829ee4010cdf6a4115fdc11587-1024x998.png 1024w, https:\/\/shugomatsuzawa.com\/techblog\/wp-content\/uploads\/sites\/3\/2025\/03\/5f623d829ee4010cdf6a4115fdc11587-300x293.png 300w, https:\/\/shugomatsuzawa.com\/techblog\/wp-content\/uploads\/sites\/3\/2025\/03\/5f623d829ee4010cdf6a4115fdc11587-768x749.png 768w, https:\/\/shugomatsuzawa.com\/techblog\/wp-content\/uploads\/sites\/3\/2025\/03\/5f623d829ee4010cdf6a4115fdc11587-1536x1498.png 1536w, https:\/\/shugomatsuzawa.com\/techblog\/wp-content\/uploads\/sites\/3\/2025\/03\/5f623d829ee4010cdf6a4115fdc11587.png 1600w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>\u30b5\u30fc\u30d3\u30b9\u30a2\u30ab\u30a6\u30f3\u30c8\u306e\u8a73\u7d30\u753b\u9762\u3092\u958b\u3044\u305f\u3089\u300c\u9375\u300d\u30bf\u30d6\u306b\u79fb\u52d5\u3057\u3001<br>\u300c\u30ad\u30fc\u3092\u8ffd\u52a0\u300d\u304b\u3089JSON\u30ad\u30fc\u3092\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u3059\u308b\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"780\" src=\"https:\/\/shugomatsuzawa.com\/techblog\/wp-content\/uploads\/sites\/3\/2025\/03\/8b91235cc6fc3daa049b79b4cdc9b379-1024x780.png\" alt=\"\" class=\"wp-image-439\" srcset=\"https:\/\/shugomatsuzawa.com\/techblog\/wp-content\/uploads\/sites\/3\/2025\/03\/8b91235cc6fc3daa049b79b4cdc9b379-1024x780.png 1024w, https:\/\/shugomatsuzawa.com\/techblog\/wp-content\/uploads\/sites\/3\/2025\/03\/8b91235cc6fc3daa049b79b4cdc9b379-300x229.png 300w, https:\/\/shugomatsuzawa.com\/techblog\/wp-content\/uploads\/sites\/3\/2025\/03\/8b91235cc6fc3daa049b79b4cdc9b379-768x585.png 768w, https:\/\/shugomatsuzawa.com\/techblog\/wp-content\/uploads\/sites\/3\/2025\/03\/8b91235cc6fc3daa049b79b4cdc9b379-1536x1170.png 1536w, https:\/\/shugomatsuzawa.com\/techblog\/wp-content\/uploads\/sites\/3\/2025\/03\/8b91235cc6fc3daa049b79b4cdc9b379.png 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>\u30b5\u30fc\u30d0\u30fc\u4e0a\u306e\u5916\u90e8\u304b\u3089\u30a2\u30af\u30bb\u30b9\u3067\u304d\u306a\u3044\u5834\u6240\u306bJSON\u30ad\u30fc\u3092\u4fdd\u5b58\u3057\u3001<code>GOOGLE_APPLICATION_CREDENTIALS<\/code>\u74b0\u5883\u5909\u6570\u3067\u30ad\u30fc\u306e\u4fdd\u5b58\u5834\u6240\u3092\u8a2d\u5b9a\u3059\u308b\u3002<\/p>\n\n\n\n<p>Apache\u306evhost\u8a2d\u5b9a\u30d5\u30a1\u30a4\u30eb\u306e\u4f8b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SetEnv GOOGLE_APPLICATION_CREDENTIALS \"\/path\/to\/json-key.json\"<\/code><\/pre>\n\n\n\n<p>Apache\u3092\u518d\u8d77\u52d5\u3057\u3066\u53cd\u6620\u3059\u308b\u3002<\/p>\n\n\n\n<p>\u4f8b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo \/opt\/bitnami\/ctlscript.sh restart apache<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u53c2\u8003<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/cloud.google.com\/recaptcha\/docs\/implementation-workflow?hl=ja\" data-type=\"link\" data-id=\"https:\/\/cloud.google.com\/recaptcha\/docs\/implementation-workflow?hl=ja\" target=\"_blank\" rel=\"noreferrer noopener\">reCAPTCHA \u306e\u5b9f\u88c5\u306b\u3064\u3044\u3066 \u00a0|\u00a0 reCAPTCHA Enterprise \u00a0|\u00a0 Google Cloud<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/developers.google.com\/recaptcha\/intro?hl=ja\" data-type=\"link\" data-id=\"https:\/\/developers.google.com\/recaptcha\/intro?hl=ja\" target=\"_blank\" rel=\"noreferrer noopener\">\u30c7\u30d9\u30ed\u30c3\u30d1\u30fc \u30ac\u30a4\u30c9 \u00a0|\u00a0 reCAPTCHA \u00a0|\u00a0 Google for Developers<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/cloud.google.com\/sdk\/docs\/install-sdk?hl=ja\" data-type=\"link\" data-id=\"https:\/\/cloud.google.com\/sdk\/docs\/install-sdk?hl=ja\" target=\"_blank\" rel=\"noreferrer noopener\">\u30af\u30a4\u30c3\u30af\u30b9\u30bf\u30fc\u30c8: Google Cloud CLI \u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3059\u308b \u00a0|\u00a0 Google Cloud CLI Documentation<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/cloud.google.com\/docs\/authentication?hl=ja\" data-type=\"link\" data-id=\"https:\/\/cloud.google.com\/docs\/authentication?hl=ja\" target=\"_blank\" rel=\"noreferrer noopener\">Google \u3067\u306e\u8a8d\u8a3c\u65b9\u6cd5 \u00a0|\u00a0 Authentication \u00a0|\u00a0 Google Cloud<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/github.com\/googleapis\/google-cloud-php-recaptcha-enterprise\" data-type=\"link\" data-id=\"https:\/\/github.com\/googleapis\/google-cloud-php-recaptcha-enterprise\" target=\"_blank\" rel=\"noreferrer noopener\">googleapis\/google-cloud-php-recaptcha-enterprise<\/a><\/li>\n<\/ul>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"\u65b0\u3057\u304f\u306a\u3063\u305freCAPTCHA (Google Cloud) \u3092\u3001\u81ea\u524d\u3067\u5b9f\u88c5\u3057\u3066\u307f\u305f\u3002reCAPTCHA\u3092\u81ea\u524d\u3067\u5b9f\u88c5\u3059\u308b\u3053\u3068\u81ea\u4f53\u304c\u521d\u3081\u3066\u306a\u306e\u3067\u3001\u5b66\u3093\u3060\u3053\u3068\u3092\u307e\u3068\u3081\u305f\u3002 reCAPTCHA\u30ad\u30fc\u306e\u4f5c\u6210 \u307e\u305a\u306fGoogle C [&hellip;]","protected":false},"author":1,"featured_media":441,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"activitypub_content_warning":"","activitypub_content_visibility":"","activitypub_max_image_attachments":3,"activitypub_interaction_policy_quote":"anyone","activitypub_status":"federate","footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[8,39,47],"tags":[93,101,81,9,53,100,10],"class_list":["post-433","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-system-management","category-backend","category-frontend","tag-docker","tag-google-cloud","tag-laravel","tag-linux","tag-php","tag-recaptcha","tag-memo"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/shugomatsuzawa.com\/techblog\/wp-content\/uploads\/sites\/3\/2025\/03\/service-6929022_1920.png","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/shugomatsuzawa.com\/techblog\/wp-json\/wp\/v2\/posts\/433","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/shugomatsuzawa.com\/techblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/shugomatsuzawa.com\/techblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/shugomatsuzawa.com\/techblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/shugomatsuzawa.com\/techblog\/wp-json\/wp\/v2\/comments?post=433"}],"version-history":[{"count":4,"href":"https:\/\/shugomatsuzawa.com\/techblog\/wp-json\/wp\/v2\/posts\/433\/revisions"}],"predecessor-version":[{"id":440,"href":"https:\/\/shugomatsuzawa.com\/techblog\/wp-json\/wp\/v2\/posts\/433\/revisions\/440"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/shugomatsuzawa.com\/techblog\/wp-json\/wp\/v2\/media\/441"}],"wp:attachment":[{"href":"https:\/\/shugomatsuzawa.com\/techblog\/wp-json\/wp\/v2\/media?parent=433"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/shugomatsuzawa.com\/techblog\/wp-json\/wp\/v2\/categories?post=433"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/shugomatsuzawa.com\/techblog\/wp-json\/wp\/v2\/tags?post=433"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}