当前位置:网站首页>PHP获取微信小程序和小程序商店外链地址
PHP获取微信小程序和小程序商店外链地址
2022-07-01 18:51:00 【withoutfear】
这里需要注意的是 文档上说的 path 参数要填 __plugin__ 到 ? 之间的路径地址
我的是微信小商店 填这个路径会报错 40165 参数 path 填写错误
实际填写 ? 之前的路径地址是正确的 不知道是不是微信小程序和小程序商店有这个区别
query 填写 ? 之后的地址
我是获取直播间外链地址
// 获取 access_token
$getUrl = 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=你的小程序或者小程序商店的appid&secret=你的小程序或者小程序商店的secret';
$access_token_arr = curl($getUrl);
$access_token = $access_token_arr['access_token'];
// 外链生产请求地址
$postUrl = 'https://api.weixin.qq.com/wxa/generate_urllink?access_token=' . $access_token;
// 外链请求参数
$data = array(
"path" => "小程序路径 ? 之前的",
"query" => "小程序路径 ? 之后的",
"expire_type" => 1,
"expire_interval" => 1,
"env_version" => "release",
);
echo '<pre>';
var_dump(curl($postUrl, json_encode($data), 1));
die;
/**
* $url 请求地址
* $params GET请求为 false POST请求为数据参数
* $ispost GET请求为 0 POST请求为 1
*/
function curl($url, $params = false, $ispost = 0)
{
$httpInfo = array();
//初始化
$ch = curl_init();
/*CURL_HTTP_VERSION_NONE (默认值,让 cURL 自己判断使用哪个版本),CURL_HTTP_VERSION_1_0 (强制使用 HTTP/1.0)或CURL_HTTP_VERSION_1_1 (强制使用 HTTP/1.1)。
*/
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
// 判断php版本 如果5.6+ 则含有CURLFILE 这个类 ,如果5.6-则设置如下,为解决php不同版本的问题
if (class_exists('\CURLFile')) {
curl_setopt($ch, CURLOPT_SAFE_UPLOAD, true);
} else {
if (defined('CURLOPT_SAFE_UPLOAD')) {
curl_setopt($ch, CURLOPT_SAFE_UPLOAD, false);
}
}
//在HTTP请求中包含一个"User-Agent: "头的字符串。
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36');
//尝试连接等待的时间,以毫秒为单位。设置为0,则无限等待。 如果 libcurl 编译时使用系统标准的名称解析器( standard system name resolver),那部分的连接仍旧使用以秒计的超时解决方案,最小超时时间还是一秒钟。
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 60);
// 允许 cURL 函数执行的最长秒数。
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
//TRUE 将curl_exec()获取的信息以字符串返回,而不是直接输出。
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
//TRUE 时将会根据服务器返回 HTTP 头中的 "Location: " 重定向。(注意:这是递归的,"Location: " 发送几次就重定向几次,除非设置了 CURLOPT_MAXREDIRS,限制最大重定向次数。)。
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
//FALSE 禁止 cURL 验证对等证书(peer's certificate)。
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
//设置为 1 是检查服务器SSL证书中是否存在一个公用名(common name)。译者注:公用名(Common Name)一般来讲就是填写你将要申请SSL证书的域名 (domain)或子域名(sub domain)。 设置成 2,会检查公用名是否存在,并且是否与提供的主机名匹配。 0 为不检查名称。 在生产环境中,这个值应该是 2(默认值)。
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
//设置编码格式,为空表示支持所有格式的编码
curl_setopt($ch, CURLOPT_ENCODING, '');
if ($ispost) {
// TRUE 时会发送 POST 请求,类型为:application/x-www-form-urlencoded,是 HTML 表单提交时最常见的一种。
curl_setopt($ch, CURLOPT_POST, true);
//全部数据使用HTTP协议中的 "POST" 操作来发送
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
//需要获取的 URL 地址,也可以在curl_init() 初始化会话的时候。
curl_setopt($ch, CURLOPT_URL, $url);
} else {
if ($params) {
curl_setopt($ch, CURLOPT_URL, $url . '?' . $params);
} else {
curl_setopt($ch, CURLOPT_URL, $url);
}
}
$response = curl_exec($ch);
if ($response === FALSE) {
//echo "cURL Error: " . curl_error($ch);
return false;
}
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$httpInfo = array_merge($httpInfo, curl_getinfo($ch));
curl_close($ch);
return json_decode($response, true);
}
边栏推荐
- DS transunet: Dual Swing transformer u-net for medical image segmentation
-
- Win11怎么关闭开机自启动软件
- HLS4ML报错The board_part definition was not found for tul.com.tw:pynq-z2:part0:1.0.
- ModSim基本使用(Modbus模拟器)
- 开发那些事儿:EasyCVR平台添加播放地址鉴权功能
- 一文读懂C语言中的结构体
- [research materials] Huawei Technology ICT 2021: at the beginning of the "Yuan" year, the industry is "new" -- download attached
- Wechat applet realizes keyword highlighting
- Set object value changes null value object
猜你喜欢
一个悄然崛起的国产软件,低调又强大!
uniapp使用腾讯地图选点 没有window监听回传用户的位置信息,怎么处理
ModSim基本使用(Modbus模拟器)
JVM内存模型
Redis installation and startup in Windows environment (background startup)
开发那些事儿:EasyCVR平台添加播放地址鉴权功能
Why has instagram changed from a content sharing platform to a marketing tool? How do independent sellers use this tool?
Process steps of vibrating wire acquisition module for measuring vibrating wire sensor
Review the collection container again
Procédure de mesure du capteur d'accord vibrant par le module d'acquisition d'accord vibrant
随机推荐
math_利用微分算近似值
Stack Overflow 2022 开发者调查:行业走向何方?
[exercise] HashSet
Arduino Stepper库驱动28BYJ-48步进电机测试程序
【AI服务器搭建】CUDA环境
Interview questions shared in today's group
mysql 報錯 Can‘t create table ‘demo01.tb_Student‘ (errno: 150)*
MYSLQ十种锁,一篇文章带你全解析
DS Transunet:用于医学图像分割的双Swin-Transformer U-Net
Object creation
JS ternary expression complex condition judgment
Bao, what if the O & M 100+ server is a headache? Use Xingyun housekeeper!
Technology T3 domestic platform! Successfully equipped with "Yihui domestic real-time system sylixos"
February 15, 2022: sweeping robot. There is a floor sweeping robot in the room (represented by a grid). Each grid in the grid has two possibilities: empty and obstacles. The sweeping robot provides fo
EasyCVR通过国标GB28181协议接入设备,出现设备自动拉流是什么原因?
[research materials] Huawei Technology ICT 2021: at the beginning of the "Yuan" year, the industry is "new" -- download attached
Regular expression =regex=regular expression
Axure does not display catalogs
JS的Proxy
Easycvr accesses the equipment through the national standard gb28181 protocol. What is the reason for the automatic streaming of the equipment?