-
Notifications
You must be signed in to change notification settings - Fork 1
/
gas.html
84 lines (79 loc) · 3.98 KB
/
gas.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<!DOCTYPE html>
<html lang="zh-TW">
<head>
<meta charset="UTF-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<meta http-equiv="X-UA-Compatible" content="ie=edge"/>
<title>用 reCAPTCHA v3 來做非機器人驗證 - August - Let's Write</title>
<link rel="canonical" href="https://www.letswrite.tw/recaptcha-v3/"/>
<meta property="og:url" content="https://letswritetw.github.io/letswrite-recaptcha-v3/"/>
<meta property="fb:app_id" content="911000986339138"/>
<meta property="og:type" content="website"/>
<meta property="og:site_name" content="Let's Write"/>
<meta property="og:title" content="用 reCAPTCHA v3 來做非機器人驗證 - August - Let's Write"/>
<meta itemprop="name" content="用 reCAPTCHA v3 來做非機器人驗證 - August - Let's Write"/>
<meta name="description" content="Google Apps Script 的程式碼"/>
<meta property="og:description" content="Google Apps Script 的程式碼"/>
<meta itemprop="description" content="Google Apps Script 的程式碼"/>
<meta itemprop="image" content="https://letswritetw.github.io/letswrite-recaptcha-v3/fb.jpg"/>
<meta property="og:image" content="https://letswritetw.github.io/letswrite-recaptcha-v3/fb.jpg"/>
<meta property="og:image:width" content="1200"/>
<meta property="og:image:height" content="630"/>
<meta property="og:image:alt" content="用 reCAPTCHA v3 來做非機器人驗證"/>
<link rel="shortcut icon" href="https://letswritetw.github.io/letswritetw/dist/img/logo_512.png"/>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/water.css@2/out/light.css"/>
<link rel="stylesheet" href="dist/style.min.css"/>
<!-- Google Tag Manager-->
<script>
(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','GTM-PGQ9WQT');
</script>
</head>
<body>
<!-- Google Tag Manager (noscript)-->
<noscript>
<iframe src="https://www.googletagmanager.com/ns.html?id=GTM-PGQ9WQT" height="0" width="0" style="display:none;visibility:hidden"></iframe>
</noscript>
<div class="container" id="app">
<h1 class="text-center">reCAPTCHA v3 使用範例</h1>
<hr/>
<div class="tab text-center"><a href="index.html">方法一</a><a href="index2.html">方法二</a><a class="active" href="gas.html">後端 GAS</a><a href="https://letswrite.tw/recaptcha-v3/" target="_blank">筆記文</a></div>
<hr/>
<h2>Google Apps Script 的程式碼</h2>
<p>參考文件:<a href="https://developers.google.com/recaptcha/docs/verify" target="_blank" rel="noopener noreferrer">Verifying the user's response</a></p>
<h3>code</h3>
<pre><code>function doPost(e) {
var params = e.parameter;
var token = params.token; // 從前端傳來的 token
var ip = params.ip; // 從前端傳來的 IP
var uri = 'https://www.google.com/recaptcha/api/siteverify';
var data = {
secret: 'reCAPTCHA 後台取得的「密鑰」',
response: token,
remoteip: ip
}
var option = {
method: 'post',
payload: data
};
var response = UrlFetchApp.fetch(uri, option);
return ContentService.createTextOutput(response).setMimeType(ContentService.MimeType.JSON);
}
</code></pre>
<p>remoteip 為選填。</p>
<p>程式碼寫完後要「發佈 > 部署為網路應用程式」,並把取得的 URL 給前端 POST。</p>
<h3>回傳的會是 JSON,範例</h3>
<pre><code>{
"success": true|false,
"score": number, // 0.0 - 1.0。0 代表是機器人、1 代表是人類
"action": string, // 可以比對跟我們送出去的 action 相不相同
"challenge_ts": yyyy-MM-dd'T'HH:mm:ssZZ,
"hostname": string,
"error-codes": [...] // optional
}</code></pre>
</div>
</body>
</html>