- 打開終端,安裝http-server
MBP ~ % npm install -g http-server
- cd到游戲目錄下,如cocos creator項(xiàng)目是在構(gòu)建出來的游戲包根目錄(build/fb-instant-game),然后生成私鑰,接著生成證書,生成證書時(shí)需要填資料,可以隨便填
MBP ~ % cd /Users/***/***/***/build/fb-instant-games
MBP ~ % openssl genrsa 2048 > key.pem
MBP ~ % openssl req -x509 -days 1000 -new -key key.pem -out cert.pem
// Fill out information
....
- 開始啟用本地server服務(wù),Ctrl + C可以停止,每次使用本地服務(wù)器測(cè)試前需要輸入此指令。
http-server --ssl -c-1 -p 8080 -a 127.0.0.1
- 打開以下網(wǎng)址開始運(yùn)行游戲進(jìn)行測(cè)試,<YOUR_GAME_ID>替換成自己的游戲ID
https://www.facebook.com/embed/instantgames/<YOUR_GAME_ID>/player?game_url=https://localhost:8080
第一次打開的時(shí)候可能會(huì)遇到游戲加載不進(jìn)去,打開控制臺(tái)可以看到以下問題:

image.png
這是因?yàn)槭褂玫氖潜镜刈远x的證書,瀏覽器不信任導(dǎo)致的,這時(shí)候需要輸入并打開網(wǎng)址:https://localhost:8080,然后在控制臺(tái)界面輸入:
sendCommand(SecurityInterstitialCommandId.CMD_PROCEED)

image.png
然后再重新打開測(cè)試鏈接,就可以了