当前位置:网站首页>PHP gets the external chain address of wechat applet and applet store
PHP gets the external chain address of wechat applet and applet store
2022-07-01 20:06:00 【withoutfear】
What needs to be noted here is The document says path Parameters should be filled __plugin__ To ? Path address between
My wechat store Filling in this path will report an error 40165 Parameters path Fill in the wrong
Actual filling ? The previous path address is correct I don't know if there is such a difference between wechat apps and app stores
query Fill in ? Address after
I get the address of the outside chain of the live broadcast room
// obtain access_token
$getUrl = 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid= Your app or app store appid&secret= Your app or app store secret';
$access_token_arr = curl($getUrl);
$access_token = $access_token_arr['access_token'];
// Outer chain production request address
$postUrl = 'https://api.weixin.qq.com/wxa/generate_urllink?access_token=' . $access_token;
// External chain request parameters
$data = array(
"path" => " Applet path ? Previous ",
"query" => " Applet path ? After that ",
"expire_type" => 1,
"expire_interval" => 1,
"env_version" => "release",
);
echo '<pre>';
var_dump(curl($postUrl, json_encode($data), 1));
die;
/**
* $url Request address
* $params GET Request for false POST The request is a data parameter
* $ispost GET Request for 0 POST Request for 1
*/
function curl($url, $params = false, $ispost = 0)
{
$httpInfo = array();
// initialization
$ch = curl_init();
/*CURL_HTTP_VERSION_NONE ( The default value is , Give Way cURL Decide which version to use ),CURL_HTTP_VERSION_1_0 ( Compulsory use HTTP/1.0) or CURL_HTTP_VERSION_1_1 ( Compulsory use HTTP/1.1).
*/
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
// Judge php edition If 5.6+ It contains CURLFILE This class , If 5.6- The settings are as follows , To solve the problem php Different versions of the problem
if (class_exists('\CURLFile')) {
curl_setopt($ch, CURLOPT_SAFE_UPLOAD, true);
} else {
if (defined('CURLOPT_SAFE_UPLOAD')) {
curl_setopt($ch, CURLOPT_SAFE_UPLOAD, false);
}
}
// stay HTTP The request contains a "User-Agent: " The string of the header .
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');
// Time to try to connect and wait , In Milliseconds . Set to 0, Then wait indefinitely . If libcurl Compile using the system standard name parser ( standard system name resolver), That part of the connection still uses the timeout solution in seconds , The minimum timeout is still one second .
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 60);
// allow cURL The maximum number of seconds a function can execute .
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
//TRUE take curl_exec() The information obtained is returned as a string , Instead of direct output .
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
//TRUE Will return according to the server HTTP In the header "Location: " Redirect .( Be careful : It's recursive ,"Location: " Send it a few times, redirect it a few times , Unless set CURLOPT_MAXREDIRS, Limit the maximum number of redirections .).
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
//FALSE prohibit cURL Verify peer certificate (peer's certificate).
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
// Set to 1 It's checking the server SSL Whether there is a common name in the certificate (common name). translator's note : Common name (Common Name) Generally speaking, it is to fill in the application you are going to apply for SSL Domain name of certificate (domain) Or subdomain (sub domain). Set to 2, Will check if the common name exists , And whether it matches the provided host name . 0 For not checking the name . In the production environment , This value should be 2( The default value is ).
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
// Set the encoding format , If it is blank, it means that all formats are supported
curl_setopt($ch, CURLOPT_ENCODING, '');
if ($ispost) {
// TRUE Will send POST request , The type is :application/x-www-form-urlencoded, yes HTML The most common type of form submission .
curl_setopt($ch, CURLOPT_POST, true);
// All data use HTTP In the agreement "POST" Operation to send
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
// Need to get URL Address , It can also be in curl_init() When initializing a session .
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);
}
边栏推荐
- A quietly rising domestic software, low-key and powerful!
- SwiftUI 4 新功能大全之 Toggle与 Mixed Toggle 多个绑定组件
- Richview trvdocparameters page parameter settings
- Process steps of vibrating wire acquisition module for measuring vibrating wire sensor
- GaussDB(for MySQL) :Partial Result Cache,通过缓存中间结果对算子进行加速
- How can a programmer grow rapidly
- 寫博客文檔
- Win11快捷键切换输入法无反应怎么办?快捷键切换输入法没有反应
- Items in richview documents
- ORA-01950
猜你喜欢
Bind this of the current scope for callback functions in other cases such as timers and delayers
What if the win11 shortcut key switching input method doesn't respond? Shortcut key switching input method does not respond
windows环境 redis安装和启动(后台启动)
300题线性代数 第四讲 线性方程组
Myslq ten kinds of locks, an article will take you to fully analyze
Win11 how to hide the taskbar? Win11 method to hide the taskbar
Review the collection container again
EasyCVR通过国标GB28181协议接入设备,出现设备自动拉流是什么原因?
Win11快捷键切换输入法无反应怎么办?快捷键切换输入法没有反应
EasyCVR集群视频广场页面切换时,请求流未能终止的问题优化
随机推荐
internship:复杂json格式数据编写接口
What if win11 can't pause the update? Win11 pause update is gray. How to solve it?
Process steps of vibrating wire acquisition module for measuring vibrating wire sensor
对金额进行求和
Big factories are wolves, small factories are dogs?
EURA欧瑞E1000系列变频器使用PID实现恒压供水功能的相关参数设置及接线
8K HDR!|为 Chromium 实现 HEVC 硬解 - 原理/实测指南
Tensorflow reports an error, could not load dynamic library 'libcudnn so. eight
Leetcode 1380 lucky numbers in matrix [array] the leetcode path of heroding
2022/5/23-2022/5/30
实例讲解将Graph Explorer搬上JupyterLab
fastDFS入门
math_ Use differentiation to calculate approximate value
Stack overflow 2022 developer survey: where is the industry going?
[mysql] install mysql5.7
windows环境 redis安装和启动(后台启动)
墨天轮沙龙 | 清华乔嘉林:Apache IoTDB,源于清华,建设开源生态之路
PHP获取微信小程序和小程序商店外链地址
Wechat applet realizes keyword highlighting
漏洞复现-.Net-ueditor上传