当前位置:网站首页>PHP gets the applet code, and the applet jumps with parameters
PHP gets the applet code, and the applet jumps with parameters
2022-07-28 16:26:00 【Sun Fendou】
PHP Get the applet code , Applet jump with parameters
To get the applet code, you need to get Accesstoken , Here's how to get Accesstoken, Pay attention to the timeout, so I mentioned the time forward , When generating applet code, first call and obtain Accesstoken Methods
// obtain accesstokn And save
public function getAccessToken(){
//$file_path = VENDOR_PATH.'wchat/access_token';
$file_path = '../application/common/access_token';
if(is_file($file_path)){
$connect = file_get_contents($file_path);
if($connect!=''){
$ret = json_decode($connect,true);
// Already exists
if($ret['access_token'] && time()-$ret['time'] <7000){
$this->access_token = $ret['access_token'];
return true;
}
}
}
$wx_url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={
$this->wxAppId}&secret={
$this->wxAppSecret}";
$ret = httpUtil($wx_url);
$ret = json_decode($ret,true);
if($ret['access_token']){
$data = array(
'access_token'=>$ret['access_token'],
'time'=>time()
);
file_put_contents($file_path, json_encode($data));
$this->access_token = $ret['access_token'];
return true;
}
}
// Get the applet code
public function getQrCode($openid){
$this->getAccessToken();// to update accesstoken
$url = "https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=$this->access_token";// Official access applet code url
$data['page']='pages/index/index';// The jump page address of the applet
$data['scene'] = "$openid"; // Request parameters
$res = httpUtil($url,json_encode($data),'POST');
if(!empty($res['errcode'])){
return false;
}
$file ="qrcode/$openid.jpg";
file_put_contents('./'.$file,$res);
if (file_exists($file)) {
//return $_SERVER ['HTTP_HOST'].'/'.$file;
return '/'.$file;
}else{
return false;
}
}
边栏推荐
- Fifth uncle's thinking
- 学会使用MySQL的Explain执行计划,SQL性能调优从此不再困难
- R语言使用GGally包的ggpairs函数可视化分组多变量的两两关系图、设置alpha参数改变图像透明度、对角线上连续变量密度图、离散变量条形图、两两关系图中包含散点图、直方图、箱图以及相关性数值
- Writing of factorial
- Telecommuting can be easily realized in only three steps
- 微信公众号获取素材列表
- JS queue
- c语言编程当中两个!!的作用
- 五舅的思考
- LabVIEW LINX Toolkit控制Arduino设备(拓展篇—1)
猜你喜欢

Instructions for mictr01 Tester development kit (vibrating wire acquisition reader)

mysql 查看事件状态语句和修改办法

QT packaging

Rust Getting Started Guide (crite Management)

JS array (summary)

带你来浅聊一下!单商户功能模块汇总

Why do most people who learn programming go to Shenzhen and Beijing?

【Multisim仿真】LM339过零电路仿真

leetcode 题目

Common problems and precautions of remote serial port server (adapter) uart/i2c/1-wire/spi PS304
随机推荐
关于web对接针式打印机问题,Lodop使用
Fifth uncle's thinking
JS stack
百度编辑器ueditor,编辑内容过多时,工具栏不可见,不方便编辑或上传问题
兆骑科创创新创业大赛人才引进平台,双创赛事高层次人才引进
Telecommuting can be easily realized in only three steps
The epidemic dividend disappeared, and the "home fitness" foam dissipated
跳表的实现
LabVIEW LINX Toolkit控制Arduino设备(拓展篇—1)
Rosen's QT journey 102 listmodel
一大早支付宝来短信说你中“奖”了?处理服务器挖矿病毒 - kthreaddi
Stm32cube infrared remote control: input capture
STM32F103C8T6 + 0.96“ I2C OLED显示3D_Cube
ffmpeg获取首帧
软考 系统架构设计师 简明教程 | 软件调试
Qt学习之Qt Designer(设计师)
NTC, PT100 thermal resistance to 4-20mA temperature signal converter
R语言使用fs包的file_delete函数删除指定文件夹下的指定文件、举一反三、dir_delete函数、link_delete函数可以用来删除文件夹和超链接
Paging query in applet
2021-10-21 notes