dever пре 6 година
родитељ
комит
b3d67107db

+ 13 - 0
README.md

@@ -0,0 +1,13 @@
+# wechat
+
+service:微信业务
+developer:微信开发者平台
+component:微信第三方平台
+subscribe:微信公众号
+applet:微信小程序
+pay:微信支付
+
+
+public:对外接口
+
+

+ 9 - 0
boot.php

@@ -0,0 +1,9 @@
+<?php
+$_SERVER['SERVER_NAME'] = 'localhost';
+define('DEVER_PROJECT', 'wechat');
+define('DEVER_PROJECT_PATH', dirname(__FILE__) . DIRECTORY_SEPARATOR);
+if (defined('DEVER_PACKAGE')) {
+	include('dever_package/'.DEVER_PACKAGE.'/index.php');
+} else {
+	include('dever/boot.php');
+}

+ 13 - 0
component/config/component.php

@@ -0,0 +1,13 @@
+<?php
+
+# 微信第三方平台 接口配置
+
+$config = array();
+
+$path = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'component' . DIRECTORY_SEPARATOR;
+
+# 载入素材配置
+//$config += include($path . 'media.php');
+
+
+return $config;

+ 7 - 0
component/index.php

@@ -0,0 +1,7 @@
+<?php
+define('DEVER_APP_NAME', 'component');
+define('DEVER_APP_LANG', '第三方平台');
+define('DEVER_APP_PATH', dirname(__FILE__) . DIRECTORY_SEPARATOR);
+define('DEVER_MANAGE_ORDER', 100);
+define('DEVER_MANAGE_ICON', 'glyphicon glyphicon-magnet');
+include(DEVER_APP_PATH . '../boot.php');

+ 509 - 0
component/service/Receive.php

