文件中
```
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="" # 跳转的页面路径 如: pages/index/index
JUMP_QUERY="" # 跳转参数 如要跳转到详情页 如: spuNo=1042087&storeId=3308103
IS_EXPIRE=false # 生成的scheme码类型,到期失效:true,永久有效:false
EXPIRE_TIME=1611912056 # (秒级)到期失效的scheme码的失效时间,为Unix时间戳。生成的到期失效 scheme码在该时间前有效。最长有效期为1年。生成到期失效的scheme时必填。
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//\\/} # 把所有的 \ (转义后是//) 替换为空
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>微信外部跳转到微信并拉起小程序</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()">点我跳转到微信小程序</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文件已生成
```
最后在终端执行
$ chmod+x./generate.sh&&sh./generate.sh
详情:https://www.jianshu.com/p/8560f7e94fa3