dever 5 years ago
commit
9982661548
4 changed files with 142 additions and 0 deletions
  1. 16 0
      config/base.php
  2. 44 0
      config/wechat.php
  3. 7 0
      index.php
  4. 75 0
      src/Auth.php

+ 16 - 0
config/base.php

@@ -0,0 +1,16 @@
+<?php
+
+# 一些基本配置
+$config['base'] = array
+(
+	# 后台头部菜单
+	'top' => 'main/project_id-2',
+);
+
+# 模板配置
+$config['template'] = array
+(
+	
+);
+
+return $config;

+ 44 - 0
config/wechat.php

@@ -0,0 +1,44 @@
+<?php
+# 公众号基本配置
+$config['type'] = 2;
+
+$config['token'] = array
+(
+	'name' => '获取公众号的token',
+	'method' => 'get',
+	'json' => false,
+	'url' => 'https://api.weixin.qq.com/cgi-bin/token?',
+	'param' => array
+	(
+		'appid' => 'appid',
+		'secret' => 'secret',
+		'grant_type' => 'client_credential',
+	),
+	//针对一些返回的名称,做转换
+	'response' => array
+	(
+		'access_token' => 'token',
+		'expires_in' => 'expires_in',
+	),
+);
+
+$config['ticket'] = array
+(
+	'name' => '获取公众号的ticket',
+	'method' => 'get',
+	'json' => false,
+	'url' => 'https://api.weixin.qq.com/cgi-bin/ticket/getticket?',
+	'param' => array
+	(
+		'type' => 'jsapi',
+		'access_token' => 'token',
+	),
+	//针对一些返回的名称,做转换
+	'response' => array
+	(
+		'jsapi_ticket' => 'ticket',
+		'expires_in' => 'expires_in',
+	),
+);
+
+return $config;

+ 7 - 0
index.php

@@ -0,0 +1,7 @@
+<?php
+define('DEVER_APP_NAME', 'service');
+define('DEVER_APP_LANG', '公众号');
+define('DEVER_APP_PATH', dirname(__FILE__) . DIRECTORY_SEPARATOR);
+define('DEVER_MANAGE_ORDER', 80);
+define('DEVER_MANAGE_ICON', 'glyphicon glyphicon-hdd layui-icon-cellphone');
+include(DEVER_APP_PATH . '../boot.php');

+ 75 - 0
src/Auth.php

@@ -0,0 +1,75 @@
+<?php
+/*
+|--------------------------------------------------------------------------
+| auth.php 用于做权限验证
+|--------------------------------------------------------------------------
+*/
+namespace Wechat_service\Src;
+
+use Dever;
+use Token\Lib\Wechat;
+
+class Auth
+{
+	/**
+	 * wechat
+	 *
+	 * @var Wechat
+	 */
+	private $wechat;
+	
+	/**
+	 * result
+	 *
+	 * @var array
+	 */
+	private $result;
+	
+	/**
+	 * output
+	 *
+	 * @var string
+	 */
+	private $output;
+	
+	/**
+     * 构造函数 初始化
+     * 
+     * @return mixed
+     */
+	public function __construct()
+	{
+		$this->wechat = new Wechat(false, 'wechat_service');
+	}
+
+	/**
+     * 获取签名数据,主要用于jssdk
+     * 
+     * @return mixed
+     */
+	public function sign()
+	{
+		$url = Dever::input('url');
+		return $this->wechat->sign($url);
+	}
+
+	/**
+     * 获取ticket
+     * 
+     * @return mixed
+     */
+	public function ticket()
+	{
+		return $this->wechat->ticket(false, false, 2000, true);
+	}
+
+	/**
+     * 获取token 一般为系统token
+     * 
+     * @return mixed
+     */
+	public function token()
+	{
+		return $this->wechat->token(false, false, 2000, true);
+	}
+}