@@ -0,0 +1,509 @@
+<?php
+/*
+|--------------------------------------------------------------------------
+| receive.php 用于接收微信发过来的信息
+|--------------------------------------------------------------------------
+*/
+namespace Component\Service;
+
+use Dever;
+use Main\Lib\Wechat;
+
+class Receive
+{
+	const TYPE = 5;
+
+	/**
+	 * wechat
+	 *
+	 * @var Wechat
+	 */
+	private $wechat;
+	
+	/**
+	 * result
+	 *
+	 * @var array
+	 */
+	private $result;
+	
+	/**
+	 * output
+	 *
+	 * @var string
+	 */
+	private $output;
+	
+	/**
+     * 构造函数 初始化
+     * 
+     * @return mixed
+     */
+	public function __construct()
+	{
+		$appid = Dever::input('appid');
+		$project = false;
+		if ($appid) {
+			$info = Dever::db('main/project')->one(array('option_type' => self::TYPE, 'option_appid' => $appid));
+			if ($info) {
+				$project = $info['id'];
+			}
+		}
+		$this->wechat = new Wechat('component', $project);
+	}
+	
+	/**
+     * 业务推送接口 微信服务器会将所有请求都推送到这里
+     * 
+     * @return mixed
+     */
+	public function main()
+	{
+		$this->output = '';
+		
+		# 获取微信消息
+		$this->request();
+		
+		# 对消息进行验证,并根据类型得到本平台的配置数据
+		//$this->response();
+		
+		# 输出
+		$this->output();
+	}
+	
+	/**
+     * 输出
+     * 
+     * @return mixed
+     */
+	private function output()
+	{
+		if (!$this->output) {
+			$this->output = 'success';
+		}
+		echo $this->output;die;
+	}
+	
+	/**
+     * 据类型得到本平台的配置数据
+     * 
+     * @return mixed
+     */
+	private function response()
+	{
+		if ($this->output) {
+			return;
+		}
+		
+		if ($this->result && isset($this->result['add_type'])) {
+			if (isset($this->result['subscribe'])) {
+				if ($this->result['subscribe'] == true) {
+					# 订阅成功 发送消息
+					$this->msg('msg1');
+					# 发送消息之后,往用户表更新信息
+					$this->user();
+					$this->setSubscribe(1);
+				}
+				if ($this->result['subscribe'] == false) {
+					# 取消订阅 不发送消息
+					//$this->msg('msg1');
+					# 改变当前用户的订阅状态
+					$this->setSubscribe(2);
+				}
+			} elseif (isset($this->result['add_content'][0]['Content'])) {
+				$this->match($this->result['add_content'][0]['Content']);
+			} else {
+				# 如果没有匹配到,则直接返回默认回复消息
+				$this->msg('msg2');
+			}
+		}
+	}
+
+    /**
+     * 获取微信发送的内容
+     * 
+     * @return mixed
+     */
+    private function request()
+    {
+		$post = isset($GLOBALS["HTTP_RAW_POST_DATA"]) ? $GLOBALS["HTTP_RAW_POST_DATA"] : false;
+
+/*
+		$post = ' <xml>
+ <ToUserName><![CDATA[toUser]]></ToUserName>
+ <FromUserName><![CDATA[ow29VvzICifpOTq_9EDGT3AhYpqg]]></FromUserName> 
+ <CreateTime>1442067297</CreateTime>
+ <MsgType><![CDATA[text]]></MsgType>
+ <Content><![CDATA[dfd]]></Content>
+ <MsgId>1311112322222222</MsgId>
+ </xml>';
+ 
+ /*
+		$post = '<xml>
+<ToUserName><![CDATA[toUser]]></ToUserName>
+<FromUserName><![CDATA[FromUser]]></FromUserName>
+<CreateTime>123456789</CreateTime>
+<MsgType><![CDATA[event]]></MsgType>
+<Event><![CDATA[subscribe]]></Event>
+</xml>';
+
+
+		$post = ' <xml>
+ <ToUserName><![CDATA[toUser]]></ToUserName>
+ <FromUserName><![CDATA[ow29VvzICifpOTq_9EDGT3AhYpqg]]></FromUserName>
+ <CreateTime>1442067297</CreateTime>
+ <MsgType><![CDATA[image]]></MsgType>
+ <PicUrl><![CDATA[http://mmbiz.qpic.cn/mmbiz/OxUBpiaYgpHiaDaiccrsX3MrFEVtjIfEAZk8zoJDZ4gXWWW2CIFic6Dicqndu23wMgA4Icg3yE4SRZg6L5jqanu9kvQ/0]]></PicUrl>
+ <MediaId><![CDATA[media_id]]></MediaId>
+ <MsgId>111</MsgId>
+ </xml>';
+
+ 		$post = '<xml>
+<ToUserName><![CDATA[toUser]]></ToUserName>
+<FromUserName><![CDATA[ow29VvzICifpOTq_9EDGT3AhYpqg]]></FromUserName>
+<CreateTime>1442067297</CreateTime>
+<MsgType><![CDATA[voice]]></MsgType>
+<MediaId><![CDATA[media_id]]></MediaId>
+<Format><![CDATA[Format]]></Format>
+<MsgId>23123213</MsgId>
+</xml>';
+
+
+		$post = '<xml>
+<ToUserName><![CDATA[toUser]]></ToUserName>
+<FromUserName><![CDATA[FromUser]]></FromUserName>
+<CreateTime>123456789</CreateTime>
+<MsgType><![CDATA[event]]></MsgType>
+<Event><![CDATA[CLICK]]></Event>
+<EventKey><![CDATA[EVENTKEY]]></EventKey>
+</xml>';
+*/
+		Dever::log(time());
+		if (!empty($post)) {
+			Dever::log($post);
+			libxml_disable_entity_loader(true);
+          	$result = (array) simplexml_load_string($post, 'SimpleXMLElement', LIBXML_NOCDATA);
+
+          	$this->handle($result);
+		} else {
+			return false;
+		}
+    }
+    
+    /**
+     * 对微信的内容做处理,得到最终结果
+     * 
+     * @return mixed
+     */
+    private function handle($result)
+    {
+    	return;
+		$config = array
+		(
+			'AppId' => 'add_appid',
+			'CreateTime' => 'add_create_date',
+			'InfoType' => 'add_type',
+			'ComponentVerifyTicket' => 'add_ticket',
+		);
+		
+		foreach ($config as $k => $v) {
+			$this->result($k, $v, $result);
+		}
+		
+		# 事件处理
+		$this->event();
+		
+		$this->save();
+	}
+	
+	/**
+     * 事件处理
+     * 
+     * @return mixed
+     */
+	private function event()
+	{
+		if ($this->result['add_type'] == 'component_verify_ticket') {
+			
+		}
+	}
+	
+	/**
+     * 入库
+     * 
+     * @return mixed
+     */
+	private function save()
+	{
+		$this->result['add_info'] = is_array($this->result['add_info']) ? implode(',', $this->result['add_info']) : $this->result['add_info'];
+		$this->result['add_site'] = $this->core->site();
+		
+		# 入库 使用mid排重
+		$info = array();
+		if (isset($this->result['add_mid'])) {
+			$info = Dever::load('weixin/usermsg-getOne', array('where_mid' => $this->result['add_mid'], 'where_site' => $this->result['add_site']));
+			$this->result['id'] = $info['id'];
+		}
+
+		if (!$info) {
+			$this->result['id'] = Dever::load('weixin/usermsg-insert', $this->result);
+
+			# 记录点对点聊天记录 暂时不记录了
+			/*
+			if($this->result['add_type'] == 'text')
+			{
+				$update['add_state'] = 1;
+				$update['add_openid'] = $this->result['add_from'];
+				$update['add_usermsg_id'] = $this->result['id'];
+				$update['add_account'] = -1;
+				$update['add_type'] = $this->result['add_type'];
+				$update['add_info'] = Dever::load('weixin/user.msg', $this->result['id']);
+
+				Dever::load('weixin/usermsg_log-insert', $update);
+			}
+			*/
+		}
+	}
+	
+	/**
+     * 得到最终结果
+     * 
+     * @return mixed
+     */
+    private function result($key, $index, $result, $name = '')
+    {
+		if (isset($result[$key])) {
+			$value = trim($result[$key]);
+			if ($index == 'add_type') {
+				$this->type($value, $result);
+			}
+			if ($index == 'add_content') {
+				//$key = $name ? $name : $key;
+				$this->result[$index][0][$key] = $value;
+				$this->info($key, $value);
+			} elseif ($index == 'add_ctime') {
+				$this->result[$index] = $value ? $value : time();
+			} else {
+				$this->result[$index] = $value;
+			}
+		}
+	}
+
+	/**
+     * 根据状态得到用户发送的具体内容,为了响应及时,这里不做解析。
+     * 
+     * @return mixed
+     */
+    private function info($key, $value)
+    {
+    	$this->result['add_info'][] = $value;
+    }
+	
+	/**
+     * 得到type的值
+     * 
+     * @return mixed
+     */
+    private function type($index, $result)
+    {
+		$type = $this->config($index);
+		if (is_array($type)) {
+			foreach ($type as $k => $v) {
+				if (is_numeric($k)) {
+					$k = $v;
+				}
+				$this->result($k, 'add_content', $result, $v);
+			}
+		} else {
+			$this->result($type, 'add_content', $result);
+		}
+	}
+	
+	/**
+     * 得到对应关系
+     * 
+     * @return mixed
+     */
+    private function keywords($type)
+    {
+		# 根据keywords的type设定来设置对应关系
+		$config = array
+		(
+			1 => 'text',
+			2 => 'news',
+			//3 => 'news',
+			4 => 'voice',
+			5 => 'video',
+			6 => 'image',
+		);
+		
+		if (!isset($config[$type])) {
+			return false;
+		}
+		
+		$this->result['type'] = $config[$type];
+		
+		return $config[$type];
+	}
+
+    /**
+     * 配置type类型
+     * 
+     * @return mixed
+     */
+    private function config($key, $type = 'get')
+    {
+    	$config = array
+    	(
+    		# 文本
+    		'text' => array
+    		(
+				# 设置获取的key 应答
+				'get' => 'Content',
+				# 设置赋值的key 回复
+				'set' => 'Content',
+			),
+    		# 图片
+    		'image' => array
+    		(
+				'get' => array('PicUrl', 'MediaId'),
+				'set' => array
+				(
+					'Image' => array('MediaId' => 'pic')
+				),
+			),
+    		# 语音
+    		'voice' => array
+    		(
+				'get' => array('MediaId', 'Format'),
+				'set' => array
+				(
+					'Voice' => array('MediaId' => 'mp3')
+				),
+			),
+			# 视频
+    		'video' => array
+    		(
+				'get' => array('MediaId', 'ThumbMediaId'),
+				'set' => array
+				(
+					'Voice' => array('MediaId' => 'mp4', 'Title' => 'title', 'Description' => 'info')
+				),
+			),
+			# 小视频
+    		'shortvideo' => array
+    		(
+				'get' => array('MediaId', 'ThumbMediaId'),
+				'set' => false,
+			),
+			# 地理位置
+    		'location' => array
+    		(
+				'get' => array('Location_X', 'Location_Y', 'Scale', 'Label'),
+				'set' => false,
+			),
+			# 链接消息
+    		'link' => array
+    		(
+				'get' => array('Title', 'Description', 'Url', 'Label'),
+				'set' => false,
+			),
+			# 单图文消息
+    		'new' => array
+    		(
+				'get' => false,
+				'set' => array
+				(
+					'ArticleCount' => 1,
+					'Articles' => array
+					(
+						'item' => array('Title' => 'title', 'Description' => 'info', 'PicUrl' => 'pic', 'Url' => 'link')
+					)
+				),
+			),
+			# 多图文消息
+    		'news' => array
+    		(
+				'get' => false,
+				'set' => array
+				(
+					'ArticleCount' => 'total',
+					'Articles' => array
+					(
+						'item' => array('Title' => 'title', 'Description' => 'info', 'PicUrl' => 'pic', 'Url' => 'link')
+					)
+				),
+			),
+			# 音乐消息
+			'music' => array
+    		(
+				'get' => false,
+				'set' => false,
+			),
+			
+			# 事件消息,所有事件返回的字段都在此做说明
+			'event' => array
+    		(
+				'get' => array
+				(
+					'Event' => '事件',
+					'EventKey' => '事件ID',
+					'Latitude' => '纬度',
+					'Longitude' => '经度',
+					'Precision' => '精度',
+					'Ticket' => '二维码',
+					'MsgID' => '消息ID',
+					'Status' => '状态',
+					'TotalCount' => '粉丝数',
+					'FilterCount' => '过滤数',
+					'SentCount' => '成功数',
+					'ErrorCount' => '失败数',
+				),
+				'set' => false,
+			),
+    	);
+    	
+    	return $config[$key][$type];
+    }
+
+    /**
+     * 获取当前时间
+     * 
+     * @return mixed
+     */
+    private function time()
+    {
+		return time();
+    }
+
+    /**
+     * 拼装xml相应代码
+     * 
+     * @return mixed
+     */
+    private function xml($content)
+    {
+    	$xml = 	"<xml>\r\n"
+    	.$this->tag('ToUserName', $this->result['add_from']) . "\r\n"
+    	.$this->tag('FromUserName', $this->result['add_to']) . "\r\n"
+    	.$this->tag('CreateTime', $this->time()) . "\r\n"
+    	.$this->tag('MsgType', $this->result['type']) . "\r\n"
+    	.$content . "\r\n"
+    	.'</xml>';
+
+		return $xml;
+    }
+
+    /**
+     * 生成tag
+     * 
+     * @return mixed
+     */
+    private function tag($tag, $value = '')
+    {
+		if (!is_numeric($value) && strpos($value, '<') === false) {
+			$value = '<![CDATA['.$value.']]>';
+		}
+    	return '<'.$tag.'>'.$value.'</'.$tag.'>';
+    } 
+}

