Achieved effect
Implementation ideas
Refer to the official document, first obtain the accesstoken, and then call the official url to pass in the accessed page path and query parameters to generate URLScheme
<?php
$appId = 'your_appid'; // 替换为你的小程序的AppID
$appSecret = 'your_appsecret'; // 替换为你的小程序的AppSecret
$url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=$appId&secret=$appSecret";
$response = file_get_contents($url);
$data = json_decode($response, true);
$accessToken = $data['access_token'];
echo $accessToken;
?>
<?php
$accessToken = "YOUR_ACCESS_TOKEN";
$url = "https://api.weixin.qq.com/wxa/generatescheme?access_token=" . $accessToken;
$data = array(
"jump_wxa" => array(
"path" => "/pages/publishHomework/publishHomework",
"query" => "",
"env_version" => "release"
),
"is_expire" => true,
"expire_type" => 1,
"expire_interval" => 1
);
$dataJSON = json_encode($data);
$options = array(
"http" => array(
"header" => "Content-Type: application/json",
"method" => "POST",
"content" => $dataJSON
)
);
$context = stream_context_create($options);
$response = file_get_contents($url, false, $context);
if ($response === false) {
// handle error
} else {
$responseData = json_decode($response, true);
if ($responseData["errcode"] === 0) {
$openlink = $responseData["openlink"];
// handle success, use $openlink
} else {
$errMsg = $responseData["errmsg"];
// handle error, use $errMsg
}
}
?>