Ejemplo n.º 1
0
 public function beforeAction($action)
 {
     if ($action->actionMethod == 'actionWxNotify') {
         $action->controller->enableCsrfValidation = false;
     }
     $alipay = Yii::$app->alipay;
     $wxpay = Yii::$app->wxpay;
     $request = Yii::$app->getRequest();
     $get = $request->get();
     $appId = isset($get['app_id']) && $get['app_id'] ? $get['app_id'] : '100002';
     if (!$appId) {
         // app_id 为必须参数
         die('app_id required');
     }
     $sso = new SsoSettingInfo();
     $mch = $sso->getMchByAppid($appId);
     $mch = json_decode($mch['mch_info'], true);
     if (arr_null($mch)) {
         // TODO:: 应用sso配置中没有设置商户信息
         die('mch information required');
     }
     $wxpayi = $mch['wxpay'];
     $alipayi = $mch['alipay'];
     WxPayConfig::$appId = $wxpayi['app_id'];
     WxPayConfig::$appSecret = $wxpayi['app_secret'];
     WxPayConfig::$mchId = $wxpayi['mch_id'];
     WxPayConfig::$key = $wxpayi['key'];
     WxPayConfig::$sslcert_path = $wxpayi['sslcert_path'];
     WxPayConfig::$sslkey_path = $wxpayi['sslkey_path'];
     $alipay->sellerEmail = $alipayi['seller_email'];
     $alipay->partner = $alipayi['partner'];
     $alipay->key = $alipayi['key'];
     $login = UserBaseInfo::isLogin();
     if ($login) {
         return parent::beforeAction($action);
     }
     return $this->redirect(['user/login']);
 }
Ejemplo n.º 2
0
 /**
  * 通过app_url获取一条应用信息
  */
 public static function getByAppUrl($appUrl)
 {
     if (!Yii::$app->util->regularUrl($appUrl)) {
         return false;
     }
     $domainWhites = SsoSettingInfo::getDomainWhites();
     foreach ($domainWhites as $key => $value) {
         if (in_array($appUrl, $value)) {
             $appId = $key;
         }
     }
     if (empty($appId)) {
         $appId = 100000;
     }
     return self::find()->Where(['app_id' => $appId])->asArray()->one();
 }
Ejemplo n.º 3
0
 /**
  * 获取绑定SSO服务应用对应的配置
  */
 public function configs()
 {
     $result = false;
     $mServiceBind = new ServiceBinding();
     $appids = $mServiceBind->getAllAppID($this->serviceID);
     if ($appids) {
         // TODO: 获取指定个应用的配置数据
         $result = SsoSettingInfo::findByAppIds($appids);
         /*
                     $result = [
            [
                'id' => 1,
                'app_id' => '10001',
                'domain_white_list' => [
                    'www.iheima.com',
                    'app.iheima.net',
                    'www.iheima.net',
                ],
                'ip_white_list' => [
                    '182.92.76.1',
                ],
                'profile_api' => [
                    'auth' => [
                        'app_id' => 'ihm2c677f02a36095e6a2c94495d0597',
                        'app_secret' => 'ihm10001',
                    ],
                    'api' => [
                        'domain' => 'app.iheima.net',
                        'mobile' => 'app=member&controller=userdatacenter&action=mobile_datacenter',
                        'email' => 'app=member&controller=userdatacenter&action=email',
                        'password' => 'app=member&controller=userdatacenter&action=password',
                        'profile' => 'app=member&controller=userdatacenter&action=profile',
                        'access_token' => 'app=ihminterface&controller=igrant&action=getAccessToken',
                    ]
                ]
            ],
                     ];
         */
     }
     return $result;
 }
 /**
  * sso绑定服务 配置方法
  */
 public function actionSsoServiceSettingSubmit()
 {
     $post = Yii::$app->request->post();
     $sso = new SsoSettingInfo();
     $id = $post['id'];
     if (!Yii::$app->util->regularUrl($post['sign_in'])) {
         return $this->redirect(['service-setting', 'id' => $id, 'serviceId' => $post['serviceId'], 'error' => '登录url错误']);
     }
     if (!Yii::$app->util->regularUrl($post['sign_out'])) {
         return $this->redirect(['service-setting', 'id' => $id, 'serviceId' => $post['serviceId'], 'error' => '退出url错误']);
     }
     if (!Yii::$app->util->regularUrl($post['domain'])) {
         return $this->redirect(['service-setting', 'id' => $id, 'serviceId' => $post['serviceId'], 'error' => '域名格式错误']);
     }
     $domainWhites = explode(',', $post['domain_white_list']);
     foreach ($domainWhites as $value) {
         if (!Yii::$app->util->regularUrl($value)) {
             return $this->redirect(['service-setting', 'id' => $id, 'serviceId' => $post['serviceId'], 'error' => '白域名格式错误']);
         }
     }
     $ipWhites = explode(',', $post['ip_white_list']);
     foreach ($ipWhites as $value) {
         if (!Yii::$app->util->regularIp($value)) {
             return $this->redirect(['service-setting', 'id' => $id, 'serviceId' => $post['serviceId'], 'error' => 'Ip白名单格式错误']);
         }
     }
     if (SsoSettingInfo::findByAppId($post['app_id'])) {
         $res = $sso->updateSsoSetting($post);
         if (!$res) {
             return $this->redirect(['service-setting', 'id' => $id, 'serviceId' => $post['serviceId'], 'error' => '更改失败']);
         }
         return $this->redirect(['binding-service-view', 'id' => $id]);
     } else {
         $res = $sso->addSsoSetting($post);
         if (!$res) {
             return $this->redirect(['sso-service-setting', 'id' => $id, 'serviceId' => $post['serviceId'], 'error' => '添加失败']);
         }
         return $this->redirect(['binding-service-view', 'id' => $id]);
     }
 }
Ejemplo n.º 5
0
 /**
  * 获取个应用系统清除登录信息接口地址
  *
  * @return array|null
  */
 public function getUncookieUrl()
 {
     $cookieUrl = null;
     $sso = SsoSettingInfo::findAll();
     if ($sso) {
         foreach ($sso as $k => $val) {
             if (isset($val['log_out']['sign_out']) && $val['log_out']['sign_out']) {
                 $cookieUrl[] = $val['log_out']['sign_out'];
             }
         }
     }
     return $cookieUrl;
 }