+ 15 - 0
config/base.php

@@ -0,0 +1,15 @@
+<?php
+
+# 一些基本配置
+$config['base'] = array
+(
+	
+);
+
+# 模板配置
+$config['template'] = array
+(
+	
+);
+
+return $config;

+ 11 - 0
config/dyna.php

@@ -0,0 +1,11 @@
+<?php
+# 动态配置,可以用于seo配置,请在项目下建立该配置文件
+
+return array
+(
+	# 首页 可与route相同
+	'home' => array
+	(
+		
+	)
+);

+ 242 - 0
config/env/localhost/wechat.php

@@ -0,0 +1,242 @@
+<?php
+# 集成项目的大部分配置,此为默认设置。环境不同,以下的配置也有可能不同,可以根据项目名建立配置文件
+
+# 基本配置
+$config['base'] = array
+(
+	# 项目部署的相对路径(部署在服务器的根目录,如果不定义DEVER_PROJECT_NAME,则本项必须启用并有效)
+	'path' => DIRECTORY_SEPARATOR . 'workspace' . DIRECTORY_SEPARATOR,
+
+	# 访问assets目录的物理路径
+	'assets' => DEVER_APP_PATH . 'assets' . DIRECTORY_SEPARATOR,
+
+	# 访问data目录的物理路径
+	'data' 	=> DEVER_PROJECT_PATH . 'data' . DIRECTORY_SEPARATOR,
+
+	# 访问当前项目目录的物理路径,如果项目和dever类库在一个目录中,则为DEVER_PATH,如果不在,则为DEVER_APP_PATH,当然也可随意更改,这里目前只影响合并操作(merge)
+	'workspace' => DEVER_APP_PATH,
+	
+	# 定义api的token明文,如果和其他业务有合作,建议使用系统自带的接口api,自带加密解密程序。
+	'token' => 'dever_api_2016',
+	
+	# 是否启用nocache,如果是互动类的项目且主域增加了cdn,建议开启
+	'clearHeaderCache' => false,
+
+	# api文档生成是否开启,开启后,将会根据访问来生成文档。生产环境建议禁止
+	'apiDoc' => true,
+	# api日志是否开启,开启后,将会记录所有带有_api后缀方法的请求参数和响应参数
+	'apiLog' => false,
+
+	# 定义自动转为api的目录,可以将该目录下的所有类的公共方法,都转为可以访问的api,开启该功能可能有安全性问题。
+	'apiOpenPath' => 'src',
+
+	# 启用后,将会根据api目录下的配置文件自动定位api
+	//'apiConfig' => true,
+	
+	# 开启用户触发cron,主要用于无法加到系统计划任务的虚拟主机,必须安装manage组件,谨慎开启,会稍微影响程序执行效率
+	//'cron' => true,
+);
+
+# 模板配置
+$config['template'] = array
+(
+	# 是否启用静态资源域名动态化,启用之后,静态资源的域名将动态加载,适合使用多个域名或publish启用
+	'domain' => true,
+
+	# 是否开启强制刷新页面缓存
+	'shell' => 'temp',
+	
+	# 是否开启手动更改模板名称,允许通过$_GET的方式来更改当前模板,值为$_GET的key值,默认关闭
+	//'name' => 'template',
+
+	# publish 是否发布,此项开启后,系统不会检测service(意味着不用将service打包上线),适合生产环境,并能对代码起到一定的加密保护。
+	//'publish' => true,
+);
+
+# 数据库配置
+$config['database'] = array
+(
+	# database 中的reuqest的兼容定义,如果启用了该选项,需要自行开发database/compatible目录下相对应的数据表文件中的request方法。
+	//'compatible' => 'model',
+
+	# 是否开启sql自动优化,将sql中的select * 转换为 select a,b形式,将sql中的where条件按照索引从左到右自动排序,必须打开上述的opt选项,数据量大时建议打开。
+	//'sql' => true,
+
+	# 关闭自助建表,生产环境建议开启,开启之后无法对数据表结构进行更新操作
+	//'create' => true,
+
+	# 是否开启mysql自助优化功能,开启后,会记录所有where条件和order的字段,可以方便的在后台进行分析、增加索引,必须安装manage组件
+	'opt' => true,
+
+	# 默认数据库配置
+	'default' => array
+	(
+		'type' => 'pdo',
+		'host' => array
+		(
+			'read' => 'web-mysql:3306',
+			'update' => 'web-mysql:3306',
+		),
+		'database' => 'wechat',
+		'username' => 'root',
+		'password' => '123456',
+		'charset' => 'utf8',
+	),
+
+	'mongo' => array
+	(
+		'type' => 'mongo',
+		'host' => 'server-mongodb:27017',
+		'database' => 'dever',
+		'username' => 'root',
+		'password' => '123456',
+		'charset' => 'utf8',
+	),
+);
+
+# 缓存配置
+$config['cache'] = array
+(
+	# 启用mysql数据库缓存,这个缓存是根据表名自动生成,dever::load形式和service的all、one形式均自动支持,无需手动添加
+	'mysql' => 0,
+	# 启用页面缓存 会根据当前的url来生成缓存,相当于页面静态化。
+	'html' => 0,
+	# 启用数据级别缓存 这个缓存是程序员自定义的:Dever::cache('name', 'value', 3600);
+	'data' => 3600,
+	# 启用load加载器缓存,一般不加载
+	'load' => 0,
+	# 启用load加载器的远程加载缓存
+	'curl' => 3600,
+
+	# 缓存精细控制,可以根据缓存的key(mysql为表名、service为小写类名,规则是模糊匹配),来控制每一条缓存
+	'loadKey' => array
+	(
+		# 定义缓存名为auth.data的缓存时间
+		'auth.data' => 200,
+	),
+	
+	# 缓存清理的参数名,请通过shell=clearcache执行
+	'shell' => 'clearcache',
+
+	# 是否启用key失效时间记录,启用之后,将会记录每个key的失效时间
+	'expire' => true,
+
+	# 缓存类型
+	'type' => 'memcache',//memcache、redis
+
+	# 缓存保存方式,支持多个数据源、多台缓存服务器
+	'store' => array
+	(
+		/*
+		array
+		(
+			'host' => 'server_memcached',
+			'port' => '11211',
+			'weight' => 100,
+		),
+
+		array
+		(
+			'host' => 'server_memcached',
+			'port' => '11212',
+			'weight' => 100,
+		),
+		*/
+	),
+);
+
+# debug配置
+$config['debug'] = array
+(
+	# 开启错误提示 生产环境建议禁止
+	'error' => true,
+	
+	# 错误日志记录,为空则不开启,为数组则为socket等服务
+	'log' => array('type' => 'file', 'host' => 'host', 'port' => 'port'),
+	# 是否开启记录超时时间,单位为秒
+	'overtime' => 3,
+
+	# 开始访问报告
+	# 生产环境建议禁止或添加ip限制,多个ip用逗号隔开
+	# 如禁止,值为false,下述shell也将失效
+	# 值为2,则开启强制模式,任何输出都将打印debug
+	'request' => Dever::ip(),
+
+	# 设定打印访问报告的指令
+	'shell' => 'debug',
+	# 以上指令,请通过&shell=debug来执行,如果你想设置断点或者打印当前业务逻辑下的sql,请直接用Dever::debug();打印数据
+
+);
+$local = isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : 'localhost';
+# 本地可用这个
+$host = 'http://'.$local . '/';
+
+# 定义assets的域名
+$assets = DEVER_APP_HOST . 'assets/';
+if (DEVER_APP_NAME == 'manage') {
+	$assets = $host . 'dever_package/manage/assets/';
+}
+
+# host 设置
+$config['host'] = array
+(
+	# 跟域名
+	'base' 	=> DEVER_APP_HOST,
+
+	# cookie 域名
+	'cookie' => '',
+	
+	# assets网络路径,会自动将assets替换为assets/模板
+	'assets' => $assets,
+	# public
+	'public' => $assets . 'public/',
+	'css' => $assets . 'css/',
+	'js' => $assets . 'js/',
+	'img' => $assets . 'img/',
+	'images' => $assets . 'images/',
+	'lib' => $assets . 'lib/',
+
+	# 后台管理系统的assets路径
+	'manage' => $host . 'dever_package/manage/assets/public/',
+	
+	# 合并之后的网络路径,填写之后自动合并资源,不填写则不合并,适合把资源放到云端
+	'merge' => $host . 'wechat/data/assets/' . DEVER_PROJECT . '/',
+	
+	# 上传系统的上传路径的域名(不带action)
+	'upload'=> $host . 'wechat/upload/?save',
+	# 上传系统的资源访问地址
+	'uploadRes'	=> $host . 'wechat/data/upload/',
+
+	# 域名替换,支持*通配符
+	/*
+    'domain' => array
+    (
+        'rule' => function()
+        {
+            $source = $desc = 'http://';
+            if(function_exists('isHttps') && isHttps())
+            {
+                $desc = 'https://';
+            }
+
+            return array($source, $desc);
+        },
+        'replace' => array('*.selfimg.com.cn')
+    ),
+    */
+	
+	# 是否启用代理功能
+	//'proxy' => $host . 'dever/application/applet/main/?data.proxy?',
+
+	# 项目定义,Dever::load将自动转为这个配置,替换掉data/project/default.php里的数据
+	'project' => array
+	(
+		//'main' => array('url' => 'ff'),
+	),
+);
+
+if (DEVER_APP_NAME == 'manage') {
+	$config['host']['merge'] = false;
+}
+
+return $config;

