<?php
// +----------------------------------------------------------------------
// | onezan-admin 快速开发的管理平台
// +----------------------------------------------------------------------
// | 官方网址：https://www.onezan.cn
// +----------------------------------------------------------------------
// | onezan团队 版权所有 开源版本可自由商用
// +----------------------------------------------------------------------
// | Author: 543885307@qq.com
// +----------------------------------------------------------------------
namespace app\api\controller\channel;

use app\api\controller\BaseApiController;
use app\service\api\channel\AuthService;
use think\Request;


/**
 * C端渠道认证控制器
 * 微信/支付宝小程序登录、微信授权与回调
 * @package app\api\controller\channel
 */
class Auth extends BaseApiController
{
    /**
     * 微信小程序登录
     * @param Request $request
     * @return \think\response\Json
     */
    public function weappLogin(Request $request)
    {
        $result = $this->app->make(AuthService::class)->weappLogin($request);
        $httpStatus = (int)($result['_http_status'] ?? 200);
        unset($result['_http_status']);
        return json($result, $httpStatus);
    }


    /**
     * 微信授权
     * @param Request $request
     * @return \think\response\Json
     */
    public function wechatAuthorize(Request $request)
    {
        $result = $this->app->make(AuthService::class)->wechatAuthorize($request);
        $httpStatus = (int)($result['_http_status'] ?? 200);
        unset($result['_http_status']);
        return json($result, $httpStatus);
    }

    /**
     * 微信回调
     * @param Request $request
     * @return \think\response\Json
     */
    public function wechatCallback(Request $request)
    {
        $result = $this->app->make(AuthService::class)->wechatCallback($request);
        $httpStatus = (int)($result['_http_status'] ?? 200);
        unset($result['_http_status']);
        return json($result, $httpStatus);
    }

    /**
     * 支付宝小程序登录
     * @param Request $request
     * @return \think\response\Json
     */
    public function aliappLogin(Request $request)
    {
        $result = $this->app->make(AuthService::class)->aliappLogin($request);
        $httpStatus = (int)($result['_http_status'] ?? 200);
        unset($result['_http_status']);
        return json($result, $httpStatus);
    }


    /**
     * 微信小程序手机号登录
     * @param Request $request
     * @return \think\response\Json
     */
    public function weappPhoneLogin(Request $request)
    {
        $result = $this->app->make(AuthService::class)->weappPhoneLogin($request);
        $httpStatus = (int)($result['_http_status'] ?? 200);
        unset($result['_http_status']);
        return json($result, $httpStatus);
    }
}