protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { try { tranghientai = "localhost:1834/zalo.aspx"; Zalo3rdAppClient appClient = new Zalo3rdAppClient(new Zalo3rdAppInfo(2127518896466871150, "OUKlCdL8uYLIMe73QB65", tranghientai)); string loginUrl = appClient.getLoginUrl(); code = Request.QueryString["code"]; JObject token = appClient.getAccessToken(code); if (string.IsNullOrEmpty(code)) { Response.Redirect(loginUrl.ToString()); } else { string chuoitoken = token.Property("access_token").Value.ToString(); JObject profile = appClient.getProfile(chuoitoken, "name,picture,id,userIdByOA"); // userIdByOA => ID cần gửi tin txtHDinfo.Value = profile.ToString(); //txtTenNguoiDung.Text = profile.Property("name").Value.ToString(); txtTenNguoiDung.Text = "NTSoft"; JObject invitableFriends = appClient.getInvitableFriends(chuoitoken, 0, 0, "id, name, picture, gender"); int soluong = 0; soluong = int.Parse(invitableFriends["summary"]["total_count"].ToString()); //JObject banbe = appClient.getInvitableFriends(chuoitoken, 0, soluong, "id, name, picture, gender,userIdByOA"); JObject banbe = JObject.Parse(JObject.Parse(new WebClient().DownloadString("https://openapi.zalo.me/v2.0/oa/getfollowers?access_token=w8i4LtUoispYX0XGUxoyOk633rryexLkf-1d5N-lg6-twqXHLRs2Q8dZH54MtvCfmfqXG2ltwtBMcoPA7lVnTSMD94WZnUGQ-89M91Yua6F-yoDS5CdZ8y-39s8szEymwhqQ3t_gqZ7ZfHft1CV83kg267HtkiWuWkv_V6oYgpwnWKX6RkkcVx6HTZ9Gsy9PZu4r6NRMW27hW4qV0CU4TfYdGZL-neDLw_bFQ16D_JNij0S86SB8OVFx6IOfagaSnVb9JmcVWn_qw5DIhGw22dQhj6m&data={offset=0,count=5}"))["data"].ToString()); string[,] mangid = new string[banbe["followers"].Count <JToken>(), 3]; ZaloOaInfo zaloOaInfo = new ZaloOaInfo(739460368435099423, "n30YrpHUT626CuAUWW15"); ZaloOaClient oaClient = new ZaloOaClient(zaloOaInfo); for (int i = 0; i < banbe["followers"].Count <JToken>(); i++) { long idphu = long.Parse(banbe["followers"][i].Value <JToken>()["user_id"].ToString()); JObject a1 = oaClient.getProfile(idphu); mangid[i, 0] = idphu.ToString(); mangid[i, 1] = a1["data"].Value <JToken>()["avatar"].ToString(); mangid[i, 2] = a1["data"].Value <JToken>()["displayName"].ToString(); } json_dsbb = JsonConvert.SerializeObject(mangid); } } catch (Exception ex) { Response.Write(ex.Message); } } }
public async Task <IActionResult> ZaloRegister([FromForm] ExternalUserLogin obj) { Zalo3rdAppInfo appInfo = new Zalo3rdAppInfo(Int64.Parse(_externalProvider.Value.Zalo.AppId), _externalProvider.Value.Zalo.SecretCode, _externalProvider.Value.Zalo.CallbackUrl); Zalo3rdAppClient appClient = new Zalo3rdAppClient(appInfo); JObject profile = appClient.getProfile(obj.AccessToken, "name, id, picture"); var tmpData = profile.ToObject <ExternalUserModel>(); var user = new ApplicationUser(); user.Email = obj.Email; user.UserName = "******" + tmpData.id; user.FullName = tmpData.name; user.PasswordHash = tmpData.id.ToString(); user.Avatar = tmpData.picture.data.url; return(await ExternalUser(user)); }