+ 14 - 0
config/plugin.php

@@ -0,0 +1,14 @@
+<?php
+//插件配置
+$config = array
+(
+	# manage 下的 node类
+	'manage/node.get_api' => array
+	(
+		'start' => 'test.get',
+		//'end' => 'test.get',
+		//'cover' => 'test.get',
+	),
+);
+
+return $config;

+ 6 - 0
config/route.php

@@ -0,0 +1,6 @@
+<?php
+
+return array
+(
+	'home' => 'home',
+);

+ 31 - 0
config/sign.php

@@ -0,0 +1,31 @@
+<?php
+
+# 数据收集的配置
+$config['accessToken'] = array
+(
+	'url' => 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential',
+	
+	/*
+	1 => array
+	(
+		'appid' => 'wx1bd1c3bfc6b0515e', 
+		'secret' => '21f8ebe7b419a4920eb9b72532798523'
+	),
+
+	# 牛游
+	2 => array
+	(
+		'appid' => 'wx4978eeb711847a5a', 
+		'secret' => '510645c52d352d915773999f3a3cf5c1'
+	),
+	*/
+);
+
+//$config['accessToken'] += Dever::load('weixin/site-getAll');
+
+//print_r($config['accessToken']);die;
+
+$config['ticket'] = 'https://api.weixin.qq.com/cgi-bin/ticket/getticket?type=jsapi&access_token=';
+
+
+return $config;

