<?php
/*
 * description：
 * author：wh
 * email：
 * createTime：{2023/11/19} {22:32} 
 */

namespace app\index\controller;


use think\Controller;
use wanghua\general_utility_tools_php\tool\Tools;
use wanghua\general_utility_tools_php\wechat\TmpWexinauth;
use wanghua\general_utility_tools_php\wechat\UserAuth;
use wanghua\general_utility_tools_php\wechat\WechatLogic;

/**
 *
 */
class Login extends Controller
{

    function login()
    {
        $username = input('username');
        $password = input('password');


        return json(Tools::set_res(200,'ok',['username'=>$username]));
    }

    /**
     * desc：微信授权
     * author：wh
     */
    function wxauth()
    {
        try {
            $code = input('code');
            if(empty($code)){
                return Tools::set_fail('CODE参数错误');
            }
            $wxconfig = get_boom_union_wechat_config();

            $res = (new UserAuth($wxconfig,$wxconfig['access_token_path']))->usrAccessTokenApplet($code);

            //绑定客户端ID和用户openid


            return json(Tools::set_ok('ok',$res));
        }catch (\Exception $e){
            Tools::log_to_write_text([
                'error'=>'微信授权异常。'.$e->getMessage(),
                'input'=>input(),
                'error_info'=>$e->getTraceAsString()
            ]);

            return json(Tools::set_fail('请求异常'));
        }

    }
}