因为一个TP项目中客户需要全部网页分享支持自定义图片和描述信息,于是自己封装了下
//share()微信分享链接
//参数1 appid
//参数2 appsert
//参数3 nonceStr随机码
//参数4 timestamp时间戳
public function share($appid,$appsert,$nonceStr,$timestamp){
//获取token
$token='https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid='.$appid.'&secret='.$appsert;
$token=file_get_contents($token);
$token=json_decode($token);
$token=$token->access_token;
//获取jsapi_ticket
$ticket='https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token='.$token.'&type=jsapi';
$ticket=file_get_contents($ticket);
$ticket=json_decode($ticket);
$ticket=$ticket->ticket;
$protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443) ? "https://" : "http://";
//获取当前域名
$url = "$protocol$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
//返回签名
$signaturestring = "jsapi_ticket=$ticket&noncestr=$nonceStr×tamp=$timestamp&url=$url";
$signature = sha1($signaturestring);
//返回HTML页面需要的全部参数信息
return array('appid'=>$appid,'timestamp'=>$timestamp,'nonceStr'=>$nonceStr,'signature'=>$signature,'ticket'=>$ticket);
} php官方已经提供了Iterator(迭代器)接口,通过网上资料的学习,目前看适合超大集合或者数组提取使用。学习一个函数的实现对比内存占用差距.使用迭代器和普通循环实现range()函数。(1).普通循环实现range()函数。function newrange($low, $h...
php7新增的特性(1).强制限制只能返回一种类型<?php class task { } //must return an integer function add(): int { &nb...
<?php //如果支持exec函数,可以使用的方式 exec('chcp 65001'); //如果exec函数因安全问题禁用,可以使用的方式 pclose(popen('chcp 65001', 'r'));...
有时候我们需要爬一个接口,但是这个接口需要很多参数,包括header和cookie要去编写,使用php curl模拟实在太慢。我们可以通过浏览器的network来复制请求为curl命令。例如我需要模拟请求接口地址:https://www.xkmz.cc/Ajax/Debug/delly,我们只需要在...
将jsonp转为PHP数组和对象。/** * jsonp转数组|Jsonp转json * @param string $jsonp jsonp字符串 * @param bool $as...
经常我们下载国外资源容易被墙,可以通过php脚本获取远程文件流然后输出给我们的浏览器来下载。<?php //设置下载文件的url $url = 'https://mirrors.huaweicloud.com/ubuntukylin/ubuntukylin-19....