Init Repo

This commit is contained in:
root
2019-09-06 23:53:10 +08:00
commit f0ef89dfbb
7905 changed files with 914138 additions and 0 deletions

57
vendor/wechat/src/WeChat/Extend/Authorize.php vendored Executable file
View File

@ -0,0 +1,57 @@
<?php
namespace WeChat\Extend;
/**
* 微信授权接口
* Interface Authorize
* @package WeChat\Extend
*/
interface Authorize
{
/**
* 首次关注
* @param \WeChat\Core\Authorize->returnData 返回数据数组
* @param \WeChat\Core\Authorize->config 微信数据包
* @return mixed
*/
public function follow();
/**
* 扫码关注
* @param \WeChat\Core\Authorize->returnData 返回数据数组
* @param \WeChat\Core\Authorize->config 微信数据包
* @return mixed
*/
public function scanFollow();
/**
* 点击事件
* @param \WeChat\Core\Authorize->returnData 返回数据数组
* @param \WeChat\Core\Authorize->config 微信数据包
* @return mixed
*/
public function click();
/**
* 扫描商品
* @param \WeChat\Core\Authorize->returnData 返回数据数组
* @param \WeChat\Core\Authorize->config 微信数据包
* @return mixed
*/
public function scanProduct();
/**
* 扫码事件
* @return mixed
*/
public function scan();
/**
* 用户输入
* @return mixed
*/
public function input();
}

81
vendor/wechat/src/WeChat/Extend/File.php vendored Executable file
View File

@ -0,0 +1,81 @@
<?php
namespace WeChat\Extend;
/**
* Class File 微信存储类
* @package wechat\lib
*/
class File
{
/**
* 定义常量 / 路径连接符
*/
private static $ext = '/';
/**
* 存储对象文件,可扩展
* @param string $var
* @param array $val
* @return null
*/
public static function param(string $var, array $val = [])
{
$file_path = self::mkdir('param');
$fileCont = json_decode(file_get_contents($file_path), true);
if(empty($fileCont) and empty($val)) return null;
if(!empty($val) and !empty($var)){
$val['time'] = time();
$fileCont[$var] = $val;
file_put_contents($file_path,json_encode($fileCont));
}
if(!empty($val) and empty($var)){
if ($fileCont[$var]['time'] - time() <= 7100){
unset($fileCont[$var]['time']);
if (!empty($fileCont[$var])) return $fileCont[$var];
}
return null;
}
}
/**
* 支付日志
* @param string $type
* @param array $param
* @return mixed
*/
public static function paylog(string $type = 'wechat', array $param = [])
{
$file_path = self::mkdir('wechat');
if (!empty($type) and empty($param)) {
return json_decode(file_get_contents($file_path), true);
}
$data = '['.date('Y-m-d H:i:s').'] => '.json_encode($param) . PHP_EOL;
file_put_contents($file_path, $data, FILE_APPEND);
}
/**
* 创建日志类型文件
* @param string $type
* @return string
*/
private static function mkdir(string $type = 'param')
{
$file_dir = dirname(__FILE__) . static::$ext . 'log' ;
(!is_dir($file_dir)) && mkdir($file_dir, 0755);
$file_dir .= static::$ext . date('Y-m-d-H') . static::$ext;
if ($type == 'param') {
$file_dir = dirname(__FILE__) . static::$ext . 'log' . static::$ext . 'param' . static::$ext;
}
$file_name = $type . '.log';
(!is_dir($file_dir)) && mkdir($file_dir, 0755);
if (!is_file($file_dir . $file_name)) {
file_put_contents($file_dir . $file_name, '');
}
return $file_dir . $file_name;
}
}

59
vendor/wechat/src/WeChat/Extend/Json.php vendored Executable file
View File

@ -0,0 +1,59 @@
<?php
namespace WeChat\Extend;
use Throwable;
/**
* Class Json json输出类
* @package wechat\lib
*/
class Json extends \Exception
{
public function __construct(string $message = "", int $code = 0, Throwable $previous = null)
{
parent::__construct($message, $code, $previous);
}
/**
* 请求失败
* @param string $msg
*/
public static function error(string $msg = '请求失败')
{
self::return_abnormal(400, $msg);
}
/**
* 请求成功
* @param string $msg 返回消息
* @param array $data 返回data数据
*/
public static function success(string $msg = '请求成功', array $data = [])
{
self::return_abnormal(200, $msg, $data);
}
/**
* 输出JSON
* @param int $code 状态码
* @param string $msg 原因
* @param array $data 输出数据
*/
public static function return_abnormal(int $code,string $msg,array $data = [])
{
$code_state = $code == 200 ? 'OK' : 'Bad Request';
$param = [
'code' => $code,
'msg' => $msg,
'data' => $data,
];
header("HTTP/1.1 " . $code . " " . $code_state);
header('Content-Type:application/json;charset=utf-8');
if ($param !== null) {
echo json_encode($param, JSON_UNESCAPED_UNICODE);
}
exit();
}
}

