blizzard api fix

This commit is contained in:
mikx 2019-06-13 20:09:32 -04:00
parent 3f10507909
commit 01f733823b
9 changed files with 59 additions and 15 deletions

View File

@ -8,4 +8,13 @@
<remove invariant="MySql.Data.MySqlClient" />
<add description=".Net Framework Data Provider for MySQL" invariant="MySql.Data.MySqlClient" name="MySQL Data Provider" type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Version=6.10.6.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
</DbProviderFactories>
</system.data></configuration>
</system.data>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-10.0.0.0" newVersion="10.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>

View File

@ -32,10 +32,12 @@ namespace MxWs.JSON
public static string GetURL(string region, string realm, string api)
{
string token = Utilities.OAuth.GetOAuth(Server.settings_apiKey, Server.settings_apiSecret);
using (WebClient wc = new WebClient())
{
ServicePointManager.ServerCertificateValidationCallback += (p1, p2, p3, p4) => true;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
var json = wc.DownloadString(@"https://" + Server.region + ".api.battle.net/wow/auction/data/" + Server.realm + "?locale=en_US&apikey=" + Server.settings_apiKey);
var json = wc.DownloadString($@"https://{Server.region}.api.blizzard.com/wow/auction/data/{Server.realm}?locale=en_US&access_token={token}");
RootObject j = JsonConvert.DeserializeObject<RootObject>(json);
return j.files[0].url;
}

View File

@ -112,7 +112,6 @@ namespace MxWs.JSON
}
sb.Append(string.Join(",", Rows));
sb.Append(";");
Utilities.MSG.CMW(sb.ToString(), true, 1);
InsertIndex(sb.ToString());
}

View File

@ -18,6 +18,7 @@ namespace MxWs.JSON
public class SETTINGS
{
public string apikey { get; set; }
public string apisecret { get; set; }
public string dbname { get; set; }
public string dbhost { get; set; }
public string dbuser { get; set; }
@ -33,6 +34,8 @@ namespace MxWs.JSON
SETTINGS j = JsonConvert.DeserializeObject<SETTINGS>(File.ReadAllText("settings.json"));
Server.settings_apiKey = j.apikey;
Utilities.MSG.CMW(string.Format("APIKey: {0}", j.apikey), true, 1);
Server.settings_apiSecret = j.apisecret;
Utilities.MSG.CMW(string.Format("APISecret: {0}", j.apisecret), true, 1);
Server.settings_dbname = j.dbname;
Utilities.MSG.CMW(string.Format("DB Name: {0}", j.dbname), true, 1);
Server.settings_dbhost = j.dbhost;

View File

@ -34,11 +34,12 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Accessibility" />
<Reference Include="MySql.Data, Version=6.10.6.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d, processorArchitecture=MSIL">
<HintPath>..\packages\MySql.Data.6.10.6\lib\net452\MySql.Data.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.10.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
<Reference Include="Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.12.0.2\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.ComponentModel" />
@ -68,6 +69,7 @@
<Compile Include="Utilities\MSG.cs" />
<Compile Include="Server.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Utilities\OAuth.cs" />
<Compile Include="Utilities\Random.cs" />
<Compile Include="Utilities\Web.cs" />
</ItemGroup>
@ -77,11 +79,4 @@
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="..\packages\GitInfo.2.0.9\build\GitInfo.targets" Condition="Exists('..\packages\GitInfo.2.0.9\build\GitInfo.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\GitInfo.2.0.9\build\GitInfo.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\GitInfo.2.0.9\build\GitInfo.targets'))" />
</Target>
</Project>

View File

@ -15,7 +15,7 @@ namespace MxWs
{
class Server
{
public static string version = ThisAssembly.Git.Commit;
public static string version = "3.1.1";
public static bool debug = false;
public static bool serverLoop = true;
public static bool indexBool = false;
@ -27,6 +27,7 @@ namespace MxWs
// Settings Variables
// Values are set by ReadSettings() during "init" state.
public static string settings_apiKey = ""; // Store the Blizzard Dev API Key
public static string settings_apiSecret = ""; // Store the Blizzard Dev API Secret
public static string settings_dbname = ""; // Store the MySQL Database Name
public static string settings_dbhost = ""; // Store the MySQL Database Host
public static string settings_dbuser = ""; // Store the MySQL Database User

33
MxWs/Utilities/OAuth.cs Normal file
View File

@ -0,0 +1,33 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
namespace MxWs.Utilities
{
class OAuth
{
public class OAuthObjects
{
public string access_token { get; set; }
public string token_type { get; set; }
public int expires_in { get; set; }
}
public static string GetOAuth(string key, string secret)
{
using (WebClient wc = new WebClient())
{
ServicePointManager.ServerCertificateValidationCallback += (p1, p2, p3, p4) => true;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
var json = wc.DownloadString($@"https://us.battle.net/oauth/token?client_id={key}&client_secret={secret}&grant_type=client_credentials");
OAuthObjects j = JsonConvert.DeserializeObject<OAuthObjects>(json);
return j.access_token;
}
}
}
}

View File

@ -20,6 +20,9 @@ namespace MxWs.Utilities
{
using (WebClient wc = new WebClient())
{
ServicePointManager
.ServerCertificateValidationCallback +=
(sender, cert, chain, sslPolicyErrors) => true;
wc.DownloadFile(url, file);
}
}

View File

@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="GitInfo" version="2.0.9" targetFramework="net452" developmentDependency="true" />
<package id="MySql.Data" version="6.10.6" targetFramework="net452" />
<package id="Newtonsoft.Json" version="10.0.3" targetFramework="net452" />
<package id="Newtonsoft.Json" version="12.0.2" targetFramework="net452" />
</packages>