Application/Common/Tool/Wxtoken.class.php
(开头部分) 2KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
<?php
namespace Common\Tool;
class Wxtoken {
private $wxappid;
private $wxappsecret;
public function __construct($wxappid='',$wxappsecret='') {
$this->wxappid = $wxappid;
$this->wxappsecret = $wxappsecret;
}
public function getSignPackage() {
$jsapiTicket = $this->getJsApiTicket();
// 注意 URL 一定要动态获取,不能 hardcode.
$protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443) ? "https://" : "http://";
$url = "$protocol$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
$timestamp = time();
$nonceStr = $this->createNonceStr();
// 这里参数的顺序要按照 key 值 ASCII 码升序排序
$string = "jsapi_ticket=$jsapiTicket&noncestr=$nonceStr×tamp=$timestamp&url=$url";
$signature = sha1($string);
$signPackage = array(
"appId" => $this->wxappid,
"nonceStr" => $nonceStr,
"timestamp" => $timestamp,
"url" => $url,
"signature" => $signature,
"rawString" => $string
);
return $signPackage;
}
private function getJsApiTicket() {
$url = "http://www.haokuaiwang.com/haokuaiwang/getdata/getwxticket.php?cappid=".$this->wxappid."&cappsecret=".$this->wxappsecret.'&uweb='.$_SERVER['HTTP_HOST'];
$ticket = $this->httpGet($url);
return trim($ticket);
}
public function getAccessToken() {
$url = "http://www.haokuaiwang.com/haokuaiwang/getdata/getwxtoken.php?cappid=".$this->wxappid."&cappsecret=".$this->wxappsecret."&uweb=".$_SERVER['HTTP_HOST'];
$access_token = $this->httpGet($url);
return trim($access_token);
}
private function createNonceStr($length = 16) {
$chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
$str = "";
for ($i = 0; $i < $length; $i++) {
$str .= substr($chars, mt_rand(0, strlen($chars) - 1), 1);
}
return $str;
}
private function httpGet($url) {
后面还有 13 行代码,购买后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明
AI 解读 AI
登录后可用,每次 10 算力,解读结果公开显示在下面。
还没有人解读过这个文件。