在网站跳转小程序(QQ/微信)-资源论坛-资源分享-数据动力

在网站跳转小程序(QQ/微信)

大家好,我是[玫瑰][滑稽]KongHen[滑稽][玫瑰]

今天在写一个页面的时候,需要用到跳转小程序,就查了一点资料,写了一个简单PHP例子,
提供需要的人看看这里是

QQ小程序

//网站跳转QQ小程序较简单,可能是用户较少,官方懒得维护更新吧
$url = ‘https://m.q.qq.com/a/p/这里填写小程序appid?s=这里填写页面路径&mode=wanba’;

//跳转QQ小游戏(不涉及页面路径,a和b是参数,a=1&b=2)
$url = ‘https://m.q.qq.com/a/p/这里填写小游戏appid?s=a=参数1&b=参数2’;

如图1

微信小程序

//微信小程序较麻烦,且生成的链接有效期为30天,且每个链接只能点击一次,所以,每次用都要重新生成一次,好在每天都能生成50万条,不用担心数量限制。
$token = file_get_contents(‘https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=这里是appid&secret=这里是appsecert’);
$token = json_decode($token, true);
$token = $token[“access_token”];
$url=’https://api.weixin.qq.com/wxa/generatescheme?access_token=’.$token;
$options = array(
‘http’ => array(
‘method’ => ‘POST’,
‘jump_wxa’=> ‘{
“path”: “”,//这里是小程序的页面路径,注意,不可以是tabber页面,空的时候就跳转首页
“query”: “”
}’,
),
);
$result = file_get_contents($url, false, stream_context_create($options));
$link = json_decode($result, true)[“openlink”];
//这个link就是最终生成的链接
$link = ‘https://servicewechat.com/wxascheme/jump_wxa?url=’.$link;

如图2图片[1]-朝晞小屋图片[2]-朝晞小屋

请登录后发表评论

    没有回复内容