206 lines
6.4 KiB
C#
206 lines
6.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using Games.Events;
|
|
using Module.Log;
|
|
using UnityEngine;
|
|
|
|
public class SdkAndroidYuCheng : SdkAndroidBase
|
|
{
|
|
private const string _serverListUri = "http://rk.jjbb.yoseleather.com/YcApi/server/cid/2-10003";
|
|
private const string _loginUri = "http://rk.jjbb.yoseleather.com/YcApi/login/cid/2-10003";
|
|
|
|
private const string _paymentUri = "http://rk.jjbb.yoseleather.com/YcApi/createOrder/cid/2-10003";
|
|
|
|
// 兑换码超链接
|
|
private const string _redemptionUri = "http://rk.jjbb.yoseleather.com/Gift/receiveGiftPackage";
|
|
private const string _noticeUri = "http://rk.jjbb.yoseleather.com/YcApi/notice/cid/2-10003";
|
|
|
|
private SdkUser _user;
|
|
|
|
public override string sdkAccount
|
|
{
|
|
get { return _user == null ? string.Empty : _user.id; }
|
|
}
|
|
|
|
public override string platformId
|
|
{
|
|
get { return "2-10003"; }
|
|
}
|
|
|
|
protected override string redemptionUri
|
|
{
|
|
get { return _redemptionUri; }
|
|
}
|
|
|
|
protected override string noticeUri
|
|
{
|
|
get { return _noticeUri; }
|
|
}
|
|
|
|
public override bool IsLogin()
|
|
{
|
|
return _user != null;
|
|
}
|
|
|
|
public override void GetServerList()
|
|
{
|
|
var data = new Dictionary<string, string>();
|
|
data["mem_id"] = _user.id;
|
|
data["user_token"] = _user.userToken;
|
|
Debug.Log(string.Format("MemId = {0}, Token = {1}", _user.id, _user.userToken));
|
|
var jsonDownloader = new DownloadJsonFile(_serverListUri, 10f, data)
|
|
{
|
|
onDownloadComplete = OnGetServerListComplete
|
|
};
|
|
jsonDownloader.Start();
|
|
}
|
|
|
|
private void OnGetServerListComplete(DownloadJsonFile action)
|
|
{
|
|
var result = ParseServerList(action);
|
|
EventDispatcher.GetInstance().Dispatch(EventId.ServerListCallback, result);
|
|
}
|
|
|
|
public override void LoginPhp(int serverId)
|
|
{
|
|
var data = new Dictionary<string, string>();
|
|
data["mem_id"] = _user.id;
|
|
data["user_token"] = _user.userToken;
|
|
data["server_id"] = serverId.ToString();
|
|
data["recom_server_id"] = defaultServer.ToString();
|
|
Debug.Log(string.Format("Login Php: mem_id = {0}, user_token = {1}, serverId = {2}, reconmServer = {3}",
|
|
_user.id, _user.userToken, serverId, defaultServer));
|
|
var jsonDownloader = new DownloadJsonFile(_loginUri, 10f, data)
|
|
{
|
|
onDownloadComplete = OnPhpLoginComplete
|
|
};
|
|
jsonDownloader.Start();
|
|
}
|
|
|
|
private void OnPhpLoginComplete(DownloadJsonFile action)
|
|
{
|
|
LoginPhpWithToken(action, _user.userToken);
|
|
}
|
|
|
|
public override void Payment(int goodsId)
|
|
{
|
|
var playerData = GameManager.gameManager.PlayerDataPool;
|
|
var data = new Dictionary<string, string>();
|
|
data["serverId"] = LoginData.accountData.serverId.ToString();
|
|
data["userRoleId"] = playerData.MainPlayerBaseAttr.Guid.ToString();
|
|
data["goodsId"] = goodsId.ToString();
|
|
data["mServerId"] = SdkControl.instance.currentServerData.m_id.ToString();
|
|
data["level"] = playerData.MainPlayerBaseAttr.Level.ToString();
|
|
var jsonDownloader = new DownloadJsonFile(_paymentUri, 10f, data)
|
|
{
|
|
onDownloadComplete = OnPaymentPhpComplete
|
|
};
|
|
jsonDownloader.Start();
|
|
}
|
|
|
|
private void OnPaymentPhpComplete(DownloadJsonFile action)
|
|
{
|
|
Dictionary<string, string> payData = null;
|
|
if (!string.IsNullOrEmpty(action.error))
|
|
Debug.LogError(action.error);
|
|
else
|
|
try
|
|
{
|
|
var json = action.jsonData;
|
|
var msg = json["msg"].ToString();
|
|
if (msg != "success")
|
|
{
|
|
Debug.LogError(string.Format("OnPaymentPhpComplete Error: " + msg));
|
|
}
|
|
else
|
|
{
|
|
payData = new Dictionary<string, string>();
|
|
var data = json["data"];
|
|
payData["OrderId"] = data["cp_order_id"].ToString();
|
|
payData["Price"] = data["product_price"].ToString();
|
|
payData["Count"] = data["product_count"].ToString();
|
|
payData["Id"] = data["product_id"].ToString();
|
|
payData["Name"] = data["product_name"].ToString();
|
|
payData["Desc"] = data["product_desc"].ToString();
|
|
payData["Ext"] = data["ext"].ToString();
|
|
}
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Debug.LogError(e);
|
|
payData = null;
|
|
}
|
|
|
|
if (payData != null)
|
|
{
|
|
var roleInfo = GetRoleInfoMap(RoleDataSubmit.Other);
|
|
var payInfo = ConvertToJavaMap(payData);
|
|
javaObject.Call("Payment", payInfo, roleInfo);
|
|
}
|
|
}
|
|
|
|
public override bool LoginComplete(string args)
|
|
{
|
|
var result = IsSuccess(args);
|
|
if (result)
|
|
{
|
|
var argList = args.Split(',');
|
|
bool isAuthentication;
|
|
if (argList.Length > 4 &&
|
|
bool.TryParse(argList[4], out isAuthentication))
|
|
{
|
|
_user = new SdkUser(argList[1].Trim(), argList[3].Trim(), isAuthentication);
|
|
}
|
|
else
|
|
{
|
|
result = false;
|
|
LogModule.ErrorLog("Login success but with no enough args: " + args);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
LogModule.ErrorLog("Login failed: " + args);
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
public override bool LogOutComplete(string args)
|
|
{
|
|
Debug.Log("Logout Complete: " + args);
|
|
bool result;
|
|
if (_user == null)
|
|
{
|
|
LogModule.ErrorLog("Logout before login!");
|
|
result = false;
|
|
}
|
|
else
|
|
{
|
|
result = IsSuccess(args);
|
|
}
|
|
|
|
if (result)
|
|
_user = null;
|
|
return result;
|
|
}
|
|
|
|
public override bool PaymentComplete(string data)
|
|
{
|
|
var result = IsSuccess(data);
|
|
return result;
|
|
}
|
|
|
|
public class SdkUser
|
|
{
|
|
public readonly bool isAuthentication;
|
|
public readonly string id;
|
|
public readonly string userToken;
|
|
|
|
public SdkUser(string id, string userToken, bool isAuthentication)
|
|
{
|
|
this.id = id;
|
|
this.userToken = userToken;
|
|
this.isAuthentication = isAuthentication;
|
|
}
|
|
}
|
|
} |