文件中
```
bash #!/bin/bash
SCHEME_URL="https://api.weixin.qq.com/wxa/generatescheme"
TOKEN_URL="https://api.weixin.qq.com/cgi-bin/token"
APPID="小程序APPID"
SECRET="小程序APPSECRET"
JUMP_PATH="" # 跳轉(zhuǎn)的頁(yè)面路徑 如: pages/index/index
JUMP_QUERY="" # 跳轉(zhuǎn)參數(shù) 如要跳轉(zhuǎn)到詳情頁(yè) 如: spuNo=1042087&storeId=3308103
IS_EXPIRE=false # 生成的scheme碼類(lèi)型婚瓜,到期失效:true个粱,永久有效:false
EXPIRE_TIME=1611912056 # (秒級(jí))到期失效的scheme碼的失效時(shí)間灌旧,為Unix時(shí)間戳。生成的到期失效? ? scheme碼在該時(shí)間前有效魄揉。最長(zhǎng)有效期為1年。生成到期失效的scheme時(shí)必填。
function getToken() {
? RES=`curl -slient -X GET ${TOKEN_URL}'?grant_type=client_credential&appid='${APPID}'&secret='${SECRET}`
? TK=${RES#*access_token\"\:\"}
? TK=${TK%%\"*}
? echo ${TK}
}
TOKEN=`getToken`
function generateURLScheme() {
? SCHEME=`curl -s -X POST -d '{"jump_wxa":{"path":"'${JUMP_PATH}'","query":"'${JUMP_QUERY}'"},"is_expire":'${IS_EXPIRE}',"expire_time": '${EXPIRE_TIME}'}' ${SCHEME_URL}?access_token=${TOKEN}`
? SCHEME=${SCHEME#*openlink\"\:\"}
? SCHEME=${SCHEME%%\"*}
? SCHEME=${SCHEME//\\/} # 把所有的 \ (轉(zhuǎn)義后是//) 替換為空
? echo $SCHEME
}
URL_SCHEME=`generateURLScheme`
echo 'URL_SCHEME:'$URL_SCHEME
HTML_CONTENT='<html><head><meta charset="utf-8"><metaname="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no"><title>微信外部跳轉(zhuǎn)到微信并拉起小程序</title><style>html,body{height: 100%; padding: 0px; margin: 0px;}</style></head><body><div style="width: 100%;height: 100%; justify-content: center; align-items: center; display: flex;"><h1><a href="javascript:void(0);" onclick="jumpToMp()">點(diǎn)我跳轉(zhuǎn)到微信小程序</a></h1></div></body><script>function jumpToMp(){window.location.href="'$URL_SCHEME'"}jumpToMp()</script></html>'
echo '' > scheme_html.html
echo $HTML_CONTENT >> scheme_html.html
echo scheme_html.html文件已生成
```
最后在終端執(zhí)行
$ chmod+x./generate.sh&&sh./generate.sh
詳情:http://www.reibang.com/p/8560f7e94fa3