|
@@ -61,7 +61,7 @@ namespace TEAMModelBI.Controllers.BICommon
|
|
|
string url = "https://api2.teammodel.net";
|
|
|
if (request.srvAdr == "China") url = "https://api2.teammodel.cn";
|
|
|
|
|
|
- string AccessToken = await getCoreAccessToken();
|
|
|
+ string AccessToken = await getCoreAccessToken(request.srvAdr);
|
|
|
var client = _http.CreateClient();
|
|
|
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", AccessToken);
|
|
|
HttpResponseMessage response = await client.PostAsJsonAsync($"{url}/Service/GenerateCoupon", request);
|
|
@@ -96,10 +96,11 @@ namespace TEAMModelBI.Controllers.BICommon
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
- //string url = _configuration.GetValue<string>("HaBookAuth:CoreAPI");
|
|
|
- string url = "https://api2.teammodel.net";
|
|
|
- if (request.srvAdr == "China") url = "https://api2.teammodel.cn";
|
|
|
- string AccessToken = await getCoreAccessToken();
|
|
|
+ string HaBookAuthString = (_option.Location.Contains("Global") && request.srvAdr.Equals("China")) ? "HaBookAuthCN" : "HaBookAuth";
|
|
|
+ //string url = "https://api2.teammodel.net";
|
|
|
+ //if (request.srvAdr == "China") url = "https://api2.teammodel.cn";
|
|
|
+ string url = _configuration.GetValue<string>($"{HaBookAuthString}:CoreAPI");
|
|
|
+ string AccessToken = await getCoreAccessToken(request.srvAdr);
|
|
|
var client = _http.CreateClient();
|
|
|
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", AccessToken);
|
|
|
HttpResponseMessage response = await client.PostAsJsonAsync($"{url}/Service/CouponConsolidation", request);
|
|
@@ -129,10 +130,11 @@ namespace TEAMModelBI.Controllers.BICommon
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
- //string url = _configuration.GetValue<string>("HaBookAuth:CoreAPI");
|
|
|
- string url = "https://api2.teammodel.net";
|
|
|
- if (request.srvAdr == "China") url = "https://api2.teammodel.cn";
|
|
|
- string AccessToken = await getCoreAccessToken();
|
|
|
+ string HaBookAuthString = (_option.Location.Contains("Global") && request.srvAdr.Equals("China")) ? "HaBookAuthCN" : "HaBookAuth";
|
|
|
+ //string url = "https://api2.teammodel.net";
|
|
|
+ //if (request.srvAdr == "China") url = "https://api2.teammodel.cn";
|
|
|
+ string url = _configuration.GetValue<string>($"{HaBookAuthString}:CoreAPI");
|
|
|
+ string AccessToken = await getCoreAccessToken(request.srvAdr);
|
|
|
var client = _http.CreateClient();
|
|
|
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", AccessToken);
|
|
|
HttpResponseMessage response = await client.PostAsJsonAsync($"{url}/Service/PushNotify", request);
|
|
@@ -151,15 +153,16 @@ namespace TEAMModelBI.Controllers.BICommon
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private async Task<string> getCoreAccessToken()
|
|
|
+ private async Task<string> getCoreAccessToken(string srvAdr)
|
|
|
{
|
|
|
string AccessToken = "";
|
|
|
try
|
|
|
{
|
|
|
- string Url = _configuration.GetValue<string>("HaBookAuth:CoreAPI") + "/oauth2/token";
|
|
|
+ string HaBookAuthString = (_option.Location.Contains("Global") && srvAdr.Equals("China")) ? "HaBookAuthCN" : "HaBookAuth"; //GL站點 => 可取得GL、CN兩站點設定資料 CN站點 => 只取自身站點資料
|
|
|
+ string Url = _configuration.GetValue<string>($"{HaBookAuthString}:CoreAPI") + "/oauth2/token";
|
|
|
string GrantType = "device";
|
|
|
- string ClientID = _configuration.GetValue<string>("HaBookAuth:CoreService:clientID");
|
|
|
- string Secret = _configuration.GetValue<string>("HaBookAuth:CoreService:clientSecret");
|
|
|
+ string ClientID = _configuration.GetValue<string>($"{HaBookAuthString}:CoreService:clientID");
|
|
|
+ string Secret = _configuration.GetValue<string>($"{HaBookAuthString}:CoreService:clientSecret");
|
|
|
var content = new { grant_type = GrantType, client_id = ClientID, client_secret = Secret };
|
|
|
var response = await _http.CreateClient().PostAsJsonAsync($"{Url}", content);
|
|
|
if (response.IsSuccessStatusCode)
|