119
vendor/wechat/src/WeChat/Extend/Request.php vendored Executable file
View File

@ -0,0 +1,119 @@
<?php
namespace WeChat\Extend;
/**
* Class Request 请求类
* @package wechat\lib
*/
class Request
{
/**
* 支持请求类型
* @var array $methods
*/
private static $methods = ['get','post'];
/**
* 发送 header 请求
* @param string $url 请求链接
* @param array $params 请求参数
*/
public static function header(string $url,array $params = []):void
{
if (!empty($params)) $url .= static::ToUrlParams($params);
header('Location: ' . $url);
exit();
}
/**
* 发送 <script>window.top.location.href</script> 请求
* @param string $url
* @param array $params
*/
public static function jump(string $url,array $params = [])
{
if (!empty($params)) $url .= static::ToUrlParams($params);
exit( '<script>window.top.location.href='.$url.'</script>');
}
/**
* 发送curl请求
* @param string $method 【类型 : get | post】
* @param string $url 请求链接
* @param array $params 请求参数
* @return array
*/
public static function request(string $method,string $url, $params = []):array
{
$method = strtolower($method);
$isHttp = stristr($url,'https') ? true : false;
if (!in_array($method,static::$methods)) Json::error('请求类型错误~');
if ($method === 'get' and !empty($params)) $url .= static::ToUrlParams($params);
return static::curl_request($url,$isHttp,$method,$params);
}
/**
* [curl_request 发送http请求]
* @param [url] $url [请求地址]
* @param boolean $https [是否使用HTTPS]
* @param string $method [请求方式:GET / POST]
* @param [array] $data [post 数据]
* @return [result] [成功返回对方返回的结果,是非返回false]
*/
public static function curl_request($url, $https = false, $method = 'get', $data = null)
{
/**************** 初始化curl ******************/
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //结果为字符串且输出到屏幕上
/**************** 发送 https请求 ******************/
if ($https === true) {
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
}
/******** 发送 POST 请求 类型为:application/x-www-form-urlencoded **********/
if ($method == 'post') {
curl_setopt($ch, CURLOPT_POST, 1); //post提交方式
curl_setopt($ch, CURLOPT_HEADER, 0); //设置header
// 所需传的数组用 http_build_query() 函数处理一下,就可以传递二维数组了
if (is_array($data) and count($data) > 0) $data = http_build_query($data);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
} else {
curl_setopt($ch, CURLOPT_TIMEOUT, 500);
}
/**************** 发送请求 ******************/
curl_setopt($ch, CURLOPT_URL, $url);
$result = curl_exec($ch);
$url_status = curl_getinfo($ch);
/**************** 关闭连接 并 返回数据 ******************/
curl_close($ch);
if (intval($url_status["http_code"]) == 200){
if (json_decode($result,true) != false){
return json_decode($result,true);
}
return $result;
}
return false;
}
/**
*
* 拼接签名字符串
* @param array $urlObj
*
* @return 返回已经拼接好的字符串
*/
public static function ToUrlParams($urlObj)
{
$buff = "?";
foreach ($urlObj as $k => $v) {
if ($k != "sign") {
$buff .= $k . "=" . $v . "&";
}
}
$buff = trim($buff, "&");
return $buff;
}
}

179
vendor/wechat/src/WeChat/Extend/Tool.php vendored Executable file
View File

