/// <summary>
        /// if need, run this method for auto-login.
        /// </summary>
        /// <returns></returns>
        private async void ClickSubmitButtonIfAutoAsync()
        {
            Submit.IsEnabled   = false;
            SubitRing.IsActive = true;
            var user = EmailBox.Text;
            var pass = PasswordBox.Password;

            PasswordAndUserEncryption(user, pass);

            // set the abort button with keybord-focus, so that the vitual keyboad in the mobile device with disappear.
            Abort.Focus(FocusState.Keyboard);

            var result = await DoubanWebProcess.PostDoubanResponseAsync(
                path : "https://frodo.douban.com/service/auth2/token",
                host : "frodo.douban.com",
                reffer : null,
                content :
                new HttpFormUrlEncodedContent(new List <KeyValuePair <string, string> > {
                new KeyValuePair <string, string>("client_id", "0dad551ec0f84ed02907ff5c42e8ec70"),
                new KeyValuePair <string, string>("client_secret", "9e8bb54dc3288cdf"),
                new KeyValuePair <string, string>("redirect_uri", "frodo://app/oauth/callback/"),
                new KeyValuePair <string, string>("grant_type", "password"),
                new KeyValuePair <string, string>("username", user),
                new KeyValuePair <string, string>("password", pass),
                //new KeyValuePair<string, string>("apiKey","0dad551ec0f84ed02907ff5c42e8ec70"),
                new KeyValuePair <string, string>("os_rom", "android"),
            }),
                isMobileDevice : true);

            var tokenReturn = default(APITokenReturn);

            try {
                JObject jo = JObject.Parse(result);
                tokenReturn = new APITokenReturn {
                    AccessToken  = jo["access_token"].Value <string>(),
                    RefreshToken = jo["refresh_token"].Value <string>(),
                    ExpiresIn    = jo["expires_in"].Value <string>(),
                    UserId       = jo["douban_user_id"].Value <string>(),
                    UserName     = jo["douban_user_name"].Value <string>(),
                };
                MainLoginPopup.IsOpen = false;
                try {
                    await MainPage.SetUserStatusAsync(tokenReturn.UserId);

                    //await MainPage.SetUserStatusAsync("155845973");
                    NavigateToBase?.Invoke(
                        null,
                        null,
                        GetFrameInstance(FrameType.UserInfos),
                        GetPageType(NavigateType.UserInfo));
                } catch { /* Ignore. */ }
            } catch {
                ReportHelper.ReportAttentionAsync(GetUIString("LoginFailed"));
            }
        }
Beispiel #2
0
 private static async Task <string> GetSongDetailsAsync(string sids)
 {
     try {
         return(await DoubanWebProcess.PostDoubanResponseAsync(
                    path : $"{"https://"}api.douban.com/v2/fm/redheart/songs?version=644&app_name=radio_android&apikey={APIKey}",
                    host : "api.douban.com",
                    reffer : null,
                    userAgent : @"api-client/2.0 com.douban.radio/4.6.4(464) Android/18 TCL_P306C TCL TCL-306C",
                    bearer : AccessToken,
                    content : new HttpFormUrlEncodedContent(new List <KeyValuePair <string, string> > {
             new KeyValuePair <string, string>("sids", sids),
             new KeyValuePair <string, string>("kbps", "192"),
         })));
     } catch {
         System.Diagnostics.Debug.WriteLine("fetch red-heart detials error.");
         return(null);
     }
 }
        private async Task InitListResourcesAsync(int list_id)
        {
            var result = is_daily?
                         await DoubanWebProcess.GetMDoubanResponseAsync(
                path : $"{"https://"}api.douban.com/v2/fm/songlist/user_daily/?version=644&app_name=radio_android&kbps=192&apikey={APIKey}",
                host : "api.douban.com",
                reffer : null,
                bearer : bearer,
                userAgt : @"api-client/2.0 com.douban.radio/4.6.4(464) Android/18 TCL_P306C TCL TCL-306C"):
                         await DoubanWebProcess.PostDoubanResponseAsync(
                path : $"{"https://"}api.douban.com/v2/fm/songlist/{list_id}/detail",
                host : "api.douban.com",
                reffer : null,
                userAgent : @"api-client/2.0 com.douban.radio/4.6.4(464) Android/18 TCL_P306C TCL TCL-306C",
                content : new HttpFormUrlEncodedContent(new List <KeyValuePair <string, string> > {
                new KeyValuePair <string, string>("version", "644"),
                new KeyValuePair <string, string>("kbps", "320"),
                new KeyValuePair <string, string>("app_name", "radio_android"),
                new KeyValuePair <string, string>("apikey", APIKey),
            }), bearer : bearer);

            try {
                var song_list = JsonHelper.FromJson <MHzSongList>(result);
                if (song_list.Cover == "")
                {
                    song_list.Cover = "ms-appx:///Assets/231.jpg";
                }
                inner_list = new ObservableCollection <MHzSong>();
                song_list.Songs.ToList().ForEach(i => inner_list.Add(i));
                var query = await StorageHelper.GetAllStorageFilesByExtensionAsync(StorageHelper.JsonExtension);

                foreach (var item in inner_list)
                {
                    item.IsCached = StorageHelper.IsExistLocalJsonBySHA256(MHzSongBaseHelper.GetIdentity(item), query);
                }
                ListResources.Source = inner_list;
                SetListHeader(song_list);
            } catch { /* Ignore */ } finally { IncrementalLoadingBorder.SetVisibility(false); }
        }
Beispiel #4
0
        public static async Task <bool> AddToRedHeartAsync(SongBase song, long list_id, string api_key, string bearer, Guid app_did, bool is_add = true)
        {
            var model = new RedHeartPost {
                Type = is_add ? "r" : "u", PlayMode = null, PlaySource = "n", SID = song.SID, Time = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"), PID = list_id
            };
            IList <RedHeartPost> list = new List <RedHeartPost> {
                model
            };
            var json    = JsonHelper.ToJson(list);
            var content = new HttpFormUrlEncodedContent(new List <KeyValuePair <string, string> > {
                new KeyValuePair <string, string>("version", "644"),
                new KeyValuePair <string, string>("records", json),
                new KeyValuePair <string, string>("app_name", "radio_android"),
                new KeyValuePair <string, string>("client", $"s:mobile|v:4.6.4|y:android 4.3|f:644|m:Taobao|d:{app_did}|e:tcl_tcl-p306c"),
                new KeyValuePair <string, string>("apikey", api_key),
            });
            var result = default(string);

            try {
                result = await DoubanWebProcess.PostDoubanResponseAsync(
                    $"{"https://"}api.douban.com/v2/fm/action_log?udid={app_did}",
                    "api.douban.com",
                    null,
                    userAgent : @"api-client/2.0 com.douban.radio/4.6.4(464) Android/18 TCL_P306C TCL TCL-306C",
                    content : content,
                    bearer : bearer);
            } catch { return(false); }
            if (result.Contains(@"""r"":0"))
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }