107 lines
4.8 KiB
PHP
107 lines
4.8 KiB
PHP
<?php
|
|
/**
|
|
* SAAS应用系统 --- 十年开发经验汇集巨献!
|
|
* ==========================================================
|
|
* Copy right 2020-2050 成都众联思索科技有限公司,保留所有权利。
|
|
* ----------------------------------------------------------
|
|
* 官方网址: https://www.zoomtk.com
|
|
* 这不是自由软件!未经允许不得用于商业目或程序代码摘取及修改。
|
|
* 任何企业和个人未经允许对程序代码以任何形式任何目的再发布传播。
|
|
* 唯一发布渠道www.zoomtk.com;非官方渠道统一视为侵权行为。
|
|
* ==========================================================
|
|
*/
|
|
namespace addon\aliapp\shop\controller;
|
|
use addon\aliapp\model\Config;
|
|
use addon\aliapp\model\MinCode;
|
|
use app\Controller;
|
|
use think\facade\Session;
|
|
use think\facade\Db;
|
|
class Auth extends Controller
|
|
{
|
|
/**
|
|
* 授权接入
|
|
* @return string
|
|
* @throws \Exception
|
|
*/
|
|
public function authinfo()
|
|
{
|
|
$openPlatform = new MinCode();
|
|
$authCode = input('app_auth_code');
|
|
$state_base64 = input('state');
|
|
$state = url_safe_base64_decode($state_base64);
|
|
if ($authCode) {
|
|
if ($state) {
|
|
list($site_id, $type, $ag_site_id) = explode('|', $state);
|
|
} else {
|
|
$userInfo = Session::get("shop_user_info");
|
|
if ($userInfo) {
|
|
$type = 'minapp';
|
|
$site_id = $userInfo['site_id'];
|
|
$ag_site_id = Db::name('site')->where('site_id', '=', $site_id)->value('agent_id');
|
|
} else {
|
|
$this->error('会员信息无效', url("shop/login/login"));
|
|
}
|
|
}
|
|
$authinfo = $openPlatform->handleAuthorize($authCode);
|
|
if (isset($authinfo['code']) && $authinfo['code'] == 10000) {
|
|
$token = current($authinfo['tokens']);
|
|
switch ($type) {
|
|
case 'minapp':
|
|
$paydata = [
|
|
'line_type' => 'auth',
|
|
'app_type' => 'aliapp',
|
|
'site_id' => $site_id ?? 0,
|
|
'ag_site_id' => $ag_site_id ?? 0,
|
|
'appid' => $token['auth_app_id'],
|
|
'appsecret' => '',
|
|
'token' => '',
|
|
'app_name' => '',
|
|
'head_img' => '',
|
|
'qrcode' => '',
|
|
'account' => $token['user_id'],
|
|
'alipay_public' => '',
|
|
'private_key' => '',
|
|
'app_auth_token' => $token['app_auth_token'],
|
|
'app_refresh_token' => $token['app_refresh_token'],
|
|
'app_original' => $token['user_id'],
|
|
'original_values' => $token,
|
|
];
|
|
cache($state_base64, 'yes');
|
|
$paydata['state'] = $state;
|
|
event('MiniappAuthInfo', $paydata);
|
|
if ($site_id) {
|
|
$minapp = new Config();
|
|
$minapp->setAlipayConfig($token['auth_app_id'], $paydata, $site_id, $paydata['app_original']);
|
|
}
|
|
$this->assign('desc', '授权成功');
|
|
$this->assign('img', 'success');
|
|
return $this->fetch('aliapp/success');
|
|
case 'all':
|
|
break;
|
|
default;
|
|
$paydata = [
|
|
'appid' => $authinfo['auth_app_id'],
|
|
'appsecret' => '',
|
|
'user_id' => $token['user_id'],
|
|
'app_auth_token' => $authinfo['app_auth_token'],
|
|
'app_refresh_token' => $authinfo['app_refresh_token'],
|
|
'public_key' => '',
|
|
'private_key' => '',
|
|
'alipay_public_key' => '',
|
|
'is_isp' => 1,
|
|
'transfer_status' => 1,
|
|
'refund_status' => 1,
|
|
'pay_status' => 1,
|
|
];
|
|
$config = new Config();
|
|
$config->setAlipayConfig($authinfo['auth_app_id'], $paydata, $site_id);
|
|
return $this->success('授权成功', addon_url('aliapp/shop/aliapp/setting'));
|
|
}
|
|
} else {
|
|
return $this->error('授权失败', addon_url('aliapp/shop/aliapp/setting'));
|
|
}
|
|
} else {
|
|
return $this->error('授权失败', addon_url('aliapp/shop/aliapp/setting'));
|
|
}
|
|
}
|
|
} |