+ 2 - 0
index.php

@@ -0,0 +1,2 @@
+<?php
+include('main/index.php');

+ 81 - 0
main/database/col.php

@@ -0,0 +1,81 @@
+<?php
+
+return array
+(
+	# 表名
+	'name' => 'col',
+	# 显示给用户看的名称
+	'lang' => '维度管理',
+	'order' => -10,
+	'check' => 'key',
+	# 数据结构
+	'struct' => array
+	(
+		'id' 		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> 'ID',
+			'default' 	=> '',
+			'desc' 		=> '',
+			'match' 	=> 'is_numeric',
+			//'search'	=> 'order',
+			'order'		=> 'desc',
+			'list'		=> true,
+		),
+		
+		'name'		=> array
+		(
+			'type' 		=> 'varchar-60',
+			'name' 		=> '维度名称',
+			'default' 	=> '',
+			'desc' 		=> '请输入维度名称',
+			'match' 	=> 'is_string',
+			'update'	=> 'text',
+			'search'	=> 'fulltext',
+			'list'		=> true,
+		),
+
+		'key'		=> array
+		(
+			'type' 		=> 'varchar-60',
+			'name' 		=> '维度key',
+			'default' 	=> '',
+			'desc' 		=> '请输入维度key',
+			'match' 	=> 'is_string',
+			'update'	=> 'text',
+			'search'	=> 'fulltext',
+			'list'		=> true,
+		),
+
+		'state'		=> array
+		(
+			'type' 		=> 'tinyint-1',
+			'name' 		=> '状态',
+			'default' 	=> '1',
+			'desc' 		=> '请选择状态',
+			'match' 	=> 'is_numeric',
+		),
+		
+		'cdate'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '录入时间',
+			'match' 	=> array('is_numeric', time()),
+			'desc' 		=> '',
+			# 只有insert时才生效
+			'insert'	=> true,
+			'list'		=> 'date("Y-m-d H:i:s", {cdate})',
+		),
+	),
+	
+	'manage' => array
+	(
+
+	),
+	
+	# request 请求接口定义
+	'request' => array
+	(
+		
+	),
+);

