<?php

namespace App\Http\Appadapter;

/**
* 适配器（基类）
*/
class Adapter
{

    /**
     * 检测内容方是否存在该用户，不存在则创建
     * @param $appid
     * @param $appUsername
     * @param $password
     * @return array
     */
    public function syncUser($appid, $appUsername , $password){
        return array('code' => 1, 'msg'=>'');

        $result = array('code'=>-1, 'msg'=>'');
        if($appid == 1){//体育
            $config = ['name' => 'agentname', 'key' => 'agentkey', 'secret' => 'agentsecret'];
            $proxy = new Sport();
            $proxy->Init($config);
            $ret = $proxy->caca($appUsername, $password);
            if($ret['key_error'] == 1){
                $result = array('code'=>1, 'msg'=>'成功');
            }elseif ($ret['key_error'] == 3){
                $result = array('code'=>-3, 'msg'=>'用户名太长');
            }else{
                $result = array('code'=>-1, 'msg'=>'服务器繁忙');
            }
        }else{
            $result = array('code'=>-100, 'msg'=>'应用不存在');
        }

        return $result;
    }

    /**
     * 登陆游戏
     * @param $appid
     * @param $appUsername
     * @param $password
     * @param $money
     * @return array
     */
    public function login($appid, $appUsername , $password, $money){
        return array('code' => 1, 'msg'=>'成功');

        $result = array('code'=>-2, 'msg'=>'');
        if($appid == 1){//体育
            $config = ['name' => 'agentname', 'key' => 'agentkey', 'secret' => 'agentsecret'];
            $proxy = new Sport();
            $proxy->Init($config);
            $ret = $proxy->tg($appUsername, $password);
            if($ret['key_error'] == 1){
                //转账
                $ret2 = $proxy->ptc($appUsername, $password, '', $money, 'IN');
                if($ret2['key_error'] != 1){
                    $result = array('code'=>1, 'msg'=>'成功');
                }else{
                    $result = array('code'=>-1, 'msg'=>'服务器繁忙');
                }
            }else{
                $result = array('code'=>-1, 'msg'=>'服务器繁忙');
            }
        }else{
            $result = array('code'=>-100, 'msg'=>'应用不存在');
        }

        return $result;
    }
}
