当前位置:网站首页>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);
}
边栏推荐
- What if win11 can't pause the update? Win11 pause update is gray. How to solve it?
- Richview trvdocparameters page parameter settings
- EDA工具对芯片产业的重要性知识科普
- qobject_ Cast usage
- 想得到股票开户的优惠链接,如何得知?在线开户是安全么?
- 使用Zadig从0到1搭建持续交付平台
- GaussDB(for MySQL) :Partial Result Cache,通过缓存中间结果对算子进行加速
- Summary of SQL aggregate query method for yyds dry goods inventory
- Stack overflow 2022 developer survey: where is the industry going?
- Develop those things: easycvr platform adds playback address authentication function
猜你喜欢
[research materials] Huawei Technology ICT 2021: at the beginning of the "Yuan" year, the industry is "new" -- download attached
300题线性代数 第四讲 线性方程组
STC 32-bit 8051 single chip microcomputer development example tutorial three program compilation setting and download
Is Dao safe? Build finance encountered a malicious governance takeover and was looted!
What if the win11 shortcut key switching input method doesn't respond? Shortcut key switching input method does not respond
Modsim basic use (Modbus simulator)
MYSLQ十种锁,一篇文章带你全解析
RichView TRVDocParameters 页面参数设置
Graduation season | Huawei experts teach the interview secret: how to get a high paying offer from a large factory?
Example explanation: move graph explorer to jupyterlab
随机推荐
为定时器和延时器等其它情况的回调函数绑定当前作用域的this
Solve the problem of slow or failed vscode download
[Mysql]安装Mysql5.7
Tensorflow reports an error, could not load dynamic library 'libcudnn so. eight
Swiftui 4 new features complete toggle and mixed toggle multiple binding components
[mysql] install mysql5.7
STC 32位8051单片机开发实例教程 二 I/O工作模式及其配置
What if win11 can't pause the update? Win11 pause update is gray. How to solve it?
STC 32-bit 8051 single chip microcomputer development example tutorial three program compilation setting and download
GaussDB(for MySQL) :Partial Result Cache,通过缓存中间结果对算子进行加速
List is divided into sets that meet and do not meet conditions (partitioningby)
Écrire un document de blog
The large list set is divided into multiple small list sets in equal proportion
EasyCVR通过国标GB28181协议接入设备,出现设备自动拉流是什么原因?
GaussDB(for MySQL) :Partial Result Cache,通过缓存中间结果对算子进行加速
What if the win11 shortcut key switching input method doesn't respond? Shortcut key switching input method does not respond
8K HDR!|为 Chromium 实现 HEVC 硬解 - 原理/实测指南
How to prevent repeated submission of new orders
Servlet knowledge points
C # joint Halcon application - Dahua camera acquisition class