|

楼主 |
发表于 2020-7-3 22:38:35
|
显示全部楼层
河小马 发表于 2020-7-3 21:23
- N- Z& h9 c* l7 A# n( Zshopify 可以前面挂cf吗?2 h: G% g+ L$ b2 b4 v* h7 E$ L- t
P" [2 ]4 \2 x' R9 p i9 {cf 实现这个很容易 & ?! G) w7 ?8 S8 f' `
应该不行,只能用DNS Only模式,然后shopify会generate一个let's encrypt,我看几个top shopify店铺都是这样的$ u3 b9 t3 Z6 ~& X3 c
; o& m1 s+ f* u' N4 Y$ K
自己写code感觉就很麻烦了。。。
! Q' z: \0 S9 Z2 X# V: [' r5 a6 b, n' g! I
在shopify的社区找到了这个代码,不过这个freegeoip.app感觉不稳
' y& U2 g0 x: q: W+ P' @, @# b6 B
- s" f7 ^* n: X+ {; N# ?- // IpGeolocation
! v8 S1 [1 v" o - var httpRequest = new XMLHttpRequest();9 z: p! N4 F _5 h
- & t4 Y/ ]- b* ]4 p* B
- httpRequest.onreadystatechange = function() {$ i7 `8 N j( e, R3 l+ W4 X" K1 d
- if (4 === this.readyState && 200 === this.status) {
8 u* W- q& q; y( C" h0 Y - var json = JSON.parse(this.responseText);$ P. ]4 ?/ t, D0 }+ w
- redirect(json.country_code);
+ q7 R! O y6 ^* j - }) A, O$ G3 r6 e3 ~6 d
- }
4 ]+ T3 M" s5 y4 r - httpRequest.open("GET", "https://freegeoip.app/json/", false);: e7 w% ~0 ?6 d7 c
- httpRequest.setRequestHeader("Accept", "application/json");0 r8 z/ {6 L& ]" L1 E9 d9 n
- httpRequest.send();
2 @& e- p4 L# i s6 ?9 k1 ?
, ~* {& s8 ]# G9 ?% `& t1 r$ b) x- function redirect(country_code) {
; h$ K4 I- a& h! f) _ - % E: b2 c, t$ f- I- K" L4 P
- if (country_code == "CN" ) {
: s0 Y% E Z% o2 Y9 X$ J
& `6 f4 z& Y# U- ^, `: h- window.location.href = "https://www.nasa.gov/";
) Q- q! `' I5 E* N; ]! W& [, m. K* R( Y - }0 c9 B/ r9 ~- q2 ]
8 d% _8 S: P" n. d- else if4 h9 b9 G6 \$ s9 d
- (country_code == "MO" ) {
3 p/ a' L& A) @( A - window.location.href = "https://www.nasa.gov/";1 g, x0 U' R; v. N: e7 z) x" s O0 D" W
- }1 Z2 J) X, @$ @
- : k, _5 g, `& m% Q: h6 o
, q& R. g( |; ^7 F& T- else if+ {) T$ \1 ^4 F5 |5 f. b" m3 u' o7 e
- (country_code == "SG" ) {5 W; v3 d5 e; @: w6 z
# h4 d8 K$ l' N4 F, m- window.location.href = "https://www.nasa.gov/";" r' e7 l& g0 Q* M2 f; Y
- }' ]' s. p! b7 R4 |+ m! _
- & ]& B6 q" ?- _" \( b
- else if
& F4 j4 U" g- q; B2 Z - (country_code == "EE" ) {
( ^6 y5 H+ m8 _" J5 U - 8 c& N: Y' C5 X( X( y0 @ g
- window.location.href = "https://www.nasa.gov/";1 }3 \* b6 J$ m8 u" v0 o
- }
. t7 i- m$ D7 C' f& r; F) m9 F9 b- k - ~( @2 ~- ]9 \9 s" y' O$ c
8 N$ r9 F+ U' j# c( J1 z; C- else {, Q7 B5 t! r' `* U! \3 S) J8 J
- return) w0 ~# t/ ]6 z$ d* Y n8 K6 e) H
- }
8 m: i; G: n1 [% v1 m0 R - }
复制代码 |
|