基础用途:
- 其他平台引流到微信小程序,例如快手,抖音
- 网站快速跳转到小程序
高级用途:
- 微信小程序支付
- 跳转小程序观看广告后网页端下发奖励
使用前提:
非个人主体小程序
使用说明:
修改appid和密钥为自己小程序的,如果有参数需要传递,在下面参数位置填写
跳转小程序接口源码,返回的是微信url scheme
微信官方文档:
https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/url-scheme.html
抖音快手小程序都有相同方法
具体代码:
<?php
// 仅限非个人主体小程序
$appid = ""; // 小程序appid
$appkey = ""; // 小程序密钥
// 获取微信开放平台token
$token = file_get_contents('https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid='.$appid.'&secret='.$appkey);
$token = json_decode($token, true);
$token = $token["access_token"];
// 获取微信小程序schemeUrl
$url='https://api.weixin.qq.com/wxa/generatescheme?access_token='.$token;
$data = json_encode(array(
"jump_wxa" => array(
"path" => "/pages/index/index", // 页面地址
"query" => "" // 需要传递的参数,可留空:a=****&b=*****······
)
)
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_ENCODING, "");
curl_setopt($ch, CURLOPT_AUTOREFERER, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 15);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_MAXREDIRS, 10);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
"Accept: application/json, text/plain, */*",
"Accept-Language: zh-CN,zh;q=0.9,en;q=0.8",
"Content-Type: application/json",
"Origin: https://api.weixin.qq.com",
"Content-Type: application/json"
));
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_ENCODING, "gzip");
$result = curl_exec($ch);
curl_close($ch);
//提取link
$link = json_decode($result, true)["openlink"];
$data = array(
'code'=>200,
'url'=>$link
);
exit(json_encode($data));
?>
本文来自投稿,不代表本站立场,如若转载,请注明出处:
00000
66666666666666666666666666666