安兔兔跑分
- CPU : 43878
- GPU : 15359
- UX : 25461
- MEM: 7840
—
431 total views, no views today
—
沒有背景服務,所以 APP 關閉就結束執行。FCM 推播無法顯示訊息,官方推薦 cordova-plugin-local-notifications 早就沒有維護無法使用
—
1 2 3 4 5 6 7 |
>cordova run android --device Checking Java JDK and Android SDK versions ANDROID_SDK_ROOT=undefined (recommended setting) ANDROID_HOME=C:\Users\DAE User 201909\AppData\Local\Android\sdk (DEPRECATED) Could not find an installed version of Gradle either in Android Studio, or on your system to install the gradle wrapper. Please include gradle in your path, or install Android Studio |
—
因為是 Cordova 所以 Android 可以忽略 Android Studio IDE 以及 AVD ,因為要直接連手機測試
但是 IOS 就沒有省略 Xcode 的方式,因為 Mac 的硬體效能較佳,不像 PC 的差異
—
步驟
—
將手機切換到開發者模式之後,開啟 USB 偵錯,連上電腦後就可以開始安裝 Cordova 以及測試了
1 2 3 4 5 |
>npm install -g cordova >cordova create MyApp >cd MyApp >cordova platform add android >cordova run android --device |
—
編輯 PATH 環境變數,增加 C:\Users\user name\AppData\Roaming\npm 路徑即可
—
—
1,191 total views, no views today
你可以設定
—
1 |
<content src="index.html" /> |
—
1 |
<preference name="orientation" value="portrait" /> |
Anddroid
根據陀螺儀翻轉方向
1 2 3 |
<platform name="android"> <preference name="Orientation" value="sensorLandscape" /> </platform> |
—
1 |
<preference name="Fullscreen" value="true" /> |
—
1 |
<preference name="DisallowOverscroll" value="true"/> |
—
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 |
<?xml version='1.0' encoding='utf-8'?> <widget android-versionCode="2" id="tw.idv.hoyo.kashiu" version="1.0.2" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0"> <name>掃買樂</name> <description> 買東西掃條碼、忘記以前買的價格掃條碼 </description> <author email="pc@hoyo.idv.tw" href="https://www.hoyo.idv.tw">黃志賢</author> <content src="index.html" /> <plugin name="cordova-plugin-whitelist" spec="1" /> <access origin="*" /> <allow-intent href="http://*/*" /> <allow-intent href="https://*/*" /> <allow-intent href="tel:*" /> <allow-intent href="sms:*" /> <allow-intent href="mailto:*" /> <allow-intent href="geo:*" /> <preference name="Orientation" value="portrait" /> <preference name="DisallowOverscroll" value="true"/> <icon src="www/img/logo.png" /> <platform name="android"> <allow-intent href="market:*" /> </platform> <platform name="ios"> <allow-intent href="itms:*" /> <allow-intent href="itms-apps:*" /> </platform> <plugin name="phonegap-plugin-barcodescanner" spec="^8.0.0"> <variable name="ANDROID_SUPPORT_V4_VERSION" value="27.+" /> </plugin> <plugin name="cordova-plugin-camera" spec="^4.0.3" /> <plugin name="cordova-plugin-dialogs" spec="^2.0.1" /> <plugin name="cordova-plugin-googleplus" spec="^5.3.0"> <variable name="WEB_APPLICATION_CLIENT_ID" value="41386861907-o4if4t5378s4imgadld7c5t3n7i7s0of.apps.googleusercontent.com" /> </plugin> <plugin name="cordova-plugin-android-permissions" spec="^1.0.0" /> <plugin name="cordova-plugin-ionic-keyboard" spec="^2.1.2" /> <engine name="android" spec="^7.0.0" /> </widget> |
—
1,217 total views, 3 views today
—
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
<?php session_start(); require_once __DIR__ . '/3rdParty/php-graph-sdk-5.x/src/Facebook/autoload.php'; $fb = new \Facebook\Facebook([ 'app_id' => '221787181332517', 'app_secret' => 'c0c5f3e2890c21a937e173f19aaadca6', 'default_graph_version' => 'v3.1' ]); $helper = $fb->getRedirectLoginHelper(); $permissions = ['email']; // Optional permissions $loginUrl = $helper->getLoginUrl('https://member.hoyo.idv.tw/Facebook.php&b=OAuth', $permissions); echo '<a href="' . htmlspecialchars($loginUrl) . '">Facebook 登入</a>'; |
如此即會產生如以下這樣的連結
1 |
<a href="https://www.facebook.com/v3.1/dialog/oauth?client_id=221787181332517&state=6bff312f5abde8028fdb163c1fdf9e62&response_type=code&sdk=php-sdk-5.7.0&redirect_uri=https%3A%2F%2Fmember.hoyo.idv.tw%2FFacebook.php%26b%3DOAuth&scope=email">Facebook 登入</a> |
—
這裡只列出 Facebook OAuth class 的程式碼,前面還有一個 index.php 處理網站入口,例如後面說的 session 錯誤就是寫在 index.php 內
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 85 86 87 88 89 |
<?php require_once HDPath . '/3rdParty/Facebook/autoload.php'; class FacebookLogin { function __construct() { // if ( !empty( $_GET['b'] ) ) { $MethodName = $_GET['b']; switch( $MethodName ) { case (preg_match('/\w/', $MethodName) ? true : false): if ( method_exists(__CLASS__, $MethodName) ) { $this->$MethodName(); exit; } break; } } } // 處理臉書登入後資訊一直到取得 access token 到對應的臉書基本資料 function OAuth() { $fb = new \Facebook\Facebook([ 'app_id' => '2217899999992517', 'app_secret' => 'c0c5f3e28............aaadca6', 'default_graph_version' => 'v3.1' ]); $helper = $fb->getRedirectLoginHelper(); try { $accessToken = $helper->getAccessToken(); } catch(\Facebook\Exceptions\FacebookResponseException $e) { // When Graph returns an error echo 'Graph returned an error: ' . $e->getMessage(); exit; } catch(\Facebook\Exceptions\FacebookSDKException $e) { // When validation fails or other local issues echo 'Facebook SDK returned an error: ' . $e->getMessage(); exit; } if (! isset($accessToken)) { if ($helper->getError()) { header('HTTP/1.0 401 Unauthorized'); echo "Error: " . $helper->getError() . "\n"; echo "Error Code: " . $helper->getErrorCode() . "\n"; echo "Error Reason: " . $helper->getErrorReason() . "\n"; echo "Error Description: " . $helper->getErrorDescription() . "\n"; } else { header('HTTP/1.0 400 Bad Request'); echo 'Bad request'; } exit; } $oAuth2Client = $fb->getOAuth2Client(); $tokenMetadata = $oAuth2Client->debugToken($accessToken); $tokenMetadata->validateAppId('221787181332517'); // Replace {app-id} with your app id $tokenMetadata->validateExpiration(); if (! $accessToken->isLongLived()) { // Exchanges a short-lived access token for a long-lived one try { $accessToken = $oAuth2Client->getLongLivedAccessToken($accessToken); } catch (\Facebook\Exceptions\FacebookSDKException $e) { echo "<p>Error getting long-lived access token: " . $e->getMessage() . "</p>\n\n"; exit; } } $GraphURL = 'https://graph.facebook.com/v3.1/me?fields=id,name,email'; $GraphURL .= '&access_token='. (string)$accessToken; $GraphURL .= '&format=json&method=get&pretty=0'; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $GraphURL); curl_setopt($ch, CURLOPT_RETURNTRANSFER , 1); $FBUserInfo = curl_exec($ch); curl_close($ch); // 使用者資訊 $UserInfo = json_decode($FBUserInfo, true); print_r($UserInfo); } } |
—
$UserInfo 如此即可得到該登入使用者在 Facebook 的基本資料 id, name, email
1 |
Array ( [id] => 637955764 [name] => 黃志賢 [email] => pc@hoyo.idv.tw ) |
—
請使用 Facebook 提供 SDK ,注意流程即可避免此問題
—
PHP 必須開啟 session_start();
—
—
因為 Facebook 的 js 寫的很爛只能跑在「較新版」的 Chrome 例如 v62 ,而 Google 可以跑在 Chrome v44 所以使用 PHP 沒有 js 相容性問題
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 |
<script> window.fbAsyncInit = function() { FB.init({ appId : '2217999999999517', autoLogAppEvents : true, xfbml : true, version : 'v3.1' }); }; (function(d, s, id){ var js, fjs = d.getElementsByTagName(s)[0]; if (d.getElementById(id)) {return;} js = d.createElement(s); js.id = id; js.src = "https://connect.facebook.net/en_US/sdk.js"; fjs.parentNode.insertBefore(js, fjs); }(document, 'script', 'facebook-jssdk')); FB.getLoginStatus(function(response) { statusChangeCallback(response); }); </script> <fb:login-button scope="public_profile,email" onlogin="checkLoginState();"> </fb:login-button> <div id="status"> </div> |
—
4,433 total views, 4 views today
—
—
—
1 2 |
# wget https://dl.eff.org/certbot-auto # chmod a+x ./certbot-auto |
單一網站
1 |
# certbot certonly --webroot -w /WEBSite/www/WWW/ -d hoyo.idv.tw |
通配網址
1 |
# ./certbot-auto certonly --manual --preferred-challenges dns -d *.hoyo.idv.tw |
執行,記得產生一個通配網域一個只有網域名稱證書,如此單獨使用網域名稱時才不會 SSL_ERROR_BAD_CERT_DOMAIN 證書問題
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 |
[root@hoyoserver ~]# ./certbot-auto certonly --manual --preferred-challenges dns -d *.hoyo.idv.tw -d hoyo.idv.tw Saving debug log to /var/log/letsencrypt/letsencrypt.log Plugins selected: Authenticator manual, Installer None Cert is due for renewal, auto-renewing... Renewing an existing certificate Performing the following challenges: dns-01 challenge for hoyo.idv.tw - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - NOTE: The IP of this machine will be publicly logged as having requested this certificate. If you're running certbot in manual mode on a machine that is not your server, please ensure you're okay with that. Are you OK with your IP being logged? - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - (Y)es/(N)o: y - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Please deploy a DNS TXT record under the name _acme-challenge.hoyo.idv.tw with the following value: 2ezwTObsoUiEdGvpi9t3_UTTwXl3_02MkAzXNUl4MJg Before continuing, verify the record is deployed. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Press Enter to Continue Waiting for verification... Cleaning up challenges IMPORTANT NOTES: - Congratulations! Your certificate and chain have been saved at: /etc/letsencrypt/live/hoyo.idv.tw/fullchain.pem Your key file has been saved at: /etc/letsencrypt/live/hoyo.idv.tw/privkey.pem Your cert will expire on 2019-01-11. To obtain a new or tweaked version of this certificate in the future, simply run certbot-auto again. To non-interactively renew *all* of your certificates, run "certbot-auto renew" - If you like Certbot, please consider supporting our work by: Donating to ISRG / Let's Encrypt: https://letsencrypt.org/donate Donating to EFF: https://eff.org/donate-le |
編輯 DNS
1 |
vi /etc/named/hoyo.idv.tw.db |
1 2 |
_acme-challenge.hoyo.idv.tw. 600 IN TXT "PR-w7263U8CSYKmH8gbydAWjVhXnS7QZdfHFysF7fCE" _acme-challenge.hoyo.idv.tw. 601 IN TXT "h_FU0vnvtDKAIRx-QCY0JPsQRUqyMp_Qu2iJQDtSEtY" |
重新啟動 DNS
1 |
# systemctl restart named |
驗證
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
[root@hoyoserver ~]# dig _acme-challenge.hoyo.idv.tw txt ; <<>> DiG 9.9.4-RedHat-9.9.4-61.el7 <<>> _acme-challenge.hoyo.idv.tw txt ;; global options: +cmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 16167 ;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1 ;; OPT PSEUDOSECTION: ; EDNS: version: 0, flags:; udp: 512 ;; QUESTION SECTION: ;_acme-challenge.hoyo.idv.tw. IN TXT ;; ANSWER SECTION: _acme-challenge.hoyo.idv.tw. 599 IN TXT "2ezwTObsoUiEdGvpi9t3_UTTwXl3_02MkAzXNUl4MJg" ;; Query time: 54 msec ;; SERVER: 8.8.8.8#53(8.8.8.8) ;; WHEN: 日 10月 14 00:03:23 CST 2018 ;; MSG SIZE rcvd: 112 |
Enter 繼續執行,沒問題出現以下畫面就代表證書建立完成
1 2 3 4 5 6 7 8 9 10 11 12 13 |
IMPORTANT NOTES: - Congratulations! Your certificate and chain have been saved at: /etc/letsencrypt/live/hoyo.idv.tw/fullchain.pem Your key file has been saved at: /etc/letsencrypt/live/hoyo.idv.tw/privkey.pem Your cert will expire on 2018-08-28. To obtain a new or tweaked version of this certificate in the future, simply run certbot-auto again. To non-interactively renew *all* of your certificates, run "certbot-auto renew" - If you like Certbot, please consider supporting our work by: Donating to ISRG / Let's Encrypt: https://letsencrypt.org/donate Donating to EFF: https://eff.org/donate-le |
—
1 |
# ./certbot-auto certonly --manual --preferred-challenges dns -d *.hoyo.idv.tw -d hoyo.idv.tw |
—
網頁即可
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 |
# ./certbot-auto certonly --manual -d *.hoyo.idv.tw -d hoyo.idv.tw Your system is not supported by certbot-auto anymore. certbot-auto and its Certbot installation will no longer receive updates. You will not receive any bug fixes including those fixing server compatibility or security problems. Please visit https://certbot.eff.org/ to check for other alternatives. Saving debug log to /var/log/letsencrypt/letsencrypt.log Plugins selected: Authenticator manual, Installer None Cert is due for renewal, auto-renewing... Renewing an existing certificate Performing the following challenges: dns-01 challenge for hoyo.idv.tw http-01 challenge for hoyo.idv.tw - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - NOTE: The IP of this machine will be publicly logged as having requested this certificate. If you're running certbot in manual mode on a machine that is not your server, please ensure you're okay with that. Are you OK with your IP being logged? - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - (Y)es/(N)o: y - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Please deploy a DNS TXT record under the name _acme-challenge.hoyo.idv.tw with the following value: oMeBMG91IC_pX20hKHUxo1JPDeob97DGkihBtAkKpp4 Before continuing, verify the record is deployed. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Press Enter to Continue - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Create a file containing just this data: 8zHg86nGLkz8zU-SUHCG92hQUQ6Ze7IVG7MHBTLcMSU.RDdk2sTQ5QfyVyl3xudYprau-lsGy_OsOlKNdzSCksA And make it available on your web server at this URL: http://hoyo.idv.tw/.well-known/acme-challenge/8zHg86nGLkz8zU-SUHCG92hQUQ6Ze7IVG7MHBTLcMSU (This must be set up in addition to the previous challenges; do not remove, replace, or undo the previous challenge tasks yet.) - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Press Enter to Continue Waiting for verification... Cleaning up challenges IMPORTANT NOTES: - Congratulations! Your certificate and chain have been saved at: /etc/letsencrypt/live/hoyo.idv.tw/fullchain.pem Your key file has been saved at: /etc/letsencrypt/live/hoyo.idv.tw/privkey.pem Your cert will expire on 2021-09-25. To obtain a new or tweaked version of this certificate in the future, simply run certbot-auto again. To non-interactively renew *all* of your certificates, run "certbot-auto renew" - If you like Certbot, please consider supporting our work by: Donating to ISRG / Let's Encrypt: https://letsencrypt.org/donate Donating to EFF: https://eff.org/donate-le |
不過認證之前必須注意要把網址 Rewrite 關閉,例如 http 轉 https,否則會失敗
—
—
—
-目前手動更新中-
—
1 2 |
# chown root:named /etc/named # chmod 770 -R /etc/named |
1 2 3 4 5 6 |
# nsupdate -k /etc/named/Kdnskey.+165+50851.key<< co >server 127.0.0.1 >update delete _acme-challenge.hoyo.idv.tw TXT >update add _acme-challenge.hoyo.idv.tw 0 TXT $CERTBOT_VALIDATION >send |
—
—
655 total views, no views today
jQuery 插入內容時可以使用 append(), prepend(), before(), after() 四個函式,不同的函式插入的位置不同
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
<div id="aaa" style="border: 1px solid #aaa;">aaaaa</div> <script> $('#aaa').before('<div>before 1</div>'); $('#aaa').before('<div>before 2</div>'); $('#aaa').after('<div>after 1</div>'); $('#aaa').after('<div>after 2</div>'); $('#aaa').append('<div>append 1</div>'); $('#aaa').append('<div>append 2</div>'); $('#aaa').prepend('<div>prepend 1</div>'); $('#aaa').prepend('<div>prepend 2</div>'); </script> |
—
662 total views, no views today