public function actionToken()
 {
     $request = Yii::$app->getRequest();
     $params = $request->get();
     $params = array_map('htmlEntityString', $params);
     $appid = isset($params['app_id']) ? $params['app_id'] : '';
     $appkey = isset($params['app_key']) ? $params['app_key'] : '';
     if (!$appid) {
         return responseArray(1101, 'appid_params_missing', '缺失应用ID参数');
     }
     if (!$appkey) {
         return responseArray(1102, 'appkey_params_missing', '缺失应用KEY参数');
     }
     try {
         // 验证app_id app_key有效性
         $application = new ApplicationBase();
         $ret = $application->validateApp($appid, $appkey);
         if (!$ret) {
             return responseArray(2101, 'appid_appkey_invalid', '应用ID或者应用KEY无效');
         }
         $accessToken = new AccessToken();
         $tokenEntity = $accessToken->getAccessToken($appid, $appkey);
         $result = null;
         if ($tokenEntity == null || strtotime($tokenEntity->expires_in) < time()) {
             $token = generateRandString();
             // 有效期默认两小时
             $expires_in = date('Y-m-d H:i:s', time() + 7200);
             if ($tokenEntity == null) {
                 $result = $accessToken->setAccessToken($token, $appid, $appkey, $expires_in);
             } else {
                 $tokenEntity->access_token = $token;
                 $tokenEntity->expires_in = $expires_in;
                 $result = $tokenEntity->save();
             }
             //TODO:: 保存access_token失败的处理
             if (!$result) {
                 return responseArray(1, 'network_anomaly', '网络异常请稍后重试');
             }
         } else {
             $token = $tokenEntity->access_token;
             // 有效期默认两小时
             $expires_in = $tokenEntity->expires_in;
         }
         $ret = ['access_token' => $token, 'expires' => $expires_in];
         return responseArray(1, 'success', '授权成功', $ret);
     } catch (Exception $ex) {
         return responseArray(1, 'network_anomaly', '网络异常,请稍后重试');
     }
 }
 /**
  * weixin/qq/weibo第三方登录绑定判断
  */
 public function actionThirdParty()
 {
     $params = Yii::$app->getRequest()->post();
     $params = array_map('htmlEntityString', $params);
     $openid = isset($params['open_id']) ? $params['open_id'] : '';
     $type = isset($params['type']) ? $params['type'] : '';
     if (!$openid) {
         return responseArray(1101, 'openid_params_missing', '缺失用户身份唯一标识openid参数');
     }
     if (!$type) {
         return responseArray(1102, 'type_params_missing', '缺失第三方登录类型参数');
     }
     try {
         $user = UserBaseInfo::find()->select(['id'])->where(['open_id' => $openid, 'status' => UserBaseInfo::USER_NORMAL_STATUS])->one();
         if (!$user) {
             return responseArray(2101, 'user_not_exists', '用户不存在或被禁用');
         }
         $thridParty = new UserThirdPartyLogin();
         $thridParty = $thridParty->getByUserId($user->id, UserThirdPartyLogin::BIND_API_CHANNEL, $type);
         if ($thridParty && $thridParty['status'] == UserThirdPartyLogin::STATUS_LOGIN_BIND) {
             return responseArray(0, 'user_bind_thirdparty', '用户已绑定该类型第三方登录', ['open_id' => $thridParty->open_id, 'type' => $thridParty->type, 'profile_info' => $thridParty->profile_info]);
         } else {
             return responseArray(1103, 'user_notbind_thirdparty', '用户未绑定该类型第三方登录');
         }
     } catch (Exception $ex) {
         return responseArray(1, 'network_anomaly', '网络异常,请稍后重试');
     }
 }
 public function getUserBindInfo($username, $type, $openId)
 {
     $third = new UserThirdPartyLogin();
     $channel = UserThirdPartyLogin::BIND_API_CHANNEL;
     if (!$username) {
         return responseArray(1101, 'username_pwd_params_missing', '用户标识丢失');
     }
     if (!$type) {
         return responseArray(1201, 'third_type_not_found', '第三方类型不能为空');
     }
     if (!$openId) {
         return responseArray(1202, 'third_openId_not_found', '第三方账号关联open_id丢失');
     }
     $user = UserBaseInfo::find()->where(['mobile' => $username])->orWhere(['email' => $username])->one();
     $userOpenId['open_id'] = $user['open_id'];
     if ($user == null) {
         return responseArray(1102, 'user_not_exists', '用户不存在');
     }
     $info = $third->checkBindByUAT($user['id'], $channel, $type, true);
     $beenBind = $third->checkBeenBindUAT($user['id'], $channel, $type, true);
     if ($info && is_array($info) || $beenBind) {
         if ($beenBind['open_id'] == $openId) {
             return responseArray(0, 'success', '用户已绑定并与现操作绑定号一致', $beenBind['open_id']);
         }
         $beenBind['profile_info'] = json_decode($beenBind['profile_info']);
         $oldBind = [];
         if (isset($beenBind['profile_info'])) {
             foreach ($beenBind['profile_info'] as $key => $value) {
                 $oldBind[$key] = $value;
             }
         }
         $oldBind['open_id'] = $beenBind['open_id'];
         return responseArray(1401, 'has_been_bind', '用户已绑定但与现操作绑定号不一致', $oldBind);
     }
     if (!is_array($info)) {
         return responseArray(1301, 'user_not_bind', '用户未绑定', $user->attributes);
     }
 }
Exemple #4
0
function testArrayData()
{
    $aData = '';
    $aData = array(3, 2, 4, 1, 6, 0);
    responseArray($aData, '原来顺序');
    responseArray(selectSort($aData), '选择排序');
    responseArray(quickSort($aData), '快速排序');
    responseArray(insertSort($aData), '插入排序');
    responseArray(bubbleSort($aData), '冒泡排序');
    responseArray(reQuickSort($aData), '反序排序');
    echo '<b>最 大 值:</b>' . $GLOBALS['PHPMax']($aData) . '<hr>';
    echo '<b>最 小 值:</b>' . $GLOBALS['PHPMin']($aData) . '<hr>';
}
 /**
  * 用户修改信息
  */
 public function actionModify()
 {
     $params = Yii::$app->getRequest()->post();
     $params = array_map('htmlEntityString', $params);
     $params['open_id'] = isset($params['open_id']) ? $params['open_id'] : '';
     try {
         $userService = new UserService();
         $ret = $userService->modify($params);
         return $ret;
     } catch (Exception $ex) {
         return responseArray(1, 'network_anomaly', '网络异常,请稍后重试');
     }
 }