@ -0,0 +1,179 @@
<?php
namespace WeChat\Extend;
/**
* Trait Tool 工具类
* @package wechat\lib
*/
trait Tool
{
/**
* 接口 json 成功输出
* @param string $msg 输出内容,输出参数~
* @param array $data
*/
public static function success($msg = '操作成功', array $data = [])
{
if (is_array($msg)){
Json::success('操作成功~', $data);
}
Json::success($msg, $data);
}
/**
* 接口 json 失败输出
* @param string $msg
*/
public static function error(string $msg = '操作失败')
{
Json::error($msg);
}
/**
* 重载路由
* @param string $url
* @param array $params
*/
public static function header(string $url, array $params = []): void
{
Request::header($url, $params);
}
/**
* curl 发送 POST 请求
* @param string $url
* @param array $params
* @return array
*/
public static function post(string $url,$params = [])
{
return Request::request('POST',$url,$params);
}
/**
* curl 发送 GET 请求
* @param string $url
* @param array $params
* @return array
*/
public static function get(string $url,array $params = [])
{
return Request::request('GET',$url,$params);
}
/**
* url拼接数组
* @param array $params
* @return string
*/
public static function url_splice_array(array $params = [])
{
$buff = "";
foreach ($params as $k => $v) {
if ($k != "sign") {
$buff .= $k . "=" . $v . "&";
}
}
$buff = trim($buff, "&");
return $buff;
}
/**
* 创建唯一字符
* @param string $strBlur 原字符
* @param string $strType 加密方式 :[w所有|s字符|d数字]
* @param int $strLen 返回字符长度,建议大于16位
* @return string 字符串
*/
public static function randOnlyStr(string $strBlur = '',string $strType = 'w',int $strLen = 18):string
{
$dStr = '0123456789';
$sStr = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$wStr = '!$&()*,/:;=?@-._~';
$strBlurLen = (strlen(static::uniqueString($strBlur)) + 1) == 1 ? 0 : strlen(static::uniqueString($strBlur)) + 1;
$strSuffix = $strBlurLen > 0 ? '#'.static::uniqueString($strBlur) : '';
switch ($strType)
{
case 's': # 字符串
return static::getGapStrByStr($sStr,$strLen - $strBlurLen).$strSuffix;
break;
case 'd': # 数字
return static::getGapStrByStr($dStr,$strLen - $strBlurLen).$strSuffix;
break;
case 'w': # 匹配包括下划线的任何单词字符。等价于“[A-Za-z0-9_]”。
return static::getGapStrByStr($dStr.$sStr.$wStr,$strLen - $strBlurLen).$strSuffix;
break;
default : # 默认大小写字母
return static::getGapStrByStr($sStr,$strLen - $strBlurLen).$strSuffix;
break;
}
}
/**
* 获取对应字符
* @param string $str 字符串
* @param int $strLen 长度
* @return string 随机字符串
*/
public static function getGapStrByStr(string $str = '', int $strLen = 18)
{
static $newStr = '';
static $i = 0;
if ($i < $strLen)
{
$newStr .= $str[rand(0,strlen($str))];
$i ++;
static::getGapStrByStr($str,$strLen);
}
return $newStr;
}
/**
* 生成唯一字符串
* @param $type $type 类型
* @return string 字符串
*/
public static function uniqueString(string $type)
{
return bin2hex($type);
}
/**
* 获取唯一字符串类型
* @param $string $string 唯一字符串
* @return bool|string 返回结果:字符串或者false
*/
public static function uniqueType(string $string)
{
return hex2bin($string);
}
/**
* 小程序检验数据的真实性,并且获取解密后的明文.
* @param string $appID 加密的用户数据
* @param string $sessionKey 与用户数据一同返回的初始向量
* @param string $encryptedData 解密后的原文
* @param string $iv 成功0,失败返回对应的错误码
* @return string
*/
public static function decryptData(string $appID, string $sessionKey, string $encryptedData, string $iv )
{
if (strlen($sessionKey) != 24) return '4';
if (strlen($iv) != 24) return '3';
$aesKey = base64_decode($sessionKey);
$aesIV = base64_decode($iv);
$aesCipher = base64_decode($encryptedData);
$result = openssl_decrypt($aesCipher,"AES-128-CBC",$aesKey,1,$aesIV);
$dataObj = json_decode($result,true);
if( $dataObj == NULL ) return '2';
if( $dataObj['watermark']['appid'] != $appID ) return '1';
return $result;
}
}

View File

@ -0,0 +1 @@
{"access_token":{"access_token":"22_TkrZweCYc9K1gZtrP7YjI-rKHTeaWhEfWS6XWVd1MbGHdPXLd72rFNx3ziElXYKoFKwYVUOiAzHrUQPvlEvxdRCElu03JlDSJWkdF6U3z6AsPq44YQLVFinkSewiRd6h74TKo6Y_Xjn_Bo3sUJCcAGAZOH","expires_in":7200,"time":1561616075}}