当前位置:网站首页>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);
}边栏推荐
- STC 32位8051单片机开发实例教程 三 程序编译设置与下载
- Using qeventloop to realize synchronous waiting for the return of slot function
- Anaconda installs the virtual environment to the specified path
- SwiftUI 4 新功能大全之 Toggle与 Mixed Toggle 多个绑定组件
- PHP获取微信小程序和小程序商店外链地址
- A quietly rising domestic software, low-key and powerful!
- Écrire un document de blog
- 毕业季 | 华为专家亲授面试秘诀:如何拿到大厂高薪offer?
- RichView RichEdit SRichViewEdit PageSize 页面设置与同步
- qobject_ Cast usage
猜你喜欢

3D panoramic model display visualization technology demonstration

一个悄然崛起的国产软件,低调又强大!

Getting started with fastdfs

STC 32-bit 8051 single chip microcomputer development example tutorial II i/o working mode and its configuration

Win11如何取消任务栏隐藏?Win11取消任务栏隐藏的方法

Use of common built-in classes of JS

为定时器和延时器等其它情况的回调函数绑定当前作用域的this

Realize pyramids through JS (asterisk pyramid, palindrome symmetric digital pyramid)

关于元宇宙下一代入口——脑机接口的实现

What if win11 can't pause the update? Win11 pause update is gray. How to solve it?
随机推荐
EURA欧瑞E1000系列变频器使用PID实现恒压供水功能的相关参数设置及接线
Face recognition system opencv face detection
Hls4ml entry method
简单但现代的服务器仪表板Dashdot
Keras machine translation practice
ORA-01950
Problems encountered in installing MySQL in docker Ubuntu container
Using qeventloop to realize synchronous waiting for the return of slot function
Interview questions shared in today's group
Use of common built-in classes of JS
Win11怎么关闭开机自启动软件
墨天轮沙龙 | 清华乔嘉林:Apache IoTDB,源于清华,建设开源生态之路
Optimization of the problem that the request flow fails to terminate during page switching of easycvr cluster video Plaza
使用Zadig从0到1搭建持续交付平台
对金额进行求和
实战项目笔记(一)——虚拟机的创建
windows环境 redis安装和启动(后台启动)
关于new Set( )还有哪些是你不知道的
Graduation season | Huawei experts teach the interview secret: how to get a high paying offer from a large factory?
Arduino Stepper库驱动28BYJ-48步进电机测试程序