[更新]ComposerUpdate

This commit is contained in:
Anyon 2018-04-20 12:44:03 +08:00
parent edc30af40b
commit 3a50473818
37 changed files with 987 additions and 84 deletions

View File

@ -79,6 +79,8 @@ return [
'pathinfo_depr' => '/',
// HTTPS代理标识
'https_agent_name' => '',
// IP代理获取标识
'http_agent_ip' => 'X-REAL-IP',
// URL伪静态后缀
'url_html_suffix' => 'html',
// URL普通方式参数 用于自动生成

View File

@ -20,7 +20,7 @@ use think\route\Dispatch;
*/
class App implements \ArrayAccess
{
const VERSION = '5.1.10';
const VERSION = '5.1.11';
/**
* 当前模块路径

View File

@ -39,6 +39,12 @@ class Container
*/
protected $bind = [];
/**
* 容器标识别名
* @var array
*/
protected $name = [];
/**
* 获取当前容器的实例(单例)
* @access public
@ -177,6 +183,8 @@ class Container
$vars = [];
}
$abstract = isset($this->name[$abstract]) ? $this->name[$abstract] : $abstract;
if (isset($this->instances[$abstract]) && !$newInstance) {
return $this->instances[$abstract];
}
@ -187,7 +195,8 @@ class Container
if ($concrete instanceof Closure) {
$object = $this->invokeFunction($concrete, $vars);
} else {
$object = $this->make($concrete, $vars, $newInstance);
$this->name[$abstract] = $concrete;
return $this->make($concrete, $vars, $newInstance);
}
} else {
$object = $this->invokeClass($abstract, $vars);
@ -203,13 +212,17 @@ class Container
/**
* 删除容器中的对象实例
* @access public
* @param string $abstract 类名或者标识
* @param string|array $abstract 类名或者标识
* @return void
*/
public function delete($abstract)
{
if (isset($this->instances[$abstract])) {
unset($this->instances[$abstract]);
foreach ((array) $abstract as $name) {
$name = isset($this->name[$name]) ? $this->name[$name] : $name;
if (isset($this->instances[$name])) {
unset($this->instances[$name]);
}
}
}
@ -222,6 +235,7 @@ class Container
{
$this->instances = [];
$this->bind = [];
$this->name = [];
}
/**

View File

@ -41,10 +41,10 @@ class Loader
private static $fallbackDirsPsr0 = [];
/**
* 自动加载的文件列表
* 需要加载的文件
* @var array
*/
private static $autoloadFiles = [];
private static $files = [];
/**
* Composer安装路径
@ -88,7 +88,7 @@ class Loader
$declaredClass = get_declared_classes();
$composerClass = array_pop($declaredClass);
foreach (['prefixLengthsPsr4', 'prefixDirsPsr4', 'prefixesPsr0', 'classMap'] as $attr) {
foreach (['prefixLengthsPsr4', 'prefixDirsPsr4', 'fallbackDirsPsr4', 'prefixesPsr0', 'fallbackDirsPsr0', 'classMap', 'files'] as $attr) {
if (property_exists($composerClass, $attr)) {
self::${$attr} = $composerClass::${$attr};
}
@ -340,22 +340,20 @@ class Loader
self::addClassMap($classMap);
}
}
if (is_file($composerPath . 'autoload_files.php')) {
self::$files = require $composerPath . 'autoload_files.php';
}
}
// 加载composer autofile文件
public static function loadComposerAutoloadFiles()
{
if (is_file(self::$composerPath . 'autoload_files.php')) {
$includeFiles = require self::$composerPath . 'autoload_files.php';
foreach ($includeFiles as $fileIdentifier => $file) {
if (isset($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
continue;
}
foreach (self::$files as $fileIdentifier => $file) {
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
__require_file($file);
if (empty(self::$autoloadFiles[$fileIdentifier])) {
__require_file($file);
self::$autoloadFiles[$fileIdentifier] = true;
}
$GLOBALS['__composer_autoload_files'][$fileIdentifier] = true;
}
}
}

View File

@ -207,7 +207,10 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
{
// 设置当前模型 确保查询返回模型对象
$class = $this->query;
$query = (new $class())->connect($this->connection)->model($this)->json($this->json);
$query = (new $class())->connect($this->connection)
->model($this)
->json($this->json)
->setJsonFieldType($this->jsonType);
// 设置当前数据表和模型名
if (!empty($this->table)) {

View File

@ -33,6 +33,7 @@ abstract class Builder
'parseBetweenTime' => ['BETWEEN TIME', 'NOT BETWEEN TIME'],
'parseTime' => ['< TIME', '> TIME', '<= TIME', '>= TIME'],
'parseExists' => ['NOT EXISTS', 'EXISTS'],
'parseColumn' => ['COLUMN'],
];
// SQL表达式
@ -182,13 +183,13 @@ abstract class Builder
* 字段名分析
* @access public
* @param Query $query 查询对象
* @param string $key 字段名
* @param mixed $key 字段名
* @param bool $strict 严格检测
* @return string
*/
public function parseKey(Query $query, $key, $strict = false)
{
return $key;
return $key instanceof Expression ? $key->getValue() : $key;
}
/**
@ -207,9 +208,7 @@ abstract class Builder
$array = [];
foreach ($fields as $key => $field) {
if ($field instanceof Expression) {
$array[] = $field->getValue();
} elseif (!is_numeric($key)) {
if (!is_numeric($key)) {
$array[] = $this->parseKey($query, $key) . ' AS ' . $this->parseKey($query, $field, true);
} else {
$array[] = $this->parseKey($query, $field);
@ -412,7 +411,12 @@ abstract class Builder
$value = $value->__toString();
}
$bindType = isset($binds[$field]) ? $binds[$field] : PDO::PARAM_STR;
if (strpos($field, '->')) {
$jsonType = $query->getJsonFieldType($field);
$bindType = $this->connection->getFieldBindType($jsonType);
} else {
$bindType = isset($binds[$field]) ? $binds[$field] : PDO::PARAM_STR;
}
if (is_scalar($value) && !in_array($exp, ['EXP', 'NOT NULL', 'NULL', 'IN', 'NOT IN', 'BETWEEN', 'NOT BETWEEN']) && strpos($exp, 'TIME') === false) {
if (strpos($value, ':') !== 0 || !$query->isBind(substr($value, 1))) {
@ -458,7 +462,7 @@ abstract class Builder
// 模糊匹配
if (is_array($value)) {
foreach ($value as $k => $item) {
$bindKey = $bindName . '_' . $k;
$bindKey = $bindName . '_' . intval($k);
$bind[$bindKey] = [$item, $bindType];
$array[] = $key . ' ' . $exp . ' :' . $bindKey;
}
@ -473,6 +477,30 @@ abstract class Builder
return $whereStr;
}
/**
* 表达式查询
* @access protected
* @param Query $query 查询对象
* @param string $key
* @param string $exp
* @param array $value
* @param string $field
* @param string $bindName
* @param integer $bindType
* @return string
*/
protected function parseColumn(Query $query, $key, $exp, array $value, $field, $bindName, $bindType)
{
// 字段比较查询
list($op, $field2) = $value;
if (!in_array($op, ['=', '<>', '>', '>=', '<', '<='])) {
throw new Exception('where express error:' . var_export($value, true));
}
return '( ' . $key . ' ' . $op . ' ' . $this->parseKey($query, $field2, true) . ' )';
}
/**
* 表达式查询
* @access protected
@ -1113,8 +1141,6 @@ abstract class Builder
*/
public function selectInsert(Query $query, $fields, $table)
{
$options = $query->getOptions();
if (is_string($fields)) {
$fields = explode(',', $fields);
}
@ -1123,7 +1149,7 @@ abstract class Builder
$field = $this->parseKey($query, $field, true);
}
return 'INSERT INTO ' . $this->parseTable($query, $table, $options) . ' (' . implode(',', $fields) . ') ' . $this->select($options);
return 'INSERT INTO ' . $this->parseTable($query, $table) . ' (' . implode(',', $fields) . ') ' . $this->select($query);
}
/**

View File

@ -1313,7 +1313,7 @@ abstract class Connection
*/
public function aggregate(Query $query, $aggregate, $field)
{
$field = $aggregate . '(' . $this->builder->parseKey($query, $field) . ') AS tp_' . strtolower($aggregate);
$field = $aggregate . '(' . $this->builder->parseKey($query, $field, true) . ') AS tp_' . strtolower($aggregate);
return $this->value($query, $field, 0);
}

View File

@ -1339,20 +1339,27 @@ class Query
/**
* 比较两个字段
* @access public
* @param string $field1 查询字段
* @param string $operator 比较操作符
* @param string $field2 比较字段
* @param string $logic 查询逻辑 and or xor
* @param string|array $field1 查询字段
* @param string $operator 比较操作符
* @param string $field2 比较字段
* @param string $logic 查询逻辑 and or xor
* @return $this
*/
public function whereColumn($field1, $operator, $field2 = null, $logic = 'AND')
public function whereColumn($field1, $operator = null, $field2 = null, $logic = 'AND')
{
if (is_array($field1)) {
foreach ($field1 as $item) {
$this->whereColumn($item[0], $item[1], isset($item[2]) ? $item[2] : null);
}
return $this;
}
if (is_null($field2)) {
$field2 = $operator;
$operator = '=';
}
return $this->whereExp($field1, $operator . ' ' . $field2, [], $logic);
return $this->parseWhereExp($logic, $field1, 'COLUMN', [$operator, $field2], [], true);
}
/**
@ -2076,6 +2083,29 @@ class Query
return $this;
}
/**
* 设置字段类型信息
* @access public
* @param array $type 字段类型信息
* @return $this
*/
public function setJsonFieldType(array $type)
{
$this->options['field_type'] = $type;
return $this;
}
/**
* 获取字段类型信息
* @access public
* @param string $field 字段名
* @return string|null
*/
public function getJsonFieldType($field)
{
return isset($this->options['field_type'][$field]) ? $this->options['field_type'][$field] : null;
}
/**
* 添加查询范围
* @access public

View File

@ -32,6 +32,7 @@ class Mysql extends Builder
'parseBetweenTime' => ['BETWEEN TIME', 'NOT BETWEEN TIME'],
'parseTime' => ['< TIME', '> TIME', '<= TIME', '>= TIME'],
'parseExists' => ['NOT EXISTS', 'EXISTS'],
'parseColumn' => ['COLUMN'],
];
protected $insertAllSql = '%INSERT% INTO %TABLE% (%FIELD%) VALUES %DATA% %COMMENT%';
@ -105,7 +106,7 @@ class Mysql extends Builder
* 字段和表名处理
* @access public
* @param Query $query 查询对象
* @param string $key 字段名
* @param mixed $key 字段名
* @param bool $strict 严格检测
* @return string
*/
@ -113,7 +114,10 @@ class Mysql extends Builder
{
if (is_int($key)) {
return $key;
} elseif ($key instanceof Expression) {
return $key->getValue();
}
$key = trim($key);
if (strpos($key, '->') && false === strpos($key, '(')) {

View File

@ -50,12 +50,18 @@ class Pgsql extends Builder
* 字段和表名处理
* @access public
* @param Query $query 查询对象
* @param string $key 字段名
* @param mixed $key 字段名
* @param bool $strict 严格检测
* @return string
*/
public function parseKey(Query $query, $key, $strict = false)
{
if (is_int($key)) {
return $key;
} elseif ($key instanceof Expression) {
return $key->getValue();
}
$key = trim($key);
if (strpos($key, '->') && false === strpos($key, '(')) {

View File

@ -58,13 +58,20 @@ class Sqlite extends Builder
* 字段和表名处理
* @access public
* @param Query $query 查询对象
* @param string $key 字段名
* @param mixed $key 字段名
* @param bool $strict 严格检测
* @return string
*/
public function parseKey(Query $query, $key, $strict = false)
{
if (is_int($key)) {
return $key;
} elseif ($key instanceof Expression) {
return $key->getValue();
}
$key = trim($key);
if (strpos($key, '.')) {
list($table, $key) = explode('.', $key, 2);

View File

@ -77,7 +77,7 @@ class Sqlsrv extends Builder
* 字段和表名处理
* @access public
* @param Query $query 查询对象
* @param string $key 字段名
* @param mixed $key 字段名
* @param bool $strict 严格检测
* @return string
*/
@ -85,6 +85,8 @@ class Sqlsrv extends Builder
{
if (is_int($key)) {
return $key;
} elseif ($key instanceof Expression) {
return $key->getValue();
}
$key = trim($key);

View File

@ -36,6 +36,12 @@ trait Attribute
*/
protected $json = [];
/**
* JSON数据表字段类型
* @var array
*/
protected $jsonType = [];
/**
* 数据表废弃字段
* @var array

View File

@ -48,7 +48,15 @@ class File
{
if (!empty($vars) && is_array($vars)) {
// 模板阵列变量分解成为独立变量
extract($vars, EXTR_OVERWRITE);
if (isset($vars['cacheFile'])) {
$_think_cacheFile = $cacheFile;
$cacheFile = $vars['cacheFile'];
unset($vars['cacheFile'], $vars['_think_cacheFile']);
extract($vars, EXTR_OVERWRITE);
include $_think_cacheFile;
return;
}
extract($vars);
}
//载入模版缓存文件

View File

@ -77,6 +77,8 @@ class Php
if (isset($data['template'])) {
$__template__ = $template;
$template = $data['template'];
unset($data['template'], $data['__template__']);
extract($data, EXTR_OVERWRITE);
include $__template__;
} else {
@ -96,6 +98,8 @@ class Php
{
if (isset($data['content'])) {
$__content__ = $content;
$content = $data['content'];
unset($data['content'], $data['__content__']);
extract($data, EXTR_OVERWRITE);
eval('?>' . $__content__);
} else {

2
vendor/autoload.php vendored
View File

@ -4,4 +4,4 @@
require_once __DIR__ . '/composer/autoload_real.php';
return ComposerAutoloaderInit7f21c27a120d47e6491fd4a016f044cb::getLoader();
return ComposerAutoloaderInit634fe4faf75443ee005458ef619df6f4::getLoader();

View File

@ -139,6 +139,12 @@ return array(
'WeChat\\Template' => $vendorDir . '/zoujingli/wechat-developer/WeChat/Template.php',
'WeChat\\User' => $vendorDir . '/zoujingli/wechat-developer/WeChat/User.php',
'WeChat\\Wifi' => $vendorDir . '/zoujingli/wechat-developer/WeChat/Wifi.php',
'WeMini\\Crypt' => $vendorDir . '/zoujingli/wechat-developer/WeMini/Crypt.php',
'WeMini\\Plugs' => $vendorDir . '/zoujingli/wechat-developer/WeMini/Plugs.php',
'WeMini\\Poi' => $vendorDir . '/zoujingli/wechat-developer/WeMini/Poi.php',
'WeMini\\Qrcode' => $vendorDir . '/zoujingli/wechat-developer/WeMini/Qrcode.php',
'WeMini\\Template' => $vendorDir . '/zoujingli/wechat-developer/WeMini/Template.php',
'WeMini\\Total' => $vendorDir . '/zoujingli/wechat-developer/WeMini/Total.php',
'WeOpen\\Service' => $vendorDir . '/zoujingli/weopen-developer/WeOpen/Service.php',
'app\\admin\\controller\\Auth' => $baseDir . '/application/admin/controller/Auth.php',
'app\\admin\\controller\\Config' => $baseDir . '/application/admin/controller/Config.php',

View File

@ -10,6 +10,7 @@ return array(
'think\\captcha\\' => array($vendorDir . '/topthink/think-captcha/src'),
'app\\' => array($baseDir . '/application'),
'WeOpen\\' => array($vendorDir . '/zoujingli/weopen-developer/WeOpen'),
'WeMini\\' => array($vendorDir . '/zoujingli/wechat-developer/WeMini'),
'WeChat\\' => array($vendorDir . '/zoujingli/wechat-developer/WeChat'),
'Symfony\\Component\\OptionsResolver\\' => array($vendorDir . '/symfony/options-resolver'),
'Qiniu\\' => array($vendorDir . '/qiniu/php-sdk/src/Qiniu'),

View File

@ -2,7 +2,7 @@
// autoload_real.php @generated by Composer
class ComposerAutoloaderInit7f21c27a120d47e6491fd4a016f044cb
class ComposerAutoloaderInit634fe4faf75443ee005458ef619df6f4
{
private static $loader;
@ -19,15 +19,15 @@ class ComposerAutoloaderInit7f21c27a120d47e6491fd4a016f044cb
return self::$loader;
}
spl_autoload_register(array('ComposerAutoloaderInit7f21c27a120d47e6491fd4a016f044cb', 'loadClassLoader'), true, true);
spl_autoload_register(array('ComposerAutoloaderInit634fe4faf75443ee005458ef619df6f4', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader();
spl_autoload_unregister(array('ComposerAutoloaderInit7f21c27a120d47e6491fd4a016f044cb', 'loadClassLoader'));
spl_autoload_unregister(array('ComposerAutoloaderInit634fe4faf75443ee005458ef619df6f4', 'loadClassLoader'));
$useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded());
if ($useStaticLoader) {
require_once __DIR__ . '/autoload_static.php';
call_user_func(\Composer\Autoload\ComposerStaticInit7f21c27a120d47e6491fd4a016f044cb::getInitializer($loader));
call_user_func(\Composer\Autoload\ComposerStaticInit634fe4faf75443ee005458ef619df6f4::getInitializer($loader));
} else {
$map = require __DIR__ . '/autoload_namespaces.php';
foreach ($map as $namespace => $path) {
@ -48,19 +48,19 @@ class ComposerAutoloaderInit7f21c27a120d47e6491fd4a016f044cb
$loader->register(true);
if ($useStaticLoader) {
$includeFiles = Composer\Autoload\ComposerStaticInit7f21c27a120d47e6491fd4a016f044cb::$files;
$includeFiles = Composer\Autoload\ComposerStaticInit634fe4faf75443ee005458ef619df6f4::$files;
} else {
$includeFiles = require __DIR__ . '/autoload_files.php';
}
foreach ($includeFiles as $fileIdentifier => $file) {
composerRequire7f21c27a120d47e6491fd4a016f044cb($fileIdentifier, $file);
composerRequire634fe4faf75443ee005458ef619df6f4($fileIdentifier, $file);
}
return $loader;
}
}
function composerRequire7f21c27a120d47e6491fd4a016f044cb($fileIdentifier, $file)
function composerRequire634fe4faf75443ee005458ef619df6f4($fileIdentifier, $file)
{
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
require $file;

View File

@ -4,7 +4,7 @@
namespace Composer\Autoload;
class ComposerStaticInit7f21c27a120d47e6491fd4a016f044cb
class ComposerStaticInit634fe4faf75443ee005458ef619df6f4
{
public static $files = array (
'1cfd2761b63b0a29ed23657ea394cb2d' => __DIR__ . '/..' . '/topthink/think-captcha/src/helper.php',
@ -24,6 +24,7 @@ class ComposerStaticInit7f21c27a120d47e6491fd4a016f044cb
'W' =>
array (
'WeOpen\\' => 7,
'WeMini\\' => 7,
'WeChat\\' => 7,
),
'S' =>
@ -61,6 +62,10 @@ class ComposerStaticInit7f21c27a120d47e6491fd4a016f044cb
array (
0 => __DIR__ . '/..' . '/zoujingli/weopen-developer/WeOpen',
),
'WeMini\\' =>
array (
0 => __DIR__ . '/..' . '/zoujingli/wechat-developer/WeMini',
),
'WeChat\\' =>
array (
0 => __DIR__ . '/..' . '/zoujingli/wechat-developer/WeChat',
@ -217,6 +222,12 @@ class ComposerStaticInit7f21c27a120d47e6491fd4a016f044cb
'WeChat\\Template' => __DIR__ . '/..' . '/zoujingli/wechat-developer/WeChat/Template.php',
'WeChat\\User' => __DIR__ . '/..' . '/zoujingli/wechat-developer/WeChat/User.php',
'WeChat\\Wifi' => __DIR__ . '/..' . '/zoujingli/wechat-developer/WeChat/Wifi.php',
'WeMini\\Crypt' => __DIR__ . '/..' . '/zoujingli/wechat-developer/WeMini/Crypt.php',
'WeMini\\Plugs' => __DIR__ . '/..' . '/zoujingli/wechat-developer/WeMini/Plugs.php',
'WeMini\\Poi' => __DIR__ . '/..' . '/zoujingli/wechat-developer/WeMini/Poi.php',
'WeMini\\Qrcode' => __DIR__ . '/..' . '/zoujingli/wechat-developer/WeMini/Qrcode.php',
'WeMini\\Template' => __DIR__ . '/..' . '/zoujingli/wechat-developer/WeMini/Template.php',
'WeMini\\Total' => __DIR__ . '/..' . '/zoujingli/wechat-developer/WeMini/Total.php',
'WeOpen\\Service' => __DIR__ . '/..' . '/zoujingli/weopen-developer/WeOpen/Service.php',
'app\\admin\\controller\\Auth' => __DIR__ . '/../..' . '/application/admin/controller/Auth.php',
'app\\admin\\controller\\Config' => __DIR__ . '/../..' . '/application/admin/controller/Config.php',
@ -258,9 +269,9 @@ class ComposerStaticInit7f21c27a120d47e6491fd4a016f044cb
public static function getInitializer(ClassLoader $loader)
{
return \Closure::bind(function () use ($loader) {
$loader->prefixLengthsPsr4 = ComposerStaticInit7f21c27a120d47e6491fd4a016f044cb::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit7f21c27a120d47e6491fd4a016f044cb::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInit7f21c27a120d47e6491fd4a016f044cb::$classMap;
$loader->prefixLengthsPsr4 = ComposerStaticInit634fe4faf75443ee005458ef619df6f4::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit634fe4faf75443ee005458ef619df6f4::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInit634fe4faf75443ee005458ef619df6f4::$classMap;
}, null, ClassLoader::class);
}

View File

@ -80,17 +80,17 @@
},
{
"name": "zoujingli/wechat-developer",
"version": "v1.0.5",
"version_normalized": "1.0.5.0",
"version": "v1.1.1",
"version_normalized": "1.1.1.0",
"source": {
"type": "git",
"url": "https://github.com/zoujingli/WeChatDeveloper.git",
"reference": "e05fe6bb24438d15259a6af4915bd0638dc3914a"
"reference": "d0877f695a45a911a4a40b6ef8e59e5c261c1b6c"
},
"dist": {
"type": "zip",
"url": "https://files.phpcomposer.com/files/zoujingli/WeChatDeveloper/e05fe6bb24438d15259a6af4915bd0638dc3914a.zip",
"reference": "e05fe6bb24438d15259a6af4915bd0638dc3914a",
"url": "https://files.phpcomposer.com/files/zoujingli/WeChatDeveloper/d0877f695a45a911a4a40b6ef8e59e5c261c1b6c.zip",
"reference": "d0877f695a45a911a4a40b6ef8e59e5c261c1b6c",
"shasum": ""
},
"require": {
@ -98,12 +98,13 @@
"ext-openssl": "*",
"php": ">=5.4"
},
"time": "2018-04-09T11:07:00+00:00",
"time": "2018-04-19T10:18:10+00:00",
"type": "library",
"installation-source": "dist",
"autoload": {
"psr-4": {
"WeChat\\": "WeChat"
"WeChat\\": "WeChat",
"WeMini\\": "WeMini"
}
},
"notification-url": "https://packagist.org/downloads/",
@ -175,17 +176,17 @@
},
{
"name": "topthink/framework",
"version": "v5.1.10",
"version_normalized": "5.1.10.0",
"version": "v5.1.11",
"version_normalized": "5.1.11.0",
"source": {
"type": "git",
"url": "https://github.com/top-think/framework.git",
"reference": "66b546f7cac130712d1e08fe2620105228f4bd8a"
"reference": "3156528b80dfa004109dfbfdbeb770b376a13f01"
},
"dist": {
"type": "zip",
"url": "https://files.phpcomposer.com/files/top-think/framework/66b546f7cac130712d1e08fe2620105228f4bd8a.zip",
"reference": "66b546f7cac130712d1e08fe2620105228f4bd8a",
"url": "https://files.phpcomposer.com/files/top-think/framework/3156528b80dfa004109dfbfdbeb770b376a13f01.zip",
"reference": "3156528b80dfa004109dfbfdbeb770b376a13f01",
"shasum": ""
},
"require": {
@ -201,7 +202,7 @@
"sebastian/phpcpd": "2.*",
"squizlabs/php_codesniffer": "2.*"
},
"time": "2018-04-16T05:33:00+00:00",
"time": "2018-04-19T10:12:09+00:00",
"type": "think-framework",
"installation-source": "dist",
"notification-url": "https://packagist.org/downloads/",

View File

@ -2,4 +2,4 @@
/.git
/.DS_Store
/vendor
/WeChat/Cache
/Cache

View File

@ -16,20 +16,20 @@ PHP开发技术交流QQ群 513350915
[![PHP微信开发群 (SDK)](http://pub.idqqimg.com/wpa/images/group.png)](http://shang.qq.com/wpa/qunwpa?idkey=ae25cf789dafbef62e50a980ffc31242f150bc61a61164458216dd98c411832a)
> WeChatDeveloper 是基于官方接口封装,在做微信开发前,必需先阅读微信官方文档。
>* 微信官方文档http://mp.weixin.qq.com/wiki
>* 商户支付文档https://pay.weixin.qq.com/wiki/doc/api/index.html
WeChatDeveloper 是基于官方接口封装,在做微信开发前,必需先阅读微信官方文档。
* 微信官方文档https://mp.weixin.qq.com/wiki
* 商户支付文档https://pay.weixin.qq.com/wiki/doc/api/index.html
> 针对 WeChatDeveloper 也有一准备了帮助资料可供参考。
>* 开发文档地址http://www.kancloud.cn/zoujingli/wechat-developer
>* Think.Adminhttps://github.com/zoujingli/Think.Admin
针对 WeChatDeveloper 也有一准备了帮助资料可供参考。
* ThinkAdminhttps://github.com/zoujingli/Think.Admin
* 开发文档地址https://www.kancloud.cn/zoujingli/wechat-developer
Repositorie
--
WeChatDeveloper 为开源项目,允许把它用于任何地方,不受任何约束,欢迎 fork 项目。
>* GitHub 托管地址https://github.com/zoujingli/WeChatDeveloper
>* OSChina 托管地址http://git.oschina.net/zoujingli/WeChatDeveloper
WeChatDeveloper 为开源项目,允许把它用于任何地方,不受任何约束,欢迎 fork 项目。
* Gitee 托管地址https://gitee.com/zoujingli/WeChatDeveloper
* GitHub 托管地址https://github.com/zoujingli/WeChatDeveloper
Install
@ -39,7 +39,7 @@ Install
# 首次安装 线上版本(稳定)
composer require zoujingli/wechat-developer
# 首次安装 开发版本
# 首次安装 开发版本(开发)
composer require zoujingli/wechat-developer dev-master
# 更新 WeChatDeveloper

View File

@ -0,0 +1,20 @@
<?php
include '../include.php';
// 小程序配置
$config = [
'appid' => 'wx6bb7b70258da09c6',
'appsecret' => '78b7b8d65bd67b078babf951d4342b42',
];
// 解码数据
$iv = 'ltM/wT7hsAl0TijEBI4v/g==';
$code = '013LyiTR0TwjC92QjJRR0mEsTR0LyiT3';
$decode = 'eIoVtIC2YzLCnrwiIs1IBbXMvC0vyL8bo1IhD38fUQIRbk3lgTWa0Hdw/Ty7NTs3iu7YlqqZBti+cxd6dCfeXBUQwTO2QpbHg0WTeDAdrihsHRHm4dCWdfTx8rzDloGbNOIsKdRElIhUH5YFdiTr5AYiufUDb34cwJ4GNWLAUq4bR0dmFeVEi+3nfwe2MAjGYDl4aq719VLsHodOggK6lXZvM5wjoDyuZsK2dPqJr3/Ji30Z0mdyFq32R4uR3rtJH/h+Rj0+/QmE9QYG7Y6Z48hgPE8cpnhRQNwH49jnC/zKZ9wtDkQ/J8J3Ed2i58zcuY01v8IV+pZ8oBUKXfO5ha+APOxtBSTzyHraU/2RGo8UWtOF6h64OQZhd/UQQy362eyc/qoq8sF9JnEFRP0mRmTDJ+u9oyDhxswCu6x8V73ERWaJeEGSCyjiGpep7/DxZ6eSSBq36OB0BWBkJqsq9Q==';
$sessionKey = 'OetNxl86B/yMpbwG6wtMEw==';
$mini = new WeMini\Crypt($config);
echo '<pre>';
//print_r($mini->session($code));
print_r($mini->decode($iv, $sessionKey, $decode));
//print_r($mini->userInfo($code, $iv, $decode));

View File

@ -0,0 +1,21 @@
<?php
include '../include.php';
// 小程序配置
$config = [
'appid' => 'wx6bb7b70258da09c6',
'appsecret' => '78b7b8d65bd67b078babf951d4342b42',
];
$mini = new WeMini\Qrcode($config);
//echo '<pre>';
try {
header('Content-type:image/jpeg');//输出的类型
// echo $mini->createDefault('pages/index?query=1');
// echo $mini->createMiniScene('432432', 'pages/index/index');
echo $mini->createMiniPath('pages/index?query=1');
} catch (Exception $e) {
var_dump($e->getMessage());
}

View File

@ -122,6 +122,7 @@ class BasicWeChat
* 以GET获取接口数据并转为数组
* @param string $url 接口地址
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
*/
protected function httpGetForJson($url)
{
@ -133,6 +134,7 @@ class BasicWeChat
$this->isTry = true;
return call_user_func_array([$this, $this->currentMethod['method']], $this->currentMethod['arguments']);
}
throw new InvalidResponseException($e->getMessage(), $e->getCode());
}
}
@ -142,6 +144,7 @@ class BasicWeChat
* @param array $data 请求数据
* @param bool $buildToJson
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
*/
protected function httpPostForJson($url, array $data, $buildToJson = true)
{
@ -149,10 +152,10 @@ class BasicWeChat
return Tools::json2arr(Tools::post($url, $buildToJson ? Tools::arr2json($data) : $data));
} catch (InvalidResponseException $e) {
if (!$this->isTry && in_array($e->getCode(), ['40014', '40001', '41001', '42001'])) {
$this->delAccessToken();
$this->isTry = true;
[$this->delAccessToken(), $this->isTry = true];
return call_user_func_array([$this, $this->currentMethod['method']], $this->currentMethod['arguments']);
}
throw new InvalidResponseException($e->getMessage(), $e->getCode());
}
}

View File

@ -306,7 +306,7 @@ class Tools
private static function getCacheName($name)
{
if (empty(self::$cache_path)) {
self::$cache_path = dirname(__DIR__) . DIRECTORY_SEPARATOR . 'Cache' . DIRECTORY_SEPARATOR;
self::$cache_path = dirname(dirname(__DIR__)) . DIRECTORY_SEPARATOR . 'Cache' . DIRECTORY_SEPARATOR;
}
self::$cache_path = rtrim(self::$cache_path, '/\\') . DIRECTORY_SEPARATOR;
file_exists(self::$cache_path) || mkdir(self::$cache_path, 0755, true);

View File

@ -0,0 +1,83 @@
<?php
// +----------------------------------------------------------------------
// | WeChatDeveloper
// +----------------------------------------------------------------------
// | 版权所有 2014~2018 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
// +----------------------------------------------------------------------
// | 官方网站: http://think.ctolog.com
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | github开源项目https://github.com/zoujingli/WeChatDeveloper
// +----------------------------------------------------------------------
namespace WeMini;
use WeChat\Contracts\BasicWeChat;
use WeChat\Contracts\Tools;
use WeChat\Exceptions\InvalidDecryptException;
use WeChat\Exceptions\InvalidResponseException;
/**
* 数据加密处理
* Class Crypt
* @package WeMini
*/
class Crypt extends BasicWeChat
{
/**
* 数据签名校验
* @param string $iv
* @param string $sessionKey
* @param string $encryptedData
* @return bool
*/
public function decode($iv, $sessionKey, $encryptedData)
{
require_once __DIR__ . DIRECTORY_SEPARATOR . 'crypt' . DIRECTORY_SEPARATOR . 'wxBizDataCrypt.php';
$pc = new \WXBizDataCrypt($this->config->get('appid'), $sessionKey);
$errCode = $pc->decryptData($encryptedData, $iv, $data);
if ($errCode == 0) {
return json_decode($data, true);
}
return false;
}
/**
* 登录凭证校验
* @param string $code 登录时获取的 code
* @return array
*/
public function session($code)
{
$appid = $this->config->get('appid');
$secret = $this->config->get('appsecret');
$url = "https://api.weixin.qq.com/sns/jscode2session?appid={$appid}&secret={$secret}&js_code={$code}&grant_type=authorization_code";
return json_decode(Tools::get($url), true);
}
/**
* 换取用户信息
* @param string $code 用户登录凭证(有效期五分钟)
* @param string $iv 加密算法的初始向量
* @param string $encryptedData 加密数据( encryptedData )
* @return array
* @throws InvalidDecryptException
* @throws InvalidResponseException
*/
public function userInfo($code, $iv, $encryptedData)
{
$result = $this->session($code);
if (empty($result['session_key'])) {
throw new InvalidResponseException('Code 换取 SessionKey 失败', 403);
}
$userinfo = $this->decode($iv, $result['session_key'], $encryptedData);
if (empty($userinfo)) {
throw new InvalidDecryptException('用户信息解析失败', 403);
}
return array_merge($result, $userinfo);
}
}

View File

@ -0,0 +1,98 @@
<?php
// +----------------------------------------------------------------------
// | WeChatDeveloper
// +----------------------------------------------------------------------
// | 版权所有 2014~2018 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
// +----------------------------------------------------------------------
// | 官方网站: http://think.ctolog.com
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | github开源项目https://github.com/zoujingli/WeChatDeveloper
// +----------------------------------------------------------------------
namespace WeMini;
use WeChat\Contracts\BasicWeChat;
/**
* 微信小程序插件管理
* Class Plugs
* @package WeMini
*/
class Plugs extends BasicWeChat
{
/**
* 1.申请使用插件
* @param string $plugin_appid 插件appid
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function apply($plugin_appid)
{
$url = 'https://api.weixin.qq.com/wxa/plugin?access_token=ACCESS_TOKEN';
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->callPostApi($url, ['action' => 'apply', 'plugin_appid' => $plugin_appid], true);
}
/**
* 2.查询已添加的插件
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function getList()
{
$url = 'https://api.weixin.qq.com/wxa/plugin?access_token=ACCESS_TOKEN';
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->callPostApi($url, ['action' => 'list'], true);
}
/**
* 3.删除已添加的插件
* @param string $plugin_appid 插件appid
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function unbind($plugin_appid)
{
$url = 'https://api.weixin.qq.com/wxa/plugin?access_token=ACCESS_TOKEN';
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->callPostApi($url, ['action' => 'unbind', 'plugin_appid' => $plugin_appid], true);
}
/**
* 4.获取当前所有插件使用方(供插件开发者调用)
* @param integer $page 拉取第page页的数据
* @param integer $num 表示每页num条记录
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function devApplyList($page = 1, $num = 10)
{
$url = 'https://api.weixin.qq.com/wxa/plugin?access_token=ACCESS_TOKEN';
$this->registerApi($url, __FUNCTION__, func_get_args());
$data = ['action' => 'dev_apply_list', 'page' => $page, 'num' => $num];
return $this->callPostApi($url, $data, true);
}
/**
* 5.修改插件使用申请的状态(供插件开发者调用)
* @param string $action dev_agree同意申请dev_refuse拒绝申请dev_delete删除已拒绝的申请者
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function devAgree($action = 'dev_agree')
{
$url = 'https://api.weixin.qq.com/wxa/plugin?access_token=ACCESS_TOKEN';
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->callPostApi($url, ['action' => $action], true);
}
}

View File

@ -0,0 +1,91 @@
<?php
// +----------------------------------------------------------------------
// | WeChatDeveloper
// +----------------------------------------------------------------------
// | 版权所有 2014~2018 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
// +----------------------------------------------------------------------
// | 官方网站: http://think.ctolog.com
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | github开源项目https://github.com/zoujingli/WeChatDeveloper
// +----------------------------------------------------------------------
namespace WeMini;
use WeChat\Contracts\BasicWeChat;
/**
* 微信小程序地址管理
* Class Poi
* @package WeMini
*/
class Poi extends BasicWeChat
{
/**
* 添加地点
* @param string $related_name 经营资质主体
* @param string $related_credential 经营资质证件号
* @param string $related_address 经营资质地址
* @param string $related_proof_material 相关证明材料照片临时素材mediaid
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function addBearByPoi($related_name, $related_credential, $related_address, $related_proof_material)
{
$url = 'https://api.weixin.qq.com/wxa/addnearbypoi?access_token=ACCESS_TOKEN';
$this->registerApi($url, __FUNCTION__, func_get_args());
$data = [
'related_name' => $related_name, 'related_credential' => $related_credential,
'related_address' => $related_address, 'related_proof_material' => $related_proof_material,
];
return $this->callPostApi($url, $data, true);
}
/**
* 查看地点列表
* @param integer $page 起始页id从1开始计数
* @param integer $page_rows 每页展示个数最多1000个
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function getNearByPoiList($page = 1, $page_rows = 1000)
{
$url = "https://api.weixin.qq.com/wxa/getnearbypoilist?page={$page}&page_rows={$page_rows}&access_token=ACCESS_TOKEN";
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->callGetApi($url);
}
/**
* 删除地点
* @param string $poi_id 附近地点ID
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function delNearByPoiList($poi_id)
{
$url = "https://api.weixin.qq.com/wxa/delnearbypoi?access_token=ACCESS_TOKEN";
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->callPostApi($url, ['poi_id' => $poi_id], true);
}
/**
* 展示/取消展示附近小程序
* @param string $poi_id 附近地点ID
* @param string $status 0取消展示1展示
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function setNearByPoiShowStatus($poi_id, $status)
{
$url = "https://api.weixin.qq.com/wxa/setnearbypoishowstatus?access_token=ACCESS_TOKEN";
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->callPostApi($url, ['poi_id' => $poi_id, 'status' => $status], true);
}
}

View File

@ -0,0 +1,86 @@
<?php
// +----------------------------------------------------------------------
// | WeChatDeveloper
// +----------------------------------------------------------------------
// | 版权所有 2014~2018 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
// +----------------------------------------------------------------------
// | 官方网站: http://think.ctolog.com
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | github开源项目https://github.com/zoujingli/WeChatDeveloper
// +----------------------------------------------------------------------
namespace WeMini;
use WeChat\Contracts\BasicWeChat;
use WeChat\Contracts\Tools;
/**
* 微信小程序二维码管理
* Class Qrcode
* @package WeMini
*/
class Qrcode extends BasicWeChat
{
/**
* 获取小程序码(永久有效)
* 接口A: 适用于需要的码数量较少的业务场景
* @param string $path 不能为空,最大长度 128 字节
* @param integer $width 二维码的宽度
* @param bool $auto_color 自动配置线条颜色,如果颜色依然是黑色,则说明不建议配置主色调
* @param array $line_color auto_color false 时生效
* @return array|string
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function createMiniPath($path, $width = 430, $auto_color = false, $line_color = ["r" => "0", "g" => "0", "b" => "0"])
{
$url = 'https://api.weixin.qq.com/wxa/getwxacode?access_token=ACCESS_TOKEN';
$this->registerApi($url, __FUNCTION__, func_get_args());
$data = ['path' => $path, 'width' => $width, 'auto_color' => $auto_color, 'line_color' => $line_color];
$result = Tools::post($url, Tools::arr2json($data));
return strlen($result) > 256 ? $result : Tools::json2arr($result);
}
/**
* 获取小程序码(永久有效)
* 接口B适用于需要的码数量极多的业务场景
* @param string $scene 最大32个可见字符只支持数字
* @param string $page 必须是已经发布的小程序存在的页面
* @param integer $width 二维码的宽度
* @param bool $auto_color 自动配置线条颜色,如果颜色依然是黑色,则说明不建议配置主色调
* @param array $line_color auto_color false 时生效
* @return array|string
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function createMiniScene($scene, $page, $width = 430, $auto_color = false, $line_color = ["r" => "0", "g" => "0", "b" => "0"])
{
$url = 'https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=ACCESS_TOKEN';
$data = ['scene' => $scene, 'width' => $width, 'auto_color' => $auto_color, 'page' => $page, 'line_color' => $line_color];
$this->registerApi($url, __FUNCTION__, func_get_args());
$result = Tools::post($url, Tools::arr2json($data));
return strlen($result) > 256 ? $result : Tools::json2arr($result);
}
/**
* 获取小程序二维码(永久有效)
* 接口C适用于需要的码数量较少的业务场景
* @param string $path 不能为空,最大长度 128 字节
* @param integer $width 二维码的宽度
* @return array|string
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function createDefault($path, $width = 430)
{
$url = 'https://api.weixin.qq.com/cgi-bin/wxaapp/createwxaqrcode?access_token=ACCESS_TOKEN';
$this->registerApi($url, __FUNCTION__, func_get_args());
$result = Tools::post($url, Tools::arr2json(['path' => $path, 'width' => $width]));
return strlen($result) > 256 ? $result : Tools::json2arr($result);
}
}

View File

@ -0,0 +1,110 @@
<?php
// +----------------------------------------------------------------------
// | WeChatDeveloper
// +----------------------------------------------------------------------
// | 版权所有 2014~2018 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
// +----------------------------------------------------------------------
// | 官方网站: http://think.ctolog.com
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | github开源项目https://github.com/zoujingli/WeChatDeveloper
// +----------------------------------------------------------------------
namespace WeMini;
use WeChat\Contracts\BasicWeChat;
/**
* 公众号小程序模板消息支持
* Class Mini
* @package WeChat
*/
class Template extends BasicWeChat
{
/**
* 获取小程序模板库标题列表
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function getTemplateLibraryList()
{
$url = 'https://api.weixin.qq.com/cgi-bin/wxopen/template/library/list?access_token=ACCESS_TOKEN';
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->callPostApi($url, ['offset' => '0', 'count' => '20'], true);
}
/**
* 获取模板库某个模板标题下关键词库
* @param string $template_id 模板标题id可通过接口获取也可登录小程序后台查看获取
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function getTemplateLibrary($template_id)
{
$url = 'https://api.weixin.qq.com/cgi-bin/wxopen/template/library/get?access_token=ACCESS_TOKEN';
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->callPostApi($url, ['id' => $template_id], true);
}
/**
* 组合模板并添加至帐号下的个人模板库
* @param string $template_id 模板标题id可通过接口获取也可登录小程序后台查看获取
* @param array $keyword_id_list 开发者自行组合好的模板关键词列表,关键词顺序可以自由搭配(例如[3,5,4][4,5,3]最多支持10个关键词组合
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function addTemplate($template_id, array $keyword_id_list)
{
$url = 'https://api.weixin.qq.com/cgi-bin/wxopen/template/add?access_token=ACCESS_TOKEN';
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->callPostApi($url, ['id' => $template_id, 'keyword_id_list' => $keyword_id_list], true);
}
/**
* 获取帐号下已存在的模板列表
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function getTemplateList()
{
$url = 'https://api.weixin.qq.com/cgi-bin/wxopen/template/list?access_token=ACCESS_TOKEN';
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->callPostApi($url, ['offset' => '0', 'count' => '20'], true);
}
/**
* 删除模板消息
* @param string $template_id 要删除的模板id
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function delTemplate($template_id)
{
$url = 'https://api.weixin.qq.com/cgi-bin/wxopen/template/del?access_token=ACCESS_TOKEN';
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->callPostApi($url, ['template_id' => $template_id], true);
}
/**
* 发送模板消息
* @param array $data 发送的消息对象数组
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function send(array $data)
{
$url = 'https://api.weixin.qq.com/cgi-bin/message/wxopen/template/send?access_token=ACCESS_TOKEN';
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->callPostApi($url, $data, true);
}
}

View File

@ -0,0 +1,176 @@
<?php
// +----------------------------------------------------------------------
// | WeChatDeveloper
// +----------------------------------------------------------------------
// | 版权所有 2014~2018 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
// +----------------------------------------------------------------------
// | 官方网站: http://think.ctolog.com
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | github开源项目https://github.com/zoujingli/WeChatDeveloper
// +----------------------------------------------------------------------
namespace WeMini;
use WeChat\Contracts\BasicWeChat;
/**
* 微信小程序数据接口
* Class Total
* @package WeMini
*/
class Total extends BasicWeChat
{
/**
* 数据分析接口
* @param string $begin_date 开始日期
* @param string $end_date 结束日期限定查询1天数据end_date允许设置的最大值为昨日
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function getWeanalysisAppidDailySummarytrend($begin_date, $end_date)
{
$url = 'https://api.weixin.qq.com/datacube/getweanalysisappiddailysummarytrend?access_token=ACCESS_TOKEN';
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->callPostApi($url, ['begin_date' => $begin_date, 'end_date' => $end_date], true);
}
/**
* 访问分析
* @param string $begin_date 开始日期
* @param string $end_date 结束日期限定查询1天数据end_date允许设置的最大值为昨日
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function getWeanalysisAppidDailyVisittrend($begin_date, $end_date)
{
$url = 'https://api.weixin.qq.com/datacube/getweanalysisappiddailyvisittrend?access_token=ACCESS_TOKEN';
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->callPostApi($url, ['begin_date' => $begin_date, 'end_date' => $end_date], true);
}
/**
* 周趋势
* @param string $begin_date 开始日期,为周一日期
* @param string $end_date 结束日期,为周日日期,限定查询一周数据
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function getWeanalysisAppidWeeklyVisittrend($begin_date, $end_date)
{
$url = 'https://api.weixin.qq.com/datacube/getweanalysisappidweeklyvisittrend?access_token=ACCESS_TOKEN';
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->callPostApi($url, ['begin_date' => $begin_date, 'end_date' => $end_date], true);
}
/**
* 月趋势
* @param string $begin_date 开始日期,为自然月第一天
* @param string $end_date 结束日期,为自然月最后一天,限定查询一个月数据
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function getWeanalysisAppidMonthlyVisittrend($begin_date, $end_date)
{
$url = 'https://api.weixin.qq.com/datacube/getweanalysisappidmonthlyvisittrend?access_token=ACCESS_TOKEN';
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->callPostApi($url, ['begin_date' => $begin_date, 'end_date' => $end_date], true);
}
/**
* 访问分布
* @param string $begin_date 开始日期
* @param string $end_date 结束日期限定查询1天数据end_date允许设置的最大值为昨日
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function getWeanalysisAppidVisitdistribution($begin_date, $end_date)
{
$url = 'https://api.weixin.qq.com/datacube/getweanalysisappidvisitdistribution?access_token=ACCESS_TOKEN';
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->callPostApi($url, ['begin_date' => $begin_date, 'end_date' => $end_date], true);
}
/**
* 日留存
* @param string $begin_date 开始日期
* @param string $end_date 结束日期限定查询1天数据end_date允许设置的最大值为昨日
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function getWeanalysisAppidDailyRetaininfo($begin_date, $end_date)
{
$url = 'https://api.weixin.qq.com/datacube/getweanalysisappiddailyretaininfo?access_token=ACCESS_TOKEN';
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->callPostApi($url, ['begin_date' => $begin_date, 'end_date' => $end_date], true);
}
/**
* 周留存
* @param string $begin_date 开始日期,为周一日期
* @param string $end_date 结束日期,为周日日期,限定查询一周数据
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function getWeanalysisAppidWeeklyRetaininfo($begin_date, $end_date)
{
$url = 'https://api.weixin.qq.com/datacube/getweanalysisappidweeklyretaininfo?access_token=ACCESS_TOKEN';
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->callPostApi($url, ['begin_date' => $begin_date, 'end_date' => $end_date], true);
}
/**
* 月留存
* @param string $begin_date 开始日期,为自然月第一天
* @param string $end_date 结束日期,为自然月最后一天,限定查询一个月数据
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function getWeanalysisAppidMonthlyRetaininfo($begin_date, $end_date)
{
$url = 'https://api.weixin.qq.com/datacube/getweanalysisappidmonthlyretaininfo?access_token=ACCESS_TOKEN';
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->callPostApi($url, ['begin_date' => $begin_date, 'end_date' => $end_date], true);
}
/**
* 访问页面
* @param string $begin_date 开始日期
* @param string $end_date 结束日期限定查询1天数据end_date允许设置的最大值为昨日
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function getWeanalysisAppidVisitPage($begin_date, $end_date)
{
$url = 'https://api.weixin.qq.com/datacube/getweanalysisappidvisitpage?access_token=ACCESS_TOKEN';
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->callPostApi($url, ['begin_date' => $begin_date, 'end_date' => $end_date], true);
}
/**
* 用户画像
* @param string $begin_date 开始日期
* @param string $end_date 结束日期开始日期与结束日期相差的天数限定为0/6/29分别表示查询最近1/7/30天数据end_date允许设置的最大值为昨日
* @return array
* @throws \WeChat\Exceptions\InvalidResponseException
* @throws \WeChat\Exceptions\LocalCacheException
*/
public function getWeanalysisAppidUserportrait($begin_date, $end_date)
{
$url = 'https://api.weixin.qq.com/datacube/getweanalysisappiduserportrait?access_token=ACCESS_TOKEN';
$this->registerApi($url, __FUNCTION__, func_get_args());
return $this->callPostApi($url, ['begin_date' => $begin_date, 'end_date' => $end_date], true);
}
}

View File

@ -0,0 +1,20 @@
<?php
/**
* error code 说明.
* <ul>
* <li>-41001: encodingAesKey 非法</li>
* <li>-41003: aes 解密失败</li>
* <li>-41004: 解密后得到的buffer非法</li>
* <li>-41005: base64加密失败</li>
* <li>-41016: base64解密失败</li>
* </ul>
*/
class ErrorCode
{
public static $OK = 0;
public static $IllegalAesKey = -41001;
public static $IllegalIv = -41002;
public static $IllegalBuffer = -41003;
public static $DecodeBase64Error = -41004;
}

View File

@ -0,0 +1,59 @@
<?php
/**
* 对微信小程序用户加密数据的解密示例代码.
*
* @copyright Copyright (c) 1998-2014 Tencent Inc.
*/
class WXBizDataCrypt
{
private $appid;
private $sessionKey;
/**
* 构造函数
* @param $sessionKey string 用户在小程序登录后获取的会话密钥
* @param $appid string 小程序的appid
*/
public function __construct($appid, $sessionKey)
{
$this->appid = $appid;
$this->sessionKey = $sessionKey;
include_once __DIR__ . DIRECTORY_SEPARATOR . "errorCode.php";
}
/**
* 检验数据的真实性,并且获取解密后的明文.
* @param $encryptedData string 加密的用户数据
* @param $iv string 与用户数据一同返回的初始向量
* @param $data string 解密后的原文
*
* @return int 成功0失败返回对应的错误码
*/
public function decryptData($encryptedData, $iv, &$data)
{
if (strlen($this->sessionKey) != 24) {
return \ErrorCode::$IllegalAesKey;
}
$aesKey = base64_decode($this->sessionKey);
if (strlen($iv) != 24) {
return \ErrorCode::$IllegalIv;
}
$aesIV = base64_decode($iv);
$aesCipher = base64_decode($encryptedData);
$result = openssl_decrypt($aesCipher, "AES-128-CBC", $aesKey, 1, $aesIV);
$dataObj = json_decode($result);
if ($dataObj == null) {
return \ErrorCode::$IllegalBuffer;
}
if ($dataObj->watermark->appid != $this->appid) {
return \ErrorCode::$IllegalBuffer;
}
$data = $result;
return \ErrorCode::$OK;
}
}

View File

@ -23,7 +23,8 @@
},
"autoload": {
"psr-4": {
"WeChat\\": "WeChat"
"WeChat\\": "WeChat",
"WeMini\\": "WeMini"
}
}
}

View File

@ -14,8 +14,14 @@
// 动态注册SDK自动加载
spl_autoload_register(function ($classname) {
$filename = __DIR__ . DIRECTORY_SEPARATOR . str_replace('\\', DIRECTORY_SEPARATOR, $classname) . '.php';
if (stripos($classname, 'WeChat') === 0 && file_exists($filename)) {
include $filename;
$separator = DIRECTORY_SEPARATOR;
$filename = __DIR__ . $separator . str_replace('\\', $separator, $classname) . '.php';
if (file_exists($filename)) {
if (stripos($classname, 'WeChat') === 0) {
include $filename;
}
if (stripos($classname, 'WeMini') === 0) {
include $filename;
}
}
});