| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- <?php
- /**
- * 重庆赤晓店信息科技有限公司
- * https://www.chixiaodian.com
- * Copyright (c) 2023 赤店商城 All rights reserved.
- */
- namespace app\modules\alliance\controllers\alipay;
- use app\models\Option;
- use app\modules\alliance\behaviors\Auth;
- use app\modules\alliance\behaviors\UserLogin;
- use Overtrue\Socialite\SocialiteManager;
- use yii\helpers\ArrayHelper;
- use yii\helpers\Json;
- use yii\web\Controller;
- class BaseController extends Controller
- {
- // 登录白名单
- const ALLOW_LIST = [
- 'alliance/alipay/passport/auth',
- 'alliance/alipay/passport/phone'
- ];
- public $socialite;
- public $alipayConfig;
- /**
- * @return array
- */
- public function behaviors()
- {
- // $merge = [
- // [
- // 'class' => Auth::class,
- // ]
- // ];
- $merge = [];
- if ($this->isRoute()) {
- $merge[] = [
- 'class' => UserLogin::class,
- ];
- }
- return ArrayHelper::merge($merge, parent::behaviors());
- }
- public function isRoute()
- {
- $route = \Yii::$app->controller->getRoute();
- if (in_array($route, self::ALLOW_LIST)) {
- return false;
- } else {
- return true;
- }
- }
- public function init() {
- parent::init();
- $config_cache = \Yii::$app->cache->get('alipay_config_cache_' . get_store_id());
- if ($config_cache) {
- $alipay_config = Json::decode($config_cache);
- } else {
- $keys = [
- 'alipay_platform'
- ];
- $data = Option::get($keys, 0, 'saas');
- if(isset($data[0]['value'])) {
- $alipay_config = json_decode($data[0]['value'],true);
- }else{
- return false;
- }
- }
- $this->alipayConfig = $alipay_config;
- $config = [
- 'alipay' => [
- // This can also be named as 'app_id' like the official documentation.
- 'client_id' => $alipay_config['app_id'],
- // Please refer to the official documentation, in the official management background configuration RSA2.
- // Note: This is your own private key.
- // Note: Do not allow the private key content to have extra characters.
- // Recommendation: For security, you can read directly from the file. But here as long as the value, please remember to remove the head and tail of the decoration.
- 'rsa_private_key' => $alipay_config['app_private_key'],
- // Be sure to set this value and make sure that it is the same address value as set in the official admin system.
- // This can also be named as 'redirect_url' like the official documentation.
- // 'redirect' => 'http://localhost/socialite/callback.php',
- ]
- ];
- \Yii::warning($config);
- $this->socialite = new SocialiteManager($config);
- }
- }
|