|
楼主 |
发表于 2020-7-3 22:38:35
|
显示全部楼层
河小马 发表于 2020-7-3 21:23# _2 s0 C K& O M2 O! w) i
shopify 可以前面挂cf吗?: A( C8 A' r p( D2 U8 D
) S! W1 w9 Z( d5 F/ u) _cf 实现这个很容易
& t9 N7 J0 o3 k( Q& O& z x应该不行,只能用DNS Only模式,然后shopify会generate一个let's encrypt,我看几个top shopify店铺都是这样的
- {5 O0 K7 ?6 o# R; w) h
0 A8 S# S/ X8 n! h5 M# l8 p自己写code感觉就很麻烦了。。。
|: R- t4 \ ?* h! j1 ^/ I- c) v! O' V- P5 l$ e
在shopify的社区找到了这个代码,不过这个freegeoip.app感觉不稳2 Y: R& V$ x, T
+ S0 x' U( D3 [7 m4 W8 C- // IpGeolocation5 p! |0 t9 `( z
- var httpRequest = new XMLHttpRequest();
: d4 `6 h- P* T) C4 q
3 L; ]) F. j) Z7 V6 c- httpRequest.onreadystatechange = function() {+ d* |$ K5 h) R6 B" ?& ]& m8 V
- if (4 === this.readyState && 200 === this.status) {' n" O! |4 g5 {1 M) w
- var json = JSON.parse(this.responseText);
" {5 o t' a1 \% Q) X7 ]) E - redirect(json.country_code);
6 Y- r; b+ h$ F8 f - }3 |8 [3 e( A- K$ T! d1 Z
- }, h& z5 i. r* A. l
- httpRequest.open("GET", "https://freegeoip.app/json/", false);
4 L( r9 p% z3 b6 W8 h5 G( F - httpRequest.setRequestHeader("Accept", "application/json");
9 u7 F8 c/ k& d6 W/ [( U0 G$ e - httpRequest.send();, x( F: n5 ]4 G' ^* D
- $ }) Z/ z; b1 `
- function redirect(country_code) {
. |% i6 [1 t1 f& s
6 G- h9 X$ s3 U- if (country_code == "CN" ) {2 e7 Y. o4 L1 c5 c6 g
/ W3 W: C# w' a- window.location.href = "https://www.nasa.gov/";: _, {. l' f" i
- }
: L h# |2 t7 M) H- T/ [# @ - ' x) F% ]' M& I* r
- else if
; k9 F1 W0 I2 Q4 ?/ }5 D+ h - (country_code == "MO" ) {
; \ ?) o x2 N) j0 j - window.location.href = "https://www.nasa.gov/";* c _5 y0 V: f: X7 w2 O
- }1 \$ H4 i5 X" m- x
- . n$ H* J, P* I
" A$ s5 o; D- z7 B- else if
* t2 i: e0 U& T1 d - (country_code == "SG" ) {
* M! E9 R9 A# K" ~* b' X
, O( R! F$ f2 P- window.location.href = "https://www.nasa.gov/";
" o3 z9 C0 @' S - }/ Q8 a3 e% A$ t! ]7 N
( w+ d. d% A( d, O) C7 \: j: J- else if7 G5 q3 @! {% m6 C) a3 h: I0 {2 {
- (country_code == "EE" ) {' P, Q$ T2 A# ^: W1 l
2 M3 ^$ h- H- i- window.location.href = "https://www.nasa.gov/";, r0 q6 c; P% } {8 e
- }
: i0 F7 Z$ \8 T6 E7 [7 ^& z0 T' H
, P3 w, y1 ]3 F2 C4 {" @% N
N/ y) @2 o& [- else {
T3 ~( b# i9 m - return f6 R5 @: h* K7 m* M9 ~
- }6 O0 `4 N8 @, M0 g9 x) U) v
- }
复制代码 |
|