+ 90 - 0
main/database/project.php

@@ -0,0 +1,90 @@
+<?php
+
+$type = array
+(
+	1 => '服务号',
+	2 => '订阅号',
+	3 => '小程序',
+	4 => '小游戏',
+	5 => '第三方平台',
+	6 => '开发者',
+);
+
+return array
+(
+	# 表名
+	'name' => 'project',
+	# 显示给用户看的名称
+	'lang' => '项目管理',
+	'order' => -10,
+	# 数据结构
+	'struct' => array
+	(
+		'id' 		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> 'ID',
+			'default' 	=> '',
+			'desc' 		=> '',
+			'match' 	=> 'is_numeric',
+			//'search'	=> 'order',
+			'order'		=> 'desc',
+			'list'		=> true,
+		),
+		
+		'name'		=> array
+		(
+			'type' 		=> 'varchar-60',
+			'name' 		=> '项目名称',
+			'default' 	=> '',
+			'desc' 		=> '请输入项目名称',
+			'match' 	=> 'is_string',
+			'update'	=> 'text',
+			'search'	=> 'fulltext',
+			'list'		=> true,
+		),
+
+		'type'		=> array
+		(
+			'type' 		=> 'tinyint-11',
+			'name' 		=> '项目类型',
+			'default' 	=> '1',
+			'desc' 		=> '项目类型',
+			'match' 	=> 'is_numeric',
+			'update'	=> 'select',
+			'option'	=> $type,
+			'list'		=> true,
+		),
+
+		'state'		=> array
+		(
+			'type' 		=> 'tinyint-1',
+			'name' 		=> '状态',
+			'default' 	=> '1',
+			'desc' 		=> '请选择状态',
+			'match' 	=> 'is_numeric',
+		),
+		
+		'cdate'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '录入时间',
+			'match' 	=> array('is_numeric', time()),
+			'desc' 		=> '',
+			# 只有insert时才生效
+			'insert'	=> true,
+			'list'		=> 'date("Y-m-d H:i:s", {cdate})',
+		),
+	),
+	
+	'manage' => array
+	(
+
+	),
+	
+	# request 请求接口定义
+	'request' => array
+	(
+		
+	),
+);

