2025-11-21 14:49:09 +08:00

74 lines
2.3 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
// +----------------------------------------------------------------------
// | Niucloud-admin 企业快速开发的多应用管理平台
// +----------------------------------------------------------------------
// | 官方网址https://www.niucloud.com
// +----------------------------------------------------------------------
// | niucloud团队 版权所有 开源版本可自由商用
// +----------------------------------------------------------------------
// | Author: Niucloud Team
// +----------------------------------------------------------------------
namespace app\api\controller\channel;
use app\service\api\channel\AppService;
use app\service\api\login\LoginService;
use app\service\api\wechat\WechatAppService;
use core\base\BaseController;
class App extends BaseController
{
public function wechatLogin()
{
$data = $this->request->params([
[ 'code', '' ],
]);
$wechat_app_service = new WechatAppService();
return success($wechat_app_service->loginByCode($data[ 'code' ]));
}
public function register()
{
$data = $this->request->params([
[ 'register_type', '' ],
]);
switch ($data['register_type']) {
case 'wechat':
return $this->wechatRegister();
}
return fail("不支持的注册方式");
}
public function wechatRegister() {
$data = $this->request->params([
[ 'openid', '' ],
[ 'unionid', '' ],
[ 'nickname', '' ],
[ 'avatar', '' ],
[ 'mobile_code', '' ],
[ 'mobile', '' ],
]);
//参数验证
$this->validate($data, [
'mobile' => 'mobile'
]);
// 校验手机验证码
( new LoginService() )->checkMobileCode($data[ 'mobile' ]);
$wechat_app_service = new WechatAppService();
return success($wechat_app_service->register($data[ 'openid' ], $data[ 'mobile' ], $data[ 'nickname' ], $data[ 'avatar' ], $data[ 'avatar' ]));
}
public function getNewVersion()
{
$data = $this->request->params([
[ 'version_code', '' ], // 当前版本
[ 'platform', '' ], // 请求平台
]);
$app_service = new AppService();
return success(data:$app_service->getNewVersion($data));
}
}