access
This commit is contained in:
@@ -55,9 +55,9 @@
|
||||
<activity android:name=".modules.viewpagerfragments.customization.CustomizationActivity" />
|
||||
<activity android:name=".modules.information.InformationActivity" />
|
||||
<activity android:name=".modules.RecipeActivity.RecipeActivity" />
|
||||
<activity
|
||||
android:name=".LoginActivity"
|
||||
android:label="@string/title_activity_login" />
|
||||
<!--<activity-->
|
||||
<!--android:name=".LoginActivity"-->
|
||||
<!--android:label="@string/title_activity_login" />-->
|
||||
<activity android:name=".modules.addinformation.AddInformationActivity"></activity>
|
||||
</application>
|
||||
|
||||
|
||||
@@ -13,7 +13,15 @@ import com.google.gson.Gson;
|
||||
import com.orhanobut.logger.AndroidLogAdapter;
|
||||
import com.orhanobut.logger.Logger;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import okhttp3.Call;
|
||||
import okhttp3.Callback;
|
||||
@@ -36,6 +44,7 @@ public class NutritionMaster extends Application {
|
||||
mInstance = this;
|
||||
init();
|
||||
initUser();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -80,6 +89,14 @@ public class NutritionMaster extends Application {
|
||||
}
|
||||
});
|
||||
initOccupations();
|
||||
getAccessToken();
|
||||
Thread thread = new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
initBD();
|
||||
}
|
||||
});
|
||||
thread.start();
|
||||
}
|
||||
|
||||
public static NutritionMaster getInstance() {
|
||||
@@ -128,4 +145,57 @@ public class NutritionMaster extends Application {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* BDAPI init
|
||||
*/
|
||||
private void initBD() {
|
||||
ConstantUtils.BD_ACCESS_TOKEN = getAccessToken();
|
||||
Logger.d(ConstantUtils.BD_ACCESS_TOKEN);
|
||||
}
|
||||
|
||||
|
||||
private String getAccessToken() {
|
||||
String authHost = "https://aip.baidubce.com/oauth/2.0/token?";
|
||||
String ak = ConstantUtils.BD_API_KEY;
|
||||
String sk = ConstantUtils.BD_SECRET_KEY;
|
||||
String getAccessTokenUrl = authHost
|
||||
// 1. grant_type为固定参数
|
||||
+ "grant_type=client_credentials"
|
||||
// 2. 官网获取的 API Key
|
||||
+ "&client_id=" + ak
|
||||
// 3. 官网获取的 Secret Key
|
||||
+ "&client_secret=" + sk;
|
||||
try {
|
||||
URL realUrl = new URL(getAccessTokenUrl);
|
||||
// 打开和URL之间的连接
|
||||
HttpURLConnection connection = (HttpURLConnection) realUrl.openConnection();
|
||||
connection.setRequestMethod("GET");
|
||||
connection.connect();
|
||||
// 获取所有响应头字段
|
||||
Map<String, List<String>> map = connection.getHeaderFields();
|
||||
// 遍历所有的响应头字段
|
||||
for (String key : map.keySet()) {
|
||||
System.err.println(key + "--->" + map.get(key));
|
||||
}
|
||||
// 定义 BufferedReader输入流来读取URL的响应
|
||||
BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
|
||||
String result = "";
|
||||
String line;
|
||||
while ((line = in.readLine()) != null) {
|
||||
result += line;
|
||||
}
|
||||
/**
|
||||
* 返回结果示例
|
||||
*/
|
||||
System.err.println("result:" + result);
|
||||
JSONObject jsonObject = new JSONObject(result);
|
||||
String access_token = jsonObject.getString("access_token");
|
||||
return access_token;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -69,7 +69,7 @@ public class CalculateUtils {
|
||||
*/
|
||||
public static int getWeek() {
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
Logger.d( calendar.get(Calendar.DAY_OF_WEEK));
|
||||
// Logger.d( calendar.get(Calendar.DAY_OF_WEEK));
|
||||
return calendar.get(Calendar.DAY_OF_WEEK)-1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ public class ConstantUtils {
|
||||
public static String[] dailyDescibes = {"快乐陪周一", "幸运伴周二", "轻松有周三", "温馨携周四",
|
||||
"愉悦同周五", "休闲找周六", "潇洒属周日"};
|
||||
|
||||
|
||||
public static String arab2Chinese(int number) {
|
||||
switch (number) {
|
||||
case 1:
|
||||
@@ -267,4 +268,9 @@ public class ConstantUtils {
|
||||
"平和质人阴阳气血平衡,药膳调理不可偏补、贪补,以保持人体阴阳平衡状态最为紧要。所谓“不伤不扰,顺其自然”。"
|
||||
};
|
||||
|
||||
public static String BD_API_KEY = "GQfoj7AUUhj67ocHuwvA8G5q";
|
||||
public static String BD_APP_ID = "14346167";
|
||||
public static String BD_SECRET_KEY = "EEXe6pG7QGVdrqDM8eR0S3RY2WPf4Gwn";
|
||||
public static String BD_ACCESS_TOKEN = "";
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user