[更新]修改公众号网页签名支持

This commit is contained in:
Anyon 2018-04-03 13:04:17 +08:00
parent d35f045c73
commit 0d1538ad4d

View File

@ -14,12 +14,11 @@
namespace app\wechat\controller\api; namespace app\wechat\controller\api;
use service\ToolsService;
use service\WechatService; use service\WechatService;
use think\facade\Response; use think\facade\Response;
/** /**
* 微信公众号页面脚本 * 公众号页面支持
* Class Script * Class Script
* @package app\wechat\controller\api * @package app\wechat\controller\api
*/ */
@ -32,28 +31,18 @@ class Script
*/ */
protected $request; protected $request;
/**
* Wechat constructor.
*/
public function __construct()
{
ToolsService::corsOptionsHandler();
$this->request = app('request');
}
/** /**
* jsSign签名 * jsSign签名
* @throws \Exception * @throws \Exception
*/ */
public function index() public function index()
{ {
$wechat = WechatService::webOauth($this->request->get('mode', 1)); $result = app('request');
$url = $this->request->server('HTTP_REFERER', $this->request->url(true), null); $wechat = WechatService::webOauth($result->get('mode', 1));
$url = $result->server('HTTP_REFERER', $result->url(true), null);
$assign = [ $assign = [
'openid' => $wechat['openid'], 'jssdk' => json_encode(WechatService::webJsSDK($url), 256),
'fansinfo' => $wechat['fansinfo'], 'openid' => $wechat['openid'], 'fansinfo' => $wechat['fansinfo'],
'jssdk' => WechatService::webJsSDK($url),
]; ];
return Response::create(env('APP_PATH') . 'wechat/view/api/script/index.js', 'view', 200, [ return Response::create(env('APP_PATH') . 'wechat/view/api/script/index.js', 'view', 200, [
'content-type' => 'application/x-javascript;charset=utf-8', 'content-type' => 'application/x-javascript;charset=utf-8',