+ 8 - 0
main/index.php

@@ -0,0 +1,8 @@
+<?php
+
+define('DEVER_APP_NAME', 'main');
+define('DEVER_APP_LANG', '基础设置');
+define('DEVER_APP_PATH', dirname(__FILE__) . DIRECTORY_SEPARATOR);
+define('DEVER_MANAGE_ORDER', 10);
+define('DEVER_MANAGE_ICON', 'glyphicon glyphicon-road');
+include(DEVER_APP_PATH . '../boot.php');

+ 236 - 0
main/lib/Wechat.php

@@ -0,0 +1,236 @@
+<?php
+/*
+|--------------------------------------------------------------------------
+| core.php 微信平台核心类
+|--------------------------------------------------------------------------
+*/
+namespace Main\Lib;
+
+use Dever;
+
+class Wechat
+{
+	/**
+	 * config
+	 *
+	 * @var array
+	 */
+	private $config;
+
+	/**
+	 * config
+	 *
+	 * @var array
+	 */
+	private $token;
+	
+	/**
+	 * project
+	 *
+	 * @var string
+	 */
+	private $project;
+	
+	/**
+     * 构造函数 初始化
+     * 
+     * @return mixed
+     */
+	public function __construct($type = 'component', $project = false)
+	{
+		$this->config = Dever::config('sign')->cAll;
+		
+		if (!$project) {
+			$project = Dever::input('project', 1);
+		}
+
+		if (!$project) {
+			Dever::alert('project is not exits!');
+		}
+
+		$this->project = $project;
+	}
+	
+	/**
+     * 获取当前站点的配置
+     * 
+     * @return mixed
+     */
+	public function project()
+	{
+		return $this->project;
+	}
+
+	/**
+     * 获取当前站点的配置
+     * 
+     * @return mixed
+     */
+	public function config()
+	{
+		return $this->config['accessToken'][$this->project];
+	}
+	
+	/**
+     * 获取签名信息
+     * 
+     * @return mixed
+     */
+	public function get($url)
+	{
+		$ticket = $this->ticket($this->token());
+		
+		if (!$ticket) {
+			$return['status'] = 0;
+			$return['msg'] 	= 'error';
+		} else {
+			$timestamp = time();
+			$nonce = $this->nonce();
+			$signature = $this->signature($ticket, $url, $timestamp, $nonce);
+			$return = array
+			(
+				'appId'		=> $this->config['accessToken'][$this->project]['appid'],
+				'timestamp'	=> $timestamp,
+				'nonceStr'	=> $nonce,
+				'signature'	=> $signature,
+				'status'	=> 1,
+				'msg'		=> '成功',
+			);
+		}
+		
+		Dever::out($return);
+	}
+	
+	/**
+     * 获取nonce
+     * 
+     * @return mixed
+     */
+	private function nonce()
+	{
+		return substr(md5(microtime()), rand(10, 15));
+	}
+	
+    /**
+     * 获取accessToken
+     * 
+     * @return mixed
+     */
+    public function token($state = 1)
+    {
+		$url = $this->config['accessToken']['url'] . '&' . http_build_query($this->config['accessToken'][$this->project]);
+		
+		$where['where_project'] = $this->project;
+		$info = Dever::load('main/token-info', $where);
+
+		$request = $update = false;
+			
+		if ($info && ((time() - $info['mdate'] >= $info['expires_in']) || $state == 2)) {
+			$request = $update = true;
+		} elseif ($info) {
+			return $info['token'];
+		}
+		if (!$info) {
+			$request = true;
+			$update = false;
+		}
+		
+		if ($request == true) {
+			$data = json_decode(Dever::curl($url), true);
+			
+			if ($data && isset($data['access_token'])) {
+				$data['expires_in'] = $data['expires_in'] - 2000;
+				if ($update == true) {
+					$set['set_project'] = $this->project;
+					$set['set_token'] = $data['access_token'];
+					$set['set_expires_in'] = $data['expires_in'];
+					$set['where_id'] = $info['id'];
+					Dever::load('main/token-update', $set);
+				} else {
+					$insert['add_project'] = $this->project;
+					$insert['add_token'] = $data['access_token'];
+					$insert['add_expires_in'] = $data['expires_in'];
+					Dever::load('main/token-insert', $insert);
+				}
+				
+				return $data['access_token'];
+			}
+		}
+    }
+    
+    
+    /**
+     * 获取ticket
+     * 
+     * @return mixed
+     */
+    private function ticket($token)
+    {
+		$url = $this->config['ticket'] . $token;
+		
+		$where['where_project'] = $this->project;
+		$info = Dever::load('main/ticket-info', $where);
+		
+		$request = $update = false;
+			
+		if ($info && time() - $info['mdate'] >= $info['expires_in']) {
+			$request = $update = true;
+		} elseif($info) {
+			return $info['ticket'];
+		}
+		if (!$info) {
+			$request = true;
+			$update = false;
+		}
+		
+		if ($request == true) {
+			$data = json_decode(Dever::curl($url), true);
+			
+			if ($data && isset($data['ticket'])) {
+				$data['expires_in'] = $data['expires_in'] - 2000;
+				if ($update == true) {
+					$set['set_project'] = $this->project;
+					$set['set_ticket'] = $data['ticket'];
+					$set['set_expires_in'] = $data['expires_in'];
+					$set['where_name'] = $this->project;
+					Dever::load('main/ticket-update', $set);
+				} else {
+					$insert['add_project'] = $this->project;
+					$insert['add_ticket'] = $data['ticket'];
+					$insert['add_expires_in'] = $data['expires_in'];
+					Dever::load('main/ticket-insert', $insert);
+				}
+				
+				return $data['ticket'];
+			}
+		}
+    }
+    
+    
+    /**
+     * 获取signature
+     * 
+     * @return mixed
+     */
+    private function signature($ticket, $url, $timestamp, $noncestr)
+    {
+		$info = array();
+		$info['jsapi_ticket'] = $ticket;
+		$info['url'] = $url;
+		$info['timestamp'] = $timestamp;
+		$info['noncestr'] = $noncestr;
+		ksort($info);
+
+		$signature_string = substr(http_build_query($info), 0, -1);
+
+		/*
+		foreach($info as $k => $v)
+		{
+			$signature_string .= $k . '=' . $v . '&';
+		}
+		
+		$signature_string = substr($signature_string, 0, -1);
+		*/
+		return sha1($signature_string);
+	}
+}

