添加到桌面

抖音、快手引流到微信小程序,跳转微信小程序代码

首页 技术教程 正文

抖音快手引流到微信小程序,跳转微信小程序代码

基础用途:

  1. 其他平台引流到微信小程序,例如快手,抖音
  2. 网站快速跳转到小程序

高级用途:

  1. 微信小程序支付
  2. 跳转小程序观看广告后网页端下发奖励

使用前提:
非个人主体小程序

使用说明:
修改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));

?>
本文来自投稿,不代表本站立场,如若转载,请注明出处:
-- 展开阅读全文 --
2023搜狗图片搜索官方API接口
« 上一篇 12-02
【通义千问】人工智能大模型Web接口PHP对接代码源码
下一篇 » 12-02

发表评论

V注册会员 L评论等级
R2 条回复
    1. 2023-12-13 IP地址:浙江省

      00000

    2. 2023-12-04 IP地址:贵州省

      66666666666666666666666666666

    没有更多评论了