mirror of
https://gitee.com/zoujingli/ThinkAdmin.git
synced 2025-04-06 03:58:04 +08:00
[更新]增加公众号网页JSSDK支持
This commit is contained in:
parent
3193ce668d
commit
d35f045c73
63
application/wechat/controller/api/Script.php
Normal file
63
application/wechat/controller/api/Script.php
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | ThinkAdmin
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | 版权所有 2014~2017 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | 官方网站: http://think.ctolog.com
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | 开源协议 ( https://mit-license.org )
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | github开源项目:https://github.com/zoujingli/ThinkAdmin
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
|
||||||
|
namespace app\wechat\controller\api;
|
||||||
|
|
||||||
|
use service\ToolsService;
|
||||||
|
use service\WechatService;
|
||||||
|
use think\facade\Response;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 微信公众号页面脚本
|
||||||
|
* Class Script
|
||||||
|
* @package app\wechat\controller\api
|
||||||
|
*/
|
||||||
|
class Script
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 当前请求对象
|
||||||
|
* @var \think\Request
|
||||||
|
*/
|
||||||
|
protected $request;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Wechat constructor.
|
||||||
|
*/
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
ToolsService::corsOptionsHandler();
|
||||||
|
$this->request = app('request');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* jsSign签名
|
||||||
|
* @throws \Exception
|
||||||
|
*/
|
||||||
|
public function index()
|
||||||
|
{
|
||||||
|
$wechat = WechatService::webOauth($this->request->get('mode', 1));
|
||||||
|
$url = $this->request->server('HTTP_REFERER', $this->request->url(true), null);
|
||||||
|
$assign = [
|
||||||
|
'openid' => $wechat['openid'],
|
||||||
|
'fansinfo' => $wechat['fansinfo'],
|
||||||
|
'jssdk' => WechatService::webJsSDK($url),
|
||||||
|
];
|
||||||
|
return Response::create(env('APP_PATH') . 'wechat/view/api/script/index.js', 'view', 200, [
|
||||||
|
'content-type' => 'application/x-javascript;charset=utf-8',
|
||||||
|
'cache-control' => 'no-cache', 'pragma' => 'no-cache', 'expires' => '0',
|
||||||
|
])->assign($assign);
|
||||||
|
}
|
||||||
|
}
|
14
application/wechat/view/api/script/index.js
Normal file
14
application/wechat/view/api/script/index.js
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
!(function () {
|
||||||
|
if (typeof wx === 'object') {
|
||||||
|
wx.openid = '{$fansinfo.openid|default=""}';
|
||||||
|
wx.unionid = '{$fansinfo.unionid|default=""}';
|
||||||
|
wx.getUserInfo = function () {
|
||||||
|
return eval('{$fansinfo|default=[]|json_encode=###,256|raw}');
|
||||||
|
};
|
||||||
|
wx.config(eval('({$jssdk|default=[]|json_encode=###,256|raw})'));
|
||||||
|
wx.ready(function () {
|
||||||
|
wx.hideOptionMenu();
|
||||||
|
wx.hideAllNonBaseMenuItem();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
})();
|
@ -86,20 +86,21 @@ class WechatService
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取微信网页JSSDK
|
* 获取微信网页JSSDK
|
||||||
|
* @param null|string $url 签名SDK
|
||||||
* @return array
|
* @return array
|
||||||
* @throws \think\Exception
|
* @throws \think\Exception
|
||||||
* @throws \WeChat\Exceptions\InvalidResponseException
|
* @throws \WeChat\Exceptions\InvalidResponseException
|
||||||
* @throws \WeChat\Exceptions\LocalCacheException
|
* @throws \WeChat\Exceptions\LocalCacheException
|
||||||
* @throws \think\exception\PDOException
|
* @throws \think\exception\PDOException
|
||||||
*/
|
*/
|
||||||
public static function webJsSDK()
|
public static function webJsSDK($url = null)
|
||||||
{
|
{
|
||||||
switch (strtolower(sysconf('wechat_type'))) {
|
switch (strtolower(sysconf('wechat_type'))) {
|
||||||
case 'api':
|
case 'api':
|
||||||
return WechatService::script()->getJsSign(request()->url(true));
|
return WechatService::script()->getJsSign(is_null($url) ? request()->url(true) : $url);
|
||||||
case 'thr':
|
case 'thr':
|
||||||
default:
|
default:
|
||||||
return WechatService::wechat()->jsSign(request()->url(true));
|
return WechatService::wechat()->jsSign(is_null($url) ? request()->url(true) : $url);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
2
vendor/autoload.php
vendored
2
vendor/autoload.php
vendored
@ -4,4 +4,4 @@
|
|||||||
|
|
||||||
require_once __DIR__ . '/composer/autoload_real.php';
|
require_once __DIR__ . '/composer/autoload_real.php';
|
||||||
|
|
||||||
return ComposerAutoloaderInit664b5cbfe1e72b3e993dce3dea0bcb98::getLoader();
|
return ComposerAutoloaderInit95af81df6ac420fb6c658e7c9ee159af::getLoader();
|
||||||
|
14
vendor/composer/autoload_real.php
vendored
14
vendor/composer/autoload_real.php
vendored
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
// autoload_real.php @generated by Composer
|
// autoload_real.php @generated by Composer
|
||||||
|
|
||||||
class ComposerAutoloaderInit664b5cbfe1e72b3e993dce3dea0bcb98
|
class ComposerAutoloaderInit95af81df6ac420fb6c658e7c9ee159af
|
||||||
{
|
{
|
||||||
private static $loader;
|
private static $loader;
|
||||||
|
|
||||||
@ -19,15 +19,15 @@ class ComposerAutoloaderInit664b5cbfe1e72b3e993dce3dea0bcb98
|
|||||||
return self::$loader;
|
return self::$loader;
|
||||||
}
|
}
|
||||||
|
|
||||||
spl_autoload_register(array('ComposerAutoloaderInit664b5cbfe1e72b3e993dce3dea0bcb98', 'loadClassLoader'), true, true);
|
spl_autoload_register(array('ComposerAutoloaderInit95af81df6ac420fb6c658e7c9ee159af', 'loadClassLoader'), true, true);
|
||||||
self::$loader = $loader = new \Composer\Autoload\ClassLoader();
|
self::$loader = $loader = new \Composer\Autoload\ClassLoader();
|
||||||
spl_autoload_unregister(array('ComposerAutoloaderInit664b5cbfe1e72b3e993dce3dea0bcb98', 'loadClassLoader'));
|
spl_autoload_unregister(array('ComposerAutoloaderInit95af81df6ac420fb6c658e7c9ee159af', 'loadClassLoader'));
|
||||||
|
|
||||||
$useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded());
|
$useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded());
|
||||||
if ($useStaticLoader) {
|
if ($useStaticLoader) {
|
||||||
require_once __DIR__ . '/autoload_static.php';
|
require_once __DIR__ . '/autoload_static.php';
|
||||||
|
|
||||||
call_user_func(\Composer\Autoload\ComposerStaticInit664b5cbfe1e72b3e993dce3dea0bcb98::getInitializer($loader));
|
call_user_func(\Composer\Autoload\ComposerStaticInit95af81df6ac420fb6c658e7c9ee159af::getInitializer($loader));
|
||||||
} else {
|
} else {
|
||||||
$map = require __DIR__ . '/autoload_namespaces.php';
|
$map = require __DIR__ . '/autoload_namespaces.php';
|
||||||
foreach ($map as $namespace => $path) {
|
foreach ($map as $namespace => $path) {
|
||||||
@ -48,19 +48,19 @@ class ComposerAutoloaderInit664b5cbfe1e72b3e993dce3dea0bcb98
|
|||||||
$loader->register(true);
|
$loader->register(true);
|
||||||
|
|
||||||
if ($useStaticLoader) {
|
if ($useStaticLoader) {
|
||||||
$includeFiles = Composer\Autoload\ComposerStaticInit664b5cbfe1e72b3e993dce3dea0bcb98::$files;
|
$includeFiles = Composer\Autoload\ComposerStaticInit95af81df6ac420fb6c658e7c9ee159af::$files;
|
||||||
} else {
|
} else {
|
||||||
$includeFiles = require __DIR__ . '/autoload_files.php';
|
$includeFiles = require __DIR__ . '/autoload_files.php';
|
||||||
}
|
}
|
||||||
foreach ($includeFiles as $fileIdentifier => $file) {
|
foreach ($includeFiles as $fileIdentifier => $file) {
|
||||||
composerRequire664b5cbfe1e72b3e993dce3dea0bcb98($fileIdentifier, $file);
|
composerRequire95af81df6ac420fb6c658e7c9ee159af($fileIdentifier, $file);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $loader;
|
return $loader;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function composerRequire664b5cbfe1e72b3e993dce3dea0bcb98($fileIdentifier, $file)
|
function composerRequire95af81df6ac420fb6c658e7c9ee159af($fileIdentifier, $file)
|
||||||
{
|
{
|
||||||
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
|
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
|
||||||
require $file;
|
require $file;
|
||||||
|
8
vendor/composer/autoload_static.php
vendored
8
vendor/composer/autoload_static.php
vendored
@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
namespace Composer\Autoload;
|
namespace Composer\Autoload;
|
||||||
|
|
||||||
class ComposerStaticInit664b5cbfe1e72b3e993dce3dea0bcb98
|
class ComposerStaticInit95af81df6ac420fb6c658e7c9ee159af
|
||||||
{
|
{
|
||||||
public static $files = array (
|
public static $files = array (
|
||||||
'1cfd2761b63b0a29ed23657ea394cb2d' => __DIR__ . '/..' . '/topthink/think-captcha/src/helper.php',
|
'1cfd2761b63b0a29ed23657ea394cb2d' => __DIR__ . '/..' . '/topthink/think-captcha/src/helper.php',
|
||||||
@ -257,9 +257,9 @@ class ComposerStaticInit664b5cbfe1e72b3e993dce3dea0bcb98
|
|||||||
public static function getInitializer(ClassLoader $loader)
|
public static function getInitializer(ClassLoader $loader)
|
||||||
{
|
{
|
||||||
return \Closure::bind(function () use ($loader) {
|
return \Closure::bind(function () use ($loader) {
|
||||||
$loader->prefixLengthsPsr4 = ComposerStaticInit664b5cbfe1e72b3e993dce3dea0bcb98::$prefixLengthsPsr4;
|
$loader->prefixLengthsPsr4 = ComposerStaticInit95af81df6ac420fb6c658e7c9ee159af::$prefixLengthsPsr4;
|
||||||
$loader->prefixDirsPsr4 = ComposerStaticInit664b5cbfe1e72b3e993dce3dea0bcb98::$prefixDirsPsr4;
|
$loader->prefixDirsPsr4 = ComposerStaticInit95af81df6ac420fb6c658e7c9ee159af::$prefixDirsPsr4;
|
||||||
$loader->classMap = ComposerStaticInit664b5cbfe1e72b3e993dce3dea0bcb98::$classMap;
|
$loader->classMap = ComposerStaticInit95af81df6ac420fb6c658e7c9ee159af::$classMap;
|
||||||
|
|
||||||
}, null, ClassLoader::class);
|
}, null, ClassLoader::class);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user