+ 70 - 0
main/src/Data.php

@@ -0,0 +1,70 @@
+<?php
+
+namespace Main\Src;
+
+use Dever;
+
+class Data
+{
+    private function file()
+    {
+        return Dever::data() . 'log.php';
+    }
+
+    private function config()
+    {
+        $config = include($this->file());
+        return $config;
+    }
+
+    # 从数据库生成维度和项目的配置文件
+    public function create()
+    {
+        $project = Dever::db('main/project')->all();
+        
+        $config = array();
+
+        if ($project) {
+            foreach ($project as $k => $v) {
+                $config['project'][$v['key']] = $v;
+            }
+        }
+
+        $col = Dever::db('main/col')->all();
+
+        if ($col) {
+            foreach ($col as $k => $v) {
+                $config['col'][$v['key']] = $v;
+            }
+        }
+
+        $data = '<?php return ' . var_export($config, true) . ';';
+        file_put_contents($this->file(), $data);
+
+        return true;
+    }
+
+    public function add()
+    {
+        $project = Dever::input('project');
+        $config = $this->config();
+        if (!isset($config['project'][$project])) {
+            return true;
+        }
+
+        $msg['project'] = $project;
+        $input = Dever::input();
+        if (isset($config['col'])) {
+            foreach ($config['col'] as $k => $v) {
+                if (isset($input[$k])) {
+                    $msg[$k] = $input[$k];
+                }
+            }
+        }
+        if ($msg) {
+            Dever::log($msg, 3);
+        }
+
+        return true;
+    }
+}

+ 2 - 0
setup.php

@@ -0,0 +1,2 @@
+<?php
+echo '安装程序';

+ 4 - 0
upload/index.php

@@ -0,0 +1,4 @@
+<?php
+define('DEVER_PACKAGE',  'upload');
+define('DEVER_APP_SETUP', dirname(__FILE__) . DIRECTORY_SEPARATOR);
+include(dirname(__FILE__) . DIRECTORY_SEPARATOR . '../boot.php');